标签:zabbix
#!/usr/bin/python
import urllib2
import json
def login(username,password,url,data):
request = urllib2.Request(url,data)
for key in header:
request.add_header(key,header[key])
try:
result = urllib2.urlopen(request)
except URLError as e:
print "url error: ", e.code
else:
response = json.loads(result.read())
result.close()
print "login is OK your id:",response[‘result‘]
if __name__ == ‘__main__‘:
username = ‘zabbix用户名‘
password = ‘zabbix密码‘
url = ‘http://你的zabbix服务器地址 /api_jsonrpc.php‘
header = {"Content-Type":"application/json"}
data = json.dumps(
{
"jsonrpc":"2.0",
"method":"user.login",
"params":{
"user":username,
"password":password
},
"id":0
})
login(username,password,url,data)
本文出自 “小莫” 博客,请务必保留此出处http://xiaofengmo.blog.51cto.com/10116365/1747336
标签:zabbix
原文地址:http://xiaofengmo.blog.51cto.com/10116365/1747336