You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+6-5Lines changed: 6 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -150,11 +150,12 @@ Examples:
150
150
| total=2 firing=1 pending=0 inactive=1
151
151
152
152
Flags:
153
-
-h, --help help for alert
154
-
-n, --name strings The name of one or more specific alerts to check.
155
-
This parameter can be repeated e.G.: '--name alert1 --name alert2'
156
-
If no name is given, all alerts will be evaluated
157
-
-P, --problems Display only alerts which status is not inactive/OK
153
+
-h, --help help for alert
154
+
-n, --name strings The name of one or more specific alerts to check.
155
+
This parameter can be repeated e.G.: '--name alert1 --name alert2'
156
+
If no name is given, all alerts will be evaluated
157
+
-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")
158
+
-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
check.ExitError(fmt.Errorf("invalid value for --no-alerts-state: %s", cliAlertConfig.NoAlertsState))
58
+
}
59
+
43
60
var (
44
61
counterFiringint
45
62
counterPendingint
46
63
counterInactiveint
47
64
)
48
65
49
66
c:=cliConfig.NewClient()
50
-
err:=c.Connect()
67
+
err=c.Connect()
68
+
51
69
iferr!=nil {
52
70
check.ExitError(err)
53
71
}
@@ -65,6 +83,16 @@ inactive = 0`,
65
83
// Get all rules from all groups into a single list
66
84
rules:=alert.FlattenRules(alerts.Groups)
67
85
86
+
// If there are no rules we can exit early
87
+
iflen(rules) ==0 {
88
+
// Since the user is expecting the state of a certain alert and
89
+
// it that is not present it might be noteworthy.
90
+
ifcliAlertConfig.AlertName!=nil {
91
+
check.ExitRaw(check.Unknown, "No such alert defined")
92
+
}
93
+
check.ExitRaw(noAlertsState, "No alerts defined")
94
+
}
95
+
68
96
// Set initial capacity to reduce memory allocations
69
97
varlint
70
98
for_, rl:=rangerules {
@@ -164,11 +192,33 @@ inactive = 0`,
164
192
165
193
funcinit() {
166
194
rootCmd.AddCommand(alertCmd)
195
+
167
196
fs:=alertCmd.Flags()
197
+
198
+
fs.StringVarP(&cliAlertConfig.NoAlertsState, "no-alerts-state", "T", "OK", "State to assign when no alerts are found (0, 1, 2, 3, OK, WARNING, CRITICAL, UNKNOWN). If not set this defaults to OK")
0 commit comments