Class: IcingaApi::HostGroup

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

Constant Summary collapse

TARGET =
"hostgroup"
CHECKS =
{
  integer: i(
    HOSTGROUP_ID
    HOSTGROUP_OBJECT_ID
    HOSTGROUP_INSTANCE_ID
  ),
  #float: %i(
  #),
  #boolean: %i(
  #),
  string: i(
    HOSTGROUP_NAME
    HOSTGROUP_ALIAS
  ),
  #time: %i(
  #)
}

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) ⇒ HostGroup

Returns a new instance of HostGroup.



35
36
37
38
39
# File 'lib/icinga_api/host_group.rb', line 35

def initialize(connection, name)
   @connection = connection
   @name = name
   @host_group_filter = Filter.new("HOSTGROUP_NAME", "=", name)
end

Instance Attribute Details

#host_group_filterObject (readonly)

Returns the value of attribute host_group_filter.



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

def host_group_filter
  @host_group_filter
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#fetch(method) ⇒ Object



42
43
44
# File 'lib/icinga_api/host_group.rb', line 42

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

#hosts(filter = nil) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/icinga_api/host_group.rb', line 47

def hosts(filter=nil)
  filter = filter ? (@host_group_filter & filter) : @host_group_filter
  rc = request(Host::TARGET, filter, [:HOST_NAME])
  rc[:result].map do |host_hash|
    Host.new(@connection, host_hash[:HOST_NAME])
  end
end

#hosts_downObject



56
57
58
# File 'lib/icinga_api/host_group.rb', line 56

def hosts_down
  hosts(Host::F_DOWN)
end

#hosts_upObject



61
62
63
# File 'lib/icinga_api/host_group.rb', line 61

def hosts_up
  hosts(Host::F_UP)
end