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

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

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

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

このメソッドは、新しいアクションを作成することができます。

::: noteclassic
このメソッドは、*Admin*および*Super admin*タイプのユーザーのみ利用可能です。メソッドを呼び出す権限は、ユーザーの役割の設定で取り消すことができます。詳細は[ユーザーの役割](/manual/web_interface/frontend_sections/users/user_roles)を参照してください。
:::

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

[comment]: # ({e2f647f1-5a9be3c9})
### パラメータ

`(object/array)` 作成するアクション。

[標準のアクションプロパティ](object#action)に加えて、この
メソッドは以下のパラメータを受け付けます。

|パラメータ|[Type](/manual/api/reference_commentary#data-types)|説明|
|--|--|------|
|filter|object|アクション用の[アクションフィルター](/manual/api/reference/action/object#action-filter)オブジェクト。|
|operations|array|アクション用に作成する[アクション操作](/manual/api/reference/action/object#action-operation)。|
|recovery\_operations|array|アクション用に作成する[アクション復旧操作](/manual/api/reference/action/object#action-recovery-operation)。|
|update\_operations|array|アクション用に作成する[アクション更新操作](/manual/api/reference/action/object#action-update-operation)。|

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

[comment]: # ({2830affd-2830affd})
### 戻り値

`(object)` `actionids`プロパティの下に作成されたアクションのIDを含むオブジェクトを返します。返されるIDの順序は、渡されたアクションの順序と一致します。

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

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

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

[comment]: # ({9ca78970-afc96865})
#### トリガーアクションの作成

ホスト"10084"からのトリガー(名前に"memory"が含まれる)が障害状態になると実行されるトリガーアクションを作成する。
アクションには4つの操作が構成されます。
最初の即時操作では、メディアタイプ"1"を介してユーザーグループ"7"内のすべてのユーザーにメッセージが送信されます。
イベントが30分以内に解決されない場合、2番目の操作ではグループ"2"のすべてのホストで[スクリプト](/manual/web_interface/frontend_sections/alerts/scripts#configuring-a-global-script)"5"(スコープ"アクション操作"のスクリプト) が実行されます。
イベントが解決された場合は、回復操作により、問題に関するメッセージを受け取ったすべてのユーザーに通知されます。
イベントが更新されると、確認/更新操作により、問題に関するメッセージを受信したすべてのユーザーに (カスタムの件名とメッセージを使用して) 通知します。

[リクエスト](/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
}
```

レスポンス :

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

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

[comment]: # ({0f8305f5-53bdbb4b})
#### ディスカバリアクションの作成

検出されたホストにテンプレート"10001"をリンクするディスカバリアクションを作成します。

[リクエスト](/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
}
```

レスポンス :

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

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

[comment]: # ({2311dde2-de84bbc4})
#### カスタム式フィルターの使用

アクション条件を評価するためのカスタム式"A and (B or C)"を使用するトリガーアクションを作成します。
ホスト"10084"またはホスト"10106"からの"警告"以上の深刻度を持つトリガーが障害状態になると、
このアクションは、メディアタイプ"1"を介してユーザーグループ"7"のすべてのユーザーにメッセージを送信します。

[リクエスト](/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
}
```

レスポンス :

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

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

[comment]: # ({a0b5931f-b81a306b})
#### エージェントの自動登録ルール作成

ホスト名に"SRV "が含まれているか、メタデータに"AlmaLinux"が含まれている場合、ホストをホストグループ "2"に追加します。

[リクエスト](/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
}
```

レスポンス :

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

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

[comment]: # ({9410b0af-35a2b594})
#### ホストタグとエージェント自動登録ルールの作成

ホストをホストグループ"2"に追加し、2つのホストタグを追加する自動登録アクションを作成します。

[リクエスト](/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
}
```

レスポンス:

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

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

[comment]: # ({1f61bb3d-755496f7})
### 関連項目

-   [アクションフィルター](object#action-filter)
-   [アクションの実行内容](object#action-operation)
-   [スクリプト](/manual/api/reference/script/object)

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

[comment]: # ({32335876-32335876})
### ソース

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

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