Class: Nagios::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/nagios_helper/check.rb

Direct Known Subclasses

CheckEM

Constant Summary collapse

TYPES =
%w{ok crit other warn}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, &callback) ⇒ Check

Returns a new instance of Check.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/nagios_helper/check.rb', line 5

def initialize(params, &callback)
  @params = params.with_indifferent_access
  @callback = callback
  @started_at = Time.now
  @tag = "#{self.class.name}/#{params.inspect}"
  
  logger.info "=> #{@tag}"
  
  @ok = []
  @crit = []
  @warn = []
  @other = []
end

Class Method Details

.check(params = {}) ⇒ Object

synchrony check, for manually calls



41
42
43
44
45
46
47
48
49
# File 'lib/nagios_helper/check.rb', line 41

def self.check(params = {})
  result = nil
  
  inst = self.new(params) do |res|
    result = res    
  end
  
  inst.run
end

.default_error(mes) ⇒ Object



51
52
53
# File 'lib/nagios_helper/check.rb', line 51

def self.default_error(mes)
  [Nagios::OTHER, mes]
end

Instance Method Details

#resultObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/nagios_helper/check.rb', line 19

def result
  errors = [@crit, @warn, @other].flatten * '; '
          
  if @crit.present?
    [Nagios::CRIT, "CRIT: " + errors]
  elsif @warn.present?
    [Nagios::WARN, "WARN: " + errors]
  elsif @other.present?
    [Nagios::OTHER, errors]
  else
    [Nagios::OK, "OK: " + @ok * '; ']
  end
end

#runObject



33
34
35
36
37
38
# File 'lib/nagios_helper/check.rb', line 33

def run
  safe do
    execute
    send_result
  end
end