forked from wenhuwang/Work_Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_host.py
41 lines (41 loc) · 988 Bytes
/
update_host.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
#!/usr/bin/env python2.7
#coding=utf-8
import json
import urllib2
#xiaorui.cc
url = "http://10.0.99.199/zabbix/api_jsonrpc.php"
header = {"Content-Type": "application/json"}
# request json
data = json.dumps(
{
"jsonrpc":"2.0",
"method":"host.update",
"params":{
"hostid": "10134","templates_clear":[
{
"templateid": "10122"
}
]
},
"auth":"ac2828ac1ffb8f057fb74da5a30d5c85",
"id":1,
}
)
# create request object
request = urllib2.Request(url,data)
for key in header:
request.add_header(key,header[key])
# get host list
try:
result = urllib2.urlopen(request)
except URLError as e:
if hasattr(e, 'reason'):
print 'We failed to reach a server.'
print 'Reason: ', e.reason
elif hasattr(e, 'code'):
print 'The server could not fulfill the request.'
print 'Error code: ', e.code
else:
response = json.loads(result.read())
result.close()
print 'ok'