Class: ZabbixApi::HostGroups

Inherits:
Object
  • Object
show all
Defined in:
lib/zabbixapi/hostgroups.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HostGroups

Returns a new instance of HostGroups.



4
5
6
7
# File 'lib/zabbixapi/hostgroups.rb', line 4

def initialize(options = {})
  @client = Client.new(options)
  @options = options
end

Instance Method Details

#add(data) ⇒ Object



14
15
16
# File 'lib/zabbixapi/hostgroups.rb', line 14

def add(data)
  create(data)
end

#create(data) ⇒ Object



9
10
11
12
# File 'lib/zabbixapi/hostgroups.rb', line 9

def create(data)
  result = @client.api_request(:method => "hostgroup.create", :params => [data])
  result.empty? ? nil : result['groupids'][0].to_i
end

#delete(data) ⇒ Object



18
19
20
21
# File 'lib/zabbixapi/hostgroups.rb', line 18

def delete(data)
  result = @client.api_request(:method => "hostgroup.delete", :params => [:groupid => data])
  result.empty? ? nil : result['groupids'][0].to_i
end

#destroy(data) ⇒ Object



23
24
25
# File 'lib/zabbixapi/hostgroups.rb', line 23

def destroy(data)
  delete(data)
end

#get_full_data(data) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/zabbixapi/hostgroups.rb', line 34

def get_full_data(data)
  case @client.api_version 
    when "1.2"
      @client.api_request(:method => "hostgroup.get", :params => {:filter => data, :output => "extend"})
    else
      @client.api_request(:method => "hostgroup.get", :params => {:filter => data, :output => "extend"})
  end
end

#get_id(data) ⇒ Object



43
44
45
46
47
48
# File 'lib/zabbixapi/hostgroups.rb', line 43

def get_id(data)
  result = get_full_data(data)
  hostgroupid = nil
  result.each { |hgroup| hostgroupid = hgroup['groupid'].to_i if hgroup['name'] == data[:name] }
  hostgroupid
end

#get_or_create(data) ⇒ Object



27
28
29
30
31
32
# File 'lib/zabbixapi/hostgroups.rb', line 27

def get_or_create(data)
  unless hostgroupid = get_id(data)
    hostgroupid = update(data)
  end
  hostgroupid
end