Hi Brian,

I am a beginner and have minimal knowledge about alertmanager. Could you 
please provide me some guidance please.

I tried to add the subject in alertmanager.yml as below. But still no luck.
global:
  resolve_timeout: 5m
  smtp_smarthost: *********
  smtp_auth_username: '*********'
  smtp_auth_identity: '********'
  smtp_auth_password: '******'
  smtp_from: 'x...@gmail.com'
  smtp_require_tls: false

route:
  group_by: ['alertname']
  group_wait: 10s
  group_interval: 10s
  repeat_interval: 24h
  receiver: 'App-Kafka-Support'

receivers:
- name: 'App-Kafka-Support'
  email_configs:
  - to: 'x...@gmail.com'
    send_resolved: true
    headers:
      subject: '{{ if eq .Status "firing" }} DOWN {{ else if eq .Status 
"resolved" }} UP {{end}}'

Best Regards,
Suman

On Tuesday, November 23, 2021 at 2:10:17 PM UTC+5:30 Sri man wrote:

> Hello Brian,
>
> I have edited the default template as below.
>
> {{ define "__subject" }}[{{ if eq .Status "firing" }} "DOWN" {{ else }} 
> "UP" {{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }} {{ if gt 
> (len .CommonLabels) (len .GroupLabels) }}({{ with .CommonLabels.Remove 
> .GroupLabels.Names }}{{ .Values | join " " }}{{ end }}){{ end }}{{ end }}
> {{ define "__description" }}{{ end }}
>
> But am getting the below error.
> ./amtool check-config /home/sam_r/alertmanager.yml
> Checking '/home/snr_r/alertmanager.yml'  SUCCESS
> Found:
>  - global config
>  - route
>  - 0 inhibit rules
>  - 2 receivers
>  - 1 templates
>   FAILED: template: statuspal.tmpl:4: function "DOWN" not defined
>
> amtool: error: failed to validate 1 file(s)
>
> Could you please help me?
>
> Best Regards,
> Suman
>
>
>
> On Friday, November 19, 2021 at 3:03:08 PM UTC+5:30 Brian Candler wrote:
>
>> To replace any header with a new template, follow the documentation of 
>> email_config here 
>> <https://prometheus.io/docs/alerting/latest/configuration/#email_config>.
>>
>> # Further headers email header key/value pairs. Overrides any headers # 
>> previously set by the notification implementation. [ headers: { <string> 
>> <https://prometheus.io/docs/alerting/latest/configuration/#string>: 
>> <tmpl_string> 
>> <https://prometheus.io/docs/alerting/latest/configuration/#tmpl_string>, 
>> ... } ]
>>
>> The default value comes from here 
>> <https://github.com/prometheus/alertmanager/blob/main/template/default.tmpl#L80>
>>  which 
>> sets:
>> {{ define "email.default.subject" }}{{ template "__subject" . }}{{ end }}
>> That is, if you don't override it, then it uses the value of the 
>> "__subject" variable, the definition of which I pointed you to before.
>>
>> On Friday, 19 November 2021 at 06:58:08 UTC muktha...@gmail.com wrote:
>>
>>>
>>> Hi Brian,
>>>
>>> Thanks for you inputs. Could you please help me where to add in and what 
>>> to modify in the below line of code to get the email subject with the 
>>> keyword  "DOWN" for firing alerts and "UP" for resolved alerts.
>>>
>>> {{ define "__subject" }}[{{ .Status | toUpper }}{{ if eq .Status 
>>> "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ 
>>> .GroupLabels.SortedPairs.Values | join " " }} {{ if gt (len .CommonLabels) 
>>> (len .GroupLabels) }}({{ with .CommonLabels.Remove .GroupLabels.Names }}{{ 
>>> .Values | join " " }}{{ end }}){{ end }}{{ end }}
>>>
>>> Best Regards,
>>> Suman
>>> On Thursday, November 18, 2021 at 5:24:53 PM UTC+5:30 Brian Candler 
>>> wrote:
>>>
>>>> This is already done for you.  With the default templates, the subject 
>>>> line has a prefix like [FIRING:2] or [RESOLVED].
>>>>
>>>> However if your alerts are being grouped, and let's say one alert 
>>>> resolves, then you might then get an E-mail with subject [FIRING:1] which 
>>>> shows one alert still firing and one alert resolved.  That is: a single 
>>>> E-mail may contain both "DOWN" and "UP" notifications.
>>>>
>>>> You can change the templates if you like.  There is documentation here 
>>>> <https://prometheus.io/docs/alerting/latest/notifications/>.  The 
>>>> default subject line is created here 
>>>> <https://github.com/prometheus/alertmanager/blob/main/template/default.tmpl#L4>
>>>>  and 
>>>> you can override this with your own template string.
>>>>
>>>> But to be honest, I've switched off all "resolved" notifications now.  
>>>> There's a good explanation why here:
>>>>
>>>> https://www.robustperception.io/running-into-burning-buildings-because-the-fire-alarm-stopped
>>>>
>>>> In short: the fact that an alert condition has ceased is not an excuse 
>>>> to your staff to say "oh that's OK, the problem has gone; I can ignore it 
>>>> now".  There *was* a problem and it *still* needs to be investigated.  You 
>>>> can use an alert to open a ticket, but you should close the ticket 
>>>> manually.
>>>>
>>>> This document is also *very* well worth reading:
>>>>
>>>> https://docs.google.com/document/d/199PqyG3UsyXlwieHaqbGiWVa8eMWi8zzAn0YfcApr8Q/edit
>>>>
>>>> On Thursday, 18 November 2021 at 08:54:08 UTC muktha...@gmail.com 
>>>> wrote:
>>>>
>>>>> Hi Team,
>>>>>
>>>>> I want to set the subject line in alertmanager based on send_resolved 
>>>>> status. I mean before resolving the alert subject line should be "DOWN" 
>>>>> and 
>>>>> after resolving the alert subject line should be set to "UP".
>>>>>
>>>>> Could someone please guide me how to achieve this or provide me syntax 
>>>>> please?
>>>>>
>>>>> Best Regards,
>>>>> Sriman
>>>>>
>>>>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/a3fe62eb-929e-4f22-aff2-082e688c1954n%40googlegroups.com.

Reply via email to