-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouple severity from Nagios plugin return codes
This change is backwards-compatible. Nagios plugins for non-trivial services will often poke multiple data points looking for anomalous or undesirable behaviour. Each data point is often reflected with its own check Result in nagiosplugin. If all data points are within tolerance, we can rely on nagiosplugin to return an OK result to its parent process. Similarly, if one or more data points are outside tolerance, we can rely on nagiosplugin to return a non-OK (WARNING or CRITICAL) result to its parent process. This pattern greatly simplifies plugin development: plugins may focus on the monotonous task of data-gathering, leaving the ultimate 'result join' to the nagiosplugin library. Life get complicated when one or more data points are unable to be queried (for whatever reason). Prior to this change, any single UNKNOWN Result would have superseded all other batched check Results: including other WARNING or CRITICAL Results. Amongst organisations that do not treat an individual UNKNOWN result as a pageable event, this behaviour suppressed actual failures (see #8). This commit introduces the notion of a 'status policy': a mapping between a conventional check status and its severity, relative to other statuses. Results are now ordered by severity instead of the fixed numeric constants defined by Nagios. Organisations may now prioritise plugin return codes to match their established monitoring policy. Unit tests in check_test.go demonstrate use. This decoupling is invisible by default. The default status policy mimics old behaviour. To enable alternative severity prioritisation, the caller must invoke the new NewCheckWithOptions() initialiser.
- Loading branch information
Saj Goonatilleke
committed
Jan 4, 2016
1 parent
72f8b19
commit 07fe3c5
Showing
4 changed files
with
135 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package nagiosplugin | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestNewStatusPolicyAcceptsCompleteStatuses(t *testing.T) { | ||
_, err := NewStatusPolicy([]Status{OK, UNKNOWN, WARNING, CRITICAL}) | ||
if err != nil { | ||
t.Errorf("NewStatusPolicy(): %v", err) | ||
} | ||
} | ||
|
||
func TestNewStatusPolicyRejectsIncompleteStatuses(t *testing.T) { | ||
// Missing UNKNOWN. | ||
_, err := NewStatusPolicy([]Status{OK, WARNING, CRITICAL}) | ||
if err == nil { | ||
t.Errorf("expected NewStatusPolicy() to return an error") | ||
} | ||
} |