This is a translation of the original English documentation page. Help us make it better.

trigger.create

Description

object trigger.create(object/array triggers)

This method allows to create new triggers.

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) Triggers to create.

Additionally to the standard trigger properties the method accepts the following parameters.

Parameter Type Description
dependencies array Triggers that the trigger is dependent on.

The triggers must have the triggerid property defined.
tags array Trigger tags.

The trigger expression has to be given in its expanded form.

Valori di ritorno

(object) Restituisce un oggetto contenente gli ID dei trigger creati sotto la proprietà triggerids. L'ordine degli ID restituiti corrisponde all'ordine dei trigger passati.

Esempi

Creating a trigger

Create a trigger with a single trigger dependency.

Request:

{
           "jsonrpc": "2.0",
           "method": "trigger.create",
           "params": [
               {
                   "description": "Processor load is too high on {HOST.NAME}",
                   "expression": "last(/Linux server/system.cpu.load[percpu,avg1])>5",
                   "dependencies": [
                       {
                           "triggerid": "17367"
                       }
                   ]
               },
               {
                   "description": "Service status",
                   "expression": "length(last(/Linux server/log[/var/log/system,Service .* has stopped]))<>0",
                   "dependencies": [
                       {
                           "triggerid": "17368"
                       }
                   ],
                   "tags": [
                       {
                           "tag": "service",
                           "value": "{{ITEM.VALUE}.regsub(\"Service (.*) has stopped\", \"\\1\")}"
                       },
                       {
                           "tag": "error",
                           "value": ""
                       }
                   ]
               }
           ],
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

{
           "jsonrpc": "2.0",
           "result": {
               "triggerids": [
                   "17369",
                   "17370"
               ]
           },
           "id": 1
       }

Fonte

CTrigger::create() in ui/include/classes/api/services/CTrigger.php.