

# 調査を作成するようにアラームを設定する
<a name="Investigations-configure-alarms"></a>

既存の CloudWatch アラームを設定して、CloudWatch 調査で調査を自動的に作成できます。アラームが ALARM 状態になると、CloudWatch は自動的に新しい調査を作成するか、既存の調査に追加します。これは、重複排除文字列に基づきます。

調査を自動的に作成するようにアラームを設定する場合は、アラームの actionArns で Amazon リソースネーム (ARN) を指定する必要があります。この ARN は、アラームがトリガーする調査が作成される調査グループを識別します。必要に応じて、ARN に重複排除文字列を含めて、関連するアラームをグループ化できます。

## ARN 形式とパラメータ
<a name="Investigations-arn-format"></a>

調査グループアラームアクションの ARN パターンは次の形式に従います。

```
arn:aws:aiops:region:account-id:investigation-group/investigation-group-identifier#DEDUPE_STRING=value
```

次の表で、各 ARN コンポーネントについて説明します。


| パラメータ | 説明 | 
| --- | --- | 
| region (必須) | 調査グループが配置されている AWS リージョン。例: us-east-1。 | 
| account-id (必須) | 12 桁の AWS アカウント ID。例: 123456789012。 | 
| investigation-group-identifier (必須) | 調査グループの一意の識別子。例えば、sMwwg1IogXdvL7UZ | 
| DEDUPE\$1STRING=value (オプション) | 関連するアラームを同じ調査にグループ化する重複排除文字列。複数のアラームが同じ重複排除文字列を使用する場合、個別の調査を作成するのではなく、単一の調査の構成要素になります。 | 

**重複排除文字列のない例:**

```
arn:aws:aiops:us-east-1:123456789012:investigation-group/sMwwg1IogXdvL7UZ
```

**重複排除文字列のある例:**

```
arn:aws:aiops:us-east-1:123456789012:investigation-group/sMwwg1IogXdvL7UZ#DEDUPE_STRING=performance
```

### 重複排除文字列の利点
<a name="Investigations-deduplication-benefits"></a>

重複排除文字列は、関連するアラームを整理し、調査の断片化を減らすのに役立ちます。重複排除文字列は、次の場合に使用します。
+ **複数のアラームが同じシステムをモニタリングする場合** - 同じ EC2 インスタンスの CPU、メモリ、およびディスクアラームは、重複排除文字列を共有して 1 つの包括的な調査を作成できます。
+ **連鎖的に障害が発生する場合** - 1 つの問題が複数の関連アラームをトリガーする場合、重複排除文字列を同じにして、各症状に対して個別の調査を作成することを防ぎます。
+ **問題のタイプ別に分類する場合** - 「パフォーマンス」、「接続性」、「セキュリティ」などの説明文字列を使用して、問題カテゴリ別にアラームをグループ化します。

効果的な重複排除文字列の例:
+ `DEDUPE_STRING=webserver-performance` - ウェブサーバーのパフォーマンス関連のアラームをグループ化する
+ `DEDUPE_STRING=database-connectivity` - データベース接続の問題をグループ化する
+ `DEDUPE_STRING=instance-i-1234567890abcdef0` - 特定の EC2 インスタンスのすべてのアラームをグループ化する

**注記**  
重複排除文字列が指定されていない場合、システムはアラーム名、アカウント ID、リージョンのデフォルトの組み合わせを使用して調査をグループ化します。

調査グループの詳細については、「[調査グループを設定する](Investigations-GetStarted-Group.md)」を参照してください。

# 調査を作成するようにアラームを設定する
<a name="Investigations-configure-alarm-procedures"></a>

アカウントに調査グループを設定したら、既存の CloudWatch アラームを設定して、ALARM 状態になったときに調査を自動的に作成できます。これにより、手動で調査を開始する必要がなくなり、運用上の問題に一貫した対応ができます。アラームは、AWS マネジメントコンソール、AWS CLI、CloudFormation、または AWS SDK を使用して設定できます。

------
#### [ Console ]

1. CloudWatch コンソールの [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) を開いてください。

1. ナビゲーションペインで **[アラーム]** を選択し、既存のアラームを選択します。

1. **[Actions]**、**[Edit]** の順に選択します。

1. **[アラームアクション]** セクションで、**[アラームアクションを追加]** を選択します。

1. **[アクションの設定]** の **[調査アクション]** セクションで、調査グループの ARN を選択します。

1. (オプション) 重複排除文字列を追加して、関連するアラームをグループ化します。

1. **[Update alarm]** (アラームの更新) を選択します。

------
#### [ CLI ]

このコマンドでは、`alarm-actions` パラメータの ARN を指定する必要があります。ARN を作成する方法については、「[ARN 形式とパラメータ](Investigations-configure-alarms.md#Investigations-arn-format)」を参照してください。

**InvestigationGroup アクションで CloudWatch アラームを設定するには (AWS CLI)**

1. まだ AWS CLI をインストールして設定していない場合はインストールして設定します。詳細については、「[AWS CLI の最新バージョンをインストールまたは更新します。](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)」を参照してください。

1. 次のコマンドを実行して、設定するアラームに関する情報を収集します。

   ```
   aws cloudwatch describe-alarms --alarm-names "alarm name"
   ```

1. 次のコマンドを実行してアラームを更新します。各*リソースプレースホルダーの例*をユーザー自身の情報に置き換えます。

   ```
   aws cloudwatch put-metric-alarm --alarm-name name \
   --alarm-description "description" \
   --metric-name name --namespace namespace \
   --statistic statistic --period value --threshold value \
   --comparison-operator value \
   --dimensions "dimensions" --evaluation-periods value \
   --alarm-actions "arn:aws:aiops:region:{account-id}:investigation-group/{investigationGroupIdentifier}#DEDUPE_STRING={my-dedupe-string}"
   ```

   以下に例を示します。

   ```
   //Without deduplication string
   aws cloudwatch put-metric-alarm --alarm-name cpu-mon \
   --alarm-description "Alarm when CPU exceeds 70 percent" \
   --metric-name CPUUtilization --namespace AWS/EC2 \
   --statistic Average --period 300 --threshold 70 \
   --comparison-operator GreaterThanThreshold \
   --dimensions "Name=InstanceId,Value=i-12345678" --evaluation-periods 2 \
   --alarm-actions arn:aws:aiops:us-east-1:123456789012:investigation-group/sMwwg1IogXdvL7UZ \
   --unit Percent
   
   //With deduplication string
   aws cloudwatch put-metric-alarm --alarm-name cpu-mon \
   --alarm-description "Alarm when CPU exceeds 70 percent" \
   --metric-name CPUUtilization --namespace AWS/EC2 \
   --statistic Average --period 300 --threshold 70 \
   --comparison-operator GreaterThanThreshold \
   --dimensions "Name=InstanceId,Value=i-12345678" --evaluation-periods 2 \
   --alarm-actions arn:aws:aiops:us-east-1:123456789012:investigation-group/sMwwg1IogXdvL7UZ#DEDUPE_STRING=performance \
   --unit Percent
   ```

------
#### [ CloudFormation ]

このセクションでは、調査を自動的に作成または更新する CloudWatch アラームの設定に使用できる CloudFormation テンプレートについて説明します。各テンプレートでは、`AlarmActions` パラメータの ARN を指定する必要があります。ARN を作成する方法については、「[ARN 形式とパラメータ](Investigations-configure-alarms.md#Investigations-arn-format)」を参照してください。

```
//Without deduplication string
Resources:
  MyAlarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmActions:
        - !Sub "arn:aws:aiops:${AWS::Region}:${AWS::AccountId}:investigation-group/{investigationGroupIdentifier}"

//With deduplication string
Resources:
  MyAlarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmActions:
        - !Sub "arn:aws:aiops:${AWS::Region}:${AWS::AccountId}:investigation-group/{investigationGroupIdentifier}#DEDUPE_STRING={my-dedupe-string}"
```

------
#### [ SDK ]

このセクションでは、調査を自動的に作成または更新する CloudWatch アラームの設定に使用できる Java コードスニペットについて説明します。各スニペットでは、`investigationGroupArn` パラメータの ARN を指定する必要があります。ARN を作成する方法については、「[ARN 形式とパラメータ](Investigations-configure-alarms.md#Investigations-arn-format)」を参照してください。

```
import com.amazonaws.services.cloudwatch.AmazonCloudWatch;
import com.amazonaws.services.cloudwatch.AmazonCloudWatchClientBuilder;
import com.amazonaws.services.cloudwatch.model.ComparisonOperator;
import com.amazonaws.services.cloudwatch.model.Dimension;
import com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest;
import com.amazonaws.services.cloudwatch.model.PutMetricAlarmResult;
import com.amazonaws.services.cloudwatch.model.StandardUnit;
import com.amazonaws.services.cloudwatch.model.Statistic;

//Without deduplication string
private void putMetricAlarmWithCloudWatchInvestigationAction() {
        final AmazonCloudWatch cloudWatchClient =
                AmazonCloudWatchClientBuilder.defaultClient();
       
        Dimension dimension = new Dimension()
                .withName("InstanceId")
                .withValue("i-12345678");
        String investigationGroupArn = "arn:aws:aiops:us-east-1:123456789012:investigation-group/sMwwg1IogXdvL7UZ";
        
        PutMetricAlarmRequest request = new PutMetricAlarmRequest() 
                    .withAlarmName("cpu-mon")
                    .withComparisonOperator( 
                        ComparisonOperator.GreaterThanThreshold) 
                    .withEvaluationPeriods(2) 
                    .withMetricName("CPUUtilization") 
                    .withNamespace("AWS/EC2") 
                    .withPeriod(300) 
                    .withStatistic(Statistic.Average) 
                    .withThreshold(70.0) 
                    .withActionsEnabled(true) 
                    .withAlarmDescription("Alarm when CPU exceeds 70 percent") 
                    .withUnit(StandardUnit.Percent) 
                    .withDimensions(dimension) 
                    .withAlarmActions(investigationGroupArn);
          
        PutMetricAlarmResult response = cloudWatchClient.putMetricAlarm(request);
}

//With deduplication string
private void putMetricAlarmWithCloudWatchInvestigationActionWithDedupeString() {
        final AmazonCloudWatch cloudWatchClient =
                AmazonCloudWatchClientBuilder.defaultClient();
       
        Dimension dimension = new Dimension()
                .withName("InstanceId")
                .withValue("i-12345678");
        String investigationGroupArn = "arn:aws:aiops:us-east-1:123456789012:investigation-group/sMwwg1IogXdvL7UZ#DEDUPE_STRING=performance";
        
        PutMetricAlarmRequest request = new PutMetricAlarmRequest() 
                    .withAlarmName("cpu-mon")
                    .withComparisonOperator( 
                        ComparisonOperator.GreaterThanThreshold) 
                    .withEvaluationPeriods(2) 
                    .withMetricName("CPUUtilization") 
                    .withNamespace("AWS/EC2") 
                    .withPeriod(300) 
                    .withStatistic(Statistic.Average) 
                    .withThreshold(70.0) 
                    .withActionsEnabled(true) 
                    .withAlarmDescription("Alarm when CPU exceeds 70 percent") 
                    .withUnit(StandardUnit.Percent) 
                    .withDimensions(dimension) 
                    .withAlarmActions(investigationGroupArn);
          
        PutMetricAlarmResult response = cloudWatchClient.putMetricAlarm(request);
}
```

------