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.定义所需输出的参数。

The method supports the following parameters.该方法支持以下参数。

属性 类型 说明
itemids string/array Return only LLD rules with the given IDs.
hostids string/array Return only LLD rules that belong to the given hosts.
inherited boolean If set to true return only LLD rules inherited from a template.
interfaceids string/array Return only LLD rules use the given host interfaces.
monitored boolean If set to true return only enabled LLD rules that belong to monitored hosts.
templated boolean If set to true return only LLD rules that belong to templates.
templateids string/array Return only LLD rules that belong to the given templates.
selectFilter query Returns the filter used by the LLD rule in the filter property.
selectGraphs query Returns graph prototypes that belong to the LLD rule in the graphs property. Supports count.
selectHostPrototypes query Returns host prototypes that belong to the LLD rule in the hostPrototypes property. Supports count.
selectHosts query Returns the host that the LLD rule belongs to as an array in the hosts property.
selectItems query Returns item prototypes that belong to the LLD rule in the items property. Supports count.
selectTriggers query Returns trigger prototypes that belong to the LLD rule in the triggers property. Supports count.
filter object Return 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.
limitSelects integer Limits the number of records returned by subselects. Applies to the following subselects: selctItems; selectGraphs; selectTriggers.
sortfield string/array Sort the result by the given properties. Possible values are: itemid, name, key_, delay, type and status.
countOutput flagThese parameters being common for all get methods are described in detail in the reference commentary.
editable boolean
excludeSearch flag
limit integer
output query
preservekeys flag
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch flag

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”.

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. },
  36. {
  37. "itemid": "27426",
  38. "type": "0",
  39. "snmp_community": "",
  40. "snmp_oid": "",
  41. "hostid": "10202",
  42. "name": "Mounted filesystem discovery",
  43. "key_": "vfs.fs.discovery",
  44. "delay": "1h",
  45. "state": "0",
  46. "status": "0",
  47. "trapper_hosts": "",
  48. "snmpv3_securityname": "",
  49. "snmpv3_securitylevel": "0",
  50. "snmpv3_authpassphrase": "",
  51. "snmpv3_privpassphrase": "",
  52. "error": "",
  53. "templateid": "22450",
  54. "params": "",
  55. "ipmi_sensor": "",
  56. "authtype": "0",
  57. "username": "",
  58. "password": "",
  59. "publickey": "",
  60. "privatekey": "",
  61. "interfaceid": "119",
  62. "port": "",
  63. "description": "Discovery of file systems of different types as defined in global regular expression \"File systems for discovery\".",
  64. "lifetime": "30d",
  65. "snmpv3_authprotocol": "0",
  66. "snmpv3_privprotocol": "0"
  67. }
  68. ],
  69. "id": 2
  70. }

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. }

See also 参见

Source 来源

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