Class: IcingaApi::Service

Inherits:
Request
  • Object
show all
Defined in:
lib/icinga_api/service.rb

Constant Summary collapse

TARGET =
"service"
F_OK =

some popular filter definitions

Filter.new("SERVICE_CURRENT_STATE", "=", 0)
F_WARNING =
Filter.new("SERVICE_CURRENT_STATE", "=", 1)
F_CRITICAL =
Filter.new("SERVICE_CURRENT_STATE", "=", 2)
F_UNKNOWN =
Filter.new("SERVICE_CURRENT_STATE", "=", 3)
CHECKS =
{
  integer: %i(
    SERVICE_ID
    SERVICE_INSTANCE_ID
    SERVICE_OBJECT_ID
    SERVICE_CURRENT_CHECK_ATTEMPTS
    SERVICE_MAX_CHECK_ATTEMPTS
    SERVICE_STATE_COUNT
    SERVICE_OBJECT_COUNT
  ),
  float: %i(
    SERVICE_LATENCY
    SERVICE_EXECUTION_TIME
  ),
  boolean: %i(
    SERVICE_IS_ACTIVE
    SERVICE_NOTIFICATIONS_ENABLED
    SERVICE_FLAP_DETECTION_ENABLED
    SERVICE_PASSIVE_CHECKS_ENABLED
    SERVICE_EVENT_HANDLER_ENABLED
    SERVICE_ACTIVE_CHECKS_ENABLED
    SERVICE_RETAIN_STATUS_INFORMATION
    SERVICE_RETAIN_NONSTATUS_INFORMATION
    SERVICE_OBSESS_OVER_SERVICE
    SERVICE_FAILURE_PREDICTION_ENABLED
    SERVICE_PROCESS_PERFORMANCE_DATA
    SERVICE_HAS_BEEN_CHECKED
    SERVICE_IS_FLAPPING
    SERVICE_PROBLEM_HAS_BEEN_ACKNOWLEDGED
    SERVICE_SHOULD_BE_SCHEDULED
    SERVICE_IS_PENDING
    SERVICE_LAST_HARD_STATE
  ),
  string: %i(
    SERVICE_NAME
    SERVICE_DISPLAY_NAME
    SERVICE_NOTES
    SERVICE_OUTPUT
    SERVICE_LONG_OUTPUT
    SERVICE_ICON_IMAGE
    SERVICE_ICON_IMAGE_ALT
    SERVICE_NOTES_URL
    SERVICE_ACTION_URL
  ),
  time: %i(
    SERVICE_LAST_CHECK
    SERVICE_LAST_STATE_CHANGE
    SERVICE_NEXT_CHECK
    SERVICE_LAST_HARD_STATE_CHANGE
    SERVICE_LAST_NOTIFICATION
    SERVICE_STATUS_UPDATE_TIME
  )
}

Instance Attribute Summary collapse

Attributes inherited from Request

#connection

Instance Method Summary collapse

Methods inherited from Request

boolean_request, float_request, integer_request, request, string_request, time_request

Constructor Details

#initialize(connection, host, name) ⇒ Service

Returns a new instance of Service.



77
78
79
80
81
82
# File 'lib/icinga_api/service.rb', line 77

def initialize(connection, host, name)
  @connection = connection
  @host = host
  @name = name
  @service_filter = (@host.host_filter & Filter.new("SERVICE_NAME", "=", name))
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/icinga_api/service.rb', line 4

def name
  @name
end

#service_filterObject (readonly)

Returns the value of attribute service_filter.



4
5
6
# File 'lib/icinga_api/service.rb', line 4

def service_filter
  @service_filter
end

Instance Method Details

#critical?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/icinga_api/service.rb', line 121

def critical?
  current_state == :critical
end

#current_stateObject



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/icinga_api/service.rb', line 96

def current_state
  rc = request(TARGET, @service_filter, ["SERVICE_CURRENT_STATE"])
  case rc[:result][0][:SERVICE_CURRENT_STATE].to_i
    when 0 
      :ok
    when 1
      :warning
    when 2
      :critical
    when 4
      :unknown
  end
end

#fetch(method) ⇒ Object



85
86
87
# File 'lib/icinga_api/service.rb', line 85

def fetch(method)
  string_request(TARGET, @service_filter, method)
end

#ok?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/icinga_api/service.rb', line 111

def ok?
  current_state == :ok
end

#perfdataObject



90
91
92
93
# File 'lib/icinga_api/service.rb', line 90

def perfdata
  rc = request(TARGET, @service_filter, [:SERVICE_PERFDATA])
  # TODO: parsing
end

#unknown?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/icinga_api/service.rb', line 126

def unknown?
  current_state == :unknown
end

#warning?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/icinga_api/service.rb', line 116

def warning?
  current_state == :warning
end