Class: Hostmon::Models::Check

Inherits:
Base
  • Object
show all
Defined in:
lib/hostmon/models/check.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#<=>, #[], all, each, find, #to_s

Constructor Details

#initialize(name) ⇒ Check

Returns a new instance of Check.



14
15
16
17
# File 'lib/hostmon/models/check.rb', line 14

def initialize(name)
  super(name)
  @host_map = {} #Host => reports
end

Instance Attribute Details

#host_mapObject

Returns the value of attribute host_map.



4
5
6
# File 'lib/hostmon/models/check.rb', line 4

def host_map
  @host_map
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/hostmon/models/check.rb', line 3

def name
  @name
end

Class Method Details

.absorb(name, host) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/hostmon/models/check.rb', line 6

def self.absorb (name, host)
  unless c = find(name)
    c = new(name)
  end
  c.host_map[host] = host.check_reports(name)
  c
end

Instance Method Details

#host_statusObject



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

def host_status
  ok = []
  failed = []
  check_failed = []
  @host_map.each do |h, r|
    if r.last.ok?
      ok << [h, r.last]
    elsif r.last.failed?
      failed << [h, r.last]
    else
      check_failed << [h, r.last]
    end
  end
  return ok, failed, check_failed
end

#hosts_check_failingObject



41
42
43
# File 'lib/hostmon/models/check.rb', line 41

def hosts_check_failing
  host_status[2] # .map(&:first)
end

#hosts_failingObject



38
39
40
# File 'lib/hostmon/models/check.rb', line 38

def hosts_failing
  host_status[1] # .map(&:first)
end

#hosts_okObject



35
36
37
# File 'lib/hostmon/models/check.rb', line 35

def hosts_ok
  host_status[0] # .map(&:first)
end