Class: Nagios::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/nagios-plugin.rb

Constant Summary collapse

VERSION =
'0.0.1'
OK_STATE =
0
WARNING_STATE =
1
CRITICAL_STATE =
2
UNKNOWN_STATE =
3

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Plugin

Returns a new instance of Plugin.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/nagios-plugin.rb', line 14

def initialize(args = {})
	 @shortname = args[:shortname] || "Nagios::Plugin"
	 @print = args[:print] || true
	 @exit = args[:exit] || true
	 @perfdata = Hash.new
	 
	 # now, handle the arguments...
	 @opts = OptionParser.new
	 @opts.on("-w", "--warning WARNING", "WARNING THRESHOLD") do |w|
	 	 @warning = w
	 end
	 @opts.on("-c", "--critical CRITICAL", "CRITICAL THRESHOLD") do |c|
	 	 @critical = c
	 end
end

Instance Method Details

#add_perfdata(args) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/nagios-plugin.rb', line 63

def add_perfdata(args)
	   field = args[:field] or raise "must supply field!"
	   data = args[:data] or raise "must supply data!"
	   @perfdata[field] = {:data => data}
	   @perfdata[field][:uom] = args[:uom] if args[:uom]
	   @perfdata[field][:warning] = args[:warning] if args[:warning]
	   @perfdata[field][:critical] = args[:critical] if args[:critical]
end

#exit=(enabled) ⇒ Object



42
43
44
# File 'lib/nagios-plugin.rb', line 42

def exit=(enabled)
	     @exit = enabled
end

#outputObject



59
60
61
# File 'lib/nagios-plugin.rb', line 59

def output 
	     @output
end

#parse_argvObject



38
39
40
# File 'lib/nagios-plugin.rb', line 38

def parse_argv()
	     @opts.parse(ARGV)
end

#print=(enabled) ⇒ Object



46
47
48
# File 'lib/nagios-plugin.rb', line 46

def print=(enabled)
	     @print = enabled
end

#runObject

actually does the check



51
52
53
# File 'lib/nagios-plugin.rb', line 51

def run
	     raise "You must implement the run method!"
end

#stateObject



55
56
57
# File 'lib/nagios-plugin.rb', line 55

def state 
	   @state
end