zabbix api
- zabbix具有丰富的api功能
- 可通过api添加主机组、主机、获取监控数据
- 使用python操作zabbix
api使用教程
https://www.zabbix.com/documentation/4.0/zh/manual/api
登录认证说明zabbix_base.py
import json
from urllib import request
def zabbix_api_common(data):
zabbix_url="http://192.168.3.111/zabbix/api_jsonrpc.php"
zabbix_header={"Content-Type":"application/json"}
data = json.dumps(data).encode("utf-8")
req = request.Request(zabbix_url, headers=zabbix_header, data=data)
result = request.urlopen(req).read()
return json.loads(result)
def get_token():
zabbix_user="Admin"
zabbix_pass="123456"
data={
"jsonrpc":"2.0",
"method":"user.login",
"params":{
"user":zabbix_user,
"password":zabbix_pass
},
"id":0
}
result=zabbix_api_common(data)
# 登录结果说明:
# b'{"jsonrpc":"2.0","result":"3fa39886a18f81254e1bf4793a8da1b4","id":0}'
# result的值为token,可据此创建主机等操作
return result['result']
if __name__=="__main__":
token=get_token()
print(token)