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
- #host_items ⇒ Object
- #host_problems ⇒ Object
- #in_scope?(section) ⇒ Boolean
-
#initialize(statusfile, options = {}) ⇒ Status
constructor
A new instance of Status.
- #items ⇒ Object
- #problem?(section) ⇒ Boolean
- #reset_cache! ⇒ Object
- #sections ⇒ Object
- #service_items ⇒ Object
- #service_problems ⇒ 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
#host_items ⇒ Object
37 38 39 40 41 |
# File 'lib/nagios_analyzer/status.rb', line 37 def host_items @host_items ||= sections.map do |s| Section.new(s) if s =~ /^hoststatus/ && in_scope?(s) end.compact end |
#host_problems ⇒ Object
53 54 55 56 57 |
# File 'lib/nagios_analyzer/status.rb', line 53 def host_problems @host_problems ||= sections.map do |s| Section.new(s) if s =~ /^hoststatus/ && in_scope?(s) && problem?(s) end.compact end |
#in_scope?(section) ⇒ Boolean
65 66 67 68 69 |
# File 'lib/nagios_analyzer/status.rb', line 65 def in_scope?(section) @scopes.inject(true) do |memo,condition| memo && condition.call(section) end end |
#items ⇒ Object
49 50 51 |
# File 'lib/nagios_analyzer/status.rb', line 49 def items @items ||= (host_items + service_items) end |
#problem?(section) ⇒ Boolean
71 72 73 |
# File 'lib/nagios_analyzer/status.rb', line 71 def problem?(section) section.match(/current_state=(\d+)/) && $1.to_i != STATE_OK end |
#reset_cache! ⇒ Object
75 76 77 |
# File 'lib/nagios_analyzer/status.rb', line 75 def reset_cache! @items = @service_items = @host_items = nil 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("\n\n") end |