Class: Nagios::API::Hosts

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Hosts

Returns a new instance of Hosts.



5
6
7
8
# File 'lib/nagios/api/host.rb', line 5

def initialize(args = {})
  @api_client = args[:api_client]
  @host_cache = {}
end

Instance Attribute Details

#api_clientObject (readonly)

Returns the value of attribute api_client.



3
4
5
# File 'lib/nagios/api/host.rb', line 3

def api_client
  @api_client
end

Instance Method Details

#find(hostname) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/nagios/api/host.rb', line 10

def find(hostname)
  return @host_cache[hostname] if @host_cache.has_key?(hostname)
  
  host = Host.new(api_client.api.query("/host/#{hostname}").merge(api_client: api_client))
  @host_cache[hostname] = host
  host
end

#reloadObject



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

def reload
  @host_cache = {}
end