Zabbix API
说明
1) 基于Web的API,作为Web前端的一部分提供,使用JSON-RPC 2.0协议
2) 身份认证Token:在访问Zabbix中的任何数据之前,需要登录并获取身份验证令牌
3) 请求URL:http://company.com/zabbix/api_jsonrpc.php,eg. http://192.168.2.1/api_jsonrpc.php
4) Method参数:请求api方法,eg. “user.login”、”item.get”
---------------------
实例
1.获取Zabbix API版本
curl -X POST -H "Content-Type":application/json-rpc --data '{"jsonrpc":"2.0", "method":"apiinfo.version", "id":1, "auth":null, "params":{}}' http://192.168.2.1/api_jsonrpc.php
2.Zabbix Admin用户身份登录,返回认证token
curl -X POST -H "Content-Type":application/json-rpc --data '{"jsonrpc":"2.0", "method":"user.login", "id":1, "auth":null, "params":{"user":"Admin", "password":"zabbix"}}' http://192.168.2.1/api_jsonrpc.php
#fea0d07d4162362e27d0c015fb9e701a
3.检索所有已配置主机的ID、主机名和接口(auth值对应token的值)
curl -X POST -H "Content-Type":application/json-rpc --data '{"jsonrpc":"2.0", "method":"host.get", "id":1, "auth":"fea0d07d4162362e27d0c015fb9e701a", "params":{"output":["hostid","host"], "selectInterfaces":["interfaceid","ip"]}}' http://192.168.2.1/api_jsonrpc.php