-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathget_hostgroups.py
41 lines (31 loc) · 898 Bytes
/
get_hostgroups.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
41
from pyzabbix import ZabbixAPI
import pandas as pd
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
hgname=[]
hgid=[]
hi=[]
hh=[]
group = []
host=[]
url=str(raw_input("Digite a URL: "))
user=str(raw_input("Digite o User: "))
password=str(raw_input("Digite a senha: "))
zapi = ZabbixAPI(url=url, user=user, password=password)
print(zapi.api_version())
for x in zapi.host.get(output='extend'):
hi.append(x['hostid'])
hh.append(x['host'])
for linha in zapi.hostgroup.get(output='extend'):
hgid.append(linha['groupid'])
#print linha['name']
for i in hh:
#print i
for y in zapi.host.get(selectGroups='extend', filter={'host':i}):
tam = len(y['groups'])
for z in range(0, tam):
host.append(i)
group.append(y['groups'][z]['name'])
data=pd.DataFrame({'Hostname':host,'Host Group':group})
data.to_csv('zabbix_groups.csv',index=False)