Class: ZabbixManager::Graphs
- Defined in:
- lib/zabbix_manager/classes/graphs.rb
Instance Method Summary collapse
- #_update(data) ⇒ Object
-
#create_or_update(data) ⇒ Object
通过 Zabbix API 创建或更新 Graph 对象.
-
#get_full_data(data) ⇒ Object
从 Zabbix API 获取完整/扩展的 Graph 数据.
-
#get_ids_by_host(data) ⇒ Object
从 Zabbix API 获取主机的 Graph ids.
-
#get_items(data) ⇒ Object
通过 Zabbix API 获取 Graph Item 对象.
-
#get_or_create(data) ⇒ Object
通过 Zabbix API 获取或创建 Graph 对象.
-
#identify ⇒ Object
用于通过 Zabbix API 标识特定 Graph 对象的 id 字段名称.
-
#method_name ⇒ Object
用于通过 Zabbix API 与 Graphs 交互的方法名称.
Methods inherited from Basic
#add, #all, #create, #default_options, #delete, #destroy, #dump_by_id, #get, #get_id, #get_ids, #get_ids_by_identify, #get_key_ids, #get_key_ids_by_identify, #get_or_create_keys, #get_raw, #hash_equals?, #initialize, #key, #keys, #log, #merge_hashes, #normalize_array, #normalize_hash, #parse_keys, #request_raw, #symbolize_keys, #update
Constructor Details
This class inherits a constructor from ZabbixManager::Basic
Instance Method Details
#_update(data) ⇒ Object
77 78 79 80 |
# File 'lib/zabbix_manager/classes/graphs.rb', line 77 def _update(data) data.delete(:name) update(data) end |
#create_or_update(data) ⇒ Object
通过 Zabbix API 创建或更新 Graph 对象
72 73 74 75 |
# File 'lib/zabbix_manager/classes/graphs.rb', line 72 def create_or_update(data) graphid = get_id(name: data[:name], templateid: data[:templateid]) graphid ? _update(data.merge(graphid: graphid)) : create(data) end |
#get_full_data(data) ⇒ Object
从 Zabbix API 获取完整/扩展的 Graph 数据
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/zabbix_manager/classes/graphs.rb', line 16 def get_full_data(data) log "[DEBUG] 使用参数调用 get_full_data: #{data.inspect}" get_raw( { search: { identify.to_sym => data[identify.to_sym] }, output: "extend" } ) end |
#get_ids_by_host(data) ⇒ Object
从 Zabbix API 获取主机的 Graph ids
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/zabbix_manager/classes/graphs.rb', line 30 def get_ids_by_host(data) result = get_raw( { filter: { host: data[:host] }, output: "extend" } ) result.filter_map do |graph| graphid = graph["graphid"] name = graph["name"] filter = data[:filter] graphid if filter.nil? || name.match?(/#{filter}/) end end |
#get_items(data) ⇒ Object
通过 Zabbix API 获取 Graph Item 对象
50 51 52 53 54 55 56 57 58 |
# File 'lib/zabbix_manager/classes/graphs.rb', line 50 def get_items(data) @client.api_request( method: "graphitem.get", params: { graphids: [data], output: "extend" } ) end |
#get_or_create(data) ⇒ Object
通过 Zabbix API 获取或创建 Graph 对象
61 62 63 64 65 66 67 68 69 |
# File 'lib/zabbix_manager/classes/graphs.rb', line 61 def get_or_create(data) log "[DEBUG] 使用参数调用 get_or_create: #{data.inspect}" unless (id = get_id(name: data[:name], templateid: data[:templateid])) id = create(data) end id end |
#identify ⇒ Object
用于通过 Zabbix API 标识特定 Graph 对象的 id 字段名称
11 12 13 |
# File 'lib/zabbix_manager/classes/graphs.rb', line 11 def identify "name" end |
#method_name ⇒ Object
用于通过 Zabbix API 与 Graphs 交互的方法名称
6 7 8 |
# File 'lib/zabbix_manager/classes/graphs.rb', line 6 def method_name "graph" end |