获取
说明
integer/array item.get(object **parameters**)
此方法允许根据给定的参数获取监控项。
参数
(object) 参数定义期望输出。
此方法支持如下参数。
| 参数 | 类型 | 说明 |
|---|---|---|
| itemids | string/array | 返回给定IDs的监控项。 |
| groupids | string/array | 返回属于给定组的主机的监控项。 |
| templateids | string/array | 返回属于给定模板的监控项。 |
| hostids | string/array | 返回属于给定主机的监控项。 |
| proxyids | string/array | 返回被给定代理监控的监控项。 |
| interfaceids | string/array | 返回使用给定主机接口的监控项。 |
| graphids | string/array | 返回在给定图表中使用的监控项。 |
| triggerids | string/array | 返回给定触发器所使用的监控项。 |
| applicationids | string/array | 返回属于给定应用的监控项。 |
| webitems | flag | 返回结果中包含web监控项。 |
| inherited | boolean | 如果设为true,返回继承自某个模板的监控项。 |
| templated | boolean | 如果设为true,返回属于某个模板的监控项。 |
| monitored | boolean | 如果设为true,返回属于已监控主机的已启用的监控项。 |
| group | string | 返回属于给定组名的监控项。 |
| host | string | 返回给定主机名的监控项。 |
| application | string | 返回属于给定应用名的监控项。 |
| withtriggers | boolean | 如果设为true,返回在触发器中使用的监控项。 |
| selectHosts | query | 在host属性中已数组的形式返回监控项所属的主机。 |
| selectInterfaces | query | 在interfaces属性中返回在主机接口中使用的监控项。 |
| selectTriggers | query | 在triggers属性中返回使用该监控项的触发器。支持 count. |
| selectGraphs | query | 在graphs属性中返回包含该监控项的图表。支持 count. |
| selectApplications | query | 在application属性中返回监控项所属的应用。 |
| selectDiscoveryRule | query | 在discoveryRule属性中返回创建该监控项的LLD规则。 |
| selectItemDiscovery | query | 在itemDiscovery属性中返回监控项发现对象。该监控项发现对象连接该监控项到监控项原型。它有如下属性: itemdiscoveryid - (string) ID of the item discovery;itemid - (string) ID of the discovered item;parent_itemid - (string) ID of the item prototype from which the item has been created;key - (string) key of the item prototype;lastcheck - (timestamp) time when the item was last discovered;tsdelete - (timestamp) time when an item that is no longer discovered will be deleted. |
| selectPreprocessing | query | 返回“预处理”属性中的项目预处理选项。 \它具有以下特性: type - (string) 预处理选项类型:1 -自定义乘数; 2 -右纵倾; 3 -左纵倾; 4 -修剪; 5 -正则表达式匹配; 6 -布尔值到小数; 7 -八进制到十进制; 8—十六进制到十进制; 9 -简单的改变; 10 -每秒变化; 11 - XML XPath; 12 - JSONPath; 13 - In范围; 14 -匹配正则表达式; 15 -不匹配正则表达式; 16 -检查JSON中的错误 17 -检查XML中的错误; 18 -使用正则表达式检查错误; 19 -丢弃不变的; 20 -不改变心跳丢弃; 21 - JavaScript; 22 -普罗米修斯模式; 23 -普罗米修斯到JSON; 24 - CSV到JSON; 25 -替换 params - (string)预处理选项使用的附加参数。多个参数以LF (\n)字符分隔。error_handler - (string)预处理步骤失败时使用的动作类型:0 -错误信息被Zabbix服务器设置; 1 -弃值; 2 -设置自定义值; 3 -设置自定义错误信息。 error_handler_params - (string)错误处理程序参数。 |
| filter | object | 返回紧缺匹配给定筛选条件的结果。 接受数组,数组的键为属性名,值为要匹配的一个值或者值数组。 支持附加筛选条件: host - 监控项所属主机的技术名称。 |
| limitSelects | integer | 限制子查询所返回的结果的数量。 应用到如下子查询: selectGraphs - 结果排序 name;selectTriggers - 结果排序 description. |
| sortfield | string/array | 根据给定的属性对结果排序。 可能的值是: itemid, name, key, delay, history, trends, type and 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”参数)。
示例
根据key查找监控项
从ID为“10084”的主机获取key带有“system”的监控项,并以名称排序。
请求:
{"jsonrpc": "2.0","result": [{"itemid": "23298","type": "0","snmp_oid": "","hostid": "10084","name": "Context switches per second","key_": "system.cpu.switches","delay": "1m","history": "7d","trends": "365d","lastvalue": "2552","lastclock": "1351090998","prevvalue": "2641","state": "0","status": "0","value_type": "3","trapper_hosts": "","units": "sps","error": "","logtimefmt": "","templateid": "22680","valuemapid": "0","params": "","ipmi_sensor": "","authtype": "0","username": "","password": "","publickey": "","privatekey": "","lastns": "564054253","flags": "0","interfaceid": "1","description": "","inventory_link": "0","lifetime": "0s","evaltype": "0","jmx_endpoint": "","master_itemid": "0","timeout": "3s","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"},{"itemid": "23299","type": "0","snmp_oid": "","hostid": "10084","name": "CPU $2 time","key_": "system.cpu.util[,idle]","delay": "1m","history": "7d","trends": "365d","lastvalue": "86.031879","lastclock": "1351090999","prevvalue": "85.306944","state": "0","status": "0","value_type": "0","trapper_hosts": "","units": "%","error": "","logtimefmt": "","templateid": "17354","valuemapid": "0","params": "","ipmi_sensor": "","authtype": "0","username": "","password": "","publickey": "","privatekey": "","lastns": "564256864","flags": "0","interfaceid": "1","description": "The time the CPU has spent doing nothing.","inventory_link": "0","lifetime": "0s","evaltype": "0","jmx_endpoint": "","master_itemid": "0","timeout": "3s","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"},{"itemid": "23300","type": "0","snmp_oid": "","hostid": "10084","name": "CPU $2 time","key_": "system.cpu.util[,interrupt]","history": "7d","trends": "365d","lastvalue": "0.008389","lastclock": "1351091000","prevvalue": "0.000000","state": "0","status": "0","value_type": "0","trapper_hosts": "","units": "%","error": "","logtimefmt": "","templateid": "22671","valuemapid": "0","params": "","ipmi_sensor": "","authtype": "0","username": "","password": "","publickey": "","privatekey": "","lastns": "564661387","flags": "0","interfaceid": "1","description": "The amount of time the CPU has been servicing hardware interrupts.","inventory_link": "0","lifetime": "0s","evaltype": "0","jmx_endpoint": "","master_itemid": "0","timeout": "3s","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"}],"id": 1}
根据key查找依赖监控项
从ID未“10116”的主机中获取key名包含“apache”的依赖监控项。
请求:
{"jsonrpc": "2.0","method": "item.get","params": {"output": "extend","hostids": "10116","search": {"key_": "apache"},"filter": {"type": "18"}},"auth": "038e1d7b1735c6a5436ee9eae095879e","id": 1}
响应:
{"jsonrpc": "2.0","result": [{"itemid": "23298","type": "0","snmp_oid": "","hostid": "10084","name": "Context switches per second","key_": "system.cpu.switches","delay": "1m","history": "7d","trends": "365d","lastvalue": "2552","lastclock": "1351090998","prevvalue": "2641","state": "0","status": "0","value_type": "3","trapper_hosts": "","units": "sps","error": "","logtimefmt": "","templateid": "22680","valuemapid": "0","params": "","ipmi_sensor": "","authtype": "0","username": "","password": "","publickey": "","privatekey": "","lastns": "564054253","flags": "0","interfaceid": "1","description": "","inventory_link": "0","lifetime": "0s","evaltype": "0","jmx_endpoint": "","master_itemid": "0","timeout": "3s","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"},{"itemid": "23299","type": "0","snmp_oid": "","hostid": "10084","name": "CPU $2 time","key_": "system.cpu.util[,idle]","delay": "1m","history": "7d","trends": "365d","lastvalue": "86.031879","lastclock": "1351090999","prevvalue": "85.306944","state": "0","status": "0","value_type": "0","trapper_hosts": "","units": "%","error": "","logtimefmt": "","templateid": "17354","valuemapid": "0","params": "","ipmi_sensor": "","authtype": "0","username": "","password": "","publickey": "","privatekey": "","lastns": "564256864","flags": "0","interfaceid": "1","description": "The time the CPU has spent doing nothing.","inventory_link": "0","lifetime": "0s","evaltype": "0","jmx_endpoint": "","master_itemid": "0","timeout": "3s","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"},{"itemid": "23300","type": "0","snmp_oid": "","hostid": "10084","name": "CPU $2 time","key_": "system.cpu.util[,interrupt]","history": "7d","trends": "365d","lastvalue": "0.008389","lastclock": "1351091000","prevvalue": "0.000000","state": "0","status": "0","value_type": "0","trapper_hosts": "","units": "%","error": "","logtimefmt": "","templateid": "22671","valuemapid": "0","params": "","ipmi_sensor": "","authtype": "0","username": "","password": "","publickey": "","privatekey": "","lastns": "564661387","flags": "0","interfaceid": "1","description": "The amount of time the CPU has been servicing hardware interrupts.","inventory_link": "0","lifetime": "0s","evaltype": "0","jmx_endpoint": "","master_itemid": "0","timeout": "3s","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"}],"id": 1}
查找HTTP agent 监控项
根据定义的主机id来查找带有XML post报文类型的监控项。
请求:
{"jsonrpc": "2.0","method": "item.get","params": {"hostids": "10255","filter": {"type": "19","post_type": "3"}},"id": 3,"auth": "d678e0b85688ce578ff061bd29a20d3b"}
响应:
{"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": "","formula": "","error": "","logtimefmt": "","templateid": "0","valuemapid": "0","params": "","ipmi_sensor": "","authtype": "0","username": "","password": "","publickey": "","privatekey": "","flags": "0","interfaceid": "0","description": "","inventory_link": "0","lifetime": "30d","state": "0","evaltype": "0","jmx_endpoint": "","master_itemid": "0","timeout": "3s","url": "localhost","query_fields": [{"mode": "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","lastclock": "0","lastns": "0","lastvalue": "0","prevvalue": "0"}],"id": 3}
使用预处理规则检索项
从ID为“10254”的主机重新获取所有项目及其预处理规则。
请求:
{"jsonrpc": "2.0","method": "item.get","params": {"output": ["itemid", "name", "key_"],"selectPreprocessing": "extend","hostids": "10254"},"auth": "038e1d7b1735c6a5436ee9eae095879e","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() in frontends/php/include/classes/api/services/CItem.php.
