zoukankan      html  css  js  c++  java
  • zabbix-api学习之路--auth获取

    zabbix-api学习之路--auth获取

    python版本:2.7
    zabbix版本:3.4
    

    api

    网站:https://www.zabbix.com/documentation/3.4/zh/manual/api/reference/user/login

    一 : user.login

    import json
    import urllib2
    url = "http://x.x.x.x(ip)/api_jsonrpc.php"
    header = {"Content-Type": "application/json"}
    user = "Admin"
    password = "zabbix"
    def get_auth():
        data= json.dumps(
            {
                "jsonrpc": "2.0",
                "method": "user.login",
                "params": {
                    "user": user,
                    "password": password,
    
                },
                "id":0
            })
        request = urllib2.Request(url,data) #调用urllib2向服务器发送get请求
        for key in header:
            request.add_header(key,header[key]) #添加请求头
        result = urllib2.urlopen(request)
        response = json.loads(result.read()) #接收返回的json数据
        result.close()
        print response  #输出错误
        return response['result'] #提取auth
    a=get_auth()
    print a
    

    方法一: “userData” : true

    • 验证并返回有关用户的其他信息。

    • 请求:

      { 
        “jsonrpc” : “2.0” ,
        “method” : “user.login” ,
        “params” : { 
            “user” : “Admin” ,
            “password” : “zabbix” ,
            “userData” : true 
        } ,
        “id” : 1 
    }
    
    • 响应
    {
        "jsonrpc": "2.0",
        "result": {
            "userid": "1",
            "alias": "Admin",
            "name": "Zabbix",
            "surname": "Administrator",
            "url": "",
            "autologin": "1",
            "autologout": "0",
            "lang": "ru_RU",
            "refresh": "0",
            "type": "3",
            "theme": "default",
            "attempt_failed": "0",
            "attempt_ip": "127.0.0.1",
            "attempt_clock": "1355919038",
            "rows_per_page": "50",
            "debug_mode": true,
            "userip": "127.0.0.1",
            "sessionid": "5b56eee8be445e98f0bd42b435736e42",
            "gui_access": "0"
        },
        "id": 1
    }
    
  • 相关阅读:
    关于ARMv8指令的几个问题
    cocos2d-x2.2.3 Layer分析
    unity3D iTween的使用
    lucene索引库的增删改查操作
    【剑指offer】数值的整数次方
    Integer to Roman
    HTML标签之marquee
    Django练习——TodoList
    html5式程序员表白
    00085_异常
  • 原文地址:https://www.cnblogs.com/zdoubly/p/9777015.html
Copyright © 2011-2022 走看看