Class: Steto::NagiosCheck

Inherits:
BaseCheck show all
Defined in:
lib/steto/nagios_check.rb

Instance Attribute Summary collapse

Attributes inherited from BaseCheck

#name, #text

Instance Method Summary collapse

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.options = {}
  self.attributes = attributes
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



6
7
8
# File 'lib/steto/nagios_check.rb', line 6

def command
  @command
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/steto/nagios_check.rb', line 6

def options
  @options
end

Instance Method Details

#checkObject



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_lineObject



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 = options.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(' ')

  command_options = Hash[options.map { |k,v| [ k, v.to_s ] }]

  @command_line ||= Cocaine::CommandLine.new(command, params, command_options.merge(:expected_outcodes => [0, 1, 2, 3]))
end

#status_from_command_lineObject



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