Class: Nagios::Plugin
- Inherits:
-
Object
- Object
- Nagios::Plugin
- Defined in:
- lib/nagios/plugin.rb
Constant Summary collapse
- VERSION =
'3.0.2'
- EXIT_CODE =
{ unknown: 3, critical: 2, warning: 1, ok: 0 }
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.run!(*args) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/nagios/plugin.rb', line 11 def self.run!(*args) plugin = new(*args) plugin.check if plugin.respond_to?(:check) puts plugin.output exit EXIT_CODE[plugin.status] rescue => e puts "PLUGIN UNKNOWN: #{e.}\n\n" << e.backtrace.join("\n") exit EXIT_CODE[:unknown] end |
Instance Method Details
#name ⇒ Object
34 35 36 |
# File 'lib/nagios/plugin.rb', line 34 def name self.class.name.split('::').last.upcase end |
#output ⇒ Object
21 22 23 24 25 |
# File 'lib/nagios/plugin.rb', line 21 def output s = "#{name.upcase} #{status.upcase}" s << ": #{}" if ( respond_to?(:message) && !.to_s.empty? ) s end |
#status ⇒ Object
27 28 29 30 31 32 |
# File 'lib/nagios/plugin.rb', line 27 def status return :critical if critical? return :warning if warning? return :ok if ok? :unknown end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/nagios/plugin.rb', line 38 def to_s output end |