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

#array_flagObject



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

def array_flag
  true
end

#delete(data) ⇒ Object

Delete template

  • Args :

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

  • Returns :

    • Nil or Integer



23
24
25
26
# File 'lib/zabbixapi/classes/templates.rb', line 23

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



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

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



48
49
50
51
52
53
# File 'lib/zabbixapi/classes/templates.rb', line 48

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

#indentifyObject



12
13
14
# File 'lib/zabbixapi/classes/templates.rb', line 12

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



78
79
80
81
82
83
84
85
86
87
# File 'lib/zabbixapi/classes/templates.rb', line 78

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



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/zabbixapi/classes/templates.rb', line 95

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



61
62
63
64
65
66
67
68
69
70
# File 'lib/zabbixapi/classes/templates.rb', line 61

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



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

def method_name
  "template"
end