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.

Parameter behavior:
- read-only for inherited objects
lld_macro_pathsarrayLLD rule lld_macro_path options.

Parameter behavior:
- read-only for inherited objects
overridesarrayLLD rule overrides options.

Parameter behavior:
- read-only for inherited objects

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

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

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

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "itemids": [
  5. "28336"
  6. ]
  7. },
  8. "id": 1
  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. "id": 1
  16. }

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

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.