Class: Nagios::MkLiveStatus::Query
- Inherits:
-
Object
- Object
- Nagios::MkLiveStatus::Query
- Defined in:
- lib/nagios_mklivestatus/query.rb
Overview
This class is used to create a nagios mklivestatus query
-
get : is the object we are looking for
-
columns : are the fields we need from the object
-
filters : are the filters applied to the query
By default the query get all the columns of the object without filter. If you add any columns or filter they will take place in the query
- Author
-
Esco-lan Team ([email protected])
- Copyright
-
Copyright © 2011 GIP RECIA
- License
-
General Public Licence
Instance Method Summary collapse
-
#addColumn(name) ⇒ Object
Add a field to get in the query for the GET object.
-
#addFilter(expression) ⇒ Object
Add a filter to the query.
-
#get(get) ⇒ Object
Get method is used to set the object to search for in nagios mklivestatus.
-
#initialize(base = nil) ⇒ Query
constructor
Constructor of the Query instance base is by default nil but if its filled the base if associated to the GET of the query.
-
#to_s ⇒ Object
short cut to the method to_socket.
-
#to_socket ⇒ Object
method used to generate the query from the field if get is not set then the method return an empty string.
Constructor Details
#initialize(base = nil) ⇒ Query
Constructor of the Query instance base is by default nil but if its filled the base if associated to the GET of the query
20 21 22 |
# File 'lib/nagios_mklivestatus/query.rb', line 20 def initialize(base=nil) get(base) end |
Instance Method Details
#addColumn(name) ⇒ Object
Add a field to get in the query for the GET object
32 33 34 35 36 37 38 39 40 |
# File 'lib/nagios_mklivestatus/query.rb', line 32 def addColumn(name) if not name == nil or name.empty? if @columns == nil @columns=Array.new end @columns.push(name) end end |
#addFilter(expression) ⇒ Object
Add a filter to the query
43 44 45 46 47 48 49 50 51 |
# File 'lib/nagios_mklivestatus/query.rb', line 43 def addFilter(expression) if not expression == nil or expression.empty? if @filters == nil @filters=Array.new end @filters.push(expression) end end |
#get(get) ⇒ Object
Get method is used to set the object to search for in nagios mklivestatus
25 26 27 28 29 |
# File 'lib/nagios_mklivestatus/query.rb', line 25 def get(get) if get != nil and not get.empty? @get = get end end |
#to_s ⇒ Object
short cut to the method to_socket
54 55 56 |
# File 'lib/nagios_mklivestatus/query.rb', line 54 def to_s return to_socket end |
#to_socket ⇒ Object
method used to generate the query from the field if get is not set then the method return an empty string
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/nagios_mklivestatus/query.rb', line 60 def to_socket query = String.new if @get != nil query << "GET "+@get+"\n" if @columns != nil and @columns.length > 0 query << "Columns:" @columns.each do |column| query << " "+column end query << "\n" end if @filters != nil and @filters.length > 0 @filters.each do |filter| query << "Filter: "+filter+"\n" end end end return query end |