Class: ZabbixManager::Templates

Inherits:
Basic
  • Object
show all
Defined in:
lib/zabbix_manager/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, #get_ids, #get_ids_by_identify, #get_key_ids, #get_key_ids_by_identify, #get_or_create, #get_or_create_keys, #get_raw, #hash_equals?, #initialize, #key, #keys, #log, #merge_hashes, #normalize_array, #normalize_hash, #parse_keys, #request_raw, #symbolize_keys, #update

Constructor Details

This class inherits a constructor from ZabbixManager::Basic

Instance Method Details

#delete(data) ⇒ Object

通过 Zabbix API 删除模板对象



16
17
18
19
# File 'lib/zabbix_manager/classes/templates.rb', line 16

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

从 Zabbix API 获取主机的模板 id



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

def get_ids_by_host(data)
  @client.api_request(method: "template.get", params: data).map do |tmpl|
    tmpl["templateid"]
  end
end

#identifyObject

用于通过 Zabbix API 标识特定模板对象的 id 字段名称



11
12
13
# File 'lib/zabbix_manager/classes/templates.rb', line 11

def identify
  "host"
end

#mass_add(data) ⇒ Object

通过 Zabbix API 批量添加模板到主机



50
51
52
53
54
55
56
57
58
59
# File 'lib/zabbix_manager/classes/templates.rb', line 50

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

通过 Zabbix API 批量从主机移除模板



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/zabbix_manager/classes/templates.rb', line 62

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

通过 Zabbix API 批量更新主机的模板



38
39
40
41
42
43
44
45
46
47
# File 'lib/zabbix_manager/classes/templates.rb', line 38

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

#method_nameObject

Zabbix API 中与模板交互的方法名称



6
7
8
# File 'lib/zabbix_manager/classes/templates.rb', line 6

def method_name
  "template"
end