

# EventBridge で APM アラートを取り込むためのペイロード要件
<a name="idr-gs-apm-payload-requirements"></a>

**Incident Detection and Response は APM アラートをどこから取り込みますか?**

AWS Incident Detection and Response は、変換された最終的なペイロードの送信先となるイベントバスにマネージドルールをインストールします。この目的のためにカスタムイベントバスを作成するのがベストプラクティスです。

**ペイロードはどのような形式にする必要がありますか?**

AWS Incident Detection and Response によって取り込まれるイベントバスのイベントには、最低でも次の JSON キーと値のペアが必要です。

```
{  
    "detail-type": "ams.monitoring/generic-apm",  
    "source": "GenericAPMEvent"  
    "detail": {  
        "incident-detection-response-identifier": "Your alarm name from your APM",  
    }  
}
```

次の例は、変換前と変換後のパートナーイベントバスからのイベントを示しています。

**変換前:**

```
{  
    "version": "0",  
    "id": "a6150a80-601d-be41-1a1f-2c5527a99199",  
    "detail-type": "Datadog Alert Notification",  
    "source": "aws.partner/datadog.com/Datadog-aaa111bbbc",  
    "account": "123456789012",  
    "time": "2023-10-25T14:42:25Z",  
    "region": "us-east-1",  
    "resources": [],  
    "detail": {  
        "alert_type": "error",  
        "event_type": "query_alert_monitor",  
        "meta": {  
            "monitor": {  
                "id": 222222,  
                "org_id": 3333333333,  
                "type": "query alert",  
                "name": "UnHealthyHostCount",  
                "message": "@awseventbridge-Datadog-aaa111bbbc",  
                "query": "max(last_5m):avg:aws.applicationelb.un_healthy_host_count{aws_account:123456789012} <= 1",  
                "created_at": 1686884769000,  
                "modified": 1698244915000,  
                "options": {  
                    "thresholds": {  
                        "critical": 1.0  
                    }  
                },  
            },  
            "result": {  
                "result_id": 7281010972796602670,  
                "result_ts": 1698244878,  
                "evaluation_ts": 1698244868,  
                "scheduled_ts": 1698244938,  
                "metadata": {  
                    "monitor_id": 222222,  
                    "metric": "aws.applicationelb.un_healthy_host_count"  
                }  
            },  
            "transition": {  
                "trans_name": "Triggered",  
                "trans_type": "alert"  
            },  
            "states": {  
                "source_state": "OK",  
                "dest_state": "Alert"  
            },  
            "duration": 0  
        },  
        "priority": "normal",  
        "source_type_name": "Monitor Alert",  
        "tags": [  
            "aws_account:123456789012",  
            "monitor"  
        ]  
    }  
}
```

イベントが変換される前に、`detail-type` と `source` はアラートが発生した APM の詳細を示すことに注意してください。これらは取り込み前に変更する必要があります。`incident-detection-response-identifier` キーはまだ存在していないため、取り込み前に追加する必要があります。

Lambda 関数は上記のイベントを変換し、ターゲットのカスタムイベントバスまたはデフォルトのイベントバスに配置します。変換されたペイロードには、必要なキーと値のペアが含まれる必要があります。

**変換後:**

```
{  
    "version": "0",  
    "id": "7f5e0fc1-e917-2b5d-a299-50f4735f1283",  
    "detail-type": "ams.monitoring/generic-apm",  
    "source": "GenericAPMEvent",  
    "account": "123456789012",  
    "time": "2023-10-25T14:42:25Z",  
    "region": "us-east-1",  
    "resources": [],  
    "detail": {  
        "incident-detection-response-identifier": "UnHealthyHostCount",  
        "alert_type": "error",  
        "event_type": "query_alert_monitor",  
        "meta": {  
            "monitor": {  
                "id": 222222,  
                "org_id": 3333333333,  
                "type": "query alert",  
                "name": "UnHealthyHostCount",  
                "message": "@awseventbridge-Datadog-aaa111bbbc",  
                "query": "max(last_5m):avg:aws.applicationelb.un_healthy_host_count{aws_account:123456789012} <= 1",  
                "created_at": 1686884769000,  
                "modified": 1698244915000,  
                "options": {  
                    "thresholds": {  
                        "critical": 1.0  
                    }  
                },  
            },  
            "result": {  
                "result_id": 7281010972796602670,  
                "result_ts": 1698244878,  
                "evaluation_ts": 1698244868,  
                "scheduled_ts": 1698244938,  
                "metadata": {  
                    "monitor_id": 222222,  
                    "metric": "aws.applicationelb.un_healthy_host_count"  
                }  
            },  
            "transition": {  
                "trans_name": "Triggered",  
                "trans_type": "alert"  
            },  
            "states": {  
                "source_state": "OK",  
                "dest_state": "Alert"  
            },  
            "duration": 0  
        },  
        "priority": "normal",  
        "source_type_name": "Monitor Alert",  
        "tags": [  
            "aws_account:123456789012",  
            "monitor"  
        ]  
    }  
}
```

`detail-type` は `ams.monitoring/generic-apm`、ソースは `GenericAPMEvent` になり、詳細には新しいキーと値のペアである `incident-detection-response-identifier` が存在するようになりました。

`incident-detection-response-identifier` 値は、APM が送信するペイロードに基づいてアラート名から取得されます。APM アラート名のパスは、APM ごとに異なります。Lambda 関数は、Lambda が受け取った APM JSON ペイロードの正しいパスからアラーム名を取得し、`incident-detection-response-identifier` 値に使用するように設定する必要があります。

`incident-detection-response-identifier` 値は、AWS Incident Detection and Response に送信されるアラームタイプごとに一意である必要があります。`incident-detection-response-identifier` で設定される一意の名前はそれぞれ、オンボーディング中に AWS Incident Detection and Response チームに提供される必要があります。`incident-detection-response-identifier` キーの値が不明または欠落しているイベントは処理されません。