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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Request

Returns a new instance of Request.



11
12
13
14
15
16
17
18
# File 'lib/icinga_rest/request.rb', line 11

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

The standard URI library blows up with the malformed URLs required to access the Icinga REST API, but addressable works fine.



23
24
25
26
27
# File 'lib/icinga_rest/request.rb', line 23

def get
  uri = Addressable::URI.parse to_url
  r = Net::HTTP.get_response uri.normalize
  r.code == '200' ? r.body : ''
end

#to_urlObject



29
30
31
# File 'lib/icinga_rest/request.rb', line 29

def to_url
  "http://%s/icinga-web/web/api/%s/%s/authkey=%s/%s" % [host, target, url_options, authkey, output]
end