

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Amazon Managed Service for Prometheus でアラートを管理およびルーティングするためのアラートマネージャー設定を作成します。
<a name="AMP-alertmanager-config"></a>

Amazon Managed Service for Prometheus でアラートマネージャーとテンプレートを使用するには、アラートマネージャーの設定 YAML ファイルを作成します。Amazon Managed Service for Prometheus アラートマネージャーファイルには、次の 2 つの主要なセクションがあります。
+ `template_files:` には、レシーバーから送信されたメッセージに使用されるテンプレートが含まれます。詳細については、Prometheus ドキュメントの「[Template Reference](https://prometheus.io/docs/prometheus/latest/configuration/template_reference/)」と「[Template Examples](https://prometheus.io/docs/prometheus/latest/configuration/template_examples/)」を参照してください。
+ `alertmanager_config:` には、アラートマネージャーの設定が含まれます。これには、スタンドアロンの Prometheus のアラートマネージャー設定ファイルと同じ構造が使用されます。詳細については、Alertmanager ドキュメントの「[Configuration](https://prometheus.io/docs/alerting/latest/configuration/)」を参照してください。
**注記**  
Amazon Managed Service for Prometheus では、上記の Prometheus ドキュメントで説明されている `repeat_interval` 設定に追加の制限があります。許容される最大値は 5 日間です。5 日より大きい値に設定しても 5 日間として扱われ、5 日間の期間が経過すると通知が再送信されます。

**注記**  
設定ファイルは Amazon Managed Service for Prometheus コンソールで直接編集することもできますが、ここで指定する形式に従う必要があります。設定ファイルのアップロードまたは編集の詳細については、「[Amazon Managed Service for Prometheus にアラートマネージャー設定ファイルをアップロードする](AMP-alertmanager-upload.md)」を参照してください。

Amazon Managed Service for Prometheus のアラートマネージャー設定ファイルでは、YAML ファイルのルートにある `alertmanager_config` キーの中に、アラートマネージャーの設定内容をすべて含める必要があります。

以下は、アラートマネージャー設定ファイルの基本的な例です。

```
alertmanager_config: |
  route:
    receiver: 'default'
  receivers:
    - name: 'default'
      sns_configs:
      - topic_arn: arn:aws:sns:us-east-2:123456789012:My-Topic
        sigv4:
          region: us-east-2
        attributes:
          key: key1
          value: value1
```

現在サポートされているレシーバーは、Amazon Simple Notification Service (Amazon SNS) だけです。設定に他の種類のレシーバーが指定されている場合、その設定は拒否されます。

以下は別のアラートマネージャー設定ファイルの例で、`template_files` ブロックと `alertmanager_config` ブロックの両方を使用しています。

```
template_files:
  default_template: |
    {{ define "sns.default.subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}]{{ end }}
    {{ define "__alertmanager" }}AlertManager{{ end }}
    {{ define "__alertmanagerURL" }}{{ .ExternalURL }}/#/alerts?receiver={{ .Receiver | urlquery }}{{ end }}
alertmanager_config: |
  global:
  templates:
    - 'default_template'
  route:
    receiver: default
  receivers:
    - name: 'default'
      sns_configs:
      - topic_arn: arn:aws:sns:us-east-2:accountid:My-Topic
        sigv4:
          region: us-east-2
        attributes:
          key: severity
          value: SEV2
```

**デフォルトの Amazon SNS テンプレートブロック**

デフォルトの Amazon SNS の設定では、明示的にオーバーライドしない限り、以下のテンプレートが使用されます。

```
{{ define "sns.default.message" }}{{ .CommonAnnotations.SortedPairs.Values | join " " }}
  {{ if gt (len .Alerts.Firing) 0 -}}
  Alerts Firing:
    {{ template "__text_alert_list" .Alerts.Firing }}
  {{- end }} 
  {{ if gt (len .Alerts.Resolved) 0 -}} 
  Alerts Resolved:
    {{ template "__text_alert_list" .Alerts.Resolved }}
  {{- end }}
{{- end }}
```