inCaller / prometheus_bot

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

Add alert duration field [feature] #36

Open mywkaa opened 6 years ago

mywkaa commented 6 years ago

Hello,

Added new field "Duration" with time.Duration format , it equals of subtraction between endsAt and startsAt fields.

Example alert resolved: { "alerts":[ { "annotations":{ "resolve_message":"node-exporter is available test12345", "summary":"node-exporter is not available during 5 minute test12345" }, "endsAt":"2018-06-05T09:18:45.237509292Z", "generatorURL":"1111", "labels":{ "alertname":"Node exporter availability during 5 minute 12345", "instance":"22222", "severity":"critical" }, "startsAt":"2018-06-05T09:17:45.237509292Z", "Duration":60000000000 } ] }

mywkaa commented 6 years ago

In go templating this field looks like : {{ range $val := .Alerts -}} Alert duration: {{$val.Duration}} {{ end }}

result: Alert duration : 1m0s

hryamzik commented 6 years ago

So is result human-readable? Simple duration output is usually in milliseconds.

Can you also update README, please?

mywkaa commented 6 years ago

So is result human-readable? Simple duration output is usually in milliseconds.

Yes result is human readable, added "Truncate" to seconds to avoid ms output. Here is an example https://play.golang.org/p/vUR15ehvd8T

Can you also update README, please?

README has no fields related documentation. Should I add new testdata file ?

hryamzik commented 3 years ago

@mywkaa Please add usage to readme and I'll be able to merge this