Class: ZabbixManager::Usermacros
- Defined in:
- lib/zabbix_manager/classes/usermacros.rb
Instance Method Summary collapse
-
#create(data) ⇒ Integer?
创建主机宏并返回首个新建宏的 ID。.
-
#create_global(data) ⇒ Integer?
创建全局宏并返回首个新建宏的 ID。.
-
#create_or_update(data) ⇒ Integer
按主机和宏名创建或更新主机宏。.
-
#create_or_update_global(data) ⇒ Integer
按宏名创建或更新全局宏。.
-
#delete(data) ⇒ Integer?
删除指定主机宏并返回首个已删除宏的 ID。.
-
#delete_global(data) ⇒ Integer?
删除指定全局宏并返回首个已删除宏的 ID。.
-
#get_full_data(data) ⇒ Array<Hash>
获取匹配主机宏的完整数据。.
-
#get_full_data_global(data) ⇒ Array<Hash>
获取匹配全局宏的完整数据。.
-
#get_id(data) ⇒ Integer?
按宏名称及主机条件查询主机宏 ID。.
-
#get_id_global(data) ⇒ Integer?
按宏名称查询全局宏 ID。.
-
#get_or_create(data) ⇒ Integer
按主机和宏名获取主机宏,不存在时创建。.
-
#get_or_create_global(data) ⇒ Integer
按宏名获取全局宏,不存在时创建。.
-
#identify ⇒ String
返回用于唯一识别用户宏的业务字段名。.
-
#method_name ⇒ String
返回 Zabbix API 中用户宏对象的方法名前缀。.
-
#update(data) ⇒ Integer?
更新主机宏并返回首个已更新宏的 ID。.
-
#update_global(data) ⇒ Integer?
更新全局宏并返回首个已更新宏的 ID。.
Methods inherited from Basic
#add, #all, #create_raw, #default_options, #delete_raw, #destroy, #dump_by_id, #get, #get_raw, #hash_equals?, #identity_filter, #initialize, #key, #keys, #log, #normalize_hash, #parse_keys, #update_raw
Constructor Details
This class inherits a constructor from ZabbixManager::Basic
Instance Method Details
#create(data) ⇒ Integer?
创建主机宏并返回首个新建宏的 ID。
89 90 91 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 89 def create(data) request(data, "usermacro.create", "hostmacroids") end |
#create_global(data) ⇒ Integer?
创建全局宏并返回首个新建宏的 ID。
99 100 101 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 99 def create_global(data) request(data, "usermacro.createglobal", "globalmacroids") end |
#create_or_update(data) ⇒ Integer
按主机和宏名创建或更新主机宏。
181 182 183 184 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 181 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
按宏名创建或更新全局宏。
192 193 194 195 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 192 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?
删除指定主机宏并返回首个已删除宏的 ID。
109 110 111 112 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 109 def delete(data) data_delete = [data] request(data_delete, "usermacro.delete", "hostmacroids") end |
#delete_global(data) ⇒ Integer?
删除指定全局宏并返回首个已删除宏的 ID。
120 121 122 123 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 120 def delete_global(data) data_delete = [data] request(data_delete, "usermacro.deleteglobal", "globalmacroids") end |
#get_full_data(data) ⇒ Array<Hash>
获取匹配主机宏的完整数据。
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) ⇒ Array<Hash>
获取匹配全局宏的完整数据。
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?
按宏名称及主机条件查询主机宏 ID。
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}" # 兼容字符串键输入。 data = data.deep_symbolize_keys if data.key?(identify) # 标识字段缺失时拒绝继续查询。 name = data[identify.to_sym] raise Invalid, "#{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?
按宏名称查询全局宏 ID。
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}" # 兼容字符串键输入。 data = data.deep_symbolize_keys if data.key?(identify) # 标识字段缺失时拒绝继续查询。 name = data[identify.to_sym] raise Invalid, "#{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
按主机和宏名获取主机宏,不存在时创建。
151 152 153 154 155 156 157 158 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 151 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
按宏名获取全局宏,不存在时创建。
166 167 168 169 170 171 172 173 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 166 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
返回用于唯一识别用户宏的业务字段名。
8 9 10 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 8 def identify "macro" end |
#method_name ⇒ String
返回 Zabbix API 中用户宏对象的方法名前缀。
15 16 17 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 15 def method_name "usermacro" end |
#update(data) ⇒ Integer?
更新主机宏并返回首个已更新宏的 ID。
131 132 133 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 131 def update(data) request(data, "usermacro.update", "hostmacroids") end |
#update_global(data) ⇒ Integer?
更新全局宏并返回首个已更新宏的 ID。
141 142 143 |
# File 'lib/zabbix_manager/classes/usermacros.rb', line 141 def update_global(data) request(data, "usermacro.updateglobal", "globalmacroids") end |