-
Notifications
You must be signed in to change notification settings - Fork 0
/
dupdate.py
executable file
·62 lines (44 loc) · 1.58 KB
/
dupdate.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
import sys
import argparse
import logging
from pyzabbix import ZabbixAPI
#Uncomment for Debugging JSON w json request
#stream = logging.StreamHandler(sys.stdout)
#stream.setLevel(logging.DEBUG)
#log = logging.getLogger('pyzabbix')
#log.addHandler(stream)
#log.setLevel(logging.DEBUG)
parser = argparse.ArgumentParser(description='This is a simple tool to update monitored status of an host')
parser.add_argument('--url', help='URL to the zabbix server',required = True)
parser.add_argument('--user', help='The zabbix api user',required = True)
parser.add_argument('--password', help='The zabbix api password',required = True)
parser.add_argument('--disable', help='Disable monitoring on host, 1 = disabled',required = True)
parser.add_argument('--hostname', help='The zabbix hostname you want to update',required = True)
args = parser.parse_args()
if None == args.url :
print "Error: Missing --url\n\n"
exit(2)
if None == args.user :
print "Error: Missing --user\n\n"
exit(3)
if None == args.password :
print "Error: Missing --password\n\n"
exit(4)
if None == args.disable :
print "Error: Missing --enable\n\n"
exit(4)
if None == args.hostname :
print "Error: Missing --hostname\n\n"
exit(4)
zapi = ZabbixAPI(args.url)
zapi.login(args.user, args.password)
print "Connected to Zabbix API Version %s" % zapi.api_version()
for h in zapi.host.get(output="extend", filter={"host":[args.hostname]}):
print "Updating hostname: " + h['name'] + " - HostId: " + h['hostid']
#print hostname
zapi.host.update(
hostid=h['hostid'],
status=args.disable
)
print "Success !"