Class: Nagios::API::Downtime

Inherits:
Resource show all
Defined in:
lib/nagios/api/downtime.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#attributes

Instance Method Summary collapse

Methods inherited from Resource

#method_missing, #to_hash

Constructor Details

#initialize(args = {}) ⇒ Downtime

Returns a new instance of Downtime.



5
6
7
8
9
10
11
12
13
14
# File 'lib/nagios/api/downtime.rb', line 5

def initialize(args = {})
  @service = args.delete(:service)
  @host = args.delete(:host)
  
  args['end_time'] = Time.at(args['end_time'].to_i)
  args['start_time'] = Time.at(args['start_time'].to_i)
  args['created_at'] = Time.at(args['entry_time'].to_i)
  
  super(args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Nagios::API::Resource

Instance Attribute Details

#api_clientObject (readonly)

Returns the value of attribute api_client.



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

def api_client
  @api_client
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#serviceObject (readonly)

Returns the value of attribute service.



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

def service
  @service
end

Instance Method Details

#cancelObject

Raises:

  • (StandardError)


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

def cancel
  result = api_client.api.post("/cancel_downtime/#{id}", {})
  
  raise StandardError, "Unknown response canceling downtime: #{result}" unless result == "cancelled"
  
  true
end

#idObject



16
17
18
# File 'lib/nagios/api/downtime.rb', line 16

def id
  downtime_id
end