Class: NagiosAnalyzer::Status
- Inherits:
-
Object
- Object
- NagiosAnalyzer::Status
- Defined in:
- lib/nagios_analyzer/status.rb
Constant Summary collapse
- STATE_OK =
0
- STATES =
{ 0 => "OK", 1 => "WARNING", 2 => "CRITICAL", 3 => "UNKNOWN", 4 => "DEPENDENT" }
- STATES_ORDER =
{ 2 => 0, #critical => first etc. 3 => 1, 1 => 2, 4 => 3, 0 => 4 }
Instance Attribute Summary collapse
-
#last_updated ⇒ Object
Returns the value of attribute last_updated.
-
#scopes ⇒ Object
Returns the value of attribute scopes.
Instance Method Summary collapse
- #contactstatus_items ⇒ Object
- #host_items ⇒ Object
- #host_problems ⇒ Object
- #hostcomment_items ⇒ Object
- #hostdowntime_items ⇒ Object
- #hoststatus_items ⇒ Object
- #in_scope?(section) ⇒ Boolean
- #info_items ⇒ Object
-
#initialize(statusfile, options = {}) ⇒ Status
constructor
A new instance of Status.
- #items ⇒ Object
- #problem?(section) ⇒ Boolean
- #programstatus_items ⇒ Object
- #reset_cache! ⇒ Object
- #sections ⇒ Object
- #service_items ⇒ Object
- #service_problems ⇒ Object
- #servicecomment_items ⇒ Object
- #servicedowntime_items ⇒ Object
- #servicestatus_items ⇒ Object
Constructor Details
#initialize(statusfile, options = {}) ⇒ Status
Returns a new instance of Status.
21 22 23 24 25 26 27 28 29 |
# File 'lib/nagios_analyzer/status.rb', line 21 def initialize(statusfile, = {}) @file = statusfile sections #loads section at this point so we raise immediatly if file has a item @last_updated = Time.at(File.mtime(statusfile)) #scope is an array of lambda procs : it evaluates to true if service has to be displayed @scopes = [] @scopes << lambda { |section| !section.include?("current_state=#{STATE_OK}") } unless [:include_ok] @scopes << [:scope] if [:scope].is_a?(Proc) end |
Instance Attribute Details
#last_updated ⇒ Object
Returns the value of attribute last_updated.
3 4 5 |
# File 'lib/nagios_analyzer/status.rb', line 3 def last_updated @last_updated end |
#scopes ⇒ Object
Returns the value of attribute scopes.
3 4 5 |
# File 'lib/nagios_analyzer/status.rb', line 3 def scopes @scopes end |
Instance Method Details
#contactstatus_items ⇒ Object
49 50 51 |
# File 'lib/nagios_analyzer/status.rb', line 49 def contactstatus_items section_items(:contactstatus) end |
#host_items ⇒ Object
37 38 39 |
# File 'lib/nagios_analyzer/status.rb', line 37 def host_items section_items(:hoststatus) end |
#host_problems ⇒ Object
85 86 87 |
# File 'lib/nagios_analyzer/status.rb', line 85 def host_problems section_items(:hoststatus, true) end |
#hostcomment_items ⇒ Object
53 54 55 |
# File 'lib/nagios_analyzer/status.rb', line 53 def hostcomment_items section_items(:hostcomment) end |
#hostdowntime_items ⇒ Object
57 58 59 |
# File 'lib/nagios_analyzer/status.rb', line 57 def hostdowntime_items section_items(:hostdowntime) end |
#hoststatus_items ⇒ Object
61 62 63 |
# File 'lib/nagios_analyzer/status.rb', line 61 def hoststatus_items section_items(:hoststatus) end |
#in_scope?(section) ⇒ Boolean
93 94 95 96 97 |
# File 'lib/nagios_analyzer/status.rb', line 93 def in_scope?(section) @scopes.inject(true) do |memo,condition| memo && condition.call(section) end end |
#info_items ⇒ Object
65 66 67 |
# File 'lib/nagios_analyzer/status.rb', line 65 def info_items section_items(:info) end |
#items ⇒ Object
45 46 47 |
# File 'lib/nagios_analyzer/status.rb', line 45 def items @items ||= (host_items + service_items) end |
#problem?(section) ⇒ Boolean
99 100 101 |
# File 'lib/nagios_analyzer/status.rb', line 99 def problem?(section) section.match(/current_state=(\d+)/) && $1.to_i != STATE_OK end |
#programstatus_items ⇒ Object
69 70 71 |
# File 'lib/nagios_analyzer/status.rb', line 69 def programstatus_items section_items(:programstatus) end |
#reset_cache! ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/nagios_analyzer/status.rb', line 103 def reset_cache! @items = nil [ :contactstatus, :hostcomment, :hostdowntime, :hoststatus, :info, :programstatus, :servicecomment, :servicedowntime, :servicestatus, ].each do |name| self.instance_variable_set(section_var_sym(name, true), nil) self.instance_variable_set(section_var_sym(name, false), nil) end end |
#sections ⇒ Object
31 32 33 34 35 |
# File 'lib/nagios_analyzer/status.rb', line 31 def sections # don't try to instanciate each section ! on my conf (85hosts/700services), # it makes the script more 10 times slower (0.25s => >3s) @sections ||= File.read(@file).split(/\}\s*\n/).map(&:strip) end |
#service_items ⇒ Object
41 42 43 |
# File 'lib/nagios_analyzer/status.rb', line 41 def service_items section_items(:servicestatus) end |
#service_problems ⇒ Object
89 90 91 |
# File 'lib/nagios_analyzer/status.rb', line 89 def service_problems section_items(:servicestatus, true) end |
#servicecomment_items ⇒ Object
73 74 75 |
# File 'lib/nagios_analyzer/status.rb', line 73 def servicecomment_items section_items(:servicecomment) end |
#servicedowntime_items ⇒ Object
77 78 79 |
# File 'lib/nagios_analyzer/status.rb', line 77 def servicedowntime_items section_items(:servicedowntime) end |
#servicestatus_items ⇒ Object
81 82 83 |
# File 'lib/nagios_analyzer/status.rb', line 81 def servicestatus_items section_items(:servicestatus) end |