Zabbix API支持以下数据类型作为输入:
类型 | 描述 |
---|---|
boolean | 一个boolean值,接受true 或false 。 |
flag | 如果值存在且不等于null ,则视为true ;否则视为false 。 |
integer | 整数。 |
float | 浮点数。 |
string | 文本string。 |
text | 较长的文本string。 |
timestamp | Unix时间戳。 |
array | 有序值序列,即普通array。 |
object | 关联array。 |
query | 定义应返回哪些数据的值。 可定义为属性名称的array以仅返回特定属性,或使用预定义值: extend - 返回所有object属性;count - 返回检索到的记录数,仅某些子查询支持。 |
Zabbix API始终仅返回字符串或数组形式的值。
部分objects属性带有简短标签来描述其行为。使用的标签如下:
保留ID值"0"可用于过滤元素和移除被引用的objects。例如,要从主机中移除被引用的proxy,应将proxy_hostid设置为0("proxy_hostid": "0");或通过设置proxyids为0来过滤由服务器选项监控的主机("proxyids": "0")。
所有get
方法均支持以下参数:
参数 | 类型 | 描述 |
---|---|---|
countOutput | boolean | 返回结果中的记录数量而非实际数据。 |
editable | boolean | 若设为true ,仅返回用户具有写权限的objects。默认值: false 。 |
excludeSearch | boolean | 返回不符合search 参数给定条件的结果。 |
filter | object | 仅返回完全匹配给定过滤条件的结果。 接受一个object,其中键为属性名称(例如 host.get 中的主机object属性、item.get 中的监控项object属性等),值为单个匹配值或array值列表。不支持 text 数据类型的属性。注意部分方法对此参数有特殊功能,详见方法页面说明(例如host.get中的 filter 参数还支持主机接口属性)。 |
limit | integer | 限制返回的记录数量。 |
output | query | 指定返回的object属性。 默认值: extend 。 |
preservekeys | boolean | 在结果array中使用ID作为键。 |
search | object | 返回匹配给定模式的结果(不区分大小写)。 接受一个object,其中键为属性名称(例如 host.get 中的主机object属性、item.get 中的监控项object属性等),值为搜索字符串。若未指定额外选项,将执行LIKE "%…%" 搜索。仅支持 string 和text 数据类型的属性。注意部分方法对此参数有特殊功能,详见方法页面说明(例如host.get中的 search 参数还支持主机接口属性)。 |
searchByAny | boolean | 若设为true ,返回满足filter 或search 参数中任意条件的结果而非全部条件。默认值: false 。 |
searchWildcardsEnabled | boolean | 若设为true ,允许在search 参数中使用"*"作为通配符。默认值: false 。 |
sortfield | string/array | 按指定属性排序结果。可排序属性列表参考具体API获取方法说明。宏在排序前不会展开。 若未指定值,数据将无序返回。 |
sortorder | string/array | 排序顺序。若传入array,每个值将对应sortfield 参数中的属性。可选值: ASC - (默认) 升序;DESC - 降序。 |
startSearch | boolean | search 参数将匹配字段开头部分,即执行LIKE "…%" 搜索。若 searchWildcardsEnabled 设为true 则忽略此参数。 |
用户是否拥有对名称以"MySQL"或"Linux"开头的主机的写入权限?
请求:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"countOutput": true,
"search": {
"host": ["MySQL", "Linux"]
},
"editable": true,
"startSearch": true,
"searchByAny": true
},
"auth": "766b71ee543230a1182ca5c44d353e36",
"id": 1
}
响应:
零结果表示没有具备读写权限的主机。
统计名称中不包含子串"ubuntu"的主机数量
请求:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"countOutput": true,
"search": {
"host": "ubuntu"
},
"excludeSearch": true
},
"auth": "766b71ee543230a1182ca5c44d353e36",
"id": 1
}
响应:
查找名称包含"server"且接口端口为"10050"或"10071"的主机。按主机名称降序排序结果,并限制为5个主机。
请求:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["hostid", "host"],
"selectInterfaces": ["port"],
"filter": {
"port": ["10050", "10071"]
},
"search": {
"host": "*server*"
},
"searchWildcardsEnabled": true,
"searchByAny": true,
"sortfield": "host",
"sortorder": "DESC",
"limit": 5
},
"auth": "766b71ee543230a1182ca5c44d353e36",
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "50003",
"host": "WebServer-Tomcat02",
"interfaces": [
{
"port": "10071"
}
]
},
{
"hostid": "50005",
"host": "WebServer-Tomcat01",
"interfaces": [
{
"port": "10071"
}
]
},
{
"hostid": "50004",
"host": "WebServer-Nginx",
"interfaces": [
{
"port": "10071"
}
]
},
{
"hostid": "99032",
"host": "MySQL server 01",
"interfaces": [
{
"port": "10050"
}
]
},
{
"hostid": "99061",
"host": "Linux server 01",
"interfaces": [
{
"port": "10050"
}
]
}
],
"id": 1
}
如果在请求中添加"preservekeys"参数,结果将以关联array形式返回,其中键是objects的ID。
请求:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["hostid", "host"],
"selectInterfaces": ["port"],
"filter": {
"port": ["10050", "10071"]
},
"search": {
"host": "*server*"
},
"searchWildcardsEnabled": true,
"searchByAny": true,
"sortfield": "host",
"sortorder": "DESC",
"limit": 5,
"preservekeys": true
},
"auth": "766b71ee543230a1182ca5c44d353e36",
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": {
"50003": {
"hostid": "50003",
"host": "WebServer-Tomcat02",
"interfaces": [
{
"port": "10071"
}
]
},
"50005": {
"hostid": "50005",
"host": "WebServer-Tomcat01",
"interfaces": [
{
"port": "10071"
}
]
},
"50004": {
"hostid": "50004",
"host": "WebServer-Nginx",
"interfaces": [
{
"port": "10071"
}
]
},
"99032": {
"hostid": "99032",
"host": "MySQL server 01",
"interfaces": [
{
"port": "10050"
}
]
},
"99061": {
"hostid": "99061",
"host": "Linux server 01",
"interfaces": [
{
"port": "10050"
}
]
}
},
"id": 1
}