获取

描述

integer/array item.get(object parameters)

此方法允许根据给定的参数检索监控项。

此方法适用于任何类型的用户。可以在用户角色设置中撤销调用此方法的权限。更多信息请参阅用户角色

参数

(object) 定义所需输出的参数。

该方法支持以下参数。

参数类型描述
itemidsID/array只返回具有给定ID的监控项。
groupidsID/array只返回属于给定组的监控项。
templateidsID/array只返回属于给定模板的监控项。
hostidsID/array只返回属于给定主机的监控项。
proxyidsID/array只返回由给定代理监控的监控项。
interfaceidsID/array只返回使用给定主机接口的监控项。
graphidsID/array只返回在给定图表中使用的监控项。
triggeridsID/array只返回在给定触发器中使用的监控项。
webitemsflag在结果中包含网页监控项。
inheritedboolean如果设置为true,则只返回从模板继承的监控项。
templatedboolean如果设置为true,则只返回属于模板的监控项。
monitoredboolean如果设置为true,则只返回属于被监控主机的启用的监控项。
groupstring只返回属于具有给定名称的组的监控项。
hoststring只返回属于具有给定名称的主机的监控项。
evaltypeinteger标签搜索规则。

可能的值:
0 - (默认)与/或;
2 - 或。
tagsarray只返回具有给定标签的监控项。根据操作符的值,可以进行精确匹配标签,或者进行大小写敏感或不敏感的标签值搜索。
格式:[{“tag”: “<tag>”, “value”: “<value>”, “operator”: “<operator>”}, …]
空数组返回所有监控项。
可能的操作符类型:
0 - (默认)类似;
1 - 等于;
2 - 不类似;
3 - 不等于;
4 - 存在;
5 - 不存在。
withtriggersboolean如果设置为true,则只返回在触发器中使用的监控项。
selectHostsquery返回一个hosts属性,包含监控项所属的主机数组。
selectInterfacesquery返回一个interfaces属性,包含监控项使用的主机接口数组。
selectTriggersquery返回一个triggers属性,包含监控项使用的触发器。
支持count
selectGraphsquery返回一个graphs属性,包含包含监控项的图表。
支持count
selectDiscoveryRulequery返回一个discoveryRule属性,包含创建监控项的LLD规则。
selectItemDiscoveryquery返回一个itemDiscovery属性,包含监控项发现对象。该对象链接了监控项与其原型。

包含以下属性:
itemdiscoveryid - 监控项发现的ID;
itemid - 被发现监控项的ID;
parent_itemid - 创建监控项的原型ID;
key - 监控项原型的键;
lastcheck - 上次发现监控项的时间;
status - 监控项发现状态:
0 - (默认) 监控项已发现,
1 - 监控项不再被发现;
tsdelete - 不再被发现的监控项将被删除的时间;
ts_disable - 不再被发现的监控项将被禁用的时间;
disable_source - 监控项是被LLD规则还是手动禁用的指示器:
0 - (默认) 自动禁用,
1 - 由LLD规则禁用。
selectPreprocessingquery返回一个preprocessing属性,包含监控项预处理选项。
selectTagsquery返回tags属性中的监控项标签。
selectValueMapquery返回一个valuemap属性,包含监控项的值映射。
filterobject只返回完全符合给定过滤器的结果。

接受一个对象,其中键是属性名称,值是单一值或值数组。

不支持text 数据类型的属性。

支持额外属性:
host - 监控项所属的主机的技术名称。
limitSelectsinteger限制子选择返回的记录数。适用于以下子选择:selectGraphs - 结果将按name排序;selectTriggers - 结果将按description排序。
sortfieldstring/array根据给定属性对结果进行排序。可能的值:itemid, name, key, delay, history, trends, type, status
countOutputboolean这些参数对于所有get方法都是通用的,在参考注释页面中有详细描述。
editableboolean
excludeSearchboolean
limitinteger
outputquery
preservekeysboolean
searchobject
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean

返回值

(integer/array) 返回其中之一:

  • 一组对象;
  • 如果使用了 countOutput 参数,则检索对象的计数。

示例

按照关键字查找监控项

检索特定主机ID中用于触发器的所有监控项,这些监控项的项键中包含单词“system.cpu”,并按名称排序结果。

请求

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

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "itemid": "42269",
  6. "type": "18",
  7. "snmp_oid": "",
  8. "hostid": "10084",
  9. "name": "CPU utilization",
  10. "key_": "system.cpu.util",
  11. "delay": "0",
  12. "history": "7d",
  13. "trends": "365d",
  14. "status": "0",
  15. "value_type": "0",
  16. "trapper_hosts": "",
  17. "units": "%",
  18. "logtimefmt": "",
  19. "templateid": "42267",
  20. "valuemapid": "0",
  21. "params": "",
  22. "ipmi_sensor": "",
  23. "authtype": "0",
  24. "username": "",
  25. "password": "",
  26. "publickey": "",
  27. "privatekey": "",
  28. "flags": "0",
  29. "interfaceid": "0",
  30. "description": "CPU utilization in %.",
  31. "inventory_link": "0",
  32. "evaltype": "0",
  33. "jmx_endpoint": "",
  34. "master_itemid": "42264",
  35. "timeout": "",
  36. "url": "",
  37. "query_fields": [],
  38. "posts": "",
  39. "status_codes": "200",
  40. "follow_redirects": "1",
  41. "post_type": "0",
  42. "http_proxy": "",
  43. "headers": [],
  44. "retrieve_mode": "0",
  45. "request_method": "0",
  46. "output_format": "0",
  47. "ssl_cert_file": "",
  48. "ssl_key_file": "",
  49. "ssl_key_password": "",
  50. "verify_peer": "0",
  51. "verify_host": "0",
  52. "allow_traps": "0",
  53. "uuid": "",
  54. "state": "0",
  55. "error": "",
  56. "parameters": [],
  57. "lastclock": "0",
  58. "lastns": "0",
  59. "lastvalue": "0",
  60. "prevvalue": "0",
  61. "name_resolved": "CPU utilization"
  62. },
  63. {
  64. "itemid": "42259",
  65. "type": "0",
  66. "snmp_oid": "",
  67. "hostid": "10084",
  68. "name": "Load average (15m avg)",
  69. "key_": "system.cpu.load[all,avg15]",
  70. "delay": "1m",
  71. "history": "7d",
  72. "trends": "365d",
  73. "status": "0",
  74. "value_type": "0",
  75. "trapper_hosts": "",
  76. "units": "",
  77. "logtimefmt": "",
  78. "templateid": "42219",
  79. "valuemapid": "0",
  80. "params": "",
  81. "ipmi_sensor": "",
  82. "authtype": "0",
  83. "username": "",
  84. "password": "",
  85. "publickey": "",
  86. "privatekey": "",
  87. "flags": "0",
  88. "interfaceid": "1",
  89. "description": "",
  90. "inventory_link": "0",
  91. "evaltype": "0",
  92. "jmx_endpoint": "",
  93. "master_itemid": "0",
  94. "timeout": "",
  95. "url": "",
  96. "query_fields": [],
  97. "posts": "",
  98. "status_codes": "200",
  99. "follow_redirects": "1",
  100. "post_type": "0",
  101. "http_proxy": "",
  102. "headers": [],
  103. "retrieve_mode": "0",
  104. "request_method": "0",
  105. "output_format": "0",
  106. "ssl_cert_file": "",
  107. "ssl_key_file": "",
  108. "ssl_key_password": "",
  109. "verify_peer": "0",
  110. "verify_host": "0",
  111. "allow_traps": "0",
  112. "uuid": "",
  113. "state": "0",
  114. "error": "",
  115. "parameters": [],
  116. "lastclock": "0",
  117. "lastns": "0",
  118. "lastvalue": "0",
  119. "prevvalue": "0",
  120. "name_resolved": "Load average (15m avg)"
  121. },
  122. {
  123. "itemid": "42249",
  124. "type": "0",
  125. "snmp_oid": "",
  126. "hostid": "10084",
  127. "name": "Load average (1m avg)",
  128. "key_": "system.cpu.load[all,avg1]",
  129. "delay": "1m",
  130. "history": "7d",
  131. "trends": "365d",
  132. "status": "0",
  133. "value_type": "0",
  134. "trapper_hosts": "",
  135. "units": "",
  136. "logtimefmt": "",
  137. "templateid": "42209",
  138. "valuemapid": "0",
  139. "params": "",
  140. "ipmi_sensor": "",
  141. "authtype": "0",
  142. "username": "",
  143. "password": "",
  144. "publickey": "",
  145. "privatekey": "",
  146. "flags": "0",
  147. "interfaceid": "1",
  148. "description": "",
  149. "inventory_link": "0",
  150. "evaltype": "0",
  151. "jmx_endpoint": "",
  152. "master_itemid": "0",
  153. "timeout": "",
  154. "url": "",
  155. "query_fields": [],
  156. "posts": "",
  157. "status_codes": "200",
  158. "follow_redirects": "1",
  159. "post_type": "0",
  160. "http_proxy": "",
  161. "headers": [],
  162. "retrieve_mode": "0",
  163. "request_method": "0",
  164. "output_format": "0",
  165. "ssl_cert_file": "",
  166. "ssl_key_file": "",
  167. "ssl_key_password": "",
  168. "verify_peer": "0",
  169. "verify_host": "0",
  170. "allow_traps": "0",
  171. "uuid": "",
  172. "state": "0",
  173. "error": "",
  174. "parameters": [],
  175. "lastclock": "0",
  176. "lastns": "0",
  177. "lastvalue": "0",
  178. "prevvalue": "0",
  179. "name": "Load average (1m avg)"
  180. },
  181. {
  182. "itemid": "42257",
  183. "type": "0",
  184. "snmp_oid": "",
  185. "hostid": "10084",
  186. "name": "Load average (5m avg)",
  187. "key_": "system.cpu.load[all,avg5]",
  188. "delay": "1m",
  189. "history": "7d",
  190. "trends": "365d",
  191. "status": "0",
  192. "value_type": "0",
  193. "trapper_hosts": "",
  194. "units": "",
  195. "logtimefmt": "",
  196. "templateid": "42217",
  197. "valuemapid": "0",
  198. "params": "",
  199. "ipmi_sensor": "",
  200. "authtype": "0",
  201. "username": "",
  202. "password": "",
  203. "publickey": "",
  204. "privatekey": "",
  205. "flags": "0",
  206. "interfaceid": "1",
  207. "description": "",
  208. "inventory_link": "0",
  209. "evaltype": "0",
  210. "jmx_endpoint": "",
  211. "master_itemid": "0",
  212. "timeout": "",
  213. "url": "",
  214. "query_fields": [],
  215. "posts": "",
  216. "status_codes": "200",
  217. "follow_redirects": "1",
  218. "post_type": "0",
  219. "http_proxy": "",
  220. "headers": [],
  221. "retrieve_mode": "0",
  222. "request_method": "0",
  223. "output_format": "0",
  224. "ssl_cert_file": "",
  225. "ssl_key_file": "",
  226. "ssl_key_password": "",
  227. "verify_peer": "0",
  228. "verify_host": "0",
  229. "allow_traps": "0",
  230. "uuid": "",
  231. "state": "0",
  232. "error": "",
  233. "parameters": [],
  234. "lastclock": "0",
  235. "lastns": "0",
  236. "lastvalue": "0",
  237. "prevvalue": "0",
  238. "name_resolved": "Load average (5m avg)"
  239. },
  240. {
  241. "itemid": "42260",
  242. "type": "0",
  243. "snmp_oid": "",
  244. "hostid": "10084",
  245. "name": "Number of CPUs",
  246. "key_": "system.cpu.num",
  247. "delay": "1m",
  248. "history": "7d",
  249. "trends": "365d",
  250. "status": "0",
  251. "value_type": "3",
  252. "trapper_hosts": "",
  253. "units": "",
  254. "logtimefmt": "",
  255. "templateid": "42220",
  256. "valuemapid": "0",
  257. "params": "",
  258. "ipmi_sensor": "",
  259. "authtype": "0",
  260. "username": "",
  261. "password": "",
  262. "publickey": "",
  263. "privatekey": "",
  264. "flags": "0",
  265. "interfaceid": "1",
  266. "description": "",
  267. "inventory_link": "0",
  268. "evaltype": "0",
  269. "jmx_endpoint": "",
  270. "master_itemid": "0",
  271. "timeout": "",
  272. "url": "",
  273. "query_fields": [],
  274. "posts": "",
  275. "status_codes": "200",
  276. "follow_redirects": "1",
  277. "post_type": "0",
  278. "http_proxy": "",
  279. "headers": [],
  280. "retrieve_mode": "0",
  281. "request_method": "0",
  282. "output_format": "0",
  283. "ssl_cert_file": "",
  284. "ssl_key_file": "",
  285. "ssl_key_password": "",
  286. "verify_peer": "0",
  287. "verify_host": "0",
  288. "allow_traps": "0",
  289. "uuid": "",
  290. "state": "0",
  291. "error": "",
  292. "parameters": [],
  293. "lastclock": "0",
  294. "lastns": "0",
  295. "lastvalue": "0",
  296. "prevvalue": "0",
  297. "name_resolved": "Number of CPUs"
  298. }
  299. ],
  300. "id": 1
  301. }

按关键字查找依赖监控项

检索目标 ID 为 “10116” 的主机,包含关键字 “apache” 的所有依赖监控项。

请求

  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. "id": 1
  15. }

响应:

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

查找 HTTP 代理的监控项

查找具有特定主机 id 的 post 正文类型 XML 的 HTTP agent 监控项。

请求

  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": 1
  12. }

响应:

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

检索预处理规则监控项

检索 ID 为 “10254” 的主机所有监控项及其预处理规则。

请求

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "item.get",
  4. "params": {
  5. "output": ["itemid", "name", "key_"],
  6. "selectPreprocessing": "extend",
  7. "hostids": "10254"
  8. },
  9. "id": 1
  10. }

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "itemid": "23865",
  5. "name": "HTTP agent example JSON",
  6. "key_": "json",
  7. "preprocessing": [
  8. {
  9. "type": "12",
  10. "params": "$.random",
  11. "error_handler": "1",
  12. "error_handler_params": ""
  13. }
  14. ]
  15. },
  16. "id": 1
  17. }

参阅

来源

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