inCaller / prometheus_bot

Telegram bot for prometheus alerting
MIT License
394 stars 182 forks source link

can I use the alertmanager templates? #70

Open mulderx opened 2 years ago

mulderx commented 2 years ago

hello Thanks for prometheus_bot.

can I use the alertmanager templates for the telegram templates?

thank you~

mulderx commented 2 years ago

I use the production_example.tmpl but

Alert: <a href="{{ $val.GeneratorURL }}">{{ index $val.Annotations "name" }}</a>

didn't show anything

how can I fix it?

out put


~~~ Alerting ~~~
alertname = service_down

Status: FIRING 🔥

Active Alert List:
  Alert:  **<--- didn't show anything**
  Current value:Severity: critical
  Active from: 11/04/2021 16:30:20

  description: The service blackbox_http instance xxx is Down
  summary: instance xxx can't work!!!
hryamzik commented 2 years ago

You can try to ask @AndreaGreco about that template. Generally you can always sniff traffic between the bot and alert manager and add also log messages in go code.

mulderx commented 2 years ago

You can try to ask @AndreaGreco about that template. Generally you can always sniff traffic between the bot and alert manager and add also log messages in go code.

ok! thank you

AndreaGreco commented 2 years ago

You can try to ask @AndreaGreco about that template. Generally you can always sniff traffic between the bot and alert manager and add also log messages in go code.

ok! thank you

Hi, pass too many years i don't remember for. Read source code in main.go, if found solution right. if problem persist write here again and i will try help you by reading source

woloss commented 2 years ago

Alert: <a href="{{ $val.GeneratorURL }}">{{ index $val.Annotations "name" }}</a>

didn't show anything

how can I fix it?

Well, kinda late answer. Config with alerts, which configured on Prometheus side, contains annotations section. This is pure json (key/value). If you want to get value here - Alert: {{ index $val.Annotations "name" }} Current value - {{ $val.Annotations "value" }} You must add one more annotation, something like:

    annotations:
      title: '{{ $labels.instance }}'
      name: 'Instance Alert'
      value: 'Some Value'

Also, you should exclude those keys from loop (based on production_example.tmpl)

  Active from: {{ $val.StartsAt | str_FormatDate }}
  {{ range $key, $value := $val.Annotations -}}
  {{ if and (and (ne $key "name") (ne $key "value")) (ne $key "measureUnit") }}  -<<<< There
  {{$key}}: {{$value}}
  {{- end -}}