Class: IcingaRest::Request
- Inherits:
-
Object
- Object
- IcingaRest::Request
- Defined in:
- lib/icinga_rest/request.rb
Overview
Wrapper to simplify constructing the http GET request to access the Icinga REST API
Constant Summary collapse
- WGET =
'/usr/bin/wget'
Instance Attribute Summary collapse
-
#authkey ⇒ Object
The Icinga server.
-
#count_column ⇒ Object
The Icinga server.
-
#filter ⇒ Object
The Icinga server.
-
#host ⇒ Object
The Icinga server.
-
#output ⇒ Object
The Icinga server.
-
#target ⇒ Object
The Icinga server.
Instance Method Summary collapse
-
#get ⇒ Object
It would be nicer to use Net::HTTP, or something, but the URLs required by the Icinga API are not well-formed, and the URI library, used by most of the ruby http libs, barfs.
-
#initialize(params) ⇒ Request
constructor
A new instance of Request.
- #to_url ⇒ Object
Constructor Details
#initialize(params) ⇒ Request
Returns a new instance of Request.
13 14 15 16 17 18 19 20 |
# File 'lib/icinga_rest/request.rb', line 13 def initialize(params) @host = params[:host] @target = params[:target] @filter = params[:filter] @count_column = params[:count_column] @authkey = params[:authkey] @output = params[:output] end |
Instance Attribute Details
#authkey ⇒ Object
The Icinga server
4 5 6 |
# File 'lib/icinga_rest/request.rb', line 4 def authkey @authkey end |
#count_column ⇒ Object
The Icinga server
4 5 6 |
# File 'lib/icinga_rest/request.rb', line 4 def count_column @count_column end |
#filter ⇒ Object
The Icinga server
4 5 6 |
# File 'lib/icinga_rest/request.rb', line 4 def filter @filter end |
#host ⇒ Object
The Icinga server
4 5 6 |
# File 'lib/icinga_rest/request.rb', line 4 def host @host end |
#output ⇒ Object
The Icinga server
4 5 6 |
# File 'lib/icinga_rest/request.rb', line 4 def output @output end |
#target ⇒ Object
The Icinga server
4 5 6 |
# File 'lib/icinga_rest/request.rb', line 4 def target @target end |
Instance Method Details
#get ⇒ Object
It would be nicer to use Net::HTTP, or something, but the URLs required by the Icinga API are not well-formed, and the URI library, used by most of the ruby http libs, barfs. So, we shell out to wget, which is more tolerant. Fugly, but functional.
27 28 29 |
# File 'lib/icinga_rest/request.rb', line 27 def get `#{WGET} -q -O - '#{to_url}'` end |
#to_url ⇒ Object
31 32 33 |
# File 'lib/icinga_rest/request.rb', line 31 def to_url "http://%s/icinga-web/web/api/%s/%s/authkey=%s/%s" % [host, target, , authkey, output] end |