Class: NetAtlas::Plugin::Nagios
- Inherits:
-
Base
- Object
- Base
- NetAtlas::Plugin::Nagios
show all
- Defined in:
- lib/netatlas/plugin/nagios.rb
Direct Known Subclasses
HTTP
Constant Summary
Constants inherited
from Base
Base::SEVERITIES
Instance Method Summary
collapse
Methods inherited from Base
arguments, method_missing, plugin_arguments
Instance Method Details
#build_args(data_source) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/netatlas/plugin/nagios.rb', line 36
def build_args(data_source)
args = ["-H #{data_source.ip_address}"]
args << ["-p #{data_source.port}"] if data_source.port
arguments = data_source.arguments ? data_source.arguments.attributes : {}
arguments.each do |k, v|
key = "--" + k.to_s.gsub("_","-")
if v == true
args << key
else
args << "#{key} #{v}" if v
end
end
args.join(" ")
end
|
#check_scripts ⇒ Object
11
12
13
14
15
|
# File 'lib/netatlas/plugin/nagios.rb', line 11
def check_scripts
files = Dir.glob("#{NAGIOS_CONFIG['plugin_dir']}/*").collect {|f| f.split("/").last}.sort
LOGGER.debug "files = #{files}"
files
end
|
#cmd_args(data_source) ⇒ Object
27
28
29
30
31
32
33
34
35
|
# File 'lib/netatlas/plugin/nagios.rb', line 27
def cmd_args(data_source)
args = []
args << "-H #{data_source.interface.ip_address}"
args << "-c #{data_source.arguments.critical}" if data_source.arguments.critical.to_f > 0
args << "-w #{data_source.arguments.warning}" if data_source.arguments.warning.to_f > 0
args << "-p #{data_source.arguments.port}" if data_source.arguments.port.to_i > 0
args << data_source.arguments.arguments
args.join(" ")
end
|
#get_value(output, status) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/netatlas/plugin/nagios.rb', line 52
def get_value(output, status)
puts "parsing nagios data"
puts output
output, perfdata = output.split('|')
return nil unless perfdata
puts "output now #{output}, perfdata = #{perfdata}"
metrics = {}
stuff = perfdata.scan(/(\w+)=([\d|\.]+)/)
stuff.each {|i| metrics[i[0]] = i[1]}
metrics['time']
end
|
#poll(data_source, &block) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/netatlas/plugin/nagios.rb', line 16
def poll(data_source, &block)
cmd = "#{NAGIOS_CONFIG['plugin_dir']}/#{self.class.check_script || data_source.arguments.check_script} "
cmd += build_args(data_source)
puts "sending #{cmd}"
EM.system(cmd) { |output, status|
value = get_value(output, status)
puts "in nagios callback"
puts "got output = #{output}, status = #{status}"
block.call SEVERITIES[status.exitstatus], value
}
end
|