-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.rb
60 lines (52 loc) · 1.29 KB
/
example.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
#!/usr/bin/env ruby
#
require 'pit'
require 'zabbixapi'
class ZabbixManager
attr_reader :zabbix
def initialize(user, password)
@zabbix = ZabbixApi.connect(
:url => 'http://zabbix.conbu.net/api_jsonrpc.php',
:user => user,
:password => password,
)
end
def print_version
version = @zabbix.query(
:method => "apiinfo.version",
:params => {}
)
puts version
end
def graphs
graphs = zabbix.graphs.get(output: 'extend', hostids: 10084)
end
def items(graphid)
# items = zabbix.graphs.get_items(graphid)
items = zabbix.items.get(output: 'extend', graphids: graphid)
end
end
def main
config = Pit.get('zabbix',
:require => {
user: 'zabbix username',
password: 'zabbix password',
})
zm = ZabbixManager.new(config[:user], config[:password])
zm.print_version
zm.graphs.each do |graph|
graphname = graph['name']
next unless graphname.include? 'Associations'
next unless graphname.include? 'Total'
graphid = graph['graphid'].to_i
puts '%03d: %s' % [graphid, graphname]
items = zm.items(graphid.to_s)
items.each do |item|
next unless item['name'].include? 'GHz'
puts '%03d: %s' % [item['itemid'].to_i, item['name']]
end
end
end
if __FILE__ == $0 then
main
end