Class: ZabbixManager::Usermacros
- Defined in:
- lib/zabbix_manager/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.
-
#identify ⇒ 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, #create_raw, #default_options, #delete_raw, #destroy, #dump_by_id, #get, #get_hostgroup_ids, #get_or_create_hostgroups, #get_raw, #hash_equals?, #initialize, #key, #keys, #log, #merge_params, #mojo_update, #normalize_array, #normalize_hash, #parse_keys, #symbolize_keys, #update_raw
Constructor Details
This class inherits a constructor from ZabbixManager::Basic
Instance Method Details
#create(data) ⇒ Integer, Boolean
Create new User macro object using Zabbix API (with defaults)
90 91 92 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 90 def create(data) request(data, "usermacro.create", "hostmacroids") end |
#create_global(data) ⇒ Integer, Boolean
Create new Global macro object using Zabbix API (with defaults)
101 102 103 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 101 def create_global(data) request(data, "usermacro.createglobal", "globalmacroids") end |
#create_or_update(data) ⇒ Integer
Create or update User macro object using Zabbix API
189 190 191 192 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 189 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
200 201 202 203 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 200 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
112 113 114 115 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 112 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
124 125 126 127 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 124 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
65 66 67 68 69 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 65 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
77 78 79 80 81 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 77 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
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 25 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?(identify) # raise an error if identify name was not supplied name = data[identify.to_sym] raise ManagerError, "#{identify} 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
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 45 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?(identify) # raise an error if identify name was not supplied name = data[identify.to_sym] raise ManagerError, "#{identify} 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
159 160 161 162 163 164 165 166 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 159 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
174 175 176 177 178 179 180 181 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 174 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 |
#identify ⇒ String
The id field name used for identifying specific User macro objects via Zabbix API
8 9 10 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 8 def identify "macro" end |
#method_name ⇒ String
The method name used for interacting with User macros via Zabbix API
15 16 17 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 15 def method_name "usermacro" end |
#update(data) ⇒ Integer, Boolean
Update User macro object using Zabbix API
137 138 139 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 137 def update(data) request(data, "usermacro.update", "hostmacroids") end |
#update_global(data) ⇒ Integer, Boolean
Update Global macro object using Zabbix API
149 150 151 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 149 def update_global(data) request(data, "usermacro.updateglobal", "globalmacroids") end |