Class: Apolo::Notifiers::Nagios
- Inherits:
-
Object
- Object
- Apolo::Notifiers::Nagios
- Defined in:
- lib/apolo/notifiers/nagios.rb
Instance Method Summary collapse
- #critical?(value) ⇒ Boolean
-
#initialize(options = {}) ⇒ Nagios
constructor
A new instance of Nagios.
- #notify(monitor, message, value) ⇒ Object
- #ok?(value) ⇒ Boolean
- #warning?(value) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Nagios
Returns a new instance of Nagios.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/apolo/notifiers/nagios.rb', line 10 def initialize( = {}) @file = [:file] @host = [:host] @service = [:service] @warning = [:warning] @critical = [:critical] unless @file && @host && @service raise ArgumentError, 'You need to set :file, :host and :service to use nagios notify.' end end |
Instance Method Details
#critical?(value) ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/apolo/notifiers/nagios.rb', line 22 def critical?(value) unless @critical return false end if value >= @critical return true else return false end end |
#notify(monitor, message, value) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/apolo/notifiers/nagios.rb', line 52 def notify(monitor, , value) status = NAGIOS_UNKNOW status = NAGIOS_OK if ok?(value) status = NAGIOS_WARNING if warning?(value) status = NAGIOS_CRITICAL if critical?(value) output = "#{DateTime.now.strftime('%s')} PROCESS_HOST_CHECK_RESULT;" output += "#{@host};#{@service};#{status};#{}" open(@file, 'a') { |f| f.puts output } end |
#ok?(value) ⇒ Boolean
44 45 46 47 48 49 50 |
# File 'lib/apolo/notifiers/nagios.rb', line 44 def ok?(value) if @critical && @warning return true else return false end end |
#warning?(value) ⇒ Boolean
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/apolo/notifiers/nagios.rb', line 33 def warning?(value) unless @warning return false end if value >= @warning return true else return false end end |