1,zabbix-api获取token

2021-03-07 19:27

阅读:432

标签: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


评论


亲,登录后才可以留言!