Class: IcingaApi::Host

Inherits:
Request show all
Defined in:
lib/icinga_api/host.rb

Constant Summary collapse

TARGET =
"host"
F_UP =

some popular filter definitions

Filter.new("HOST_CURRENT_STATE", "=", 0)
F_DOWN =
Filter.new("HOST_CURRENT_STATE", "=", 1)
F_ACK =
Filter.new("HOST_PROBLEM_HAS_BEEN_ACKNOWLEDGED", "=", 1)
F_NACK =
Filter.new("HOST_PROBLEM_HAS_BEEN_ACKNOWLEDGED", "=", 0)
F_DOWN_ACK =
F_DOWN & F_ACK
F_DOWN_NACK =
F_DOWN & F_NACK
CHECKS =
{
  integer: i(
    HOST_ID
    HOST_OBJECT_ID
    HOST_INSTANCE_ID
    HOST_PARENT_OBJECT_ID
    HOST_CHILD_ID
    HOST_CURRENT_CHECK_ATTEMPT
    HOST_MAX_CHECK_ATTEMPTS
    HOST_STATE_COUNT
  ),
  float: i(
    HOST_LATENCY
    HOST_EXECUTION_TIME
  ),
  boolean: i(
    HOST_FLAP_DETECTION_ENABLED
    HOST_ACTIVE_CHECKS_ENABLED
    HOST_FLAP_DETECTION_ENABLED
    HOST_FRESHNESS_CHECK_ENABLED
    HOST_PASSIVE_CHECKS_ENABLED
    HOST_EVENT_HANDLER_ENABLED
    HOST_ACTIVE_CHECKS_ENABLED
    HOST_NOTIFICATIONS_ENABLED
    HOST_OBSESS_OVER_HOST
    HOST_FAILURE_PREDICTION_ENABLED
    HOST_IS_ACTIVE
    HOST_HAS_BEEN_CHECKED
    HOST_IS_FLAPPING
    HOST_PROBLEM_HAS_BEEN_AKNOWLEDGED
    HOST_IS_PENDING
    HOST_SHOULD_BE_SCHEDULED
    HOST_PROCESS_PERFORMANCE_DATA
  ),
  #HOST_NAME
  string: i(
    HOST_ALIAS
    HOST_DISPLAY_NAME
    HOST_NOTES
    HOST_OUTPUT
    HOST_LONG_OUTPUT
    HOST_PARENT_NAME
    HOST_CHILD_NAME
    HOST_ICON_IMAGE
    HOST_ICON_IMAGE_ALT
    HOST_NOTES_URL
    HOST_ACTION_URL
  ),
  time: i(
    HOST_LAST_CHECK
    HOST_LAST_STATE_CHANGE
    HOST_NEXT_CHECK
    HOST_LAST_NOTIFICATION
    HOST_STATUS_UPDATE_TIME
    HOST_LAST_HARD_STATE_CHANGE
  )
}

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, name) ⇒ Host

Returns a new instance of Host.



83
84
85
86
87
# File 'lib/icinga_api/host.rb', line 83

def initialize(connection, name)
   @connection = connection
   @name = name
   @host_filter = Filter.new("HOST_NAME", "=", name)
end

Instance Attribute Details

#host_filterObject (readonly)

Returns the value of attribute host_filter.



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

def host_filter
  @host_filter
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#addressObject



122
123
124
125
126
127
128
129
130
# File 'lib/icinga_api/host.rb', line 122

def address
  rc = request(TARGET, @host_filter, [:HOST_ADDRESS])
  address = rc[:result][0][:HOST_ADDRESS]
  begin 
    address = IPAddress(address)
  rescue
    address
  end
end

#current_stateObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/icinga_api/host.rb', line 95

def current_state
  rc = request(TARGET, @host_filter, ["HOST_CURRENT_STATE"])
  return :unknown unless rc[:success] == "true"
  case rc[:result][0][:HOST_CURRENT_STATE].to_i
    when 0 
      :up
    when 1
      :down
  end
end

#down?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/icinga_api/host.rb', line 112

def down?
  current_state == :down
end

#fetch(method) ⇒ Object



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

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

#service(name) ⇒ Object



141
142
143
# File 'lib/icinga_api/host.rb', line 141

def service(name)
  Service.new(@connection, self, name)
end

#servicesObject



133
134
135
136
137
138
# File 'lib/icinga_api/host.rb', line 133

def services
  rc = request(Service::TARGET, @host_filter, [:SERVICE_NAME])
  rc[:result].map do |service_hash|
    Service.new(@connection, self, service_hash[:SERVICE_NAME])
  end
end

#unknown?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/icinga_api/host.rb', line 117

def unknown?
  current_state == :unknown
end

#up?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/icinga_api/host.rb', line 107

def up?
  current_state == :up
end