discoveryrule.get

Description

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

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

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.
selectApplicationPrototypesqueryReturn an applicationPrototypes property with application prototypes that belong to all item prototypes that belong to this LLD rule.
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.

params - (string) Additional parameters used by preprocessing option. Multiple parameters are separated by LF (\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:
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”.

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

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

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": 39,
  12. "auth": "d678e0b85688ce578ff061bd29a20d3b"
  13. }

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. "history": "90d",
  13. "trends": "0",
  14. "status": "0",
  15. "value_type": "4",
  16. "trapper_hosts": "",
  17. "units": "",
  18. "error": "",
  19. "logtimefmt": "",
  20. "templateid": "0",
  21. "valuemapid": "0",
  22. "params": "",
  23. "ipmi_sensor": "",
  24. "authtype": "0",
  25. "username": "",
  26. "password": "",
  27. "publickey": "",
  28. "privatekey": "",
  29. "flags": "1",
  30. "interfaceid": "5",
  31. "description": "",
  32. "inventory_link": "0",
  33. "lifetime": "30d",
  34. "state": "0",
  35. "jmx_endpoint": "",
  36. "master_itemid": "0",
  37. "timeout": "3s",
  38. "url": "http://127.0.0.1/discoverer.php",
  39. "query_fields": [
  40. {
  41. "mode": "json"
  42. },
  43. {
  44. "elements": "2"
  45. }
  46. ],
  47. "posts": "",
  48. "status_codes": "200",
  49. "follow_redirects": "1",
  50. "post_type": "0",
  51. "http_proxy": "",
  52. "headers": {
  53. "X-Type": "api",
  54. "Authorization": "Bearer mF_A.B5f-2.1JcM"
  55. },
  56. "retrieve_mode": "0",
  57. "request_method": "1",
  58. "ssl_cert_file": "",
  59. "ssl_key_file": "",
  60. "ssl_key_password": "",
  61. "verify_peer": "0",
  62. "verify_host": "0",
  63. "allow_traps": "0"
  64. }
  65. ],
  66. "id": 39
  67. }

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": 39,
  10. "auth": "d678e0b85688ce578ff061bd29a20d3b"
  11. }

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. "optemplate": [
  39. {
  40. "templateid": "10170"
  41. }
  42. ]
  43. }
  44. ]
  45. },
  46. {
  47. "name": "Discover PostgreSQL host",
  48. "step": "2",
  49. "stop": "1",
  50. "filter": {
  51. "evaltype": "0",
  52. "formula": "",
  53. "conditions": [
  54. {
  55. "macro": "{#UNIT.NAME}",
  56. "operator": "8",
  57. "value": "^postgresql\\.service$"
  58. "formulaid": "A"
  59. }
  60. ],
  61. "eval_formula": "A"
  62. },
  63. "operations": [
  64. {
  65. "operationobject": "3",
  66. "operator": "2",
  67. "value": "Database host",
  68. "opstatus": {
  69. "status": "0"
  70. },
  71. "optemplate": [
  72. {
  73. "templateid": "10263"
  74. }
  75. ]
  76. }
  77. ]
  78. }
  79. ]
  80. }
  81. ],
  82. "id": 39
  83. }

See also

Source

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