-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from infraweavers/perfdata-alerting
Warning and Critical Threshold Handling
- Loading branch information
Showing
46 changed files
with
19,787 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,19 @@ | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= | ||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= | ||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= | ||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= | ||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= | ||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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,192 @@ | ||
package nagios | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Best documentation for this is: https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT | ||
|
||
func TestThis(t *testing.T) { | ||
t.Run("Test 0 to N or alert", func(t *testing.T) { | ||
parsedThing := ParseRangeString("10") | ||
assert.Equal(t, parsedThing.End, 10.0) | ||
assert.Equal(t, parsedThing.CheckRange("54"), true) | ||
assert.Equal(t, parsedThing.CheckRange("-1"), true) | ||
}) | ||
|
||
t.Run("Test N to infinity or alert", func(t *testing.T) { | ||
parsedThing := ParseRangeString("10:") | ||
assert.Equal(t, parsedThing.Start, 10.0) | ||
assert.Equal(t, parsedThing.EndInfinity, true) | ||
assert.Equal(t, parsedThing.CheckRange("10"), false) | ||
assert.Equal(t, parsedThing.CheckRange("9"), true) | ||
assert.Equal(t, parsedThing.CheckRange("-1"), true) | ||
assert.Equal(t, parsedThing.CheckRange("11"), false) | ||
}) | ||
|
||
t.Run("Within a range involving -inf", func(t *testing.T) { | ||
parsedThing := ParseRangeString("~:30") | ||
assert.Equal(t, parsedThing.StartInfinity, true) | ||
assert.Equal(t, parsedThing.End, 30.0) | ||
assert.Equal(t, parsedThing.CheckRange("5"), false) | ||
assert.Equal(t, parsedThing.CheckRange("-10"), false) | ||
assert.Equal(t, parsedThing.CheckRange("-100"), false) | ||
assert.Equal(t, parsedThing.CheckRange("30"), false) | ||
assert.Equal(t, parsedThing.CheckRange("31"), true) | ||
}) | ||
|
||
t.Run("Outside a defined range", func(t *testing.T) { | ||
parsedThing := ParseRangeString("5:33") | ||
assert.Equal(t, parsedThing.Start, 5.0) | ||
assert.Equal(t, parsedThing.End, 33.0) | ||
assert.Equal(t, parsedThing.CheckRange("33"), false) | ||
assert.Equal(t, parsedThing.CheckRange("34"), true) | ||
assert.Equal(t, parsedThing.CheckRange("4"), true) | ||
assert.Equal(t, parsedThing.CheckRange("5"), false) | ||
|
||
}) | ||
|
||
t.Run("Within a defined range", func(t *testing.T) { | ||
parsedThing := ParseRangeString("10:200") | ||
assert.Equal(t, parsedThing.Start, 10.0) | ||
assert.Equal(t, parsedThing.End, 200.0) | ||
assert.Equal(t, parsedThing.CheckRange("54"), false) | ||
assert.Equal(t, parsedThing.CheckRange("10"), false) | ||
assert.Equal(t, parsedThing.CheckRange("9"), true) | ||
assert.Equal(t, parsedThing.CheckRange("200"), false) | ||
assert.Equal(t, parsedThing.CheckRange("201"), true) | ||
}) | ||
|
||
t.Run("InsideRange", func(t *testing.T) { | ||
parsedThing := ParseRangeString("@32:64") | ||
assert.Equal(t, parsedThing.CheckRange("32"), true) | ||
assert.Equal(t, parsedThing.CheckRange("33"), true) | ||
assert.Equal(t, parsedThing.CheckRange("64"), true) | ||
assert.Equal(t, parsedThing.CheckRange("63"), true) | ||
assert.Equal(t, parsedThing.CheckRange("31"), false) | ||
assert.Equal(t, parsedThing.CheckRange("65"), false) | ||
}) | ||
|
||
t.Run("If invalid range is provided (with positive infinity) parsing should return nil", func(t *testing.T) { | ||
parsedThing := ParseRangeString("50:~") | ||
assert.Nil(t, parsedThing) | ||
}) | ||
|
||
t.Run("Alert in 0-32", func(t *testing.T) { | ||
parsedThing := ParseRangeString("@32") | ||
|
||
assert.Equal(t, parsedThing.CheckRange("32"), true) | ||
assert.Equal(t, parsedThing.CheckRange("31"), true) | ||
assert.Equal(t, parsedThing.CheckRange("0"), true) | ||
assert.Equal(t, parsedThing.CheckRange("33"), false) | ||
assert.Equal(t, parsedThing.CheckRange("-32"), false) | ||
assert.Equal(t, parsedThing.CheckRange("-1"), false) | ||
}) | ||
t.Run("Alert on value 32", func(t *testing.T) { | ||
parsedThing := ParseRangeString("@32:32") | ||
|
||
assert.Equal(t, parsedThing.CheckRange("32"), true) | ||
assert.Equal(t, parsedThing.CheckRange("31"), false) | ||
assert.Equal(t, parsedThing.CheckRange("0"), false) | ||
assert.Equal(t, parsedThing.CheckRange("33"), false) | ||
assert.Equal(t, parsedThing.CheckRange("-32"), false) | ||
assert.Equal(t, parsedThing.CheckRange("-1"), false) | ||
}) | ||
|
||
t.Run("Plugin should return exit code OK when value is within accetptable range", func(t *testing.T) { | ||
var plugin = Plugin{ | ||
ExitStatusCode: StateOKExitCode, | ||
} | ||
plugin.ServiceOutput = "CHECK-NT-REPLACEMENT" | ||
|
||
perfdata := PerformanceData{ | ||
Label: "perfdata label", | ||
Value: "18.0", | ||
UnitOfMeasurement: "C", | ||
Warn: "5:30", | ||
Crit: "0:40", | ||
} | ||
plugin.AddPerfData(false, perfdata) | ||
plugin.EvaluateThreshold(perfdata) | ||
|
||
assert.Equal(t, StateOKExitCode, plugin.ExitStatusCode) | ||
}) | ||
|
||
t.Run("Plugin should return exit code WARNING when value is within warning range", func(t *testing.T) { | ||
var plugin = Plugin{ | ||
ExitStatusCode: StateOKExitCode, | ||
} | ||
plugin.ServiceOutput = "CHECK-NT-REPLACEMENT" | ||
|
||
perfdata := PerformanceData{ | ||
Label: "perfdata label", | ||
Value: "31.0", | ||
UnitOfMeasurement: "C", | ||
Warn: "5:30", | ||
Crit: "0:40", | ||
} | ||
plugin.AddPerfData(false, perfdata) | ||
plugin.EvaluateThreshold(perfdata) | ||
|
||
assert.Equal(t, StateWARNINGExitCode, plugin.ExitStatusCode) | ||
}) | ||
|
||
t.Run("Plugin should return exit code WARNING when value is within warning range", func(t *testing.T) { | ||
var plugin = Plugin{ | ||
ExitStatusCode: StateOKExitCode, | ||
} | ||
plugin.ServiceOutput = "CHECK-NT-REPLACEMENT" | ||
|
||
perfdata := PerformanceData{ | ||
Label: "perfdata label", | ||
Value: "4.0", | ||
UnitOfMeasurement: "C", | ||
Warn: "5:30", | ||
Crit: "0:40", | ||
} | ||
plugin.AddPerfData(false, perfdata) | ||
plugin.EvaluateThreshold(perfdata) | ||
|
||
assert.Equal(t, StateWARNINGExitCode, plugin.ExitStatusCode) | ||
}) | ||
|
||
t.Run("Plugin should return exit code CRITICAL when value is within warning range", func(t *testing.T) { | ||
var plugin = Plugin{ | ||
ExitStatusCode: StateOKExitCode, | ||
} | ||
plugin.ServiceOutput = "CHECK-NT-REPLACEMENT" | ||
|
||
perfdata := PerformanceData{ | ||
Label: "perfdata label", | ||
Value: "41.0", | ||
UnitOfMeasurement: "C", | ||
Warn: "5:30", | ||
Crit: "0:40", | ||
} | ||
plugin.AddPerfData(false, perfdata) | ||
plugin.EvaluateThreshold(perfdata) | ||
|
||
assert.Equal(t, StateCRITICALExitCode, plugin.ExitStatusCode) | ||
}) | ||
|
||
t.Run("Plugin should return exit code CRITICAL when value is within warning range", func(t *testing.T) { | ||
var plugin = Plugin{ | ||
ExitStatusCode: StateOKExitCode, | ||
} | ||
plugin.ServiceOutput = "CHECK-NT-REPLACEMENT" | ||
|
||
perfdata := PerformanceData{ | ||
Label: "perfdata label", | ||
Value: "-1.0", | ||
UnitOfMeasurement: "C", | ||
Warn: "5:30", | ||
Crit: "0:40", | ||
} | ||
plugin.AddPerfData(false, perfdata) | ||
plugin.EvaluateThreshold(perfdata) | ||
|
||
assert.Equal(t, StateCRITICALExitCode, plugin.ExitStatusCode) | ||
}) | ||
} |
Oops, something went wrong.