Class: Nagira::ServiceStatusController

Inherits:
Object
  • Object
show all
Includes:
HostStatusNameConcerneable, OutputTypeable
Defined in:
app/controllers/service_status_controler.rb

Instance Attribute Summary

Attributes included from HostStatusNameConcerneable

#hostname, #resource, #service_name

Instance Method Summary collapse

Methods included from HostStatusNameConcerneable

#status, #with_service_name

Methods included from OutputTypeable

#body_with_list, #full?, #list?, #state?

Constructor Details

#initialize(nagios_status, output: nil, hostname: nil, service_name: nil) ⇒ ServiceStatusController

Returns a new instance of ServiceStatusController.

Parameters:

  • nagios_status (Hash)

    output of the Nagios status file parser

  • output (Symbol(:state)) (defaults to: nil)

    Output data: full or short state

  • hostname (String) (defaults to: nil)
  • service_name (String) (defaults to: nil)


10
11
12
13
14
15
16
17
# File 'app/controllers/service_status_controler.rb', line 10

def initialize(nagios_status, output: nil, hostname: nil, service_name: nil)

  @nagios_status = nagios_status
  @output = output
  @hostname = hostname
  @service_name = service_name
  @resource = "servicestatus"
end

Instance Method Details

#getObject

Read all statuses of the hosts’ services. Format output: full service state hash, or state only: name and state.



21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/service_status_controler.rb', line 21

def get
  case
  when state?
    with_service_name
      .values
      .first
      .slice("host_name", "current_state")
  else
    with_service_name
  end
end

#put(params) ⇒ Object



33
34
35
# File 'app/controllers/service_status_controler.rb', line 33

def put(params)
  Writer.new(:PROCESS_SERVICE_CHECK_RESULT).put with_service_and_host(params)
end

#with_service_and_host(params) ⇒ Object



37
38
39
40
41
42
# File 'app/controllers/service_status_controler.rb', line 37

def with_service_and_host(params)
  params.merge({
    'service_description' => @service_name,
    'host_name' => @hostname
    })
end