Class: ZabbixManager::Templates
- Defined in:
- lib/zabbix_manager/classes/templates.rb
Instance Method Summary collapse
-
#delete(data) ⇒ Integer?
删除指定模板并返回首个已删除模板的 ID。.
-
#get_ids_by_host(data) ⇒ Array<String>
根据查询条件获取模板 ID 列表。.
-
#get_template_ids(data) ⇒ Array<Hash>?
按模板技术名称查询,并返回可直接用于主机或模板更新的引用对象。.
-
#identify ⇒ String
返回用于唯一识别模板的业务字段名。.
-
#mass_add(data) ⇒ Boolean
批量为主机添加模板关联。.
-
#mass_remove(data) ⇒ Boolean
批量移除主机的模板或主机组关联。.
-
#mass_update(data) ⇒ Boolean
批量更新主机与模板的关联关系。.
-
#method_name ⇒ String
返回 Zabbix API 中模板对象的方法名前缀。.
Methods inherited from Basic
#add, #all, #create, #create_or_update, #create_raw, #default_options, #delete_raw, #destroy, #dump_by_id, #get, #get_full_data, #get_id, #get_or_create, #get_raw, #hash_equals?, #identity_filter, #initialize, #key, #keys, #log, #normalize_hash, #parse_keys, #update, #update_raw
Constructor Details
This class inherits a constructor from ZabbixManager::Basic
Instance Method Details
#delete(data) ⇒ Integer?
删除指定模板并返回首个已删除模板的 ID。
25 26 27 28 |
# File 'lib/zabbix_manager/classes/templates.rb', line 25 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) ⇒ Array<String>
根据查询条件获取模板 ID 列表。
36 37 38 39 40 |
# File 'lib/zabbix_manager/classes/templates.rb', line 36 def get_ids_by_host(data) @client.api_request(method: "template.get", params: data).map do |tmpl| tmpl["templateid"] end end |
#get_template_ids(data) ⇒ Array<Hash>?
按模板技术名称查询,并返回可直接用于主机或模板更新的引用对象。
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/zabbix_manager/classes/templates.rb', line 99 def get_template_ids(data) result = @client.api_request( method: "template.get", params: { output: "extend", filter: { host: Array(data) } } ).map { |template| { templateid: template.fetch("templateid") } } result.presence end |
#identify ⇒ String
返回用于唯一识别模板的业务字段名。
15 16 17 |
# File 'lib/zabbix_manager/classes/templates.rb', line 15 def identify "host" end |
#mass_add(data) ⇒ Boolean
批量为主机添加模板关联。
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/zabbix_manager/classes/templates.rb', line 65 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) ⇒ Boolean
批量移除主机的模板或主机组关联。
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/zabbix_manager/classes/templates.rb', line 82 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) ⇒ Boolean
批量更新主机与模板的关联关系。
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/zabbix_manager/classes/templates.rb', line 48 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_name ⇒ String
返回 Zabbix API 中模板对象的方法名前缀。
8 9 10 |
# File 'lib/zabbix_manager/classes/templates.rb', line 8 def method_name "template" end |