Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cmd/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ inactive = 0`,
}

var overall goresult.Overall
// We need to count how many times we added an alert for the no-alerts-state
var counterPartialResult int

for _, rl := range rules {
// If it's not the Alert we're looking for, Skip!
Expand Down Expand Up @@ -172,6 +174,8 @@ inactive = 0`,
sc.SetState(rlStatus)
sc.SetOutput(rl.GetOutput())
overall.AddSubcheck(sc)

counterPartialResult++
}

// Handle active alerts
Expand Down Expand Up @@ -225,6 +229,8 @@ inactive = 0`,
rl.Alert = alert
sc.SetOutput(rl.GetOutput())
overall.AddSubcheck(sc)

counterPartialResult++
}
}
}
Expand All @@ -239,7 +245,7 @@ inactive = 0`,
}

// When there are no alerts we add an empty PartialResult just to have consistent output
if counterAlert == 0 {
if counterPartialResult == 0 {
sc := goresult.NewPartialResult()
sc.SetDefaultState(noAlertsState)
sc.SetOutput("No alerts retrieved")
Expand Down
13 changes: 13 additions & 0 deletions cmd/alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,19 @@ exit status 2
\_ [CRITICAL] [BlackboxTLS] - Job: [blackbox] on Instance: [https://localhost:443] is firing - value: -6065338.00 - {"alertname":"TLS","icinga":"ok","instance":"https://localhost:443","job":"blackbox","severity":"critical","team":"network"}
|total=3 firing=1 pending=1 inactive=1
exit status 2
`,
},
{
name: "alert-include-label-no-alerts-state",
server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write(loadTestdata(alertTestDataSet1))
})),
args: []string{"run", "../main.go", "alert", "--include-label", "foo=bar", "--no-alerts-state", "1", "-P", "true"},
expected: `[WARNING] - No alerts retrieved
\_ [WARNING] No alerts retrieved
|total=2 firing=1 pending=1 inactive=0
exit status 1
`,
},
{
Expand Down
Loading