How can i use arithmetic operations in the description of a Prometheus Alert?

228 Views Asked by At

I have an alert in Prometheus that fires if a SSL Certificate expires 29 days from now.

The Alert works perfectly fine. The problem is the Value it returns is not in days. The query i use is as follow: probe_ssl_last_chain_expiry_timestamp_seconds - time() < 86400 * 29

Now i would like to have the number of days in my description as following:

description: "SSL certificate expires in {{ $value }} days"

But for it to be the real number of days i have to divide the value by 86400.

Here is what i already tried:

description: "SSL certificate expires in {{ $value/86400 }} days"
description: "SSL certificate expires in {{ printf \"%0.2f\" (div $value 86400) }} days"
description: "SSL certificate expires in {{ (div $value 86400) }} days"
description: "Expires in {{ $value | printf \"%.2f\" | div 86400 }}"
description: "Expires in {{ (div $value 86400) | printf \"%.2f\" }}"

I expected to value to be returned in actual days. Instead i get a error message from prometheus.

How can i achive that?

Is there a way to achieve this? Maybe i can record the value and insert it like this?

Any solution seems welcome.

Thank you

1

There are 1 best solutions below

0
On

Prometheus' Alertmanager uses go templates, and I don't think they support arithmetic out of the box.

Your idea of using (probe_ssl_last_chain_expiry_timestamp_seconds - time())/86400 < 29 is usually correct for this kind of issue.

If you need both divided and not values, or if you need to include result of another metric, you can include it through query instruction.