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

1,zabbix-api获取token

时间:2020-05-03 16:58:18      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:nbsp   token   headers   app   eth   request   result   json-rpc   class   

[root@centos7 zabbix-demo]# cat zabbix_base.py 
#! /usr/bin/python3
# -*- coding:utf-8 -*-
import json
import requests

url = http://192.168.0.11/zabbix/api_jsonrpc.php
username = Admin
password = zabbix
header = {"Content-Type": "application/json-rpc"}
    
def zabbix_api_common(data):
    
    dict_to_str = json.dumps(data)
    
    respone = requests.post(url=url,headers=header,data=dict_to_str)
    
    req_str = respone.text
    
    str_to_dict = json.loads(req_str)

    return str_to_dict    

def get_token():

    data = {
        "jsonrpc": "2.0",
        "method": "user.login",
        "params": {
            "user": username,
            "password": password
        },
            "id": 1,
        }
    result = zabbix_api_common(data)
    
    return result[result]    
    

token = get_token()
print(token)

 

1,zabbix-api获取token

标签:nbsp   token   headers   app   eth   request   result   json-rpc   class   

原文地址:https://www.cnblogs.com/k8s-pod/p/12822092.html

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