Class: ZabbixApi::Templates
- Defined in:
- lib/zabbixapi/classes/templates.rb
Instance Method Summary collapse
-
#delete(data) ⇒ Integer
Delete Template object using Zabbix API.
-
#get_ids_by_host(data) ⇒ Array
Get Template ids for Host from Zabbix API.
-
#get_or_create(data) ⇒ Integer
Get or Create Template object using Zabbix API.
-
#indentify ⇒ String
The id field name used for identifying specific Template objects via Zabbix API.
-
#mass_add(data) ⇒ Boolean
Mass add Templates to Hosts using Zabbix API.
-
#mass_remove(data) ⇒ Boolean
Mass remove Templates to Hosts using Zabbix API.
-
#mass_update(data) ⇒ Boolean
Mass update Templates for Hosts using Zabbix API.
-
#method_name ⇒ String
The method name used for interacting with Templates via Zabbix API.
Methods inherited from Basic
#add, #all, #create, #create_or_update, #default_options, #destroy, #dump_by_id, #get, #get_full_data, #get_id, #get_raw, #hash_equals?, #initialize, #key, #keys, #log, #merge_params, #normalize_array, #normalize_hash, #parse_keys, #symbolize_keys, #update
Constructor Details
This class inherits a constructor from ZabbixApi::Basic
Instance Method Details
#delete(data) ⇒ Integer
Delete Template object using Zabbix API
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) ⇒ Array
Get Template ids for Host from Zabbix API
34 35 36 37 38 |
# File 'lib/zabbixapi/classes/templates.rb', line 34 def get_ids_by_host(data) @client.api_request(method: 'template.get', params: data).map do |tmpl| tmpl['templateid'] end end |
#get_or_create(data) ⇒ Integer
Get or Create Template object using Zabbix API
46 47 48 49 50 51 |
# File 'lib/zabbixapi/classes/templates.rb', line 46 def get_or_create(data) unless (templateid = get_id(host: data[:host])) templateid = create(data) end templateid end |
#indentify ⇒ String
The id field name used for identifying specific Template objects via Zabbix API
13 14 15 |
# File 'lib/zabbixapi/classes/templates.rb', line 13 def indentify 'host' end |
#mass_add(data) ⇒ Boolean
Mass add Templates to Hosts using Zabbix API
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/zabbixapi/classes/templates.rb', line 76 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
Mass remove Templates to Hosts using Zabbix API
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/zabbixapi/classes/templates.rb', line 93 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
Mass update Templates for Hosts using Zabbix API
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/zabbixapi/classes/templates.rb', line 59 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
The method name used for interacting with Templates via Zabbix API
6 7 8 |
# File 'lib/zabbixapi/classes/templates.rb', line 6 def method_name 'template' end |