Class: Nagios::MkLiveStatus::Wait::And

Inherits:
Nagios::MkLiveStatus::Wait show all
Includes:
Nagios::MkLiveStatus
Defined in:
lib/nagios_mklivestatus/wait/and.rb

Overview

This class is used to make a logical “AND” operator between two wait expressions.

If one of the wait expression is also an “AND”, it takes all the expressions of the operator as its own.

Author

Esco-lan Team ([email protected])

Copyright

Copyright © 2012 GIP RECIA

License

General Public Licence

Instance Method Summary collapse

Methods included from Nagios::MkLiveStatus

init, #logger

Constructor Details

#initialize(left_expr, right_expr) ⇒ And

Create a new “AND” operator between left and right expressions.

Those expressions must be of type Nagios::MkLiveStatus::Wait



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/nagios_mklivestatus/wait/and.rb', line 18

def initialize(left_expr, right_expr)
  if not check_valid_condition(left_expr) or not check_valid_condition(right_expr)
    raise QueryException.new("The left and the right operand for an OR expression must be valid wait conditions.")
  end
  
  @expressions = Array.new
  if left_expr.is_a? Nagios::MkLiveStatus::Wait::And
    left_expr.get_expressions.each do |expr|
      @expressions.push expr
    end
  else
    @expressions.push left_expr
  end
  
  if right_expr.is_a? Nagios::MkLiveStatus::Wait::And
    right_expr.get_expressions.each do |expr|
      @expressions.push expr
    end
  else
    @expressions.push right_expr
  end

end

Instance Method Details

#get_expressionsObject

Return all the expressions under the “AND”. It’s used by the new method in order to get all “AND” expressions into the same object.



46
47
48
# File 'lib/nagios_mklivestatus/wait/and.rb', line 46

def get_expressions
  return @expressions
end

#to_sObject

Convert the current “AND” expression into a nagios query string

WaitCondition: ...
WaitCondition: ...
WaitConditionAnd: 2


56
57
58
59
60
61
62
63
# File 'lib/nagios_mklivestatus/wait/and.rb', line 56

def to_s
  and_arr = []
  @expressions.each do |expr|
    and_arr.push expr.to_s
  end
  and_arr.push "WaitConditionAnd: #{@expressions.length}"
  return and_arr.join("\n")
end