Class: Icinga::Server
- Inherits:
-
Object
- Object
- Icinga::Server
- Defined in:
- lib/icinga/server.rb
Constant Summary collapse
- @@default_options =
{ :host => "localhost", :port => 80, }
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #connection ⇒ Object
- #hosts ⇒ Object
-
#initialize(options = {}) ⇒ Server
constructor
A new instance of Server.
- #new_request(path) ⇒ Object
- #services ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
33 34 35 |
# File 'lib/icinga/server.rb', line 33 def initialize(={}) @options = @@default_options.merge() end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/icinga/server.rb', line 6 def @options end |
Instance Method Details
#connection ⇒ Object
13 14 15 |
# File 'lib/icinga/server.rb', line 13 def connection @conn ||= Net::HTTP.new(@options[:host], @options[:port]) end |
#hosts ⇒ Object
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 |
#services ⇒ Object
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 |