[comment]: # translation:outdated

[comment]: # ({c7f202d4-c7f202d4})
# action.create

[comment]: # ({/c7f202d4-c7f202d4})

[comment]: # ({b15ccd83-71c93aa0})
### Beschreibung

`object action.create(object/array actions)`

Diese Methode ermöglicht das Erstellen neuer Aktionen.

::: noteclassic
Diese Methode ist nur für die Benutzertypen *Admin* und *Super admin*
verfügbar. Die Berechtigungen zum Aufrufen der Methode können in den Einstellungen der Benutzerrolle
entzogen werden. Weitere Informationen finden Sie unter [Benutzerrollen](/manual/web_interface/frontend_sections/users/user_roles).
:::

[comment]: # ({/b15ccd83-71c93aa0})

[comment]: # ({e2f647f1-5a9be3c9})
### Parameter

`(object/array)` Zu erstellende Aktionen.

Zusätzlich zu den [Standard-Aktionseigenschaften](object#action) akzeptiert die
Methode die folgenden Parameter.

|Parameter|[Type](/manual/api/reference_commentary#data-types)|Beschreibung|
|--|--|------|
|filter|object|Objekt für den [Aktionsfilter](/manual/api/reference/action/object#action-filter) der Aktion.|
|operations|array|Zu erstellende [Aktionsoperationen](/manual/api/reference/action/object#action-operation) für die Aktion.|
|recovery\_operations|array|Zu erstellende [Aktions-Wiederherstellungsoperationen](/manual/api/reference/action/object#action-recovery-operation) für die Aktion.|
|update\_operations|array|Zu erstellende [Aktions-Aktualisierungsoperationen](/manual/api/reference/action/object#action-update-operation) für die Aktion.|

[comment]: # ({/e2f647f1-5a9be3c9})

[comment]: # ({2830affd-2830affd})
### Rückgabe-Werte

`(object)` Gibt ein Objekt zurück, das die IDs der erstellten Aktionen
unter der Eigenschaft `actionids` enthält. Die Reihenfolge der zurückgegebenen IDs entspricht
der Reihenfolge der übergebenen Aktionen.

[comment]: # ({/2830affd-2830affd})

[comment]: # ({b41637d2-b41637d2})
### Beispiele

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({9ca78970-afc96865})
#### Eine Auslöser-Aktion erstellen

Erstellen Sie eine Auslöser-Aktion, die beginnt, sobald ein Auslöser (mit dem Wort „memory“ in seinem Namen) von Host „10084“ in den Status PROBLEM wechselt.
Die Aktion wird 4 konfigurierte Operationen haben.
Die erste und sofortige Operation sendet eine Nachricht an alle Benutzer der Benutzergruppe „7“ über den Medientyp „1“.
Wenn das Ereignis nicht innerhalb von 30 Minuten gelöst wird, wird die zweite Operation das [Skript](/manual/web_interface/frontend_sections/alerts/scripts#configuring-a-global-script) „5“ (Skript mit dem Geltungsbereich „Action operation“) auf allen Hosts in Gruppe „2“ ausführen.
Wenn das Ereignis gelöst wird, benachrichtigt eine Wiederherstellungsoperation alle Benutzer, die Nachrichten bezüglich des Problems erhalten haben.
Wenn das Ereignis aktualisiert wird, benachrichtigt eine Bestätigungs-/Aktualisierungsoperation (mit einem benutzerdefinierten Betreff und einer benutzerdefinierten Nachricht) alle Benutzer, die Nachrichten bezüglich des Problems erhalten haben.

[Anfrage](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "action.create",
    "params": {
        "name": "Trigger action",
        "eventsource": 0,
        "esc_period": "30m",
        "filter": {
            "evaltype": 0,
            "conditions": [
                {
                    "conditiontype": 1,
                    "operator": 0,
                    "value": "10084"
                },
                {
                    "conditiontype": 3,
                    "operator": 2,
                    "value": "memory"
                }
            ]
        },
        "operations": [
            {
                "operationtype": 0,
                "esc_step_from": 1,
                "esc_step_to": 1,
                "opmessage_grp": [
                    {
                        "usrgrpid": "7"
                    }
                ],
                "opmessage": {
                    "default_msg": 1,
                    "mediatypeid": "1"
                }
            },
            {
                "operationtype": 1,
                "esc_step_from": 2,
                "esc_step_to": 2,
                "opconditions": [
                    {
                        "conditiontype": 14,
                        "operator": 0,
                        "value": "0"
                    }
                ],
                "opcommand_grp": [
                    {
                        "groupid": "2"
                    }
                ],
                "opcommand": {
                    "scriptid": "5"
                }
            }
        ],
        "recovery_operations": [
            {
                "operationtype": "11",
                "opmessage": {
                    "default_msg": 1
                }
            }
        ],
        "update_operations": [
            {
                "operationtype": "12",
                "opmessage": {
                    "default_msg": 0,
                    "message": "Custom update operation message body",
                    "subject": "Custom update operation message subject"
                }
            }
        ]
    },
    "id": 1
}
```

Antwort:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "actionids": [
            "17"
        ]
    },
    "id": 1
}
```

[comment]: # ({/9ca78970-afc96865})

[comment]: # ({0f8305f5-53bdbb4b})
#### Eine Discovery-Aktion erstellen

Erstellen Sie eine Discovery-Aktion, die die Vorlage „10001“ mit erkannten Hosts verknüpft.

[Anfrage](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "action.create",
    "params": {
        "name": "Discovery action",
        "eventsource": 1,
        "filter": {
            "evaltype": 0,
            "conditions": [
                {
                    "conditiontype": 21,
                    "operator": 0,
                    "value": "1"
                },
                {
                    "conditiontype": 10,
                    "operator": 0,
                    "value": "2"
                }
            ]
        },
        "operations": [
            {
                "operationtype": 6,
                "optemplate": [
                    {
                        "templateid": "10001"
                    }
                ]
            }
        ]
    },
    "id": 1
}
```

Antwort:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "actionids": [
            "18"
        ]
    },
    "id": 1
}
```

[comment]: # ({/0f8305f5-53bdbb4b})

[comment]: # ({2311dde2-de84bbc4})
#### Verwenden eines benutzerdefinierten Ausdrucksfilters

Erstellen Sie eine Auslöser-Aktion, die einen benutzerdefinierten Ausdruck – „A and (B or C)“ – zur Auswertung von Aktionsbedingungen verwendet.
Sobald ein Auslöser mit einem Schweregrad höher oder gleich „Warning“ von Host „10084“ oder Host „10106“ in den Status PROBLEM wechselt,
sendet die Aktion eine Nachricht über den Medientyp „1“ an alle Benutzer der Benutzergruppe „7“.
Die Formel-IDs „A“, „B“ und „C“ wurden willkürlich gewählt.

[Anfrage](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "action.create",
    "params": {
        "name": "Trigger action",
        "eventsource": 0,
        "esc_period": "15m",
        "filter": {
            "evaltype": 3,
            "formula": "A and (B or C)",
            "conditions": [
                {
                    "conditiontype": 4,
                    "operator": 5,
                    "value": "2",
                    "formulaid": "A"
                },
                {
                    "conditiontype": 1,
                    "operator": 0,
                    "value": "10084",
                    "formulaid": "B"
                },
                {
                    "conditiontype": 1,
                    "operator": 0,
                    "value": "10106",
                    "formulaid": "C"
                }
            ]
        },
        "operations": [
            {
                "operationtype": 0,
                "esc_step_from": 1,
                "esc_step_to": 1,
                "opmessage_grp": [
                    {
                        "usrgrpid": "7"
                    }
                ],
                "opmessage": {
                    "default_msg": 1,
                    "mediatypeid": "1"
                }
            }
        ]
    },
    "id": 1
}
```

Antwort:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "actionids": [
            "18"
        ]
    },
    "id": 1
}
```

[comment]: # ({/2311dde2-de84bbc4})

[comment]: # ({a0b5931f-b81a306b})
#### Agent-Autoregistrierungsregel erstellen

Erstellen Sie eine Autoregistrierungsaktion, die einen Host zur Host-Gruppe „2“ hinzufügt, wenn der Host-Name „SRV“ enthält oder die Metadaten „AlmaLinux“ enthalten.

[Anfrage](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "action.create",
    "params": {
        "name": "Register Linux servers",
        "eventsource": "2",
        "filter": {
            "evaltype": "2",
            "conditions": [
                {
                    "conditiontype": "22",
                    "operator": "2",
                    "value": "SRV"
                },
                {
                    "conditiontype": "24",
                    "operator": "2",
                    "value": "AlmaLinux"
                }
            ]
        },
        "operations": [
            {
                "operationtype": "4",
                "opgroup": [
                    {
                        "groupid": "2"
                    }
                ]
            }
        ]
    },
    "id": 1
}
```

Antwort:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "actionids": [
            19
        ]
    },
    "id": 1
}
```

[comment]: # ({/a0b5931f-b81a306b})

[comment]: # ({9410b0af-35a2b594})
#### Agent-Autoregistrierungsregel mit Host-Tags erstellen

Erstellen Sie eine Autoregistrierungsaktion, die einen Host zur Host-Gruppe „2“ hinzufügt und zwei Host-Tags hinzufügt.

[Anfrage](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "action.create",
    "params": {
        "name": "Register Linux servers with tags",
        "eventsource": "2",
        "operations": [
            {
                "operationtype": "4",
                "opgroup": [
                    {
                        "groupid": "2"
                    }
                ]
            },
            {
                "operationtype": "13",
                "optag": [
                    {
                        "tag": "location",
                        "value": "office"
                    },
                    {
                        "tag": "city",
                        "value": "Riga"
                    }
                ]
            }
        ]
    },
    "id": 1
}
```

Antwort:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "actionids": [
            20
        ]
    },
    "id": 1
}
```

[comment]: # ({/9410b0af-35a2b594})

[comment]: # ({1f61bb3d-755496f7})
### Siehe auch

-   [Aktionsfilter](object#action-filter)
-   [Aktionsoperation](object#action-operation)
-   [Skript](/manual/api/reference/script/object)

[comment]: # ({/1f61bb3d-755496f7})

[comment]: # ({32335876-32335876})
### Quelle

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

[comment]: # ({/32335876-32335876})
