Skip to content

Commit 8f19917

Browse files
authored
add new parameter "group" to filter alert rules (#70)
* add new parameter "group" to filter alert rules
1 parent a2cc377 commit 8f19917

File tree

5 files changed

+280
-12
lines changed

5 files changed

+280
-12
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ Flags:
155155
-n, --name strings The name of one or more specific alerts to check.
156156
This parameter can be repeated e.G.: '--name alert1 --name alert2'
157157
If no name is given, all alerts will be evaluated
158+
-g, --group strings The name of one or more specific groups to check.
159+
This parameter can be repeated e.G.: '--group group1 --group group2'
160+
If no group is given, all groups will be scanned for alerts
158161
-T, --no-alerts-state string State to assign when no alerts are found (0, 1, 2, 3, OK, WARNING, CRITICAL, UNKNOWN). If not set this defaults to OK (default "OK")
159162
-P, --problems Display only alerts which status is not inactive/OK. Note that in combination with the --name flag this might result in no alerts being displayed
160163
```

cmd/alert.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ inactive = 0`,
8383
}
8484

8585
// Get all rules from all groups into a single list
86-
rules := alert.FlattenRules(alerts.Groups)
86+
rules := alert.FlattenRules(alerts.Groups, cliAlertConfig.Group)
8787

8888
// If there are no rules we can exit early
8989
if len(rules) == 0 {
@@ -217,6 +217,11 @@ func init() {
217217
"\nThis parameter can be repeated e.G.: '--name alert1 --name alert2'"+
218218
"\nIf no name is given, all alerts will be evaluated")
219219

220+
fs.StringSliceVarP(&cliAlertConfig.Group, "group", "g", nil,
221+
"The name of one or more specific groups to check for alerts."+
222+
"\nThis parameter can be repeated e.G.: '--group group1 --group group2'"+
223+
"\nIf no group is given, all groups will be scanned for alerts")
224+
220225
fs.BoolVarP(&cliAlertConfig.ProblemsOnly, "problems", "P", false,
221226
"Display only alerts which status is not inactive/OK. Note that in combination with the --name flag this might result in no alerts being displayed")
222227
}

0 commit comments

Comments
 (0)