1,zabbix-api获取token
2021-03-07 19:27
标签:nbsp token headers app eth request result json-rpc class 1,zabbix-api获取token 标签:nbsp token headers app eth request result json-rpc class 原文地址:https://www.cnblogs.com/k8s-pod/p/12822092.html[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)
上一篇:windows中添加定时任务
文章标题:1,zabbix-api获取token
文章链接:http://soscw.com/index.php/essay/61466.html