Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telegram notifier ignores HTML tags #4026

Open
ntk148v opened this issue Sep 9, 2024 · 0 comments
Open

Telegram notifier ignores HTML tags #4026

ntk148v opened this issue Sep 9, 2024 · 0 comments

Comments

@ntk148v
Copy link
Contributor

ntk148v commented Sep 9, 2024

What did you do?
Setup Prometheus and Alertmanager to send message to Telegram. Message is sent as raw text, no HTML tags are parsed.

image

What did you expect to see?

Message is formatted.

image

What did you see instead? Under which circumstances?

Environment

  • System information:

  • Alertmanager version:

Alertmanager image tag 'main':

docker pull quay.io/prometheus/alertmanager@sha256:1e5f1f22c0875ebffad1c39ffb5f831c94ba6dcf0be4d5e5d910cfaade11b1b7
  • Prometheus version:

  • Alertmanager configuration file:

route:
  group_wait: 5s
  group_interval: 30s
  receiver: 'telegram'

templates:
  - iaas-alertmanager.tmpl

receivers:
  - name: 'telegram'
    telegram_configs:
      - bot_token: 'xxxx'
        chat_id: -xxxx
        message: '{{ template "telegram.iaas.message" . }}'
        parse_mode: 'HTML'

iaas-alertmanager.tmpl file (simple notification template with HTML tags)

{{ define "__iaas_alert_list" }}
{{ range . }}
---
🪪 <b>{{ .Labels.alertname }}</b>
<b></b>
{{- if .Annotations.summary }}
📝 Summary: {{ .Annotations.summary }}{{ end }}{{- if .Annotations.title }}
📕 Title: {{ .Annotations.title }}{{ end }}{{- if .Annotations.description }}
📖 Description:
<code>{{ .Annotations.description }}</code>{{ end }}{{ if .Annotations.assignees }}
🏷️ Labels:{{ if .Labels.severity }}
    <i>Instance</i>: <code>{{ .Labels.instance  }}</code>{{ end }}{{ if .Labels.job }}
    <i>Job</i>: <code>{{ .Labels.job }}</code>{{ end }}
Owner: <code>Iaas team</code>
Since: <code>{{ .StartsAt.Local.Format "02/01/2006 15:04:05"  }}</code>
{{ if not .EndsAt.IsZero }}
Ended: <code>{{ .EndsAt.Local.Format "02/01/2006 15:04:05" }}</code>{{ end }}
{{ end }}
{{ end }}


{{ define "telegram.iaas.message" }}
{{- if gt (len .Alerts.Firing) 0 }}
🔥 Alerts Firing 🔥
{{- template "__iaas_alert_list" .Alerts.Firing }}
{{- end }}
{{- if gt (len .Alerts.Resolved) 0 }}
✅ Alerts Resolved ✅
{{- template "__iaas_alert_list" .Alerts.Resolved }}
{{- end }}
{{- end }}

{{ define "telegram.iaas.message.summary" }}
{{if eq .Status "firing"}}
<b>📑 {{.CommonAnnotations.summary}}</b>
{{ (index .Alerts 0).StartsAt.Local.Format "02/01/2006 15:04:05" }}
<b></b>
{{- range $val := .Alerts }}
{{ $val.Labels.alertname }}
{{ $val.Annotations.description }}
{{- end }}
{{ end }}
{{ end }}
  • Prometheus configuration file:
global:
  scrape_interval: 1s
  evaluation_interval: 1s

rule_files:
  - 'rules.yml'

# alert
alerting:
  alertmanagers:
    - scheme: http
      static_configs:
        - targets:
            - 'localhost:9093'

scrape_configs:
  - job_name: prometheus
    metrics_path: /metrics/
    authorization:
      credentials: my_random_prometheus_secret
    static_configs:
      - targets: ['host.docker.internal:8080']
  • Logs:
nothing special
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant