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
}

转载于:https://www.cnblogs.com/zdoubly/p/9777015.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值