Module: Nagios::MkLiveStatus::QueryHelper

Includes:
Comparator, Deviation, Trigger
Included in:
Parser
Defined in:
lib/nagios_mklivestatus/query_helper.rb

Overview

This module is a Query helper. It provides convenient methods in order to create query, filter, stats, wait. As sub modules, it contains all the constants for comparator and deviation operators.

Author

Esco-lan Team ([email protected])

Copyright

Copyright © 2012 GIP RECIA

License

General Public Licence

Defined Under Namespace

Modules: Comparator, Deviation, Trigger

Constant Summary

Constants included from Trigger

Trigger::ALL, Trigger::CHECK, Trigger::COMMAND, Trigger::COMMENT, Trigger::DOWNTIME, Trigger::LOG, Trigger::STATE

Constants included from Deviation

Deviation::AVG, Deviation::AVGINV, Deviation::MAX, Deviation::MIN, Deviation::STD, Deviation::SUM, Deviation::SUMINV

Constants included from Comparator

Comparator::EQUAL, Comparator::EQUAL_IGNCASE, Comparator::GREATER, Comparator::GREATER_EQUAL, Comparator::LESSER, Comparator::LESSER_EQUAL, Comparator::NOT_EQUAL, Comparator::NOT_EQUAL_IGNCASE, Comparator::NOT_SUBSTR, Comparator::NOT_SUBSTR_IGNCASE, Comparator::SUBSTR, Comparator::SUBSTR_IGNCASE

Instance Method Summary collapse

Methods included from Trigger

#get_all_triggers

Methods included from Deviation

#get_all_deviations

Methods included from Comparator

#get_all_comparators

Instance Method Details

#nagmk_and(filter1, filter2) ⇒ Object

Create the and filter expression between two filters.



75
76
77
# File 'lib/nagios_mklivestatus/query_helper.rb', line 75

def nagmk_and(filter1, filter2)
  Nagios::MkLiveStatus::Filter::And.new(filter1, filter2)
end

#nagmk_filter(name, comparator, value) ⇒ Object

Create a filter with the parameters.



23
24
25
# File 'lib/nagios_mklivestatus/query_helper.rb', line 23

def nagmk_filter(name, comparator, value)
  Nagios::MkLiveStatus::Filter::Attr.new(name, comparator, value)
end

#nagmk_filter_from_str(filter_str) ⇒ Object

Split the string into 3 parameters in order to create the correct filter. Must match the regular expression : /^(Filter: )?(S+) (S+) ?(S+)?$/

Raises:



29
30
31
32
33
34
35
36
# File 'lib/nagios_mklivestatus/query_helper.rb', line 29

def nagmk_filter_from_str(filter_str)
  predicates = filter_str.strip.match(/^(Filter: )?(\S+) (\S+) ?([\S ]+)?$/)
  if predicates
    return nagmk_filter(predicates[2], predicates[3], predicates[4])
  end
  
  raise QueryException.new("Can't create filter because the expression doesn't match /^(Filter: )?(\S+) (\S+) ?([\S ]+)?$/")
end

#nagmk_negate(filter) ⇒ Object

Create the negate filter expression.



85
86
87
# File 'lib/nagios_mklivestatus/query_helper.rb', line 85

def nagmk_negate(filter)
  Nagios::MkLiveStatus::Filter::Negate.new(filter)
end

#nagmk_or(filter1, filter2) ⇒ Object

Create the or filter expression between two filters.



80
81
82
# File 'lib/nagios_mklivestatus/query_helper.rb', line 80

def nagmk_or(filter1, filter2)
  Nagios::MkLiveStatus::Filter::Or.new(filter1, filter2)
end

#nagmk_query(get = nil) ⇒ Object

Create a nagios query. With get initiated if given in parameter.



12
13
14
15
16
17
18
19
20
# File 'lib/nagios_mklivestatus/query_helper.rb', line 12

def nagmk_query(get=nil)
  if get
    query = Nagios::MkLiveStatus::Query.new(get)
  else
    query = Nagios::MkLiveStatus::Query.new
  end
  
  query
end

#nagmk_stats(name, comparator, value, deviation = nil) ⇒ Object

Create a stats with parameters.



39
40
41
# File 'lib/nagios_mklivestatus/query_helper.rb', line 39

def nagmk_stats(name, comparator, value, deviation=nil)
  Nagios::MkLiveStatus::Stats::Attr.new(name, comparator, value, deviation)
end

#nagmk_stats_and(stats1, stats2) ⇒ Object

Create the and stats expression between two stats.



90
91
92
# File 'lib/nagios_mklivestatus/query_helper.rb', line 90

def nagmk_stats_and(stats1, stats2)
  Nagios::MkLiveStatus::Stats::And.new(stats1, stats2)
end

#nagmk_stats_from_str(stats_str) ⇒ Object

Split the string into 4 parameters in order to create the correct stats. Must match the regular expression : /^(Stats: )?(S+) (S+) ?(S+)?$/

Raises:



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/nagios_mklivestatus/query_helper.rb', line 45

def nagmk_stats_from_str(stats_str)
  predicates = stats_str.strip.match(/^(Stats: )?(\S+) (\S+) ?([\S ]+)?$/)
  if predicates
    if get_all_deviations.include? predicates[2]
      return nagmk_stats(predicates[3], nil, nil, predicates[2])
    else
      return nagmk_stats(predicates[2], predicates[3], predicates[4])
    end
  end
  
  raise QueryException.new("Can't create stats because the expression doesn't match /^(Stats: )?(\S+) (\S+) ?([\S ]+)?$/")
end

#nagmk_stats_or(stats1, stats2) ⇒ Object

Create the or stats expression between two stats.



95
96
97
# File 'lib/nagios_mklivestatus/query_helper.rb', line 95

def nagmk_stats_or(stats1, stats2)
  Nagios::MkLiveStatus::Stats::Or.new(stats1, stats2)
end

#nagmk_wait_condition(name, comparator, value) ⇒ Object

Create a wait condition with the parameters.



59
60
61
# File 'lib/nagios_mklivestatus/query_helper.rb', line 59

def nagmk_wait_condition(name, comparator, value)
  Nagios::MkLiveStatus::Wait::Attr.new(name, comparator, value)
end

#nagmk_wait_condition_and(wait1, wait2) ⇒ Object

Create the and wait expression between two wait conditions.



100
101
102
# File 'lib/nagios_mklivestatus/query_helper.rb', line 100

def nagmk_wait_condition_and(wait1, wait2)
  Nagios::MkLiveStatus::Wait::And.new(wait1, wait2)
end

#nagmk_wait_condition_from_str(wait_cond_str) ⇒ Object

Split the string into 3 parameters in order to create the correct wait condition. Must match the regular expression : /^(WaitCondition: )?(S+) (S+) ?(S+)?$/

Raises:



65
66
67
68
69
70
71
72
# File 'lib/nagios_mklivestatus/query_helper.rb', line 65

def nagmk_wait_condition_from_str(wait_cond_str)
  predicates = wait_cond_str.strip.match(/^(WaitCondition: )?(\S+) (\S+) ?([\S ]+)?$/)
  if predicates
    return nagmk_wait_condition(predicates[2], predicates[3], predicates[4])
  end
  
  raise QueryException.new("Can't create wait condition because the expression doesn't match /^(WaitCondition: )?(\S+) (\S+) ?([\S ]+)?$/")
end

#nagmk_wait_condition_negate(wait) ⇒ Object

Create the negate wait condition expression.



110
111
112
# File 'lib/nagios_mklivestatus/query_helper.rb', line 110

def nagmk_wait_condition_negate(wait)
  Nagios::MkLiveStatus::Wait::Negate.new(wait)
end

#nagmk_wait_condition_object(obj_name) ⇒ Object

Create the wait object expression.



127
128
129
# File 'lib/nagios_mklivestatus/query_helper.rb', line 127

def nagmk_wait_condition_object(obj_name)
  Nagios::MkLiveStatus::Wait::Object.new(obj_name)
end

#nagmk_wait_condition_or(wait1, wait2) ⇒ Object

Create the or wait expression between two wait conditions.



105
106
107
# File 'lib/nagios_mklivestatus/query_helper.rb', line 105

def nagmk_wait_condition_or(wait1, wait2)
  Nagios::MkLiveStatus::Wait::Or.new(wait1, wait2)
end

#nagmk_wait_condition_timeout(timeout) ⇒ Object

Create the wait timeout expression in milliseconds.



132
133
134
# File 'lib/nagios_mklivestatus/query_helper.rb', line 132

def nagmk_wait_condition_timeout(timeout)
  Nagios::MkLiveStatus::Wait::Timeout.new(timeout)
end

#nagmk_wait_condition_trigger(trigger = nil) ⇒ Object

Create the wait trigger expression.



115
116
117
118
119
120
121
122
123
124
# File 'lib/nagios_mklivestatus/query_helper.rb', line 115

def nagmk_wait_condition_trigger(trigger=nil)
  
  if trigger
    wait = Nagios::MkLiveStatus::Wait::Trigger.new(trigger)
  else
    wait = Nagios::MkLiveStatus::Wait::Trigger.new()
  end
  
  wait
end