How to fix the error undefined variable "$labels"in Prometheus?

user1365697

I used this alret

        - alert: my alert
          expr: status{status="ERROR"}
          for: 30m
          labels:
            severity: WARNING   
          annotations:
            myData: "{{ $labels.myData }}"
            myData2: "{{ $labels.myData2 }}"

I got an error ERROR - templates/: parse error in "prometheus/templates/alertmanager-prometheusRule.yaml": template: prometheus/templates/alertmanager-prometheusRule.yaml:419: undefined variable "$labels"

I saw the same issue in

Prometheus Docker fails to start with `Template: (dynamic): parse: template: :10: undefined variable "$labels"`

but I didn't understand how to solve it

in the configuration I used this data

text: "{{ range .Alerts -}}{{ .Annotations.myData }}{{ .Annotations.myData2}}{{ end-}}"

The error is from helm lint

bjakubski

It seems you are deploying your Prometheus setup via a helm chart. This causes an issue as the same delimiters ({{ and }}) are used both by helm templating and the alerting templating in Prometheus.

The {{ $labels.myData }} has to reach prometheus config intact, so helm must not process it.

The simplest way would be to use:

{{ "{{" }} $labels.myData }}

The {{ "{{" }} block will be processed by helm and will produce {{ as a result with rest of the line not being altered and will get you the result you need.

Collected from the Internet

Please contact javaer1[email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

PHP error undefined variable notice how to fix?

how fix this error "Undefined variable: products (0)"

how to Fix undefined variable?

How to make context variable and fix error that 'Undefined name 'context'.'

How to fix error "undefined variable:sin" in plotting in gnuplot?

How to fix "Undefined variable: collaborators"?

How to fix undefined variable in javascript

How to deal with "prometheus" and "prometheus_replica" labels?

how to fix "Undefined variable: subtask" in Laravel 5.2

How to fix Undefined variable: image in Laravel 5.6

How to fix "Undefined Variable" in node-sass?

how do i fix "undefined variable"

How to fix field name is undefined error?

How to fix in KnexJs the error destroy of undefined

How to fix Typescript error "Object is possibly 'undefined'"

how to fix undefined column selected error in R?

How to fix 'Undefined columns selected' error in R?

How to fix genymotion error of undefined symbol : drmGetDevice?

undefined index error in php and How to fix it

How to fix "undefined method" error in destroy function

How to fix 'undefined is not an object' error in react native

How to fix "Cannot read property of undefined" error

How to fix Undefined offset-Error in PHP

How to fix error identifier "PlayerViewPointLocation" is undefined

How do I fix it 'error: undefined' in javascript?

How to fix "undefined name" error message in Python?

How to fix an error "this.accountService is undefined"

How can I fix this "forEach of undefined" error?

How to this error "Undefined variable: selectedType "