Skip to content

Support regex in include-exclude labels#129

Open
martialblog wants to merge 1 commit into
mainfrom
label-regex
Open

Support regex in include-exclude labels#129
martialblog wants to merge 1 commit into
mainfrom
label-regex

Conversation

@martialblog
Copy link
Copy Markdown
Member

Fixes #127

@martialblog martialblog self-assigned this May 18, 2026
@martialblog
Copy link
Copy Markdown
Member Author

@gianmarco-mameli Ciao, I think this should do it. Feel free to test it and give me feedback.

@gianmarco-mameli
Copy link
Copy Markdown
Contributor

Hi, let me try it thanks

@gianmarco-mameli
Copy link
Copy Markdown
Contributor

gianmarco-mameli commented May 18, 2026

@martialblog Hi, I think I'm doing something wrong with the regex, do you have a working example? none of my tests seems to work
Thanks

@martialblog
Copy link
Copy Markdown
Member Author

Hi, in the unittests I'm using these team=data.+ severity=crit.*. Can you give me examples of something that isn't working?

@gianmarco-mameli
Copy link
Copy Markdown
Contributor

I made 2 tests but I see strange behavior, even without regex

1st test with a ContainerKilled alert (2 containers killed)

With no filters

[CRITICAL] - 2 Alerts: 2 Firing - 0 Pending - 0 Inactive
\_ [CRITICAL] [ContainerKilled] - Job: [cadvisor] on Instance: [testnode:8088]
 is firing - value: 60.64 - {"alertname":"ContainerKilled","id":"/system.slice
/docker-c9f11108c4d687eeb644db098dac08b1b25592e2dc93b2d54f7bf4e6605a688b.scope
","image":"nodered/node-red:4.1.10","instance":"testnode:8088","job":"cadvisor
","name":"nodered","severity":"warning"}
\_ [CRITICAL] [ContainerKilled] - Job: [cadvisor] on Instance: [testnode:8088]
 is firing - value: 70.64 - {"alertname":"ContainerKilled","id":"/system.slice
/docker-f000eecbd1f920a64433d12f24f733a007a476be7becd6d060442e77c0b1fd44.scope
","image":"eclipse-mosquitto:2.1.2-alpine","instance":"testnode:8088","job":"c
advisor","name":"mosquitto","severity":"warning"}
|total=2 firing=2 pending=0 inactive=0

Working

'/usr/lib/nagios/plugins/check_prometheus' 'alert' '--hostname' 'prometheus.test.domain.it' '--insecure' '--name' 'ContainerKilled' '--port' '443' '--problems' 'false' '--secure' '--timeout' '30' '--include-label' 'instance=testnode:\d+'
[CRITICAL] - 2 Alerts: 2 Firing - 0 Pending - 0 Inactive\_ [CRITICAL] [ContainerKilled] - Job: [cadvisor] on Instance: [testnode:8088] is firing - value: 60.64 - {"alertname":"ContainerKilled","id":"/system.slice/docker-c9f11108c4d687eeb644db098dac08b1b25592e2dc93b2d54f7bf4e6605a688b.scope","image":"nodered/node-red:4.1.10","instance":"testnode:8088","job":"cadvisor","name":"nodered","severity":"warning"}
\_ [CRITICAL] [ContainerKilled] - Job: [cadvisor] on Instance: [testnode:8088] is firing - value: 70.64 - {"alertname":"ContainerKilled","id":"/system.slice/docker-f000eecbd1f920a64433d12f24f733a007a476be7becd6d060442e77c0b1fd44.scope","image":"eclipse-mosquitto:2.1.2-alpine","instance":"testnode:8088","job":"cadvisor","name":"mosquitto","severity":"warning"}
|total=2 firing=2 pending=0 inactive=0

Not working

'/usr/lib/nagios/plugins/check_prometheus' 'alert' '--hostname' 'prometheus.test.domain.it' '--insecure' '--name' 'ContainerKilled' '--port' '443' '--problems' 'false' '--secure' '--timeout' '30' '--include-label' 'name=nodered'
[OK] - 0 Alerts: 0 Firing - 0 Pending - 0 Inactive
\_ [OK] No alerts retrieved
|total=0 firing=0 pending=0 inactive=0

2nd test with a TargetDown alert (2 targets down)

No filters ouput

[CRITICAL] - 2 Alerts: 2 Firing - 0 Pending - 0 Inactive
\_ [CRITICAL] [TargetDown] - Job: [dococd] is firing - value: 100.00 - {"alert
name":"TargetDown","job":"dococd","severity":"warning"}
\_ [CRITICAL] [TargetDown] - Job: [nut-upstower] is firing - value: 100.00 - {
"alertname":"TargetDown","job":"nut-upstower","severity":"warning"}
|total=2 firing=2 pending=0 inactive=0

Not working

'/usr/lib/nagios/plugins/check_prometheus' 'alert' '--hostname' 'prometheus.test.domain.it' '--insecure' '--name' 'TargetDown' '--port' '443' '--problems' 'false' '--secure' '--timeout' '30' '--include-label' 'job=dococd'
[OK] - 0 Alerts: 0 Firing - 0 Pending - 0 Inactive
\_ [OK] No alerts retrieved
|total=0 firing=0 pending=0 inactive=0

Not working

'/usr/lib/nagios/plugins/check_prometheus' 'alert' '--hostname' 'prometheus.test.domain.it' '--insecure' '--name' 'TargetDown' '--port' '443' '--problems' 'false' '--secure' '--timeout' '30' '--include-label' 'job=nut.+'
[CRITICAL] - 2 Alerts: 2 Firing - 0 Pending - 0 Inactive
\_ [CRITICAL] [TargetDown] - Job: [dococd] is firing - value: 100.00 - {"alertname":"TargetDown","job":"dococd","severity":"warning"}
\_ [CRITICAL] [TargetDown] - Job: [nut-upstower] is firing - value: 100.00 - {"alertname":"TargetDown","job":"nut-upstower","severity":"warning"}
|total=2 firing=2 pending=0 inactive=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Use Regex on include and exclude label

2 participants