Class: Nagios::API::Services

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

Defined Under Namespace

Classes: NoHost

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Services

Returns a new instance of Services.



8
9
10
11
# File 'lib/nagios/api/service.rb', line 8

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

Instance Attribute Details

#api_clientObject (readonly)

Returns the value of attribute api_client.



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

def api_client
  @api_client
end

#hostObject

Returns the value of attribute host.



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

def host
  @host
end

Instance Method Details

#allObject

Raises:



13
14
15
16
17
18
19
# File 'lib/nagios/api/service.rb', line 13

def all
  raise NoHost unless host
  
  @services ||= api_client.api.query("/service/#{host.name}").values.collect do |service_attributes|
    Service.new(service_attributes.merge(api_client: api_client, host: host))
  end
end

#find(name) ⇒ Object

Raises:



21
22
23
24
25
# File 'lib/nagios/api/service.rb', line 21

def find(name)
  raise NoHost unless host
  
  all.find { |service| service.name.downcase == name.downcase }
end

#reloadObject



27
28
29
# File 'lib/nagios/api/service.rb', line 27

def reload
  @services = nil
end