Add option to exlcude alerts from the results#67
Merged
Conversation
Member
Author
|
How often can a person misspell "exclude"! 🤦 |
16bf1d4 to
b5fab46
Compare
Member
Author
|
@RincewindsHat The commit is ontop the others since otherwise I would have to cleanup the merge conflict and I'm so so so so lazy. Just ignore the others |
|
Looks very good. Even works with multiple excludes Check with "alert -P (--problems)" ./check_prometheus -H metrics.some-probelm-cluster.example.com -p 80 alert -P
[CRITICAL] - 1 Alerts: 1 Firing - 0 Pending - 0 Inactive
\_ [CRITICAL] [Watchdog] is firing - value: 1.00
./check_prometheus -H metrics.some-probelm-cluster.example.com -p 80 alert -P --exclude-alert Watchdog
[UNKNOWN] - 0 Alerts: 0 Firing - 0 Pending - 0 InactiveOnly "alert" ./check_prometheus -H metrics.some-probelm-cluster.example.com -p 80 alert
[CRITICAL] - 126 Alerts: 1 Firing - 0 Pending - 125 Inactive
\_ [OK] [FluxHelmReleaseNotReady] is inactive
..
\_ [OK] [TargetDown] is inactive
\_ [CRITICAL] [Watchdog] is firing - value: 1.00
\_ [OK] [InfoInhibitor] is inactive
./check_prometheus -H metrics.slfl28652.wsl.ch -p 80 alert --exclude-alert Watchdog
[OK] - 125 Alerts: 0 Firing - 0 Pending - 125 Inactive
\_ [OK] [FluxHelmReleaseNotReady] is inactive
..
\_ [OK] [TargetDown] is inactive
\_ [OK] [InfoInhibitor] is inactive
..no impact if Cluster is allready okay. verry nice ./check_prometheus -H metrics.clean-cluster.example.com -p 80 alert -P --exclude-alert Watchdog
[UNKNOWN] - 0 Alerts: 0 Firing - 0 Pending - 0 Inactive
/check_prometheus -H metrics.clean-cluster.example.com -p 80 alert --exclude-alert Watchdog
[OK] - 125 Alerts: 0 Firing - 0 Pending - 125 Inactive
\_ [OK] [FluxHelmReleaseNotReady] is inactive
..
\_ [OK] [TargetDown] is inactive
\_ [OK] [InfoInhibitor] is inactive |
RincewindsHat
requested changes
Dec 17, 2024
| // Matches a list of regular expressions against a string. | ||
| func matches(input string, regexToExclude []string) bool { | ||
| for _, regex := range regexToExclude { | ||
| re := regexp.MustCompile(regex) |
Member
There was a problem hiding this comment.
This is not ideal. If the regex is invalid (as hard as it might be to achieve that), this line panics.
I think I would prefere a controled exit with a helpful message here.
the ..MustCompile functions are preferable for static expressions.
Member
Author
There was a problem hiding this comment.
Yes, you're right. I updated the implementation
b5fab46 to
bcdd153
Compare
The use case behind this: sometimes you want to define a so called Watchdog or DeadMansSwitch alert that is always firing, in order to monitoring that the alerting is working. When such a Watchdog is defined the list of all alerts will always be Critical. Thus we add a flag to exclude certain alerts.
bcdd153 to
fa2e5bd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds an option to exclude alerts from the results.
The use case behind this: sometimes you want to define
a so called Watchdog or DeadMansSwitch alert that is always
firing, in order to monitoring that the alerting is working.
When such a Watchdog is defined the list of all alerts will
always be Critical. Thus we add a flag to exclude certain alerts.
See #61
I want to tackle the issue in two steps, this is the first. The second is a feature to specify the expected exit code.