discoveryrule.get

Description

integer/array discoveryrule.get(object parameters)

The method allows to retrieve LLD rules according to the given parameters.

This method is available to users of any type. Permissions to call the method can be revoked in user role settings. See User roles for more information.

Parameters

(object) Parameters defining the desired output.

The method supports the following parameters.

ParameterTypeDescription
itemidsstring/arrayReturn only LLD rules with the given IDs.
groupidsstring/arrayReturn only LLD rules that belong to the hosts from the given groups.
hostidsstring/arrayReturn only LLD rules that belong to the given hosts.
inheritedbooleanIf set to true return only LLD rules inherited from a template.
interfaceidsstring/arrayReturn only LLD rules use the given host interfaces.
monitoredbooleanIf set to true return only enabled LLD rules that belong to monitored hosts.
templatedbooleanIf set to true return only LLD rules that belong to templates.
templateidsstring/arrayReturn only LLD rules that belong to the given templates.
selectFilterqueryReturn a filter property with data of the filter used by the LLD rule.
selectGraphsqueryReturns a graphs property with graph prototypes that belong to the LLD rule.

Supports count.
selectHostPrototypesqueryReturn a hostPrototypes property with host prototypes that belong to the LLD rule.

Supports count.
selectHostsqueryReturn a hosts property with an array of hosts that the LLD rule belongs to.
selectItemsqueryReturn an items property with item prototypes that belong to the LLD rule.

Supports count.
selectTriggersqueryReturn a triggers property with trigger prototypes that belong to the LLD rule.

Supports count.
selectLLDMacroPathsqueryReturn an lldmacro_paths property with a list of LLD macros and paths to values assigned to each corresponding macro.
selectPreprocessingqueryReturn a preprocessing property with LLD rule preprocessing options.

It has the following properties:
type - (string) The preprocessing option type:
5 - Regular expression matching;
11 - XML XPath;
12 - JSONPath;
15 - Does not match regular expression;
16 - Check for error in JSON;
17 - Check for error in XML;
20 - Discard unchanged with heartbeat;
23 - Prometheus to JSON;
24 - CSV to JSON;
25 - Replace;
27 - XML to JSON.
28 - SNMP walk value
29 - SNMP walk to JSON

params - (string) Additional parameters used by preprocessing option. Multiple parameters are separated by the newline (\n) character.
error_handler - (string) Action type used in case of preprocessing step failure:
0 - Error message is set by Zabbix server;
1 - Discard value;
2 - Set custom value;
3 - Set custom error message.

error_handler_params - (string) Error handler parameters.
selectOverridesqueryReturn an lld_rule_overrides property with a list of override filters, conditions and operations that are performed on prototype objects.
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: selectItems, selectGraphs, selectTriggers.
sortfieldstring/arraySort the result by the given properties.

Possible values: itemid, name, key, delay, type, 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 for specific host ID.

Request:

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

Response:

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

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": ["name"],
  6. "selectFilter": "extend",
  7. "itemids": ["24681"]
  8. },
  9. "id": 1
  10. }

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": "9",
  21. "formulaid": "B"
  22. },
  23. {
  24. "macro": "{#MACRO3}",
  25. "value": "",
  26. "operator": "12",
  27. "formulaid": "C"
  28. },
  29. {
  30. "macro": "{#MACRO4}",
  31. "value": "",
  32. "operator": "13",
  33. "formulaid": "D"
  34. }
  35. ],
  36. "eval_formula": "A and B and C and D"
  37. }
  38. }
  39. ],
  40. "id": 1
  41. }

Retrieve LLD rule by URL

Retrieve LLD rule for host by rule URL field value. Only exact match of URL string defined for LLD rule is supported.

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

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "itemid": "28336",
  6. "type": "19",
  7. "snmp_oid": "",
  8. "hostid": "10257",
  9. "name": "API HTTP agent",
  10. "key_": "api_discovery_rule",
  11. "delay": "5s",
  12. "status": "0",
  13. "trapper_hosts": "",
  14. "templateid": "0",
  15. "valuemapid": "0",
  16. "params": "",
  17. "ipmi_sensor": "",
  18. "authtype": "0",
  19. "username": "",
  20. "password": "",
  21. "publickey": "",
  22. "privatekey": "",
  23. "interfaceid": "5",
  24. "description": "",
  25. "lifetime": "30d",
  26. "jmx_endpoint": "",
  27. "master_itemid": "0",
  28. "timeout": "3s",
  29. "url": "http://127.0.0.1/discoverer.php",
  30. "query_fields": [
  31. {
  32. "mode": "json"
  33. },
  34. {
  35. "elements": "2"
  36. }
  37. ],
  38. "posts": "",
  39. "status_codes": "200",
  40. "follow_redirects": "1",
  41. "post_type": "0",
  42. "http_proxy": "",
  43. "headers": {
  44. "X-Type": "api",
  45. "Authorization": "Bearer mF_A.B5f-2.1JcM"
  46. },
  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. "uuid": "",
  56. "state": "0",
  57. "error": "",
  58. "parameters": []
  59. }
  60. ],
  61. "id": 1
  62. }

Retrieve LLD rule with overrides

Retrieve one LLD rule that has various override settings.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "discoveryrule.get",
  4. "params": {
  5. "output": ["name"],
  6. "itemids": "30980",
  7. "selectOverrides": ["name", "step", "stop", "filter", "operations"]
  8. },
  9. "id": 1
  10. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "name": "Discover database host",
  6. "overrides": [
  7. {
  8. "name": "Discover MySQL host",
  9. "step": "1",
  10. "stop": "1",
  11. "filter": {
  12. "evaltype": "2",
  13. "formula": "",
  14. "conditions": [
  15. {
  16. "macro": "{#UNIT.NAME}",
  17. "operator": "8",
  18. "value": "^mysqld\\.service$",
  19. "formulaid": "A"
  20. },
  21. {
  22. "macro": "{#UNIT.NAME}",
  23. "operator": "8",
  24. "value": "^mariadb\\.service$",
  25. "formulaid": "B"
  26. }
  27. ],
  28. "eval_formula": "A or B"
  29. },
  30. "operations": [
  31. {
  32. "operationobject": "3",
  33. "operator": "2",
  34. "value": "Database host",
  35. "opstatus": {
  36. "status": "0"
  37. },
  38. "optag": [
  39. {
  40. "tag": "Database",
  41. "value": "MySQL"
  42. }
  43. ],
  44. "optemplate": [
  45. {
  46. "templateid": "10170"
  47. }
  48. ]
  49. }
  50. ]
  51. },
  52. {
  53. "name": "Discover PostgreSQL host",
  54. "step": "2",
  55. "stop": "1",
  56. "filter": {
  57. "evaltype": "0",
  58. "formula": "",
  59. "conditions": [
  60. {
  61. "macro": "{#UNIT.NAME}",
  62. "operator": "8",
  63. "value": "^postgresql\\.service$",
  64. "formulaid": "A"
  65. }
  66. ],
  67. "eval_formula": "A"
  68. },
  69. "operations": [
  70. {
  71. "operationobject": "3",
  72. "operator": "2",
  73. "value": "Database host",
  74. "opstatus": {
  75. "status": "0"
  76. },
  77. "optag": [
  78. {
  79. "tag": "Database",
  80. "value": "PostgreSQL"
  81. }
  82. ],
  83. "optemplate": [
  84. {
  85. "templateid": "10263"
  86. }
  87. ]
  88. }
  89. ]
  90. }
  91. ]
  92. }
  93. ],
  94. "id": 1
  95. }

See also

Source

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