Sha256: 6eb9ce84df7da22cf681d60ed708263a30be01822b96c02b14832d886d9edf7e
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
module NagiosPlugin class Plugin NAGIOS_PLUGIN_EXIT_CODES = { :unknown => 3, :critical => 2, :warning => 1, :ok => 0 } class << self def check(*args) plugin = new(*args) puts plugin.nagios_plugin_output exit plugin.nagios_plugin_exit_code rescue => e pretty_error = ([e.to_s, nil] + e.backtrace).join("\n") puts "PLUGIN UNKNOWN: #{pretty_error}" exit NAGIOS_PLUGIN_EXIT_CODES[:unknown] end end def nagios_plugin_exit_code NAGIOS_PLUGIN_EXIT_CODES[nagios_plugin_status] end def nagios_plugin_output output = [nagios_plugin_service] << ' ' output << nagios_plugin_status.to_s.upcase output << ': ' + message if ( respond_to?(:message) && !message.empty? ) output.join end private def nagios_plugin_status @nagios_plugin_status ||= case when critical? then :critical when warning? then :warning when ok? then :ok else :unknown end end def nagios_plugin_service self.class.name.split('::').last.gsub(/plugin$/i, '').upcase end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nagiosplugin-2.2.0 | lib/nagiosplugin/plugin.rb |