# How to define and use Prometheus Labels variables?

**URL:** <https://discuss.prometheus.io/t/how-to-define-and-use-prometheus-labels-variables/837>\
**Category:** General Help/Support\
**Created:** [March 11, 2022, 11:26am UTC](https://discuss.prometheus.io/t/how-to-define-and-use-prometheus-labels-variables/837 "2022-03-11T11:26:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![philz94](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@philz94](https://discuss.prometheus.io/u/philz94)\
**Post date:** [March 11, 2022, 11:26am UTC](https://discuss.prometheus.io/t/how-to-define-and-use-prometheus-labels-variables/837/1 "2022-03-11T11:26:52Z")

</div>

Hi experts,

I need your lights for defining and using properly labels variables.

Below you will find my prometheus config example.

I have defined

labels:  
team: ‘team1’

and want to use “team” variable in alert.rules.yml

```
labels:
  severity: critical
  origin: {{ $labels.team }}

```

But Prometheus doesn’t recognize {{ $labels.team }} as a variable, if I replace it with {{ $labels.instance }} it works well.

Any idea on how to define new variables and use it properly?

Many thanks

prometheus.yml

- job\_name: ‘blackbox\_probe’  
metrics\_path: /probe  
params:  
module: [body\_contains\_ok]  
file\_sd\_configs:  
- files: [‘targets.yml’]  
scheme: https  
relabel\_configs:  
- source\_labels: [**address**]  
target\_label: \_\_param\_target  
- source\_labels: [\_\_param\_target]  
target\_label: instance  
- target\_label: **address**  
replacement: [promtheus.blackbox.service.com:9115](http://promtheus.blackbox.service.com:9115)

======================  
targets.yml

- targets:
  - “myurl1/isAlive”  
labels:  
team: ‘team1’

- targets:
  - “myurl2/isAlive”  
labels:  
team: ‘team2’

==========================  
alert.rules.yml

groups:

- name: service\_down  
rules:
  - alert: IsAlive\_down  
expr: (count by (instance) (probe\_success{job=“blackbox\_probe”}==0 ) )==1  
for: 10s  
labels:  
severity: critical  
origin: {{ $labels.team }}  
annotations:  
summary: “blabla”
