amtool alertmanager config yml

131 views
Skip to first unread message

kiran

unread,
Jan 8, 2021, 1:22:15 AM1/8/21
to Prometheus Users
All

I am trying to validate my alertmanager config yml file using amtool.
amtool is throwing an error message 'cannot unmarshall !!map' with the following, but when I replace api_url with a slack_url(e.g https://hooks.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXX) and re-run amtool, it shows success.
Can someone guide me what I am doing wrong here?

  - name: slack_client

    slack_configs:

      - api_url: {{ .GroupLabels.slack_url }}

        channel: '{{ .GroupLabels.slack_channel }}'

        send_resolved: true

        title: "{{ range .Alerts }}{{ .Annotations.summary }}\n{{ end }}"

        text: "{{ range .Alerts }}{{ .Annotations.description }}\n{{ end }}"

Stuart Clark

unread,
Jan 8, 2021, 8:24:23 AM1/8/21
to kiran, Prometheus Users

Have you tried wrapping that in quotes?

kiran

unread,
Jan 8, 2021, 8:57:44 AM1/8/21
to Stuart Clark, Prometheus Users
Yes I did both single and double it’s complaining about quotes in url

Stuart Clark

unread,
Jan 8, 2021, 11:03:23 AM1/8/21
to kiran, Prometheus Users
Could you show the configuration you tried with the double quotes in place, as well as the error returned?
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

kiran

unread,
Jan 8, 2021, 5:32:29 PM1/8/21
to Stuart Clark, Prometheus Users
@Stuart Clark 

Here is what I tried. I am also attaching the version(with slack variables) which is not working.
Any help resolving this is appreciated.

TEST#1 Using {{ .GroupLabels.slack_url }} for api_url without any quotes:

  - name: slack_client
    slack_configs:
      - api_url: {{ .GroupLabels.slack_url }}
        channel: '{{ .GroupLabels.slack_channel }}'
        send_resolved: true
        title: "{{ range .Alerts }}{{ .Annotations.summary }}\n{{ end }}"
        text: "{{ range .Alerts }}{{ .Annotations.description }}\n{{ end }}"


Checking 'alertmanager.yml'  FAILED: yaml: unmarshal errors:
  line 67: cannot unmarshal !!map into string

amtool: error: failed to validate 1 file(s)


TEST#2 Using {{ .GroupLabels.slack_url }} for api_url with single quotes:

Checking 'alertmanager.yml'  FAILED: unsupported scheme "" for URL

amtool: error: failed to validate 1 file(s)



TEST#3 Using {{ .GroupLabels.slack_url }} for api_url with single quotes:

Checking 'alertmanager.yml'  FAILED: unsupported scheme "" for URL

amtool: error: failed to validate 1 file(s)


TEST#4 It is working when using a single slack incoming web hook url and channel instead of variables, but I want to dynamically do it using labels. I confirm that the slack labels exist in the data correctly.

dennis....@googlemail.com

unread,
Jan 9, 2021, 3:42:00 AM1/9/21
to kiran, Stuart Clark, Prometheus Users
Hi Kiran, 

Why you are not trying to create different routes based on the 'slack_channel' variable? For title and text you can create templates. If they are to many slack channels to write it down manually, I would recommend to use a template language.

Am 08.01.2021 um 23:32 schrieb kiran <kira...@gmail.com>:


--
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/CAOnWYZVWZ7A6B3c6FxFfiqrEAQNoJyWess9ZbG1cYRy9JQgQVA%40mail.gmail.com.

Stuart Clark

unread,
Jan 9, 2021, 7:36:10 AM1/9/21
to kiran, Prometheus Users
On 08/01/2021 22:32, kiran wrote:
@Stuart Clark 

Here is what I tried. I am also attaching the version(with slack variables) which is not working.
Any help resolving this is appreciated.

TEST#1 Using {{ .GroupLabels.slack_url }} for api_url without any quotes:

  - name: slack_client
    slack_configs:
      - api_url: {{ .GroupLabels.slack_url }}
        channel: '{{ .GroupLabels.slack_channel }}'
        send_resolved: true
        title: "{{ range .Alerts }}{{ .Annotations.summary }}\n{{ end }}"
        text: "{{ range .Alerts }}{{ .Annotations.description }}\n{{ end }}"

Looking at the documentation again (https://prometheus.io/docs/alerting/latest/configuration/#slack_config) The api_url is defined as <secret> rather than <tmpl_secret>, so you can't use templating in that field - only fixed strings are allowed.


kiran

unread,
Jan 9, 2021, 8:45:33 AM1/9/21
to dennis....@googlemail.com, Stuart Clark, Prometheus Users
Hi Dennis

We have multiple teams and they enter information needed slack and other notification  services through a webapp and I do not want to write that info to alertmanager yml as it is space sensitive as one mistake can stop alerts for all teams. So we thought this is better option as we don’t have to touch that yml file. I wil be having different api_url and channel combinations for each team. Yes, I will use some slack template once this basic config issue is resolved.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.

kiran

unread,
Jan 9, 2021, 11:27:53 PM1/9/21
to Stuart Clark, Prometheus Users
Thank you, @Stuart Clark 
So it cannot work for multiple slacks.

Stuart Clark

unread,
Jan 10, 2021, 5:49:11 AM1/10/21
to kiran, Prometheus Users
On 10/01/2021 04:27, kiran wrote:
Thank you, @Stuart Clark 
So it cannot work for multiple slacks.

You will need to have multiple receivers as previously mentioned.
Reply all
Reply to author
Forward
0 new messages