atc0005 / todo

A collection of TODO items not specific to any one project
MIT License
0 stars 0 forks source link

Use UNKNOWN state for invalid command-line args #55

Closed atc0005 closed 1 year ago

atc0005 commented 1 year ago

Overview

The Nagios Plugin Guidelines (see refs) provides this guidance for setting exit states:

Numeric Value | Service Status | Status Description -- | -- | -- 0 | OK | The plugin was able to check the service and it appeared to be functioning properly 1 | Warning | The plugin was able to check the service, but it appeared to be above some "warning" threshold or did not appear to be working properly 2 | Critical | The plugin detected that either the service was not running or it was above some "critical" threshold 3 | Unknown | Invalid command line arguments were supplied to the plugin or low-level failures internal to the plugin (such as unable to fork, or open a tcp socket) that prevent it from performing the specified operation. Higher-level errors (such as name resolution errors, socket timeouts, etc) are outside of the control of plugins and should generally NOT be reported as UNKNOWN states.

The last item is the focus of this GH issue.

Most of the projects I'm currently working with opt to exit with a CRITICAL state when invalid command-line arguments, flags or flag values are used. Instead, based on the guidance listed above an UNKNOWN state should be returned.

Example fix:

diff --git a/cmd/check_cert/main.go b/cmd/check_cert/main.go
index fa13b79..fbf14fd 100644
--- a/cmd/check_cert/main.go
+++ b/cmd/check_cert/main.go
@@ -53,10 +53,10 @@ func main() {

        plugin.ServiceOutput = fmt.Sprintf(
            "%s: Error initializing application",
-           nagios.StateCRITICALLabel,
+           nagios.StateUNKNOWNLabel,
        )
        plugin.AddError(cfgErr)
-       plugin.ExitStatusCode = nagios.StateCRITICALExitCode
+       plugin.ExitStatusCode = nagios.StateUNKNOWNExitCode

        return
    }

TODO

This is not an exhaustive list; I should verify all Nagios related projects that I maintain have these corrections applied.

References