Class: Nagios::MkLiveStatus::Wait::Or

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

Overview

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

If one of the wait condition expression is also an “OR”, 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) ⇒ Or

Create a new “OR” 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/or.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::Or
    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::Or
    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 “OR”. It’s used by the new method in order to get all “OR” expressions into the same object.



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

def get_expressions
  return @expressions
end

#to_sObject

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

WaitCondition: ...
WaitCondition: ...
WaitConditionOr: 2


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

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