module TungstenNagiosMonitor
Constants
- NAGIOS_CRITICAL
- NAGIOS_OK
- NAGIOS_UNKNOWN
- NAGIOS_WARNING
Public Instance Methods
Add a key=>value pair to the performance data
# File lib/continuent-tools-nagios-monitor.rb, line 74 def add_perfdata(key, value) @perfdata << "#{key}=#{value};" end
Build an output string when the value is critical
# File lib/continuent-tools-nagios-monitor.rb, line 69 def build_critical_message(value) "Value is too high (#{value})" end
Build an output string when the value has passed
# File lib/continuent-tools-nagios-monitor.rb, line 59 def build_ok_message(value) "Value is OK (#{value})" end
Build an output string when the value is at a warning level
# File lib/continuent-tools-nagios-monitor.rb, line 64 def build_warning_message(value) "Value is too high (#{value})" end
Compare the value to the collected threshold values as floats
# File lib/continuent-tools-nagios-monitor.rb, line 15 def check_threshold(value) unless value.to_s() =~ /^[0-9\.]+$/ unknown("Unable to compare a non-numeric value : #{value}") end check = value.to_s().to_f() if check >= opt(:critical_level).to_f() critical(build_critical_message(value)) elsif check >= opt(:warning_level).to_f() warning(build_warning_message(value)) else ok(build_ok_message(value)) end end
Output a Nagios-formatted critical return message and return the critical code
# File lib/continuent-tools-nagios-monitor.rb, line 101 def critical(msg) opt(:nagios_status_sent, true) TU.output "CRITICAL: #{msg} | #{perfdata()}" cleanup(NAGIOS_CRITICAL) end
Is the given value above the critical threshold
# File lib/continuent-tools-nagios-monitor.rb, line 31 def is_critical?(value) unless value.to_s() =~ /^[0-9\.]+$/ unknown("Unable to compare a non-numeric value : #{value}") end check = value.to_s().to_f() if check >= opt(:critical_level).to_f() true else false end end
Is the given value above the warning threshold
# File lib/continuent-tools-nagios-monitor.rb, line 45 def is_warning?(value) unless value.to_s() =~ /^[0-9\.]+$/ unknown("Unable to compare a non-numeric value : #{value}") end check = value.to_s().to_f() if check >= opt(:warning_level).to_f() true else false end end
Output a Nagios-formatted success return message and return the OK code
# File lib/continuent-tools-nagios-monitor.rb, line 85 def ok(msg) opt(:nagios_status_sent, true) TU.output "OK: #{msg} | #{perfdata()}" cleanup(NAGIOS_OK) end
Return a Nagios-formatted performance data string
# File lib/continuent-tools-nagios-monitor.rb, line 79 def perfdata @perfdata.join(" ") end
Output a Nagios-formatted unknown return message and return the unknown code
# File lib/continuent-tools-nagios-monitor.rb, line 109 def unknown(msg) opt(:nagios_status_sent, true) TU.output "UNKNOWN: #{msg} | #{perfdata()}" cleanup(NAGIOS_UNKNOWN) end
This script supports the warning (-w) and critical (-c) arguments. Override this function to return true if you would like to use those arguments.
# File lib/continuent-tools-nagios-monitor.rb, line 10 def uses_thresholds? false end
Output a Nagios-formatted warning return message and return the warning code
# File lib/continuent-tools-nagios-monitor.rb, line 93 def warning(msg) opt(:nagios_status_sent, true) TU.output "WARNING: #{msg} | #{perfdata()}" cleanup(NAGIOS_WARNING) end
Private Instance Methods
# File lib/continuent-tools-nagios-monitor.rb, line 138 def cleanup(code = 0) if opt(:nagios_status_sent) == false if code == 0 TU.output "OK: No errors | #{perfdata()}" code = NAGIOS_OK else TU.output "UNKNOWN: Errors were encountered while running this script | #{perfdata()}" code = NAGIOS_UNKNOWN end end super(code) end
# File lib/continuent-tools-nagios-monitor.rb, line 117 def configure super() opt(:nagios_status_sent, false) @perfdata = [] if uses_thresholds?() add_option(:warning_level, { :on => "-w String", :help => "The warning level for this monitor", :required => true, }) add_option(:critical_level, { :on => "-c String", :help => "The critical level for this monitor", :required => true, }) end end