Class: ZabbixManager::Proxies
- Defined in:
- lib/zabbix_manager/classes/proxies.rb
Instance Method Summary collapse
-
#delete(data) ⇒ Integer?
通过 Zabbix API 删除指定代理,并返回首个已删除代理的 ID。.
-
#get_proxy_id(proxy) ⇒ String?
按代理名称查询唯一代理 ID,空名称返回 nil,重名时拒绝选择。.
-
#identify ⇒ String
返回用于唯一识别代理对象的字段名。.
-
#isreadable(data) ⇒ Boolean
检查当前凭证是否可读取指定代理。.
-
#iswritable(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?
通过 Zabbix API 删除指定代理,并返回首个已删除代理的 ID。
25 26 27 28 |
# File 'lib/zabbix_manager/classes/proxies.rb', line 25 def delete(data) result = @client.api_request(method: "proxy.delete", params: data) result.empty? ? nil : result["proxyids"][0].to_i end |
#get_proxy_id(proxy) ⇒ String?
按代理名称查询唯一代理 ID,空名称返回 nil,重名时拒绝选择。
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/zabbix_manager/classes/proxies.rb', line 54 def get_proxy_id(proxy) return nil if proxy.blank? # 请求后端接口,只支持单个代理节点 result = @client.api_request( method: "proxy.get", params: { output: %w[proxyid host], filter: { host: proxy } } ) raise Conflict, "proxy lookup is ambiguous for #{proxy}" if result.length > 1 result.first&.fetch("proxyid", nil) end |
#identify ⇒ String
返回用于唯一识别代理对象的字段名。
15 16 17 |
# File 'lib/zabbix_manager/classes/proxies.rb', line 15 def identify "host" end |
#isreadable(data) ⇒ Boolean
检查当前凭证是否可读取指定代理。
36 37 38 |
# File 'lib/zabbix_manager/classes/proxies.rb', line 36 def isreadable(data) @client.api_request(method: "proxy.isreadable", params: data) end |
#iswritable(data) ⇒ Boolean
检查当前凭证是否可写入指定代理。
46 47 48 |
# File 'lib/zabbix_manager/classes/proxies.rb', line 46 def iswritable(data) @client.api_request(method: "proxy.iswritable", params: data) end |
#method_name ⇒ String
返回 Zabbix API 中代理对象的方法名前缀。
8 9 10 |
# File 'lib/zabbix_manager/classes/proxies.rb', line 8 def method_name "proxy" end |