integer/array item.get(object parameters)
该方法允许根据给定参数检索监控项。
该方法对所有类型的用户可用。调用该方法的权限可以在用户角色设置中撤销。更多信息请参阅User roles。
(object)
定义所需输出的参数
该方法支持以下参数。
参数 | 数据类型 | 描述 |
---|---|---|
itemids | ID/array | 仅返回具有指定ID的监控项。 |
groupids | ID/array | 仅返回属于给定组中主机的监控项。 |
templateids | ID/array | 仅返回属于给定模板的监控项。 |
hostids | ID/array | 仅返回属于指定主机的监控项. |
proxyids | ID/array | 仅返回由给定proxies监控的监控项. |
interfaceids | ID/array | 仅返回使用指定主机接口的监控项. |
graphids | ID/array | 仅返回给定图表中使用的监控项. |
triggerids | ID/array | 仅返回给定触发器中使用的监控项. |
webitems | flag | 在结果中包含web 监控项。 |
inherited | boolean | 若设置为true 则仅返回从模板继承的监控项 |
templated | boolean | 如果设置为true 则仅返回属于模板的监控项. |
monitored | boolean | 如果设置为true 则仅返回属于受监控主机的已启用监控项. |
group | string | 仅返回属于指定名称组的监控项。 |
host | string | 仅返回属于指定名称的一个主机的监控项。 |
evaltype | integer | 标签搜索规则. 可选值: 0 - (默认) 与/或; 2 - 或. |
tags | array | 仅返回带有指定标签的监控项. 根据运算符值决定按标签精确匹配或标签值大小写敏感/不敏感搜索. 格式: [{"tag": "<tag>", "value": "<value>", "operator": "<operator>"}, ...] .空array将返回所有监控项. 可用运算符类型: 0 - (默认) 相似; 1 - 等于; 2 - 不相似; 3 - 不等于; 4 - 存在; 5 - 不存在. |
with_triggers | boolean | 如果设置为true 则仅返回触发器中使用到的监控项 |
selectHosts | query | 返回一个hosts 属性,其array为主机,表示该监控项所属的对象。 |
selectInterfaces | query | 返回一个interfaces 属性,其array为主机接口,由监控项使用。 |
selectTriggers | query | 返回一个包含触发器信息的triggers 属性,这些触发器使用了该监控项。支持 count 。 |
selectGraphs | query | 返回包含监控项的图表所对应的graphs 属性。支持 count 。 |
selectDiscoveryData | query | 返回一个包含监控项发现object数据的discoveryData 属性。该监控项发现object将发现的监控项与其来源的监控项原型关联起来。它具有以下属性: itemdiscoveryid - 监控项发现的(string) ID;parent_itemid - 创建该监控项的监控项原型的(string) ID;key_ - 监控项原型的(string) 键值;lastcheck - 上次发现监控项的(timestamp) 时间;status - 监控项发现状态的(int) :0 - (默认) 已发现监控项, 1 - 不再发现监控项; ts_delete - 不再发现的监控项将被删除的(timestamp) 时间;ts_disable - 不再发现的监控项将被禁用的(timestamp) 时间;disable_source - 指示监控项是由LLD规则还是手动禁用的(int) :0 - (默认) 自动禁用, 1 - 由LLD规则禁用。 |
selectDiscoveryRule | query | 返回一个discoveryRule 属性,其中包含创建该监控项的LLD规则。 |
selectDiscoveryRulePrototype | query | 返回一个discoveryRulePrototype 属性,其中包含创建该监控项的父级LLD规则原型。 |
selectItemDiscovery | query | 返回一个带有监控项发现object的itemDiscovery 属性。该监控项发现object将监控项与其创建来源的监控项原型相关联。此query已弃用,请改用 selectDiscoveryData 。 |
selectPreprocessing | query | 返回带有 监控项 预处理选项的 preprocessing 属性。 |
selectTags | query | 返回 tags 属性中的 监控项标签。 |
selectValueMap | query | 返回带有监控项值映射的valuemap 属性. |
filter | object | 仅返回与给定筛选条件完全匹配的结果。 接受一个object,其中键为属性名称,值为单个值或用于匹配的array。 不支持 text 类型的属性数据类型。支持附加属性: host - 监控项所属主机的技术名称。 |
limitSelects | integer | 限制子查询返回的记录数量。 适用于以下子查询: selectGraphs - 结果将按 name 排序;selectTriggers - 结果将按 description 排序。 |
sortfield | string/array | 按给定属性对结果进行排序. 可选值: itemid , name , key_ , delay , history , trends , type , status . |
countOutput | boolean | 这些参数在通用get方法参数中有详细描述. |
editable | boolean | |
excludeSearch | boolean | |
limit | integer | |
output | query | |
preservekeys | boolean | |
search | object | |
searchByAny | boolean | |
searchWildcardsEnabled | boolean | |
sortorder | string/array | |
startSearch | boolean |
(integer/array)
返回以下两种结果之一:
countOutput
参数时)检索特定主机 ID中所有触发器使用的监控项,这些触发器在监控项键中包含"system.cpu"字样,并按名称排序结果。
执行请求:
{
"jsonrpc": "2.0",
"method": "item.get",
"params": {
"output": "extend",
"hostids": "10084",
"with_triggers": true,
"search": {
"key_": "system.cpu"
},
"sortfield": "name"
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"itemid": "42269",
"type": "18",
"snmp_oid": "",
"hostid": "10084",
"name": "CPU utilization",
"key_": "system.cpu.util",
"delay": "0",
"history": "7d",
"trends": "365d",
"status": "0",
"value_type": "0",
"trapper_hosts": "",
"units": "%",
"logtimefmt": "",
"templateid": "42267",
"valuemapid": "0",
"params": "",
"ipmi_sensor": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"flags": "0",
"interfaceid": "0",
"description": "CPU utilization in %.",
"inventory_link": "0",
"evaltype": "0",
"jmx_endpoint": "",
"master_itemid": "42264",
"timeout": "",
"url": "",
"query_fields": [],
"posts": "",
"status_codes": "200",
"follow_redirects": "1",
"post_type": "0",
"http_proxy": "",
"headers": [],
"retrieve_mode": "0",
"request_method": "0",
"output_format": "0",
"ssl_cert_file": "",
"ssl_key_file": "",
"ssl_key_password": "",
"verify_peer": "0",
"verify_host": "0",
"allow_traps": "0",
"uuid": "",
"state": "0",
"error": "",
"parameters": [],
"lastclock": "0",
"lastns": "0",
"lastvalue": "0",
"prevvalue": "0",
"name_resolved": "CPU utilization"
},
{
"itemid": "42259",
"type": "0",
"snmp_oid": "",
"hostid": "10084",
"name": "Load average (15m avg)",
"key_": "system.cpu.load[all,avg15]",
"delay": "1m",
"history": "7d",
"trends": "365d",
"status": "0",
"value_type": "0",
"trapper_hosts": "",
"units": "",
"logtimefmt": "",
"templateid": "42219",
"valuemapid": "0",
"params": "",
"ipmi_sensor": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"flags": "0",
"interfaceid": "1",
"description": "",
"inventory_link": "0",
"evaltype": "0",
"jmx_endpoint": "",
"master_itemid": "0",
"timeout": "",
"url": "",
"query_fields": [],
"posts": "",
"status_codes": "200",
"follow_redirects": "1",
"post_type": "0",
"http_proxy": "",
"headers": [],
"retrieve_mode": "0",
"request_method": "0",
"output_format": "0",
"ssl_cert_file": "",
"ssl_key_file": "",
"ssl_key_password": "",
"verify_peer": "0",
"verify_host": "0",
"allow_traps": "0",
"uuid": "",
"state": "0",
"error": "",
"parameters": [],
"lastclock": "0",
"lastns": "0",
"lastvalue": "0",
"prevvalue": "0",
"name_resolved": "Load average (15m avg)"
},
{
"itemid": "42249",
"type": "0",
"snmp_oid": "",
"hostid": "10084",
"name": "Load average (1m avg)",
"key_": "system.cpu.load[all,avg1]",
"delay": "1m",
"history": "7d",
"trends": "365d",
"status": "0",
"value_type": "0",
"trapper_hosts": "",
"units": "",
"logtimefmt": "",
"templateid": "42209",
"valuemapid": "0",
"params": "",
"ipmi_sensor": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"flags": "0",
"interfaceid": "1",
"description": "",
"inventory_link": "0",
"evaltype": "0",
"jmx_endpoint": "",
"master_itemid": "0",
"timeout": "",
"url": "",
"query_fields": [],
"posts": "",
"status_codes": "200",
"follow_redirects": "1",
"post_type": "0",
"http_proxy": "",
"headers": [],
"retrieve_mode": "0",
"request_method": "0",
"output_format": "0",
"ssl_cert_file": "",
"ssl_key_file": "",
"ssl_key_password": "",
"verify_peer": "0",
"verify_host": "0",
"allow_traps": "0",
"uuid": "",
"state": "0",
"error": "",
"parameters": [],
"lastclock": "0",
"lastns": "0",
"lastvalue": "0",
"prevvalue": "0",
"name_resolved": "Load average (1m avg)"
},
{
"itemid": "42257",
"type": "0",
"snmp_oid": "",
"hostid": "10084",
"name": "Load average (5m avg)",
"key_": "system.cpu.load[all,avg5]",
"delay": "1m",
"history": "7d",
"trends": "365d",
"status": "0",
"value_type": "0",
"trapper_hosts": "",
"units": "",
"logtimefmt": "",
"templateid": "42217",
"valuemapid": "0",
"params": "",
"ipmi_sensor": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"flags": "0",
"interfaceid": "1",
"description": "",
"inventory_link": "0",
"evaltype": "0",
"jmx_endpoint": "",
"master_itemid": "0",
"timeout": "",
"url": "",
"query_fields": [],
"posts": "",
"status_codes": "200",
"follow_redirects": "1",
"post_type": "0",
"http_proxy": "",
"headers": [],
"retrieve_mode": "0",
"request_method": "0",
"output_format": "0",
"ssl_cert_file": "",
"ssl_key_file": "",
"ssl_key_password": "",
"verify_peer": "0",
"verify_host": "0",
"allow_traps": "0",
"uuid": "",
"state": "0",
"error": "",
"parameters": [],
"lastclock": "0",
"lastns": "0",
"lastvalue": "0",
"prevvalue": "0",
"name_resolved": "Load average (5m avg)"
},
{
"itemid": "42260",
"type": "0",
"snmp_oid": "",
"hostid": "10084",
"name": "Number of CPUs",
"key_": "system.cpu.num",
"delay": "1m",
"history": "7d",
"trends": "365d",
"status": "0",
"value_type": "3",
"trapper_hosts": "",
"units": "",
"logtimefmt": "",
"templateid": "42220",
"valuemapid": "0",
"params": "",
"ipmi_sensor": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"flags": "0",
"interfaceid": "1",
"description": "",
"inventory_link": "0",
"evaltype": "0",
"jmx_endpoint": "",
"master_itemid": "0",
"timeout": "",
"url": "",
"query_fields": [],
"posts": "",
"status_codes": "200",
"follow_redirects": "1",
"post_type": "0",
"http_proxy": "",
"headers": [],
"retrieve_mode": "0",
"request_method": "0",
"output_format": "0",
"ssl_cert_file": "",
"ssl_key_file": "",
"ssl_key_password": "",
"verify_peer": "0",
"verify_host": "0",
"allow_traps": "0",
"uuid": "",
"state": "0",
"error": "",
"parameters": [],
"lastclock": "0",
"lastns": "0",
"lastvalue": "0",
"prevvalue": "0",
"name_resolved": "Number of CPUs"
}
],
"id": 1
}
从ID为"10116"的主机中检索所有键名包含"apache"的依赖监控项
执行请求:
{
"jsonrpc": "2.0",
"method": "item.get",
"params": {
"output": "extend",
"hostids": "10116",
"search": {
"key_": "apache"
},
"filter": {
"type": 18
}
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"itemid": "25550",
"type": "18",
"snmp_oid": "",
"hostid": "10116",
"name": "Days",
"key_": "apache.status.uptime.days",
"delay": "0",
"history": "90d",
"trends": "365d",
"status": "0",
"value_type": "3",
"trapper_hosts": "",
"units": "",
"logtimefmt": "",
"templateid": "0",
"valuemapid": "0",
"params": "",
"ipmi_sensor": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"flags": "0",
"interfaceid": "0",
"description": "",
"inventory_link": "0",
"evaltype": "0",
"jmx_endpoint": "",
"master_itemid": "25545",
"timeout": "",
"url": "",
"query_fields": [],
"posts": "",
"status_codes": "200",
"follow_redirects": "1",
"post_type": "0",
"http_proxy": "",
"headers": [],
"retrieve_mode": "0",
"request_method": "0",
"output_format": "0",
"ssl_cert_file": "",
"ssl_key_file": "",
"ssl_key_password": "",
"verify_peer": "0",
"verify_host": "0",
"allow_traps": "0",
"uuid": "",
"state": "0",
"error": "",
"parameters": [],
"lastclock": "0",
"lastns": "0",
"lastvalue": "0",
"prevvalue": "0",
"name_resolved": "Days"
},
{
"itemid": "25555",
"type": "18",
"snmp_oid": "",
"hostid": "10116",
"name": "Hours",
"key_": "apache.status.uptime.hours",
"delay": "0",
"history": "90d",
"trends": "365d",
"status": "0",
"value_type": "3",
"trapper_hosts": "",
"units": "",
"logtimefmt": "",
"templateid": "0",
"valuemapid": "0",
"params": "",
"ipmi_sensor": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"flags": "0",
"interfaceid": "0",
"description": "",
"inventory_link": "0",
"evaltype": "0",
"jmx_endpoint": "",
"master_itemid": "25545",
"timeout": "",
"url": "",
"query_fields": [],
"posts": "",
"status_codes": "200",
"follow_redirects": "1",
"post_type": "0",
"http_proxy": "",
"headers": [],
"retrieve_mode": "0",
"request_method": "0",
"output_format": "0",
"ssl_cert_file": "",
"ssl_key_file": "",
"ssl_key_password": "",
"verify_peer": "0",
"verify_host": "0",
"allow_traps": "0",
"uuid": "",
"state": "0",
"error": "",
"parameters": [],
"lastclock": "0",
"lastns": "0",
"lastvalue": "0",
"prevvalue": "0",
"name_resolved": "Hours"
}
],
"id": 1
}
查找具有XML post body类型的HTTP agent 监控项 以获取特定 主机 ID.
执行请求:
{
"jsonrpc": "2.0",
"method": "item.get",
"params": {
"hostids": "10255",
"filter": {
"type": 19,
"post_type": 3
}
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"itemid": "28252",
"type": "19",
"snmp_oid": "",
"hostid": "10255",
"name": "template item",
"key_": "ti",
"delay": "30s",
"history": "90d",
"trends": "365d",
"status": "0",
"value_type": "3",
"trapper_hosts": "",
"units": "",
"logtimefmt": "",
"templateid": "0",
"valuemapid": "0",
"params": "",
"ipmi_sensor": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"flags": "0",
"interfaceid": "0",
"description": "",
"inventory_link": "0",
"evaltype": "0",
"jmx_endpoint": "",
"master_itemid": "0",
"timeout": "",
"url": "localhost",
"query_fields": [
{
"name": "mode",
"value": "xml"
}
],
"posts": "<body>\r\n<![CDATA[{$MACRO}<foo></bar>]]>\r\n</body>",
"status_codes": "200",
"follow_redirects": "0",
"post_type": "3",
"http_proxy": "",
"headers": [],
"retrieve_mode": "1",
"request_method": "3",
"output_format": "0",
"ssl_cert_file": "",
"ssl_key_file": "",
"ssl_key_password": "",
"verify_peer": "0",
"verify_host": "0",
"allow_traps": "0",
"uuid": "",
"state": "0",
"error": "",
"parameters": [],
"lastclock": "0",
"lastns": "0",
"lastvalue": "",
"prevvalue": "",
"name_resolved": "template item"
}
],
"id": 1
}
获取指定主机 ID的所有监控项及其预处理规则
执行请求:
{
"jsonrpc": "2.0",
"method": "item.get",
"params": {
"output": ["itemid", "name", "key_"],
"selectPreprocessing": "extend",
"hostids": "10254"
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": {
"itemid": "23865",
"name": "HTTP agent example JSON",
"key_": "json",
"preprocessing": [
{
"type": "12",
"params": "$.random",
"error_handler": "1",
"error_handler_params": ""
}
]
},
"id": 1
}
CItem::get() 位于 ui/include/classes/api/services/CItem.php 文件中。