33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/zabbix_graph.rb', line 33
def select_and_open
hosts = PecoSelector.select_from(@all_hosts.sort_by do |h|
h['host']
end.map do |h|
[h['host'], h]
end)
items = zbx.client.api_request(
method: 'item.get',
params: {
hostids: hosts.map {|h| h['hostid'] },
sortfield: 'name',
sortorder: 'ASC',
},
)
selected = PecoSelector.select_from(items.map do |i|
[i['name'], i['key_']]
end.uniq.map do |name, key|
["#{name} (#{key})", [name, key]]
end)
selected_items = items.select do |i|
selected.any? do |name, key|
i['name'] == name && i['key_'] == key
end
end
if @options[:host_graph]
open_host_graph(selected_items)
elsif @options[:item_graph]
open_item_graph(selected_items)
else
open_history(selected_items)
end
end
|