Class: NagiosAnalyzer::Section

Inherits:
Hash
  • Object
show all
Defined in:
lib/nagios_analyzer/section.rb

Instance Method Summary collapse

Constructor Details

#initialize(section) ⇒ Section

Returns a new instance of Section.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/nagios_analyzer/section.rb', line 3

def initialize(section)
  section.strip!
  section.each_line do |line|
    line.strip!
    if line.match(/(\S+) \{/)
      self[:type] = $1
    elsif line.match(/(\S+)=(.*)/) #more efficient than include?+split+join..
      self[$1.to_sym] = ($2 == "#{$2.to_i}" ? $2.to_i : $2)
    end
  end
  if self[:type] == "servicestatus"
    self[:status] = Status::STATES[self[:current_state]]
  else
    self[:status] = (self[:current_state] == Status::STATE_OK ? "OK" : "CRITICAL")
  end
end

Instance Method Details

#<=>(other) ⇒ Object



20
21
22
# File 'lib/nagios_analyzer/section.rb', line 20

def <=>(other)
  self.sort_array <=> other.sort_array
end

#sort_arrayObject



24
25
26
27
28
29
# File 'lib/nagios_analyzer/section.rb', line 24

def sort_array
  [ (self[:type] == "servicestatus" ? 1 : 0),
    Status::STATES_ORDER[self[:current_state]].to_i,
    self[:host_name],
    self[:service_description].to_s ]
end