4.2.3. Alertmanager でのアラートルートの作成
Alertmanager を使用して、メール、IRC、またはその他の通知チャネルなどの外部システムにアラートを送信します。Prometheus Operator は、Alertmanager 設定を Red Hat OpenShift Container Platform (OCP) シークレットとして管理します。デフォルトでは、STF は、レシーバーを持たない基本設定をデプロイします。
alertmanager.yaml: |-
global:
resolve_timeout: 5m
route:
group_by: ['job']
group_wait: 30s
group_interval: 5m
repeat_interval: 12h
receiver: 'null'
receivers:
- name: 'null'
STF を使用してカスタム Alertmanager ルートをデプロイするには、alertmanagerConfigManifest パラメーターを Service Telemetry Operator に渡す必要があります。これにより、更新されたシークレットが作成され、Prometheus Operator の管理対象となります。詳細は、「「管理マニフェストの上書き」」を参照してください。
手順
- Red Hat OpenShift Container Platform にログインします。
service-telemetrynamespace に切り替えます。oc project service-telemetrySTF デプロイメントの
ServiceTelemetryオブジェクトを編集します。oc edit servicetelemetry stf-default新規パラメーター
alertmanagerConfigManifestおよびSecretオブジェクトコンテンツを追加して、Alertmanager のalertmanager.yaml設定を定義します。注記これにより、Service Telemetry Operator によってすでに管理されているデフォルトのテンプレートが読み込まれます。変更が正しく設定されることを確認するには、値を変更して
alertmanager-stf-defaultシークレットを返し、新しい値がメモリーに読み込まれていることを確認します。たとえば、global.resolve_timeoutの値を5mから10mに変更します。apiVersion: infra.watch/v1alpha1 kind: ServiceTelemetry metadata: name: stf-default namespace: service-telemetry spec: metricsEnabled: true alertmanagerConfigManifest: | apiVersion: v1 kind: Secret metadata: name: 'alertmanager-stf-default' namespace: 'service-telemetry' type: Opaque stringData: alertmanager.yaml: |- global: resolve_timeout: 10m route: group_by: ['job'] group_wait: 30s group_interval: 5m repeat_interval: 12h receiver: 'null' receivers: - name: 'null'設定がシークレットに適用されていることを確認します。
$ oc get secret alertmanager-stf-default -o go-template='{{index .data "alertmanager.yaml" | base64decode }}' global: resolve_timeout: 10m route: group_by: ['job'] group_wait: 30s group_interval: 5m repeat_interval: 12h receiver: 'null' receivers: - name: 'null'設定が Alertmanager にロードされたことを確認するには、
curlにアクセスできる Pod を作成します。oc run curl --generator=run-pod/v1 --image=radial/busyboxplus:curl -i --ttyalertmanager-operatedサービスに対してcurlを実行し、ステータスとconfigYAMLの内容を取得し、提供された設定が Alertmanager にロードされた設定と一致することを確認します。[ root@curl:/ ]$ curl alertmanager-operated:9093/api/v1/status {"status":"success","data":{"configYAML":"global:\n resolve_timeout: 10m\n http_config: {}\n smtp_hello: localhost\n smtp_require_tls: true\n pagerduty_url: https://events.pagerduty.com/v2/enqueue\n hipchat_api_url: https://api.hipchat.com/\n opsgenie_api_url: https://api.opsgenie.com/\n wechat_api_url: https://qyapi.weixin.qq.com/cgi-bin/\n victorops_api_url: https://alert.victorops.com/integrations/generic/20131114/alert/\nroute:\n receiver: \"null\"\n group_by:\n - job\n group_wait: 30s\n group_interval: 5m\n repeat_interval: 12h\nreceivers:\n- name: \"null\"\ntemplates: []\n",...}}configYAMLフィールドに想定の変更が追加されていることを確認します。Pod を終了します。[ root@curl:/ ]$ exit環境を消去するには、
curlPod を削除します。$ oc delete pod curl pod "curl" deleted
関連情報
Red Hat OpenShift Container Platform シークレットおよび Prometheus Operator についての詳細は、https://github.com/coreos/prometheus-operator/blob/master/Documentation/user-guides/alerting.mdを参照してください。