Class: Nagios::API::Client

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

Overview

Create a new client to interact with the nagios-api server.

client = Nagios::API::Client.new("http://nagios-server:8181")

Optionally set authentication credentials

client = Nagios::API::Client.new("http://nagios-server:8181", user: 'user', password: 'password')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, extra_args = {}) ⇒ Client

Returns a new instance of Client.



13
14
15
16
# File 'lib/nagios/api/client.rb', line 13

def initialize(base_url, extra_args = {})
  @base_url = base_url
  @options = extra_args
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



11
12
13
# File 'lib/nagios/api/client.rb', line 11

def base_url
  @base_url
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/nagios/api/client.rb', line 11

def options
  @options
end

#stateObject (readonly)

Returns the value of attribute state.



11
12
13
# File 'lib/nagios/api/client.rb', line 11

def state
  @state
end

Instance Method Details

#apiObject



18
19
20
# File 'lib/nagios/api/client.rb', line 18

def api
  @api ||= Nagios::API::Interface.new(options.merge(base_url: base_url))
end

#hostsObject



22
23
24
# File 'lib/nagios/api/client.rb', line 22

def hosts
  @hosts ||= Nagios::API::Hosts.new(api_client: self)
end