forked from lusoal/Zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_templates.py
39 lines (28 loc) · 914 Bytes
/
get_templates.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
from pyzabbix import ZabbixAPI
import pandas as pd
#Criar Classe para instanciar a API do Zabbix
hostname=[]
hostid=[]
templates=[]
h=[]
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())
#colocar em lista hostname
for x in zapi.host.get(output="extend"):
hostname.append(x['host'])
hostid.append(x['hostid'])
for linha in hostname:
for y in zapi.host.get(selectParentTemplates={'parentTemplates':'name'},filter={'host':linha}):
tam = (len(y['parentTemplates']))
if tam == 0:
h.append(linha)
templates.append('Sem Templates')
else:
for z in range(0, tam):
h.append(linha)
templates.append(y['parentTemplates'][z]['name'])
data=pd.DataFrame({'Hostname':h,'Template':templates})
data.to_csv('zabbix_templates.csv',index=False)