AlertManager - Convert Label from String to Number in GO TEMPLATE

Hello, from my query I set label “metadata” which has the following String pattern: “warn_threshhold;crit_threshold;filesytem”
Using reReplaceAll in GO Template I’m able to split the variables as I need them:
{{- $metadata := index $labels “metadata” -}}
{{- $warning := $metadata | reReplaceAll “^([^;]+);[^;]+;.$" “$1” -}}
{{- $critical := $metadata | reReplaceAll "[1]+;([^;]+);.
$” “$1” -}}
{{- $filesystem := $metadata | reReplaceAll “[2]+;[^;]+;(.*)$” “$1” -}}

Problem is $warning and $critical are seen as String, and when I try an If statement it won’t work:
{{- if (gt $last_metric $critical ) -}}

It doesn’t translate. Typecast functions like “int” “float64”, “printf %f” won’t work either.
The math functions also seem not to be available: add, sub, mul, etc …

BTW: Without getting into details, I don’t want to split “metadata” in 3 different columns.

Kind Regards


  1. ^; ↩︎

  2. ^; ↩︎

I got to a solution: Use humanize everywhere.
It looks like this now:

{{- if (gt (humanize $last_metric) (humanize $critical) ) -}}

Hope this helps in the future anyone in my shoes

B.R.,