Class: Steto::NagiosCheck
- Defined in:
- lib/steto/nagios_check.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#options ⇒ Object
Returns the value of attribute options.
Attributes inherited from BaseCheck
Instance Method Summary collapse
- #check ⇒ Object
- #command_line ⇒ Object
-
#initialize(attributes = {}) ⇒ NagiosCheck
constructor
A new instance of NagiosCheck.
- #status_from_command_line ⇒ Object
Methods inherited from BaseCheck
#attributes=, #check_if_needed, #status, #status=, #to_json
Constructor Details
#initialize(attributes = {}) ⇒ NagiosCheck
8 9 10 11 12 |
# File 'lib/steto/nagios_check.rb', line 8 def initialize(attributes = {}) self.command = "" self. = {} self.attributes = attributes end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
6 7 8 |
# File 'lib/steto/nagios_check.rb', line 6 def command @command end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/steto/nagios_check.rb', line 6 def end |
Instance Method Details
#check ⇒ Object
14 15 16 17 |
# File 'lib/steto/nagios_check.rb', line 14 def check self.text = command_line.run.chomp self.status = status_from_command_line end |
#command_line ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/steto/nagios_check.rb', line 19 def command_line # => "--critical=:critical --warning=:warning" params = .map do |option, value| unless option.to_s.size == 1 cli_option = option.to_s.gsub("_","-") unless value == true "--#{cli_option}=:#{option}" else "--#{cli_option}" end else unless value == true "-#{option} :#{option}" else "-#{option}" end end end.sort.join(' ') = Hash[.map { |k,v| [ k, v.to_s ] }] @command_line ||= Cocaine::CommandLine.new(command, params, .merge(:expected_outcodes => [0, 1, 2, 3])) end |
#status_from_command_line ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/steto/nagios_check.rb', line 43 def status_from_command_line case command_line.exit_status when 0 :ok when 1 :warning when 2 :critical else :unknown end end |