Class: Hobelar::Parsers::GetCheck

Inherits:
Hobelar::Parsers
  • Object
show all
Defined in:
lib/hobelar/parsers/getcheck.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Hobelar::Parsers

#attr_value, #characters

Constructor Details

#initializeGetCheck

Returns a new instance of GetCheck.



7
8
9
10
11
12
13
# File 'lib/hobelar/parsers/getcheck.rb', line 7

def initialize
  super
  @response[:attributes] = {}
  @response[:config] = {}
  @response[:state] = {}
  @response[:state][:metrics] = {}
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/hobelar/parsers/getcheck.rb', line 5

def response
  @response
end

Instance Method Details

#end_element(name) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/hobelar/parsers/getcheck.rb', line 46

def end_element(name)
  case name
  when "attributes"
    @in_attrs = false
  when "config"
    @in_config = false
  when "state"
    if @bloody_state
      @bloody_state = false
      @response[:state][:state] = @value
    else
      @in_state = false
    end
  when "metrics"
    @in_metrics = false
  when "uuid"
    @response[:uuid] = @value if @in_attrs
  when "name"
    @response[:name] = @value if @in_attrs
  when "module"
    @response[:module] = @value if @in_attrs
  when "target"
    @response[:target] = @value if @in_attrs
  when "last_run"
    @response[:now] = @time_now
    begin
      @response[:last_run] = DateTime.strptime(@value, "%s")
    rescue
      @response[:last_run] = nil
    end
  else
    if @in_attrs
      @response[:attributes][name.to_sym] = @value
    elsif @in_config
      @response[:config][name.to_sym] = @value
    elsif @in_state && @in_metrics
      if @m_name
        @response[:state][:metrics][@m_name.to_sym] = @value
      else
        @response[:state][:metrics][name.to_sym] = @value
      end
      @m_name = nil
    elsif @in_state
      @response[:state][name.to_sym] = @value
    end
  end
end

#start_element(name, attrs = []) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hobelar/parsers/getcheck.rb', line 15

def start_element(name, attrs = [])
  super

  case name
  when "attributes"
    @in_attrs = true
  when "config"
    @in_config = true
  when "state"
    # the state set contains an element called state. This is unhelpful.
    if @in_state 
      @bloody_state = true
    else
      @in_state = true
    end
  when "metrics"
    @in_metrics = true
  when "module","period","timeout","filterset"
    @inherited = attr_value("inherited", attrs)
  when "last_run"
    begin
      @time_now = DateTime.strptime(attr_value("now", attrs), "%s")
    rescue
      @time_now = nil
    end
  when "metric"
    @m_name = attr_value("name", attrs)
    @m_type = attr_value("type", attrs)
  end
end