

# 調査を作成するようにアラームを設定する
<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);
}
```

------