metalmatze / alertmanager-bot

[deprecated] Bot for Prometheus' Alertmanager
MIT License
661 stars 148 forks source link

default.tmpl #188

Closed va-bis closed 3 years ago

va-bis commented 3 years ago

Hi, I connected the template file to my alertmanager config, when I start alertmanager, I get the error: err="failed to parse templates: template: default.tmpl:10: function \"duration\" not defined", what needs to be fixed to add in the config, help me please

default.tmpl

{{ define "telegram.default" }} {{ range .Alerts }} {{ if eq .Status "firing"}}πŸ”₯ {{ .Labels.alertname }} πŸ”₯{{ else }}βœ… {{ .Labels.alertname }} βœ…{{ end }} Labels:{{ range $key, $value := .Labels }}{{ if ne $key "alertname" }} {{ $key }}: {{ $value }}{{ end }}{{ end }} Annotations:{{ range $key, $value := .Annotations }} {{ $key }}: {{ $value }}{{ end }}{{ if eq .Status "firing"}} Duration: {{ since .StartsAt }}{{ else }} Duration: {{ duration .StartsAt .EndsAt }} Ended: {{ .EndsAt | since }}{{ end }} {{ end }} {{ end }}

alertmanager.yml

global: resolve_timeout: 5m route: group_by: ['instance', 'alertname', 'service'] group_wait: 30s group_interval: 5m repeat_interval: 3h receiver: 'alertmananger-bot' receivers:

  • name: 'alertmananger-bot' webhook_configs:
  • send_resolved: true url: 'http://alertmananger-bot:8080' inhibit_rules:
  • source_match: severity: 'critical' target_match: severity: 'warning' equal: ['instance', 'alertname']

docker-compose.yml

alertmanager-bot: volumes:

  • ./data:/data command:
  • --alertmanager.url=http://alertmanager:9093
  • --log.level=info
  • --store=bolt
  • --bolt.path=/data/bot.db environment: TELEGRAM_ADMIN: "xxxxxxxxx" TELEGRAM_TOKEN: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx image: metalmatze/alertmanager-bot:0.4.3 container_name: alertmanager-bot networks:
  • networks ports:
  • 8080:8080 restart: unless-stopped
va-bis commented 3 years ago

Please delete this issue This problem is open to discussion