码迷,mamicode.com
首页 > Windows程序 > 详细

使用Zabbix的API登陆

时间:2016-03-04 02:05:57      阅读:257      评论:0      收藏:0      [点我收藏+]

标签: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的API登陆

标签:zabbix

原文地址:http://xiaofengmo.blog.51cto.com/10116365/1747336

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!