Class: ZabbixApi::Usermacros
- Defined in:
- lib/zabbixapi/classes/usermacros.rb
Instance Method Summary collapse
-
#create(data) ⇒ Integer, Boolean
Create new User macro object using Zabbix API (with defaults).
-
#create_global(data) ⇒ Integer, Boolean
Create new Global macro object using Zabbix API (with defaults).
-
#create_or_update(data) ⇒ Integer
Create or update User macro object using Zabbix API.
-
#create_or_update_global(data) ⇒ Integer
Create or update Global macro object using Zabbix API.
-
#delete(data) ⇒ Integer, Boolean
Delete User macro object using Zabbix API.
-
#delete_global(data) ⇒ Integer, Boolean
Delete Global macro object using Zabbix API.
-
#get_full_data(data) ⇒ Hash
Get full/extended User macro data from Zabbix API.
-
#get_full_data_global(data) ⇒ Hash
Get full/extended Global macro data from Zabbix API.
-
#get_id(data) ⇒ Integer
Get User macro object id from Zabbix API based on provided data.
-
#get_id_global(data) ⇒ Integer
Get Global macro object id from Zabbix API based on provided data.
-
#get_or_create(data) ⇒ Integer
Get or Create User macro object using Zabbix API.
-
#get_or_create_global(data) ⇒ Integer
Get or Create Global macro object using Zabbix API.
-
#indentify ⇒ String
The id field name used for identifying specific User macro objects via Zabbix API.
-
#method_name ⇒ String
The method name used for interacting with User macros via Zabbix API.
-
#update(data) ⇒ Integer, Boolean
Update User macro object using Zabbix API.
-
#update_global(data) ⇒ Integer, Boolean
Update Global macro object using Zabbix API.
Methods inherited from Basic
#add, #all, #default_options, #destroy, #dump_by_id, #get, #get_raw, #hash_equals?, #initialize, #key, #keys, #log, #merge_params, #normalize_array, #normalize_hash, #parse_keys, #symbolize_keys
Constructor Details
This class inherits a constructor from ZabbixApi::Basic
Instance Method Details
#create(data) ⇒ Integer, Boolean
Create new User macro object using Zabbix API (with defaults)
88 89 90 |
# File 'lib/zabbixapi/classes/usermacros.rb', line 88 def create(data) request(data, 'usermacro.create', 'hostmacroids') end |
#create_global(data) ⇒ Integer, Boolean
Create new Global macro object using Zabbix API (with defaults)
99 100 101 |
# File 'lib/zabbixapi/classes/usermacros.rb', line 99 def create_global(data) request(data, 'usermacro.createglobal', 'globalmacroids') end |
#create_or_update(data) ⇒ Integer
Create or update User macro object using Zabbix API
187 188 189 190 |
# File 'lib/zabbixapi/classes/usermacros.rb', line 187 def create_or_update(data) hostmacroid = get_id(macro: data[:macro], hostid: data[:hostid]) hostmacroid ? update(data.merge(hostmacroid: hostmacroid)) : create(data) end |
#create_or_update_global(data) ⇒ Integer
Create or update Global macro object using Zabbix API
198 199 200 201 |
# File 'lib/zabbixapi/classes/usermacros.rb', line 198 def create_or_update_global(data) globalmacroid = get_id_global(macro: data[:macro], hostid: data[:hostid]) globalmacroid ? update_global(data.merge(globalmacroid: globalmacroid)) : create_global(data) end |
#delete(data) ⇒ Integer, Boolean
Delete User macro object using Zabbix API
110 111 112 113 |
# File 'lib/zabbixapi/classes/usermacros.rb', line 110 def delete(data) data_delete = [data] request(data_delete, 'usermacro.delete', 'hostmacroids') end |
#delete_global(data) ⇒ Integer, Boolean
Delete Global macro object using Zabbix API
122 123 124 125 |
# File 'lib/zabbixapi/classes/usermacros.rb', line 122 def delete_global(data) data_delete = [data] request(data_delete, 'usermacro.deleteglobal', 'globalmacroids') end |
#get_full_data(data) ⇒ Hash
Get full/extended User macro data from Zabbix API
63 64 65 66 67 |
# File 'lib/zabbixapi/classes/usermacros.rb', line 63 def get_full_data(data) log "[DEBUG] Call get_full_data with parameters: #{data.inspect}" request(data, 'usermacro.get', 'hostmacroid') end |
#get_full_data_global(data) ⇒ Hash
Get full/extended Global macro data from Zabbix API
75 76 77 78 79 |
# File 'lib/zabbixapi/classes/usermacros.rb', line 75 def get_full_data_global(data) log "[DEBUG] Call get_full_data_global with parameters: #{data.inspect}" request(data, 'usermacro.get', 'globalmacroid') end |
#get_id(data) ⇒ Integer
Get User macro object id from Zabbix API based on provided data
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/zabbixapi/classes/usermacros.rb', line 23 def get_id(data) log "[DEBUG] Call get_id with parameters: #{data.inspect}" # symbolize keys if the user used string keys instead of symbols data = symbolize_keys(data) if data.key?(indentify) # raise an error if indentify name was not supplied name = data[indentify.to_sym] raise ApiError.new("#{indentify} not supplied in call to get_id") if name.nil? result = request(data, 'usermacro.get', 'hostmacroid') !result.empty? && result[0].key?('hostmacroid') ? result[0]['hostmacroid'].to_i : nil end |
#get_id_global(data) ⇒ Integer
Get Global macro object id from Zabbix API based on provided data
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/zabbixapi/classes/usermacros.rb', line 43 def get_id_global(data) log "[DEBUG] Call get_id_global with parameters: #{data.inspect}" # symbolize keys if the user used string keys instead of symbols data = symbolize_keys(data) if data.key?(indentify) # raise an error if indentify name was not supplied name = data[indentify.to_sym] raise ApiError.new("#{indentify} not supplied in call to get_id_global") if name.nil? result = request(data, 'usermacro.get', 'globalmacroid') !result.empty? && result[0].key?('globalmacroid') ? result[0]['globalmacroid'].to_i : nil end |
#get_or_create(data) ⇒ Integer
Get or Create User macro object using Zabbix API
157 158 159 160 161 162 163 164 |
# File 'lib/zabbixapi/classes/usermacros.rb', line 157 def get_or_create(data) log "[DEBUG] Call get_or_create with parameters: #{data.inspect}" unless (id = get_id(macro: data[:macro], hostid: data[:hostid])) id = create(data) end id end |
#get_or_create_global(data) ⇒ Integer
Get or Create Global macro object using Zabbix API
172 173 174 175 176 177 178 179 |
# File 'lib/zabbixapi/classes/usermacros.rb', line 172 def get_or_create_global(data) log "[DEBUG] Call get_or_create_global with parameters: #{data.inspect}" unless (id = get_id_global(macro: data[:macro], hostid: data[:hostid])) id = create_global(data) end id end |
#indentify ⇒ String
The id field name used for identifying specific User macro objects via Zabbix API
6 7 8 |
# File 'lib/zabbixapi/classes/usermacros.rb', line 6 def indentify 'macro' end |
#method_name ⇒ String
The method name used for interacting with User macros via Zabbix API
13 14 15 |
# File 'lib/zabbixapi/classes/usermacros.rb', line 13 def method_name 'usermacro' end |
#update(data) ⇒ Integer, Boolean
Update User macro object using Zabbix API
135 136 137 |
# File 'lib/zabbixapi/classes/usermacros.rb', line 135 def update(data) request(data, 'usermacro.update', 'hostmacroids') end |
#update_global(data) ⇒ Integer, Boolean
Update Global macro object using Zabbix API
147 148 149 |
# File 'lib/zabbixapi/classes/usermacros.rb', line 147 def update_global(data) request(data, 'usermacro.updateglobal', 'globalmacroids') end |