feat: add the check_output_matches plugin ()

This PR adds the `check_output_matches` plugin, which can be used to count regexp or substring matches from either text files or command outputs and determine the final status based on the amount of matches that were found.

Reviewed-on: 
Co-authored-by: Emmanuel BENOÎT <tseeker@nocternity.net>
Co-committed-by: Emmanuel BENOÎT <tseeker@nocternity.net>
This commit is contained in:
Emmanuel BENOîT 2024-07-20 22:57:10 +02:00 committed by Emmanuel BENOîT
parent 9fac656cdf
commit c46c9d76d9
22 changed files with 1063 additions and 55 deletions
cmd/zoneserial

View file

@ -15,6 +15,7 @@ import (
"nocternity.net/gomonop/pkg/perfdata"
"nocternity.net/gomonop/pkg/plugin"
"nocternity.net/gomonop/pkg/results"
"nocternity.net/gomonop/pkg/status"
)
//-------------------------------------------------------------------------------------------------------
@ -93,23 +94,23 @@ func (program *checkProgram) Results() *results.Results {
// Check the values that were specified from the command line. Returns true if the arguments made sense.
func (program *checkProgram) CheckArguments() bool {
if program.hostname == "" {
program.plugin.SetState(results.StatusUnknown, "no DNS hostname specified")
program.plugin.SetState(status.StatusUnknown, "no DNS hostname specified")
return false
}
if program.port < 1 || program.port > 65535 {
program.plugin.SetState(results.StatusUnknown, "invalid DNS port number")
program.plugin.SetState(status.StatusUnknown, "invalid DNS port number")
return false
}
if program.zone == "" {
program.plugin.SetState(results.StatusUnknown, "no DNS zone specified")
program.plugin.SetState(status.StatusUnknown, "no DNS zone specified")
return false
}
if program.rsHostname == "" {
program.plugin.SetState(results.StatusUnknown, "no reference DNS hostname specified")
program.plugin.SetState(status.StatusUnknown, "no reference DNS hostname specified")
return false
}
if program.rsPort < 1 || program.rsPort > 65535 {
program.plugin.SetState(results.StatusUnknown, "invalid reference DNS port number")
program.plugin.SetState(status.StatusUnknown, "invalid reference DNS port number")
return false
}
program.hostname = strings.ToLower(program.hostname)
@ -176,12 +177,12 @@ func (program *checkProgram) RunCheck() {
cOk, cSerial := program.getSerial("checked", checkResponse)
rOk, rSerial := program.getSerial("reference", refResponse)
if !(cOk && rOk) {
program.plugin.SetState(results.StatusUnknown, "could not read serials")
program.plugin.SetState(status.StatusUnknown, "could not read serials")
return
}
if cSerial == rSerial {
program.plugin.SetState(results.StatusOK, "serials match")
program.plugin.SetState(status.StatusOK, "serials match")
} else {
program.plugin.SetState(results.StatusCritical, "serials mismatch")
program.plugin.SetState(status.StatusCritical, "serials mismatch")
}
}