Class: Icinga::Server

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

Constant Summary collapse

@@default_options =
{
  :host => "localhost",
  :port => 80,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



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

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

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#connectionObject



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

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

#hostsObject



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

def hosts
  resp = connection.request(new_request("/icinga/cgi-bin/status.cgi?hostgroup=all&style=hostdetail&jsonoutput"))
  JSON.parse(resp.body)
end

#new_request(path) ⇒ Object



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

def new_request(path)
  req = Net::HTTP::Get.new(path)
  req.basic_auth @options[:user], @options[:password] if @options[:user]
  req
end

#servicesObject



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

def services
  resp = connection.request(new_request("/icinga/cgi-bin/status.cgi?host=all&style=servicedetail&jsonoutput"))
  JSON.parse(resp.body)
end