Class: IcingaRest::Request

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#authkeyObject

The Icinga server



4
5
6
# File 'lib/icinga_rest/request.rb', line 4

def authkey
  @authkey
end

#count_columnObject

The Icinga server



4
5
6
# File 'lib/icinga_rest/request.rb', line 4

def count_column
  @count_column
end

#filterObject

The Icinga server



4
5
6
# File 'lib/icinga_rest/request.rb', line 4

def filter
  @filter
end

#hostObject

The Icinga server



4
5
6
# File 'lib/icinga_rest/request.rb', line 4

def host
  @host
end

#outputObject

The Icinga server



4
5
6
# File 'lib/icinga_rest/request.rb', line 4

def output
  @output
end

#targetObject

The Icinga server



4
5
6
# File 'lib/icinga_rest/request.rb', line 4

def target
  @target
end

Instance Method Details

#getObject

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_urlObject



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, url_options, authkey, output]
end