-
Notifications
You must be signed in to change notification settings - Fork 4
/
getHostProxy.py
executable file
·40 lines (29 loc) · 1.12 KB
/
getHostProxy.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Print host and proxy dependancies:
# ./getHostProxy.py
HostId: 10084 - Host: sample-host | Proxy ID: 0 - Proxy: NOPROXY
HostId: 13981 - Host: another-one | Proxy ID: 10255 - Proxy: proxy01
HostId: 13982 - Host: second-test | Proxy ID: 10255 - Proxy: proxy01
HostId: 13983 - Host: the-lastone | Proxy ID: 10256 - Proxy: proxy02
"""
from zabbix.api import ZabbixAPI
import sys
zabbixServer = 'http://yourserver/zabbix/'
zabbixUser = 'someuser'
zabbixPass = 'somepass'
zapi = ZabbixAPI(url=zabbixServer, user=zabbixUser, password=zabbixPass)
proxyes = {}
proxyes['0'] = 'NOPROXY'
for proxy in zapi.proxy.get():
proxyes[proxy['proxyid']] = proxy['host']
if (sys.argv[1:]):
# Filter based on the cmdline argument
f = {'host': sys.argv[1:]}
hosts = zapi.host.get(filter=f, output=['hostids', 'host', 'proxy_hostid'])
else:
hosts = zapi.host.get(output=['hostids', 'host', 'proxy_hostid'])
for host in hosts:
prx = host['proxy_hostid']
print "HostId: {} - Host: {} | Proxy ID: {} - Proxy: {}".format(host['hostid'], host['host'], host['proxy_hostid'], proxyes[prx])