Class: Icinga::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/icinga/client.rb

Overview

Client connection to Icinga server

Constant Summary collapse

@@default_options =
{
  :host => "localhost",
  :port => 80,
  :remote_path => "/icinga/cgi-bin/status.cgi", 
  :format => "json",
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.

Parameters:

  • options (Hash) (defaults to: {})


17
18
19
# File 'lib/icinga/client.rb', line 17

def initialize(options = {})
  @options = @@default_options.merge(options)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/icinga/client.rb', line 7

def options
  @options
end

Instance Method Details

#connectionObject



29
30
31
# File 'lib/icinga/client.rb', line 29

def connection
  @conn ||= Net::HTTP.new(@options[:host], @options[:port])
end

#hostsObject



21
22
23
# File 'lib/icinga/client.rb', line 21

def hosts
  Responder.create(Host, self, new_request("?hostgroup=all&style=hostdetail"))
end

#new_request(path) ⇒ Object



33
34
35
36
37
# File 'lib/icinga/client.rb', line 33

def new_request(path)
  req = Net::HTTP::Get.new(@options[:remote_path] + path + "&" + @options[:format] + "output")
  req.basic_auth @options[:user], @options[:password] if @options[:user]
  req
end

#services(host = nil) ⇒ Object



25
26
27
# File 'lib/icinga/client.rb', line 25

def services(host=nil)
  Responder.create(Service, self, new_request("?host=#{host.nil? ? "all" : host}&style=servicedetail"))
end