Filter alertmanager notification like slack using templates

40 views
Skip to first unread message

Rahul Hada

unread,
Mar 24, 2020, 1:46:46 AM3/24/20
to Prometheus Users
Hi All, 
We are using templates to refine the parameters going to the slack channel from alertmanager, we do have one api to which we are sending alert notifications but while using same templates for api, reloading the alertmanager.yml gives error " field title not found in type config.plain". I have rechecked if there is any indentation error in yaml file. Please suggest whether it is possible for api or not. If yes , please guide me towards it.

Template file :- 
{{ define "webhook.default.title" }}{{ template "__subject" . }}{{ end }}
{{ define "webhook.default.username" }}{{ template "__alertmanager" . }}{{ end }}
{{ define "webhook.default.fallback" }}{{ template "webhook.default.title" . }} | {{ template "webhook.default.titlelink" . }}{{ end }}
{{ define "webhook.default.pretext" }}{{ end }}
{{ define "webhook.default.titlelink" }}{{ template "__alertmanagerURL" . }}{{ end }}
{{ define "webhook.default.iconemoji" }}{{ end }}
{{ define "webhook.default.iconurl" }}{{ end }}
{{ define "webhook.default.text" }}{{ end }}
{{ define "webhook.default.footer" }}{{ end }}


Alertmanager.yml file :- 
- name: "en_api"
  webhook_configs:
    title: '{{ template "webhook.default.title" . }}'
    text: |-
      {{ range .Alerts }}
         *ALERT:* {{ .Annotations.summary }} - `{{ .Labels.severity }}`
        *DESCRIPTION:* {{ .Annotations.description }}
        {{ .Annotations.identifier }}
      {{ end }}


Thanks in Advance


Murali Krishna Kanagala

unread,
Mar 25, 2020, 12:00:02 AM3/25/20
to Prometheus Users
To send an alert to a web hook there is no need for a template. The receiver api receivs the alerts in as json payload. 



--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/c01b22eb-828d-4df2-bcea-f6e448ab2ca5%40googlegroups.com.

Rahul Hada

unread,
Mar 25, 2020, 12:13:04 AM3/25/20
to Murali Krishna Kanagala, Prometheus Users
I am able to get json data, but was looking for more appropriate template so that could send only required parameters to the api. Any suggestions for that would be appreciated.

Murali Krishna Kanagala

unread,
Mar 25, 2020, 12:18:27 AM3/25/20
to Prometheus Users
I dont think the webhook receiver config supports templates. If your api receiver does not accept the json payload sent by alertmanager then you may need to write a custom translator something like a small flask app that can receive the data from alertmanager, process it and push it to your api. 
Reply all
Reply to author
Forward
0 new messages