Class: Nagios::MkLiveStatus::Filter::Attr

Inherits:
Nagios::MkLiveStatus::Filter show all
Includes:
Nagios::MkLiveStatus, QueryHelper::Comparator
Defined in:
lib/nagios_mklivestatus/filter/attr.rb

Overview

This class symbolise a filter unit. This unit represents a small filter predicate like, in the nagios query, this :

Filter: host_name = name
Author

Esco-lan Team ([email protected])

Copyright

Copyright © 2012 GIP RECIA

License

General Public Licence

Constant Summary

Constants included from QueryHelper::Comparator

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

Instance Method Summary collapse

Methods included from QueryHelper::Comparator

#get_all_comparators

Methods included from Nagios::MkLiveStatus

init, #logger

Constructor Details

#initialize(attr_name, attr_comp, attr_value) ⇒ Attr

Create the unit predicate with the column name, the operator use to compare, and the value

attr_name

name of the column

attr_comp

operator, one of the constant of the class

attr_value

the value to compare to



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nagios_mklivestatus/filter/attr.rb', line 18

def initialize (attr_name, attr_comp, attr_value)
  
  list_comparator = get_all_comparators
  
  if attr_name == nil or attr_name.empty?
    raise QueryException.new("The name of the attribute must be set in order to create the filter")
  else
    @attr_name = attr_name
  end
  
  if list_comparator.index(attr_comp) == nil
    raise QueryException.new("The comparator \"#{attr_comp}\" is not recognized.\n Please use one of : #{list_comparator.join(", ")}")
  else
    @attr_comp = attr_comp
  end
  
  @attr_value = attr_value
end

Instance Method Details

#to_sObject

Convert the class into the nagios query string:

Filter: name comp value


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/nagios_mklivestatus/filter/attr.rb', line 41

def to_s
  if @attr_name == nil or @attr_name.empty?
    raise QueryException.new("The filter cannot be converted into string because the name of the attribute is not set.")
  end
  
  if @attr_comp == nil or @attr_comp.empty?
    raise QueryException.new("The filter cannot be converted into string because the comparator of the attribute is not set.")
  end
  
  if @attr_value == nil or @attr_value.empty?
    return "Filter: "+@attr_name+" "+@attr_comp 
  end
  
  return "Filter: "+@attr_name+" "+@attr_comp+" "+@attr_value;
end