item.get

Description 说明

integer/array item.get(object **parameters**)

The method allows to retrieve items according to the given parameters. 此方法允许根据给定的参数获取监控项。

Parameters 参数

(object) Parameters defining the desired output. (object) 参数定义期望输出。

The method supports the following parameters. 此方法支持如下参数。

ParameterTypeDescription
itemidsstring/arrayReturn only items with the given IDs. 返回给定IDs的监控项。
groupidsstring/arrayReturn only items that belong to the hosts from the given groups. 返回属于给定组的主机的监控项。
templateidsstring/arrayReturn only items that belong to the given templates. 返回属于给定模板的监控项。
hostidsstring/arrayReturn only items that belong to the given hosts. 返回属于给定主机的监控项。
proxyidsstring/arrayReturn only items that are monitored by the given proxies. 返回被给定代理监控的监控项。
interfaceidsstring/arrayReturn only items that use the given host interfaces. 返回使用给定主机接口的监控项。
graphidsstring/arrayReturn only items that are used in the given graphs. 返回在给定图表中使用的监控项。
triggeridsstring/arrayReturn only items that are used in the given triggers. 返回给定触发器所使用的监控项。
applicationidsstring/arrayReturn only items that belong to the given applications. 返回属于给定应用的监控项。
webitemsflagInclude web items in the result. 返回结果中包含web监控项。
inheritedbooleanIf set to true return only items inherited from a template. 如果设为true,返回继承自某个模板的监控项。
templatedbooleanIf set to true return only items that belong to templates. 如果设为true,返回属于某个模板的监控项。
monitoredbooleanIf set to true return only enabled items that belong to monitored hosts. 如果设为true,返回属于已监控主机的已启用的监控项。
groupstringReturn only items that belong to a group with the given name. 返回属于给定组名的监控项。
hoststringReturn only items that belong to a host with the given name. 返回给定主机名的监控项。
applicationstringReturn only items that belong to an application with the given name. 返回属于给定应用名的监控项。
with_triggersbooleanIf set to true return only items that are used in triggers. 如果设为true,返回在触发器中使用的监控项。
selectHostsqueryReturns the host that the item belongs to as an array in the hosts property. 在host属性中已数组的形式返回监控项所属的主机。
selectInterfacesquery

Examples 示例

Finding items by key 根据key查找监控项

Retrieve all items from host with ID “10084” that have the word “system” in the key and sort them by name. 从ID为“10084”的主机获取key带有“system”的监控项,并以名称排序。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "item.get",
  4. "params": {
  5. "output": "extend",
  6. "hostids": "10084",
  7. "search": {
  8. "key_": "system"
  9. },
  10. "sortfield": "name"
  11. },
  12. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  13. "id": 1
  14. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "itemid": "23298",
  6. "type": "0",
  7. "snmp_community": "",
  8. "snmp_oid": "",
  9. "hostid": "10084",
  10. "name": "Context switches per second",
  11. "key_": "system.cpu.switches",
  12. "delay": "1m",
  13. "history": "7d",
  14. "trends": "365d",
  15. "lastvalue": "2552",
  16. "lastclock": "1351090998",
  17. "prevvalue": "2641",
  18. "state": "0",
  19. "status": "0",
  20. "value_type": "3",
  21. "trapper_hosts": "",
  22. "units": "sps",
  23. "snmpv3_securityname": "",
  24. "snmpv3_securitylevel": "0",
  25. "snmpv3_authpassphrase": "",
  26. "snmpv3_privpassphrase": "",
  27. "snmpv3_authprotocol": "0",
  28. "snmpv3_privprotocol": "0",
  29. "snmpv3_contextname": "",
  30. "error": "",
  31. "lastlogsize": "0",
  32. "logtimefmt": "",
  33. "templateid": "22680",
  34. "valuemapid": "0",
  35. "params": "",
  36. "ipmi_sensor": "",
  37. "authtype": "0",
  38. "username": "",
  39. "password": "",
  40. "publickey": "",
  41. "privatekey": "",
  42. "mtime": "0",
  43. "lastns": "564054253",
  44. "flags": "0",
  45. "interfaceid": "1",
  46. "port": "",
  47. "description": "",
  48. "inventory_link": "0",
  49. "lifetime": "0s",
  50. "evaltype": "0",
  51. "jmx_endpoint": "",
  52. "master_itemid": "0",
  53. "timeout": "3s",
  54. "url": "",
  55. "query_fields": [],
  56. "posts": "",
  57. "status_codes": "200",
  58. "follow_redirects": "1",
  59. "post_type": "0",
  60. "http_proxy": "",
  61. "headers": [],
  62. "retrieve_mode": "0",
  63. "request_method": "1",
  64. "output_format": "0",
  65. "ssl_cert_file": "",
  66. "ssl_key_file": "",
  67. "ssl_key_password": "",
  68. "verify_peer": "0",
  69. "verify_host": "0",
  70. "allow_traps": "0"
  71. },
  72. {
  73. "itemid": "23299",
  74. "type": "0",
  75. "snmp_community": "",
  76. "snmp_oid": "",
  77. "hostid": "10084",
  78. "name": "CPU $2 time",
  79. "key_": "system.cpu.util[,idle]",
  80. "delay": "1m",
  81. "history": "7d",
  82. "trends": "365d",
  83. "lastvalue": "86.031879",
  84. "lastclock": "1351090999",
  85. "prevvalue": "85.306944",
  86. "state": "0",
  87. "status": "0",
  88. "value_type": "0",
  89. "trapper_hosts": "",
  90. "units": "%",
  91. "snmpv3_securityname": "",
  92. "snmpv3_securitylevel": "0",
  93. "snmpv3_authpassphrase": "",
  94. "snmpv3_privpassphrase": "",
  95. "snmpv3_authprotocol": "0",
  96. "snmpv3_privprotocol": "0",
  97. "snmpv3_contextname": "",
  98. "error": "",
  99. "lastlogsize": "0",
  100. "logtimefmt": "",
  101. "templateid": "17354",
  102. "valuemapid": "0",
  103. "params": "",
  104. "ipmi_sensor": "",
  105. "authtype": "0",
  106. "username": "",
  107. "password": "",
  108. "publickey": "",
  109. "privatekey": "",
  110. "mtime": "0",
  111. "lastns": "564256864",
  112. "flags": "0",
  113. "interfaceid": "1",
  114. "port": "",
  115. "description": "The time the CPU has spent doing nothing.",
  116. "inventory_link": "0",
  117. "lifetime": "0s",
  118. "evaltype": "0",
  119. "jmx_endpoint": "",
  120. "master_itemid": "0",
  121. "timeout": "3s",
  122. "url": "",
  123. "query_fields": [],
  124. "posts": "",
  125. "status_codes": "200",
  126. "follow_redirects": "1",
  127. "post_type": "0",
  128. "http_proxy": "",
  129. "headers": [],
  130. "retrieve_mode": "0",
  131. "request_method": "1",
  132. "output_format": "0",
  133. "ssl_cert_file": "",
  134. "ssl_key_file": "",
  135. "ssl_key_password": "",
  136. "verify_peer": "0",
  137. "verify_host": "0",
  138. "allow_traps": "0"
  139. },
  140. {
  141. "itemid": "23300",
  142. "type": "0",
  143. "snmp_community": "",
  144. "snmp_oid": "",
  145. "hostid": "10084",
  146. "name": "CPU $2 time",
  147. "key_": "system.cpu.util[,interrupt]",
  148. "history": "7d",
  149. "trends": "365d",
  150. "lastvalue": "0.008389",
  151. "lastclock": "1351091000",
  152. "prevvalue": "0.000000",
  153. "state": "0",
  154. "status": "0",
  155. "value_type": "0",
  156. "trapper_hosts": "",
  157. "units": "%",
  158. "snmpv3_securityname": "",
  159. "snmpv3_securitylevel": "0",
  160. "snmpv3_authpassphrase": "",
  161. "snmpv3_privpassphrase": "",
  162. "snmpv3_authprotocol": "0",
  163. "snmpv3_privprotocol": "0",
  164. "snmpv3_contextname": "",
  165. "error": "",
  166. "lastlogsize": "0",
  167. "logtimefmt": "",
  168. "templateid": "22671",
  169. "valuemapid": "0",
  170. "params": "",
  171. "ipmi_sensor": "",
  172. "authtype": "0",
  173. "username": "",
  174. "password": "",
  175. "publickey": "",
  176. "privatekey": "",
  177. "mtime": "0",
  178. "lastns": "564661387",
  179. "flags": "0",
  180. "interfaceid": "1",
  181. "port": "",
  182. "description": "The amount of time the CPU has been servicing hardware interrupts.",
  183. "inventory_link": "0",
  184. "lifetime": "0s",
  185. "evaltype": "0",
  186. "jmx_endpoint": "",
  187. "master_itemid": "0",
  188. "timeout": "3s",
  189. "url": "",
  190. "query_fields": [],
  191. "posts": "",
  192. "status_codes": "200",
  193. "follow_redirects": "1",
  194. "post_type": "0",
  195. "http_proxy": "",
  196. "headers": [],
  197. "retrieve_mode": "0",
  198. "request_method": "1",
  199. "output_format": "0",
  200. "ssl_cert_file": "",
  201. "ssl_key_file": "",
  202. "ssl_key_password": "",
  203. "verify_peer": "0",
  204. "verify_host": "0",
  205. "allow_traps": "0"
  206. }
  207. ],
  208. "id": 1
  209. }

Finding dependent items by key 根据key查找依赖监控项

Retrieve all dependent items from host with ID “10116” that have the word “apache” in the key. 从ID未“10116”的主机中获取key名包含“apache”的依赖监控项。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "item.get",
  4. "params": {
  5. "output": "extend",
  6. "hostids": "10116",
  7. "search": {
  8. "key_": "apache"
  9. },
  10. "filter": {
  11. "type": "18"
  12. }
  13. },
  14. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  15. "id": 1
  16. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "itemid": "25550",
  6. "type": "18",
  7. "snmp_community": "",
  8. "snmp_oid": "",
  9. "hostid": "10116",
  10. "name": "Days",
  11. "key_": "apache.status.uptime.days",
  12. "delay": "",
  13. "history": "90d",
  14. "trends": "365d",
  15. "status": "0",
  16. "value_type": "3",
  17. "trapper_hosts": "",
  18. "units": "",
  19. "snmpv3_securityname": "",
  20. "snmpv3_securitylevel": "0",
  21. "snmpv3_authpassphrase": "",
  22. "snmpv3_privpassphrase": "",
  23. "formula": "",
  24. "error": "",
  25. "lastlogsize": "0",
  26. "logtimefmt": "",
  27. "templateid": "0",
  28. "valuemapid": "0",
  29. "params": "",
  30. "ipmi_sensor": "",
  31. "authtype": "0",
  32. "username": "",
  33. "password": "",
  34. "publickey": "",
  35. "privatekey": "",
  36. "mtime": "0",
  37. "flags": "0",
  38. "interfaceid": "0",
  39. "port": "",
  40. "description": "",
  41. "inventory_link": "0",
  42. "lifetime": "30d",
  43. "snmpv3_authprotocol": "0",
  44. "snmpv3_privprotocol": "0",
  45. "state": "0",
  46. "snmpv3_contextname": "",
  47. "evaltype": "0",
  48. "master_itemid": "25545",
  49. "jmx_endpoint": "",
  50. "timeout": "3s",
  51. "url": "",
  52. "query_fields": [],
  53. "posts": "",
  54. "status_codes": "200",
  55. "follow_redirects": "1",
  56. "post_type": "0",
  57. "http_proxy": "",
  58. "headers": [],
  59. "retrieve_mode": "0",
  60. "request_method": "1",
  61. "output_format": "0",
  62. "ssl_cert_file": "",
  63. "ssl_key_file": "",
  64. "ssl_key_password": "",
  65. "verify_peer": "0",
  66. "verify_host": "0",
  67. "allow_traps": "0",
  68. "lastclock": "0",
  69. "lastns": "0",
  70. "lastvalue": "0",
  71. "prevvalue": "0"
  72. },
  73. {
  74. "itemid": "25555",
  75. "type": "18",
  76. "snmp_community": "",
  77. "snmp_oid": "",
  78. "hostid": "10116",
  79. "name": "Hours",
  80. "key_": "apache.status.uptime.hours",
  81. "delay": "0",
  82. "history": "90d",
  83. "trends": "365d",
  84. "status": "0",
  85. "value_type": "3",
  86. "trapper_hosts": "",
  87. "units": "",
  88. "snmpv3_securityname": "",
  89. "snmpv3_securitylevel": "0",
  90. "snmpv3_authpassphrase": "",
  91. "snmpv3_privpassphrase": "",
  92. "formula": "",
  93. "error": "",
  94. "lastlogsize": "0",
  95. "logtimefmt": "",
  96. "templateid": "0",
  97. "valuemapid": "0",
  98. "params": "",
  99. "ipmi_sensor": "",
  100. "authtype": "0",
  101. "username": "",
  102. "password": "",
  103. "publickey": "",
  104. "privatekey": "",
  105. "mtime": "0",
  106. "flags": "0",
  107. "interfaceid": "0",
  108. "port": "",
  109. "description": "",
  110. "inventory_link": "0",
  111. "lifetime": "30d",
  112. "snmpv3_authprotocol": "0",
  113. "snmpv3_privprotocol": "0",
  114. "state": "0",
  115. "snmpv3_contextname": "",
  116. "evaltype": "0",
  117. "master_itemid": "25545",
  118. "jmx_endpoint": "",
  119. "timeout": "3s",
  120. "url": "",
  121. "query_fields": [],
  122. "posts": "",
  123. "status_codes": "200",
  124. "follow_redirects": "1",
  125. "post_type": "0",
  126. "http_proxy": "",
  127. "headers": [],
  128. "retrieve_mode": "0",
  129. "request_method": "1",
  130. "output_format": "0",
  131. "ssl_cert_file": "",
  132. "ssl_key_file": "",
  133. "ssl_key_password": "",
  134. "verify_peer": "0",
  135. "verify_host": "0",
  136. "allow_traps": "0",
  137. "lastclock": "0",
  138. "lastns": "0",
  139. "lastvalue": "0",
  140. "prevvalue": "0"
  141. }
  142. ],
  143. "id": 1
  144. }

Find HTTP agent item 查找HTTP agent 监控项

Find HTTP agent item with post body type XML for specific host id. 根据定义的主机id来查找带有XML post报文类型的监控项。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "item.get",
  4. "params": {
  5. "hostids": "10255",
  6. "filter": {
  7. "type": "19",
  8. "post_type": "3"
  9. }
  10. },
  11. "id": 3,
  12. "auth": "d678e0b85688ce578ff061bd29a20d3b"
  13. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "itemid": "28252",
  6. "type": "19",
  7. "snmp_community": "",
  8. "snmp_oid": "",
  9. "hostid": "10255",
  10. "name": "template item",
  11. "key_": "ti",
  12. "delay": "30s",
  13. "history": "90d",
  14. "trends": "365d",
  15. "status": "0",
  16. "value_type": "3",
  17. "trapper_hosts": "",
  18. "units": "",
  19. "snmpv3_securityname": "",
  20. "snmpv3_securitylevel": "0",
  21. "snmpv3_authpassphrase": "",
  22. "snmpv3_privpassphrase": "",
  23. "formula": "",
  24. "error": "",
  25. "lastlogsize": "0",
  26. "logtimefmt": "",
  27. "templateid": "0",
  28. "valuemapid": "0",
  29. "params": "",
  30. "ipmi_sensor": "",
  31. "authtype": "0",
  32. "username": "",
  33. "password": "",
  34. "publickey": "",
  35. "privatekey": "",
  36. "mtime": "0",
  37. "flags": "0",
  38. "interfaceid": "0",
  39. "port": "",
  40. "description": "",
  41. "inventory_link": "0",
  42. "lifetime": "30d",
  43. "snmpv3_authprotocol": "0",
  44. "snmpv3_privprotocol": "0",
  45. "state": "0",
  46. "snmpv3_contextname": "",
  47. "evaltype": "0",
  48. "jmx_endpoint": "",
  49. "master_itemid": "0",
  50. "timeout": "3s",
  51. "url": "localhost",
  52. "query_fields": [
  53. {
  54. "mode": "xml"
  55. }
  56. ],
  57. "posts": "<body>\r\n<![CDATA[{$MACRO}<foo></bar>]]>\r\n</body>",
  58. "status_codes": "200",
  59. "follow_redirects": "0",
  60. "post_type": "3",
  61. "http_proxy": "",
  62. "headers": [],
  63. "retrieve_mode": "1",
  64. "request_method": "3",
  65. "output_format": "0",
  66. "ssl_cert_file": "",
  67. "ssl_key_file": "",
  68. "ssl_key_password": "",
  69. "verify_peer": "0",
  70. "verify_host": "0",
  71. "allow_traps": "0",
  72. "lastclock": "0",
  73. "lastns": "0",
  74. "lastvalue": "0",
  75. "prevvalue": "0"
  76. }
  77. ],
  78. "id": 3
  79. }

See also

Source

CItem::get() in frontends/php/include/classes/api/services/CItem.php.