refactor(pkg): move Status to a separate module

This commit is contained in:
Emmanuel BENOîT 2024-07-20 18:56:51 +02:00
parent 7209591e08
commit 3263d8c583
Signed by: Emmanuel BENOîT
SSH key fingerprint: SHA256:l7PFUUF5TCDsvYeQC9OnTNz08dFY7Fvf4Hv3neIqYpg
7 changed files with 51 additions and 44 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")
}
}