Class: ZabbixApi::Templates

Inherits:
Basic
  • Object
show all
Defined in:
lib/zabbixapi/classes/templates.rb

Instance Method Summary collapse

Methods inherited from Basic

#add, #all, #create, #create_or_update, #default_options, #destroy, #dump_by_id, #get, #get_full_data, #get_id, #hash_equals?, #initialize, #key, #keys, #log, #merge_params, #normalize_hash, #parse_keys, #symbolize_keys, #update

Constructor Details

This class inherits a constructor from ZabbixApi::Basic

Instance Method Details

#delete(data) ⇒ Object

Delete template

  • Args :

    • data -> Hash with :host => “Template_Name”

  • Returns :

    • Nil or Integer



19
20
21
22
# File 'lib/zabbixapi/classes/templates.rb', line 19

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

#get_ids_by_host(data) ⇒ Object

Return templateids linked with host

  • Args :

    • data -> Hash with :hostids => [hostid]

  • Returns :

    • Array with templateids



30
31
32
33
34
35
36
# File 'lib/zabbixapi/classes/templates.rb', line 30

def get_ids_by_host(data)
  result = []
  @client.api_request(:method => "template.get", :params => data).each do |tmpl|
    result << tmpl['templateid']
  end
  result
end

#get_or_create(data) ⇒ Object

Return templateid

  • Args :

    • data -> Hash with :host => “Template_Name” and :groups => array with hostgroup ids

  • Returns :

    • Integer



44
45
46
47
48
49
# File 'lib/zabbixapi/classes/templates.rb', line 44

def get_or_create(data)
  unless (templateid = get_id(:host => data[:host]))
    templateid = create(data)
  end
  templateid
end

#indentifyObject



8
9
10
# File 'lib/zabbixapi/classes/templates.rb', line 8

def indentify
  "host"
end

#mass_add(data) ⇒ Object

Analog Zabbix api call massAdd

  • Args :

    • data -> Hash with :hosts_id => [hostid1, hostid2 …], and :templates_id => [templateid1, templateid2 …]

  • Returns :

    • True or False



74
75
76
77
78
79
80
81
82
83
# File 'lib/zabbixapi/classes/templates.rb', line 74

def mass_add(data)
  result = @client.api_request(
    :method => "template.massAdd", 
    :params => {
      :hosts => data[:hosts_id].map { |t| {:hostid => t} },
      :templates => data[:templates_id].map { |t| {:templateid => t} }
    }
  )
  result.empty? ? false : true
end

#mass_remove(data) ⇒ Object

Analog Zabbix api call massRemove

  • Args :

    • data -> Hash with :hosts_id => [hostid1, hostid2 …], and :templates_id => [templateid1, templateid2 …]

  • Returns :

    • True or False



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/zabbixapi/classes/templates.rb', line 91

def mass_remove(data)
  result = @client.api_request(
    :method => "template.massRemove",
    :params => {
      :hostids => data[:hosts_id],
      :templateids => data[:templates_id],
      :groupids => data[:group_id],
      :force => 1
    }
  )
  result.empty? ? false : true
end

#mass_update(data) ⇒ Object

Analog Zabbix api call massUpdate

  • Args :

    • data -> Hash with :hosts_id => [hostid1, hostid2 …], and :templates_id => [templateid1, templateid2 …]

  • Returns :

    • True or False



57
58
59
60
61
62
63
64
65
66
# File 'lib/zabbixapi/classes/templates.rb', line 57

def mass_update(data)
  result = @client.api_request(
    :method => "template.massAdd", 
    :params => {
      :hosts => data[:hosts_id].map { |t| {:hostid => t} },
      :templates => data[:templates_id].map { |t| {:templateid => t} }
    }
  )
  result.empty? ? false : true
end

#method_nameObject



4
5
6
# File 'lib/zabbixapi/classes/templates.rb', line 4

def method_name
  "template"
end