用Python编写zabbix的API认证接口

#!/usr/bin/env python2.7 
#coding=utf-8
import json
import urllib2
#url请求地址
url = "http://192.168.0.100/zabbix/api_jsonrpc.php"
header = {"Content-Type": "application/json"}
#认证账号以及密码
data = json.dumps(
{
        "jsonrpc": "2.0",
        "method": "user.login",
        "params":{
        "user": "admin",
        "password": "zabbix",
},
"id": 0
})
#建立请求项目
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 "Auth Failed,Please Check Your Name And Password",e.code
else:
        response = json.loads(result.read())
        result.close()
        print "Auth Successful.The Auth ID Is:",response['result']

 

发表回复

Your email address will not be published.

名字 *
电子邮件 *
站点