alertmanager icon indicating copy to clipboard operation
alertmanager copied to clipboard

Feature Request: Add in functions to convert variable types in templates

Open cbryant42 opened this issue 2 years ago • 0 comments

What did you do? Writing template for email alert notifications What did you expect to see? A function to convert strings to ints, floats What did you see instead? Under which circumstances? I have not been able to find any functions for type conversion or syntax for type casting Environment

  • System information:

Linux 4.13.12-1.el7.elrepo.x86_64 x86_64

  • Alertmanager version:

0.23.0

  • Prometheus version:

v2.32.1

  • Alertmanager configuration file:
{{range .Annotations.SortedPairs}}{{if (eq .Name "value")}}{{$temp_value = .Value float64}}{{if (ne ($temp_value | printf "%f") ($disk_value | printf "%f"))}}{{$disk_value = .Value | printf "%f"}}
  • Prometheus configuration file:
N/A
  • Logs:
header template: template: :1: function \"float64\" not defined"

I have tried many iterations of similar lines of code trying to cast the variables as floats in order to compare the values, but have had no luck thus far. I've printed the variable types before assignment and they are float64, but after assigning to .Value both variable types are string.

Is there any method for converting strings to floats? Or more specific to my problem, a way to compare numeric string values against each other? Ie. {{if gt "27.43" "87.39"}}

cbryant42 avatar May 11 '22 18:05 cbryant42