forked from janssenlima/api-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto-add-hosts.py
46 lines (36 loc) · 1005 Bytes
/
auto-add-hosts.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
42
43
44
45
46
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#author: Janssen dos Reis Lima
from pyzabbix import ZabbixAPI
import csv
from progressbar import ProgressBar, Percentage, ETA, ReverseBar, RotatingMarker, Timer
zapi = ZabbixAPI("http://localhost/zabbix")
zapi.login(user="Admin", password="zabbix")
arq = csv.reader(open('/tmp/hosts.csv'))
linhas = sum(1 for linha in arq)
f = csv.reader(open('/tmp/hosts.csv'), delimiter=';')
bar = ProgressBar(maxval=linhas,widgets=[Percentage(), ReverseBar(), ETA(), RotatingMarker(), Timer()]).start()
i = 0
for [hostname,ip] in f:
hostcriado = zapi.host.create(
host= hostname,
status= 1,
interfaces=[{
"type": 1,
"main": "1",
"useip": 1,
"ip": ip,
"dns": "",
"port": 10050
}],
groups=[{
"groupid": 2
}],
templates=[{
"templateid": 10001
}]
)
i += 1
bar.update(i)
bar.finish
print " "