discoveryrule.update

Description

object discoveryrule.update(object/array lldRules)

This method allows to update existing LLD rules.

This method is only available to Admin and Super admin user types. Permissions to call the method can be revoked in user role settings. See User roles for more information.

Parameters

(object/array) LLD rule properties to be updated.

The itemid property must be defined for each LLD rule, all other properties are optional. Only the passed properties will be updated, all others will remain unchanged.

Additionally to the standard LLD rule properties, the method accepts the following parameters.

ParameterTypeDescription
filterobjectLLD rule filter object to replace the current filter.
preprocessingarrayLLD rule preprocessing options to replace the current preprocessing options.
lld_macro_pathsarrayLLD rule lld_macro_path options.
overridesarrayLLD rule overrides options.

Return values

(object) Returns an object containing the IDs of the updated LLD rules under the itemids property.

Examples

Adding a filter to an LLD rule

Add a filter so that the contents of the {#FSTYPE} macro would match the @File systems for discovery regexp.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "discoveryrule.update",
  4. "params": {
  5. "itemid": "22450",
  6. "filter": {
  7. "evaltype": 1,
  8. "conditions": [
  9. {
  10. "macro": "{#FSTYPE}",
  11. "value": "@File systems for discovery"
  12. }
  13. ]
  14. }
  15. },
  16. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  17. "id": 1
  18. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "itemids": [
  5. "22450"
  6. ]
  7. },
  8. "id": 1
  9. }

Adding LLD macro paths

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "discoveryrule.update",
  4. "params": {
  5. "itemid": "22450",
  6. "lld_macro_paths": [
  7. {
  8. "lld_macro": "{#MACRO1}",
  9. "path": "$.json.path"
  10. }
  11. ]
  12. },
  13. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  14. "id": 1
  15. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "itemids": [
  5. "22450"
  6. ]
  7. },
  8. "id": 1
  9. }

Disable trapping

Disable LLD trapping for discovery rule.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "discoveryrule.update",
  4. "params": {
  5. "itemid": "28336",
  6. "allow_traps": "0"
  7. },
  8. "id": 36,
  9. "auth": "d678e0b85688ce578ff061bd29a20d3b"
  10. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "itemids": [
  5. "28336"
  6. ]
  7. },
  8. "id": 36
  9. }

Updating LLD rule preprocessing options

Update an LLD rule with preprocessing rule “JSONPath”.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "discoveryrule.update",
  4. "params": {
  5. "itemid": "44211",
  6. "preprocessing": [
  7. {
  8. "type": "12",
  9. "params": "$.path.to.json",
  10. "error_handler": "2",
  11. "error_handler_params": "5"
  12. }
  13. ]
  14. },
  15. "auth": "700ca65537074ec963db7efabda78259",
  16. "id": 1
  17. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "itemids": [
  5. "44211"
  6. ]
  7. },
  8. "id": 1
  9. }

Updating LLD rule script

Update an LLD rule script with a different script and remove unnecessary parameters that were used by previous script.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "discoveryrule.update",
  4. "params": {
  5. "itemid": "23865",
  6. "parameters": [],
  7. "script": "Zabbix.Log(3, 'Log test');\nreturn 1;"
  8. },
  9. "auth": "700ca65537074ec963db7efabda78259",
  10. "id": 1
  11. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "itemids": [
  5. "23865"
  6. ]
  7. },
  8. "id": 1
  9. }

Source

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