diff --git a/go.mod b/go.mod index d480e241..d5cfa041 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ module github.com/atc0005/check-vmware go 1.19 require ( - github.com/atc0005/go-nagios v0.16.1 + github.com/atc0005/go-nagios v0.16.2-0.20240601143430-96be84d30458 github.com/google/go-cmp v0.6.0 github.com/rs/zerolog v1.33.0 github.com/vmware/govmomi v0.37.2 diff --git a/go.sum b/go.sum index 2a4942f5..54ae496f 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/atc0005/go-nagios v0.16.1 h1:ef0AWjY9sqWq6dhfJuXtASe7dCkVDonoZhtYvNYWBlo= -github.com/atc0005/go-nagios v0.16.1/go.mod h1:NSm1HeneeyBe27BYzhC7FMx4gg3x8PddeZIMX9YZj5M= +github.com/atc0005/go-nagios v0.16.2-0.20240601143430-96be84d30458 h1:gBMRrLUDHxIlwJS1+zTRFtuXJv56jvwiPQLycPyx0JM= +github.com/atc0005/go-nagios v0.16.2-0.20240601143430-96be84d30458/go.mod h1:n2RHhsrgI8xiapqkJ240dKLwMXWbWvkOPLE92x0IGaM= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= diff --git a/vendor/github.com/atc0005/go-nagios/.golangci.yml b/vendor/github.com/atc0005/go-nagios/.golangci.yml index 28e1d931..d9835ffb 100644 --- a/vendor/github.com/atc0005/go-nagios/.golangci.yml +++ b/vendor/github.com/atc0005/go-nagios/.golangci.yml @@ -27,7 +27,6 @@ linters: - goimports - gosec - govet - - maligned - misspell - prealloc - revive diff --git a/vendor/github.com/atc0005/go-nagios/nagios.go b/vendor/github.com/atc0005/go-nagios/nagios.go index dce167ce..cf56e17d 100644 --- a/vendor/github.com/atc0005/go-nagios/nagios.go +++ b/vendor/github.com/atc0005/go-nagios/nagios.go @@ -315,7 +315,7 @@ func (p *Plugin) ReturnCheckResults() { // If set, call user-provided branding function before emitting // performance data and exiting application. if p.BrandingCallback != nil { - fmt.Fprintf(&output, "%s%s%s", CheckOutputEOL, p.BrandingCallback(), CheckOutputEOL) + _, _ = fmt.Fprintf(&output, "%s%s%s", CheckOutputEOL, p.BrandingCallback(), CheckOutputEOL) } p.handlePerformanceData(&output) @@ -330,7 +330,7 @@ func (p *Plugin) ReturnCheckResults() { // TODO: Perhaps just don't emit anything at all? switch { case p.shouldSkipOSExit: - fmt.Fprintln(os.Stderr, "Skipping os.Exit call as requested.") + _, _ = fmt.Fprintln(os.Stderr, "Skipping os.Exit call as requested.") default: os.Exit(p.ExitStatusCode) } @@ -427,7 +427,20 @@ func (p Plugin) emitOutput(pluginOutput string) { p.outputSink = os.Stdout } - fmt.Fprint(p.outputSink, pluginOutput) + // Attempt to write to output sink. If this fails, send error to + // os.Stderr. If that fails (however unlikely), we have bigger problems + // and should abort. + _, sinkWriteErr := fmt.Fprint(p.outputSink, pluginOutput) + if sinkWriteErr != nil { + _, stdErrWriteErr := fmt.Fprintf( + os.Stderr, + "Failed to write output to given output sink: %s", + sinkWriteErr.Error(), + ) + if stdErrWriteErr != nil { + panic("Failed to initial output sink failure error message to stderr") + } + } } // tryAddDefaultTimeMetric inserts a default `time` performance data metric diff --git a/vendor/github.com/atc0005/go-nagios/sections.go b/vendor/github.com/atc0005/go-nagios/sections.go index f8b023f2..e394e036 100644 --- a/vendor/github.com/atc0005/go-nagios/sections.go +++ b/vendor/github.com/atc0005/go-nagios/sections.go @@ -33,7 +33,7 @@ func (p Plugin) handleServiceOutputSection(w io.Writer) { // formatting changes to this content, simply emit it as-is. This helps // avoid potential issues with literal characters being interpreted as // formatting verbs. - fmt.Fprint(w, p.ServiceOutput) + _, _ = fmt.Fprint(w, p.ServiceOutput) } // handleErrorsSection is a wrapper around the logic used to handle/process @@ -44,7 +44,7 @@ func (p Plugin) handleErrorsSection(w io.Writer) { // hide the section ... if !p.isErrorsHidden() { - fmt.Fprintf(w, + _, _ = fmt.Fprintf(w, "%s%s**%s**%s%s", CheckOutputEOL, CheckOutputEOL, @@ -54,13 +54,13 @@ func (p Plugin) handleErrorsSection(w io.Writer) { ) if p.LastError != nil { - fmt.Fprintf(w, "* %v%s", p.LastError, CheckOutputEOL) + _, _ = fmt.Fprintf(w, "* %v%s", p.LastError, CheckOutputEOL) } // Process any non-nil errors in the collection. for _, err := range p.Errors { if err != nil { - fmt.Fprintf(w, "* %v%s", err, CheckOutputEOL) + _, _ = fmt.Fprintf(w, "* %v%s", err, CheckOutputEOL) } } @@ -80,7 +80,7 @@ func (p Plugin) handleThresholdsSection(w io.Writer) { // not opted to hide the section ... if !p.isThresholdsSectionHidden() { - fmt.Fprintf(w, + _, _ = fmt.Fprintf(w, "%s**%s**%s%s", CheckOutputEOL, p.getThresholdsLabelText(), @@ -89,7 +89,7 @@ func (p Plugin) handleThresholdsSection(w io.Writer) { ) if p.CriticalThreshold != "" { - fmt.Fprintf(w, + _, _ = fmt.Fprintf(w, "* %s: %v%s", StateCRITICALLabel, p.CriticalThreshold, @@ -98,7 +98,7 @@ func (p Plugin) handleThresholdsSection(w io.Writer) { } if p.WarningThreshold != "" { - fmt.Fprintf(w, + _, _ = fmt.Fprintf(w, "* %s: %v%s", StateWARNINGLabel, p.WarningThreshold, @@ -129,21 +129,21 @@ func (p Plugin) handleLongServiceOutput(w io.Writer) { // ServiceOutput content. switch { case !p.isThresholdsSectionHidden() || !p.isErrorsHidden(): - fmt.Fprintf(w, + _, _ = fmt.Fprintf(w, "%s**%s**%s", CheckOutputEOL, p.getDetailedInfoLabelText(), CheckOutputEOL, ) default: - fmt.Fprint(w, CheckOutputEOL) + _, _ = fmt.Fprint(w, CheckOutputEOL) } // Note: fmt.Println() (and fmt.Fprintln()) has the same issue as `\n`: // Nagios seems to interpret them literally instead of emitting an actual // newline. We work around that by using fmt.Fprintf() for output that is // intended for display within the Nagios web UI. - fmt.Fprintf(w, + _, _ = fmt.Fprintf(w, "%s%v%s", CheckOutputEOL, p.LongServiceOutput, @@ -174,18 +174,18 @@ func (p *Plugin) handlePerformanceData(w io.Writer) { // metrics are provided as a single line, leading with a pipe // character, a space and one or more metrics each separated from // another by a single space. - fmt.Fprint(w, " |") + _, _ = fmt.Fprint(w, " |") // Sort performance data values prior to emitting them so that the // output is consistent across plugin execution. perfData := p.getSortedPerfData() for _, pd := range perfData { - fmt.Fprint(w, pd.String()) + _, _ = fmt.Fprint(w, pd.String()) } // Add final trailing newline to satisfy Nagios plugin output format. - fmt.Fprint(w, CheckOutputEOL) + _, _ = fmt.Fprint(w, CheckOutputEOL) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 7b86792f..8ba38337 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/atc0005/go-nagios v0.16.1 +# github.com/atc0005/go-nagios v0.16.2-0.20240601143430-96be84d30458 ## explicit; go 1.19 github.com/atc0005/go-nagios # github.com/google/go-cmp v0.6.0