Open marclee44 opened 2 years ago
接口地址
Zabbix 网站访问地址:http://[ip]:[port] Zabbix API调用地址:http://[ip]:[port]/api_jsonrpc.php
访问方式
Content-Type
application/json-rpc
application/json
application/jsonrequest
基本请求内容
常用请求参数(params)
基本返回内容
获取监控数据流程
调用方法
user.login
返回值:auth字符串,为其他所有方法的必须字段 请求样例:
{ "jsonrpc": "2.0", "method": "user.login", "params": { "user": "Admin", "password": "zabbix" }, "id": 1 }
返回样例:
{ "jsonrpc": "2.0", "result": "0424bd59b807674191e7d77572075f33", "id": 1 }
host.get
output
filter
search
searchByAny
searchWildcardsEnabled
startSearch
hostid
host
请求样例: 列出所有名字为MySQL和Linux的主机,仅返回hostid和host属性
MySQL
Linux
{ "jsonrpc": "2.0", "method": "host.get", "params": { "output": [ "hostid", "host" ], "search": { "host": ["MySQL", "Linux"] }, "searchByAny": true }, "auth": "0424bd59b807674191e7d77572075f33", "id": 1 }
{ "jsonrpc": "2.0", "result": [ { "hostid": "10160", "host": "MySQL" }, { "hostid": "10161", "host": "Linux" } ], "id": 1 }
item.get
监控项对象主要属性:
监控项常用键值前缀:
请求样例:
{ "jsonrpc": "2.0", "method": "item.get", "params": { "output":[ "hostid", "name", "units", "lastvalue", "prevvalue" ], "hostids": "10160", "search": { "key_": [ "system.cpu.util", "vm.memory.util", "vm.memory.total", "vm.memory.used", "vfs.fs.pused", "vfs.fs.total", "vfs.fs.used", "net.if.in[", "net.if.out[" ] }, "searchByAny": true }, "id": 1, "auth": "0424bd59b807674191e7d77572075f33" }
{ "jsonrpc": "2.0", "result": [ { "itemid": "23298", "hostid": "10160", "name": "CPU xxxxxxx", "units": "%", "lastvalue": "10.45744423", "prevvalue": "25.95464746" }, { "itemid": "23299", "hostid": "10160", "name": "Memory xxxx", "units": "%", "lastvalue": "40.29122046", "prevvalue": "25.95464746" }, { "itemid": "23300", "hostid": "10160", "name": "Memory xxxxxxx", "units": "B", "lastvalue": "2595464746", "prevvalue": "2595464746" }, { "itemid": "23298", "hostid": "10160", "name": "CPU xxxxxxx", "units": "B", "lastvalue": "1045744423", "prevvalue": "673643724" }, { "itemid": "23305", "hostid": "10160", "name": "C:\\xxxx", "units": "%", "lastvalue": "40.29122046", "prevvalue": "25.95464746" }, { "itemid": "23306", "hostid": "10160", "name": "C:\\xxxx", "units": "B", "lastvalue": "259546474600", "prevvalue": "259546474600" }, { "itemid": "23307", "hostid": "10160", "name": "C:\\xxxx", "units": "B", "lastvalue": "104574442300", "prevvalue": "673643724000" }, { "itemid": "23316", "hostid": "10160", "name": "Wlan xxxxx", "units": "bps", "lastvalue": "2595464.746", "prevvalue": "1595464.746" }, { "itemid": "23317", "hostid": "10160", "name": "Wlan xxxxx", "units": "bps", "lastvalue": "10.457", "prevvalue": "6.736" } ], "id": 1 }
Zabbix 网站访问地址:http://[ip]:[port] Zabbix API调用地址:http://[ip]:[port]/api_jsonrpc.php
Content-Type
为以下值之一:application/json-rpc
、application/json
或application/jsonrequest
常用请求参数(params)
user.login
特有参数:返回值:auth字符串,为其他所有方法的必须字段 请求样例:
返回样例:
host.get
常用参数:output
、filter
、search
、searchByAny
、searchWildcardsEnabled
、startSearch
等 主机对象属性:非常多,但对于后续获取监控项,通常仅hostid
和host
有意义请求样例: 列出所有名字为
MySQL
和Linux
的主机,仅返回hostid
和host
属性返回样例:
item.get
常用参数:output
、filter
、search
、searchByAny
、searchWildcardsEnabled
、startSearch
等 特有参数:监控项对象主要属性:
监控项常用键值前缀:
请求样例:
返回样例: