Class: Icinga::Server

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

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 = {}) ⇒ Server

Returns a new instance of Server.



32
33
34
# File 'lib/icinga/server.rb', line 32

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

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/icinga/server.rb', line 5

def options
  @options
end

Instance Method Details

#connectionObject



14
15
16
# File 'lib/icinga/server.rb', line 14

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

#hostsObject



24
25
26
# File 'lib/icinga/server.rb', line 24

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

#new_request(path) ⇒ Object



18
19
20
21
22
# File 'lib/icinga/server.rb', line 18

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

#servicesObject



28
29
30
# File 'lib/icinga/server.rb', line 28

def services
  Responder.new(self, new_request("?host=all&style=servicedetail"))
end