Class: Nagios::API::Service

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

Instance Attribute Summary

Attributes inherited from Resource

#api_client, #attributes

Instance Method Summary collapse

Methods inherited from Resource

#initialize, #method_missing, #to_hash

Constructor Details

This class inherits a constructor from Nagios::API::Resource

Dynamic Method Handling

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

Instance Method Details

#downtimesObject



43
44
45
46
47
48
# File 'lib/nagios/api/service.rb', line 43

def downtimes
  return nil unless state
  
  dts = state['downtimes'] ? state['downtimes'].values : []
  dts.collect { |dt| Nagios::API::Downtime.new(dt.merge(service: self, api_client: api_client)) }
end

#nameObject



33
34
35
# File 'lib/nagios/api/service.rb', line 33

def name
  service
end

#schedule_downtime(params = {}) ⇒ Object

schedule_downtime arguments:

author
comment
start_time
fixed
duration
end_time

Raises:

  • (StandardError)


57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/nagios/api/service.rb', line 57

def schedule_downtime(params = {})
  params = params.dup
  params[:host] = host.name
  params[:service] = name
  params[:start_time] = params[:start_time].to_i if params[:start_time]
  params[:end_time] = params[:end_time].to_i if params[:end_time]
  
  result = api_client.api.post("/schedule_downtime", params)
  
  raise StandardError, "Unknown response scheduling downtime: #{result}" unless result == "scheduled"
  
  true
end

#stateObject



37
38
39
40
41
# File 'lib/nagios/api/service.rb', line 37

def state
  return nil unless host
  
  host.state['services'][name]
end

#statusObject



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/nagios/api/service.rb', line 71

def status
  case current_state.to_i
  when 0
    :ok
  when 1
    :warning
  when 2
    :critical
  else
    :unknown
  end
end

#status_detailsObject



84
85
86
# File 'lib/nagios/api/service.rb', line 84

def status_details
  plugin_output
end