zabbix API笔记
python简单demo
输出id为111主机的主机群组信息
import requests
import json
request_headers = {"Content-Type": "application/json"}
zabbix_url = "http://xxx.xxx.xxx.xxx:8080/zabbix/api_jsonrpc.php"
get_hostgroup_from_host_data = {"jsonrpc": "2.0", "method": "hostgroup.get", "params": { "output": "extend", "hostids": "111" },"auth": "xxx","id": 1}
response = requests.post(zabbix_url, data=json.dumps(get_hostgroup_from_host_data), headers=request_headers).json()
print(response["result"])
案例
导出以windows和linux开头的模板
使用output筛选字段,使用search筛选结果
get_template_request_data = {"jsonrpc": "2.0", "method": "template.get", "params": { "output": [ "templateid", "host" ], "search": { "host": ["windows", "linux"] }, "searchByAny": True, "startSearch": True }, "auth": "xxx", "id": 1}
导出id为10111的主机群组
{"jsonrpc": "2.0", "method": "configuration.export", "params": { "options": { "groups": [ "10111" ]}, "format": "xml", "prettyprint": True }, "auth": "xxx", "id": 1}
查询所有用户sendto信息(手机号)
{ "jsonrpc": "2.0", "method": "user.get", "params": { "output": ["name"], "selectMedias": ["mediatypeid", "sendto", "active"]}, "auth": "xxx", "id": 1}