Class: Hostmon::Models::Host
Constant Summary collapse
- OK =
"OK"
- FAIL =
"FAIL"
- EXEC_FAIL =
"EXEC_FAIL"
- @@clusters =
Set.new
- @@saved_reports =
1
- @@checks =
Set.new
- @@check_map =
{}
Instance Attribute Summary collapse
-
#checks ⇒ Object
readonly
Returns the value of attribute checks.
-
#cluster ⇒ Object
readonly
Returns the value of attribute cluster.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#report ⇒ Object
readonly
Returns the value of attribute report.
-
#report_time ⇒ Object
Returns the value of attribute report_time.
-
#reports ⇒ Object
Returns the value of attribute reports.
-
#status_map ⇒ Object
readonly
Returns the value of attribute status_map.
Class Method Summary collapse
-
.absorb(report) ⇒ Object
process and update (or create) a host and return it fixme saved_reports unbounded fixme special case for 0 (only store in memory).
- .check_map ⇒ Object
-
.clusters ⇒ Object
attr_*.
- .find_by_cluster(cluster) ⇒ Object
- .find_by_name_and_cluster(name, cluster) ⇒ Object
- .hosts_failing(check) ⇒ Object
- .hosts_succeeding(check) ⇒ Object
- .saved_reports ⇒ Object
- .saved_reports=(i) ⇒ Object
- .statuses ⇒ Object
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
fixme @params is always empty right now.
- #==(other) ⇒ Object
- #check_reports(check_name) ⇒ Object
-
#checks_failing ⇒ Object
return reports for checks that failed to execute properly.
- #eql?(other) ⇒ Boolean
-
#failing ⇒ Object
return reports for checks that the host fails.
- #hash ⇒ Object
-
#initialize(h, c) ⇒ Host
constructor
A new instance of Host.
-
#inspect ⇒ Object
temporary.
- #key ⇒ Object
- #name ⇒ Object
-
#sname ⇒ Object
fixme this is just silly.
-
#succeeding ⇒ Object
return reports for checks that the host passes.
-
#to_s ⇒ Object
hacks.
Methods inherited from Base
Constructor Details
#initialize(h, c) ⇒ Host
Returns a new instance of Host.
108 109 110 111 112 113 114 |
# File 'lib/hostmon/models/host.rb', line 108 def initialize(h, c) # needed to disambiguate super(h+'.'+c) @hostname = h @cluster = c @report_time = nil end |
Instance Attribute Details
#checks ⇒ Object (readonly)
Returns the value of attribute checks.
58 59 60 |
# File 'lib/hostmon/models/host.rb', line 58 def checks @checks end |
#cluster ⇒ Object (readonly)
Returns the value of attribute cluster.
58 59 60 |
# File 'lib/hostmon/models/host.rb', line 58 def cluster @cluster end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
58 59 60 |
# File 'lib/hostmon/models/host.rb', line 58 def hostname @hostname end |
#report ⇒ Object (readonly)
Returns the value of attribute report.
58 59 60 |
# File 'lib/hostmon/models/host.rb', line 58 def report @report end |
#report_time ⇒ Object
Returns the value of attribute report_time.
59 60 61 |
# File 'lib/hostmon/models/host.rb', line 59 def report_time @report_time end |
#reports ⇒ Object
Returns the value of attribute reports.
59 60 61 |
# File 'lib/hostmon/models/host.rb', line 59 def reports @reports end |
#status_map ⇒ Object (readonly)
Returns the value of attribute status_map.
58 59 60 |
# File 'lib/hostmon/models/host.rb', line 58 def status_map @status_map end |
Class Method Details
.absorb(report) ⇒ Object
process and update (or create) a host and return it fixme saved_reports unbounded fixme special case for 0 (only store in memory)
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/hostmon/models/host.rb', line 164 def self.absorb(report) h = report.host c = report.cluster unless host = find_by_name_and_cluster(h, c) host = new(h, c) puts "new host #{h}" end host.reports ||= Hash.new {|hsh,k| hsh[k] = Array.new} # fixme slightly offensive if host.reports[report.name].size < @@saved_reports host.reports[report.name] << report host.reports[report.name].sort! {|a,b| a. <=> b. } report.write elsif report. < host.reports[report.name].first. return host else pp host.reports[report.name].size pp @@saved_reports host.reports[report.name] << report host.reports[report.name].sort! {|a,b| a. <=> b. } while host.reports[report.name].size > @@saved_reports shift = host.reports[report.name].shift shift.delete end report.write end #################### time = report. if (!host.report_time) || (host.report_time < time) host.report_time = time end @@clusters << host.cluster host end |
.check_map ⇒ Object
37 38 39 |
# File 'lib/hostmon/models/host.rb', line 37 def check_map @@check_map end |
.clusters ⇒ Object
attr_*
26 27 28 |
# File 'lib/hostmon/models/host.rb', line 26 def clusters # attr_* @@clusters end |
.find_by_cluster(cluster) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/hostmon/models/host.rb', line 49 def find_by_cluster(cluster) ret = [] Host.each do |name, host| ret << host if host.cluster == cluster end return ret end |
.find_by_name_and_cluster(name, cluster) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/hostmon/models/host.rb', line 41 def find_by_name_and_cluster(name, cluster) Host.each do |host_name, host| next unless host.name == name return host if host.cluster == cluster end return nil end |
.hosts_failing(check) ⇒ Object
29 30 31 |
# File 'lib/hostmon/models/host.rb', line 29 def hosts_failing(check) @@check_map[check][FAIL]||Set.new end |
.hosts_succeeding(check) ⇒ Object
33 34 35 |
# File 'lib/hostmon/models/host.rb', line 33 def hosts_succeeding(check) @@check_map[check][OK]||Set.new end |
.saved_reports ⇒ Object
15 16 17 |
# File 'lib/hostmon/models/host.rb', line 15 def self.saved_reports @@saved_reports end |
.saved_reports=(i) ⇒ Object
18 19 20 |
# File 'lib/hostmon/models/host.rb', line 18 def self.saved_reports= (i) @@saved_reports = i end |
Instance Method Details
#<=>(other) ⇒ Object
fixme @params is always empty right now
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/hostmon/models/host.rb', line 134 def <=>(other) if @params[:host_sort] == "builtin" return key <=> other.key elsif @params[:host_sort] == "numeric" regexp = /\d+/ match = @name.match(regexp) match2 = other.name.match(regexp) if match.pre_match != match2.pre_match return match.pre_match <=> match2.pre_match else return match[0].to_i <=> match2[0].to_i end else # http://www.bofh.org.uk/2007/12/16/comprehensible-sorting-in-ruby sensible = lambda do |k| k.sname.split( /((?:(?:^|\s)[-+])?(?:\.\d+|\d+(?:\.\d+?(?:[eE]\d+)?(?:$|(?![eE\.])))?))/ms ).map { |v| Float(v) rescue v.downcase } end return sensible.call(self) <=> sensible.call(other) end end |
#==(other) ⇒ Object
124 125 126 |
# File 'lib/hostmon/models/host.rb', line 124 def ==(other) key == other.key end |
#check_reports(check_name) ⇒ Object
201 202 203 |
# File 'lib/hostmon/models/host.rb', line 201 def check_reports(check_name) reports[check_name] end |
#checks_failing ⇒ Object
return reports for checks that failed to execute properly
89 90 91 92 93 94 95 96 97 |
# File 'lib/hostmon/models/host.rb', line 89 def checks_failing failing = Set.new @reports.each do |n, r| if r.last.check_failed? failing << r.last end end failing.sort end |
#eql?(other) ⇒ Boolean
120 121 122 |
# File 'lib/hostmon/models/host.rb', line 120 def eql?(other) key == other.key end |
#failing ⇒ Object
return reports for checks that the host fails
78 79 80 81 82 83 84 85 86 |
# File 'lib/hostmon/models/host.rb', line 78 def failing failing_reports = Set.new @reports.each do |n, r| if r.last.failed? failing_reports << r.last end end failing_reports.sort end |
#hash ⇒ Object
157 158 159 |
# File 'lib/hostmon/models/host.rb', line 157 def hash key.hash end |
#inspect ⇒ Object
temporary
206 207 208 |
# File 'lib/hostmon/models/host.rb', line 206 def inspect @hostname end |
#key ⇒ Object
116 117 118 |
# File 'lib/hostmon/models/host.rb', line 116 def key "#{@cluster}#{@name}" end |
#name ⇒ Object
104 105 106 |
# File 'lib/hostmon/models/host.rb', line 104 def name @hostname end |
#sname ⇒ Object
fixme this is just silly
129 130 131 |
# File 'lib/hostmon/models/host.rb', line 129 def sname @hostname + "." + @cluster end |
#succeeding ⇒ Object
return reports for checks that the host passes
67 68 69 70 71 72 73 74 75 |
# File 'lib/hostmon/models/host.rb', line 67 def succeeding ok_reports = Set.new @reports.each do |n, r| if r.last.ok? ok_reports << r.last end end ok_reports.sort end |
#to_s ⇒ Object
hacks
100 101 102 |
# File 'lib/hostmon/models/host.rb', line 100 def to_s @hostname end |