Class: ZabbixManager::Graphs
- Defined in:
- lib/zabbix_manager/classes/graphs.rb
Instance Method Summary collapse
-
#get_full_data(data) ⇒ Hash
按名称搜索并获取图形的完整数据。.
-
#get_ids_by_host(data) ⇒ Array
获取指定主机的图形 ID,并可按名称片段进一步过滤。.
-
#get_items(data) ⇒ Hash
获取指定图形包含的图形监控项。.
-
#identify ⇒ String
返回图形对象用于业务识别的字段名。.
-
#identity_filter(data) ⇒ Hash
生成由图形名称和所属模板构成的稳定查询条件。.
-
#method_name ⇒ String
返回图形对象对应的 Zabbix API 方法前缀。.
Methods inherited from Basic
#add, #all, #create, #create_or_update, #create_raw, #default_options, #delete, #delete_raw, #destroy, #dump_by_id, #get, #get_id, #get_or_create, #get_raw, #hash_equals?, #initialize, #key, #keys, #log, #normalize_hash, #parse_keys, #update, #update_raw
Constructor Details
This class inherits a constructor from ZabbixManager::Basic
Instance Method Details
#get_full_data(data) ⇒ Hash
按名称搜索并获取图形的完整数据。
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/zabbix_manager/classes/graphs.rb', line 25 def get_full_data(data) log "[DEBUG] Call get_full_data with parameters: #{data.inspect}" @client.api_request( method: "#{method_name}.get", params: { search: { identify.to_sym => data[identify.to_sym] }, output: "extend" } ) end |
#get_ids_by_host(data) ⇒ Array
获取指定主机的图形 ID,并可按名称片段进一步过滤。
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/zabbix_manager/classes/graphs.rb', line 45 def get_ids_by_host(data) result = @client.api_request( method: "graph.get", params: { filter: { host: data[:host] }, output: "extend" } ) result.filter_map do |graph| num = graph["graphid"] name = graph["name"] filter = data[:filter] num if filter.nil? || name.include?(filter.to_s) end end |
#get_items(data) ⇒ Hash
获取指定图形包含的图形监控项。
71 72 73 74 75 76 77 78 79 |
# File 'lib/zabbix_manager/classes/graphs.rb', line 71 def get_items(data) @client.api_request( method: "graphitem.get", params: { graphids: [data], output: "extend" } ) end |
#identify ⇒ String
返回图形对象用于业务识别的字段名。
15 16 17 |
# File 'lib/zabbix_manager/classes/graphs.rb', line 15 def identify "name" end |
#identity_filter(data) ⇒ Hash
生成由图形名称和所属模板构成的稳定查询条件。
84 85 86 87 |
# File 'lib/zabbix_manager/classes/graphs.rb', line 84 def identity_filter(data) attributes = data.deep_symbolize_keys { name: attributes.fetch(:name), templateid: attributes.fetch(:templateid) } end |
#method_name ⇒ String
返回图形对象对应的 Zabbix API 方法前缀。
8 9 10 |
# File 'lib/zabbix_manager/classes/graphs.rb', line 8 def method_name "graph" end |