1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

How to notify alert to slack - Prometheusのalertmanagerでslackに通知する

Posted at

Overview

Prometheusのalertmangerを使うことでprometheusで取得しているデータについて
通知を行うことができる。

ただし、こちらの通りに設定を行っても
通知自体はしてくれるが、メッセージが表示されない。

rules.yml
groups:
  - name: InstanceDown
    rules:
    - alert: InstanceDdown
      expr: up == 0
      for: 30s
      labels:
        severity: critical
      annotations:
        description: '{{ $labels.instance }} of {{ $labels.description }} has been down for more than 1 minutes.'
        summary: 'Instance {{ $labels.instance }} down'
alertmanager.yml
global:
  resolve_timeout: 5m
  slack_api_url: 'https://hooks.slack.com/services/hogehogefugafuga'

route:
  group_by: ['alertname','job', 'monitor']
  group_wait: 10s
  group_interval: 10s
  # repeat_interval: 1h
  routes:
    - receiver: slack-notifications
      match:
        severity: critical
  receiver: blackhole

- name: slack-notifications
  slack_configs:
  - channel: '#alerts'
    # Alertmanager templates apply here.
    text: "<!channel> \nsummary: {{ .CommonAnnotations.summary }}\ndescription: {{ .CommonAnnotations.description }}"

summary, descriptionともに見事に空になる。

何故そうなっているか

こちらにやりとりが記載されているが
要するに「Slackをはじめとするチャットツールへの通知は.Common.Annotationsを渡してないよ」とのこと。

どうすれば良いか

alertmanagerのtitle, textを下記のような形で色々捻る。
GoTemplateで書けば良いのだが、難しいのでこれを使う。
分かりづらいが要するにLabelを展開して色々入れてるだけ。
ただし、rulesの方で.Annotations.description を使っているのでそのまま .Annotations.descriptionを使えば良いような気がする。

ただし、.Annotationsはより広範囲に作用するので慎重に扱え。とも書いてあるので注意深く推移を見守る必要がありそう。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?