discoveryrule.get

Description 说明

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

The method allows to retrieve LLD rules according to the given parameters. 此方法允许根据给定的参数获取LLD规则。

Parameters 参数

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

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

ParameterTypeDescription
itemidsstring/arrayReturn only LLD rules with the given IDs. 返回给定IDs的LLD规则。
hostidsstring/arrayReturn only LLD rules that belong to the given hosts. 返回属于给定主机的LLD规则。
inheritedbooleanIf set to true return only LLD rules inherited from a template. 如果设为true,返回自称自某模板的LLD规则。
interfaceidsstring/arrayReturn only LLD rules use the given host interfaces. 返回使用给定主机接口的LLD规则。
monitoredbooleanIf set to true return only enabled LLD rules that belong to monitored hosts. 如果设为true,返回已经启用的属于已监控主机的LLD规则。
templatedbooleanIf set to true return only LLD rules that belong to templates. 如果设为true,返回属于(多个)模板的LLD规则。
templateidsstring/arrayReturn only LLD rules that belong to the given templates. 返回属于给定给定模板的LLD规则。
selectFilterqueryReturns the filter used by the LLD rule in the filter property. 在filter中返回LLD使用的筛选器。
selectGraphsqueryReturns graph prototypes that belong to the LLD rule in the graphs property. 在graphs属性中返回属于LLD规则的图表原型。

Supports count.
selectHostPrototypesqueryReturns host prototypes that belong to the LLD rule in the hostPrototypes property. 在hostPrototypes属性中返回属于该LLD规则的主机原型。

Supports count.
selectHostsqueryReturns the host that the LLD rule belongs to as an array in the hosts property. 在hosts属性下以数组形式返回属于该LLD规则的主机。
selectItemsqueryReturns item prototypes that belong to the LLD rule in the items property. 在items下返回属于该LLD规则的item。

Supports count.
selectTriggersqueryReturns trigger prototypes that belong to the LLD rule in the triggers property. 在triggers属性下返回属于该触发器原型。

Supports count.
filterobjectReturn only those results that exactly match the given filter. 仅返回紧缺匹配给定筛选条件的结果。

Accepts an array, where the keys are property names, and the values are either a single value or an array of values to match against. 接受一个数组,这些数组的键为属性名称,值是一个或数组中的值的要匹配的值。

Supports additional filters:
host - technical name of the host that the LLD rule belongs to.
limitSelectsintegerLimits the number of records returned by subselects. 限制子选择返回的结果的数量。

Applies to the following subselects:
selctItems;
selectGraphs;
selectTriggers.
sortfieldstring/arraySort the result by the given properties. 根据给定的属性把结果进行排序。

Possible values are: itemid, name, key_, delay, type and status.
countOutputbooleanThese parameters being common for all get methods are described in detail in the reference commentary.
editableboolean
excludeSearchboolean
limitinteger
outputquery
preservekeysboolean
searchobject
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean

Return values 返回值

(integer/array) Returns either:

  • an array of objects;

  • the count of retrieved objects, if the countOutput parameter has been used.

Examples 示例

Retrieving discovery rules from a host 从一个主机获取多有的发现规则

Retrieve all discovery rules from host “10202”. 获取主机“10202”所有的发现规则。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "discoveryrule.get",
  4. "params": {
  5. "output": "extend",
  6. "hostids": "10202"
  7. },
  8. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  9. "id": 1
  10. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "itemid": "27425",
  6. "type": "0",
  7. "snmp_community": "",
  8. "snmp_oid": "",
  9. "hostid": "10202",
  10. "name": "Network interface discovery",
  11. "key_": "net.if.discovery",
  12. "delay": "1h",
  13. "state": "0",
  14. "status": "0",
  15. "trapper_hosts": "",
  16. "snmpv3_securityname": "",
  17. "snmpv3_securitylevel": "0",
  18. "snmpv3_authpassphrase": "",
  19. "snmpv3_privpassphrase": "",
  20. "error": "",
  21. "templateid": "22444",
  22. "params": "",
  23. "ipmi_sensor": "",
  24. "authtype": "0",
  25. "username": "",
  26. "password": "",
  27. "publickey": "",
  28. "privatekey": "",
  29. "interfaceid": "119",
  30. "port": "",
  31. "description": "Discovery of network interfaces as defined in global regular expression \"Network interfaces for discovery\".",
  32. "lifetime": "30d",
  33. "snmpv3_authprotocol": "0",
  34. "snmpv3_privprotocol": "0",
  35. "snmpv3_contextname": "",
  36. "jmx_endpoint": "",
  37. "master_itemid": "0",
  38. "timeout": "3s",
  39. "url": "",
  40. "query_fields": [],
  41. "posts": "",
  42. "status_codes": "200",
  43. "follow_redirects": "1",
  44. "post_type": "0",
  45. "http_proxy": "",
  46. "headers": [],
  47. "retrieve_mode": "0",
  48. "request_method": "1",
  49. "ssl_cert_file": "",
  50. "ssl_key_file": "",
  51. "ssl_key_password": "",
  52. "verify_peer": "0",
  53. "verify_host": "0",
  54. "allow_traps": "0"
  55. },
  56. {
  57. "itemid": "27426",
  58. "type": "0",
  59. "snmp_community": "",
  60. "snmp_oid": "",
  61. "hostid": "10202",
  62. "name": "Mounted filesystem discovery",
  63. "key_": "vfs.fs.discovery",
  64. "delay": "1h",
  65. "state": "0",
  66. "status": "0",
  67. "trapper_hosts": "",
  68. "snmpv3_securityname": "",
  69. "snmpv3_securitylevel": "0",
  70. "snmpv3_authpassphrase": "",
  71. "snmpv3_privpassphrase": "",
  72. "error": "",
  73. "templateid": "22450",
  74. "params": "",
  75. "ipmi_sensor": "",
  76. "authtype": "0",
  77. "username": "",
  78. "password": "",
  79. "publickey": "",
  80. "privatekey": "",
  81. "interfaceid": "119",
  82. "port": "",
  83. "description": "Discovery of file systems of different types as defined in global regular expression \"File systems for discovery\".",
  84. "lifetime": "30d",
  85. "snmpv3_authprotocol": "0",
  86. "snmpv3_privprotocol": "0",
  87. "snmpv3_contextname": "",
  88. "jmx_endpoint": "",
  89. "master_itemid": "0",
  90. "timeout": "3s",
  91. "url": "",
  92. "query_fields": [],
  93. "posts": "",
  94. "status_codes": "200",
  95. "follow_redirects": "1",
  96. "post_type": "0",
  97. "http_proxy": "",
  98. "headers": [],
  99. "retrieve_mode": "0",
  100. "request_method": "1",
  101. "ssl_cert_file": "",
  102. "ssl_key_file": "",
  103. "ssl_key_password": "",
  104. "verify_peer": "0",
  105. "verify_host": "0",
  106. "allow_traps": "0"
  107. }
  108. ],
  109. "id": 1
  110. }

Retrieving filter conditions

Retrieve the name of the LLD rule “24681” and its filter conditions. The filter uses the “and” evaluation type, so the formula property is empty and eval_formula is generated automatically.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "discoveryrule.get",
  4. "params": {
  5. "output": [
  6. "name"
  7. ],
  8. "selectFilter": "extend",
  9. "itemids": ["24681"]
  10. },
  11. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  12. "id": 1
  13. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "itemid": "24681",
  6. "name": "Filtered LLD rule",
  7. "filter": {
  8. "evaltype": "1",
  9. "formula": "",
  10. "conditions": [
  11. {
  12. "macro": "{#MACRO1}",
  13. "value": "@regex1",
  14. "operator": "8",
  15. "formulaid": "A"
  16. },
  17. {
  18. "macro": "{#MACRO2}",
  19. "value": "@regex2",
  20. "operator": "8",
  21. "formulaid": "B"
  22. },
  23. {
  24. "macro": "{#MACRO3}",
  25. "value": "@regex3",
  26. "operator": "8",
  27. "formulaid": "C"
  28. }
  29. ],
  30. "eval_formula": "A and B and C"
  31. }
  32. }
  33. ],
  34. "id": 1
  35. }

Retrieve LLD rule by URL 根据URL获取LLD规则

Retrieve LLD rule for host by rule URL field value. Only exact match of URL string defined for LLD rule is supported. 根据主机的规则URL字段值获取LLD规则。仅返回精确匹配定义的URL字符串的规则。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "discoveryrule.get",
  4. "params": {
  5. "hostids": "10257",
  6. "filter": {
  7. "type": "19",
  8. "url": "http://127.0.0.1/discoverer.php"
  9. }
  10. },
  11. "id": 39,
  12. "auth": "d678e0b85688ce578ff061bd29a20d3b"
  13. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "itemid": "28336",
  6. "type": "19",
  7. "snmp_community": "",
  8. "snmp_oid": "",
  9. "hostid": "10257",
  10. "name": "API HTTP agent",
  11. "key_": "api_discovery_rule",
  12. "delay": "5s",
  13. "history": "90d",
  14. "trends": "0",
  15. "status": "0",
  16. "value_type": "4",
  17. "trapper_hosts": "",
  18. "units": "",
  19. "snmpv3_securityname": "",
  20. "snmpv3_securitylevel": "0",
  21. "snmpv3_authpassphrase": "",
  22. "snmpv3_privpassphrase": "",
  23. "error": "",
  24. "lastlogsize": "0",
  25. "logtimefmt": "",
  26. "templateid": "0",
  27. "valuemapid": "0",
  28. "params": "",
  29. "ipmi_sensor": "",
  30. "authtype": "0",
  31. "username": "",
  32. "password": "",
  33. "publickey": "",
  34. "privatekey": "",
  35. "mtime": "0",
  36. "flags": "1",
  37. "interfaceid": "5",
  38. "port": "",
  39. "description": "",
  40. "inventory_link": "0",
  41. "lifetime": "30d",
  42. "snmpv3_authprotocol": "0",
  43. "snmpv3_privprotocol": "0",
  44. "state": "0",
  45. "snmpv3_contextname": "",
  46. "jmx_endpoint": "",
  47. "master_itemid": "0",
  48. "timeout": "3s",
  49. "url": "http://127.0.0.1/discoverer.php",
  50. "query_fields": [
  51. {
  52. "mode": "json"
  53. },
  54. {
  55. "elements": "2"
  56. }
  57. ],
  58. "posts": "",
  59. "status_codes": "200",
  60. "follow_redirects": "1",
  61. "post_type": "0",
  62. "http_proxy": "",
  63. "headers": {
  64. "X-Type": "api",
  65. "Authorization": "Bearer mF_A.B5f-2.1JcM"
  66. },
  67. "retrieve_mode": "0",
  68. "request_method": "1",
  69. "ssl_cert_file": "",
  70. "ssl_key_file": "",
  71. "ssl_key_password": "",
  72. "verify_peer": "0",
  73. "verify_host": "0",
  74. "allow_traps": "0"
  75. }
  76. ],
  77. "id": 39
  78. }

See also

Source

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