From 5e4cdefa3f5adcfab8951529519ff124c1225304 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 28 Nov 2024 08:43:37 +0000 Subject: [PATCH] Go Dependency: Bump github.com/atc0005/go-nagios from 0.18.1 to 0.19.0 Bumps [github.com/atc0005/go-nagios](https://github.com/atc0005/go-nagios) from 0.18.1 to 0.19.0. - [Release notes](https://github.com/atc0005/go-nagios/releases) - [Changelog](https://github.com/atc0005/go-nagios/blob/master/CHANGELOG.md) - [Commits](https://github.com/atc0005/go-nagios/compare/v0.18.1...v0.19.0) --- updated-dependencies: - dependency-name: github.com/atc0005/go-nagios dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 6 +- .../github.com/atc0005/go-nagios/CHANGELOG.md | 13 +++- vendor/github.com/atc0005/go-nagios/README.md | 3 + vendor/github.com/atc0005/go-nagios/nagios.go | 60 +++++++++++++++++++ ...iline-with-optional-perf-data-included.txt | 22 +++++++ ...-line-with-optional-perf-data-included.txt | 1 + vendor/modules.txt | 2 +- 8 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 vendor/github.com/atc0005/go-nagios/testdata/plugin-output-multiline-with-optional-perf-data-included.txt create mode 100644 vendor/github.com/atc0005/go-nagios/testdata/plugin-output-one-line-with-optional-perf-data-included.txt diff --git a/go.mod b/go.mod index 2a582c9..74a07bb 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/atc0005/check-process go 1.20 require ( - github.com/atc0005/go-nagios v0.18.1 + github.com/atc0005/go-nagios v0.19.0 github.com/rs/zerolog v1.33.0 ) diff --git a/go.sum b/go.sum index 6ee26b4..815b2e6 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/atc0005/go-nagios v0.18.1 h1:YGYNTyjNJiGXcCXYMhatHKzddjij06Peeb0va/wX45g= -github.com/atc0005/go-nagios v0.18.1/go.mod h1:n2RHhsrgI8xiapqkJ240dKLwMXWbWvkOPLE92x0IGaM= +github.com/atc0005/go-nagios v0.19.0 h1:QMqu4iAKb4SD/kdAJdnMYZjHL4KzfYOSq5Lq30AZc0U= +github.com/atc0005/go-nagios v0.19.0/go.mod h1:7XhhQHYOD+jZQVrTWXuWzSoPoDb6/FQh60dbGauQ5lQ= 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= @@ -15,7 +15,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/vendor/github.com/atc0005/go-nagios/CHANGELOG.md b/vendor/github.com/atc0005/go-nagios/CHANGELOG.md index 07eb135..fdd0538 100644 --- a/vendor/github.com/atc0005/go-nagios/CHANGELOG.md +++ b/vendor/github.com/atc0005/go-nagios/CHANGELOG.md @@ -26,6 +26,16 @@ The following types of changes will be recorded in this file: - placeholder +## [v0.19.0] - 2024-11-27 + +### Added + +- (GH-330) Add plugin output size metric + +#### Dependency Updates + +- (GH-323) Go Dependency: Bump github.com/stretchr/testify from 1.9.0 to 1.10.0 + ## [v0.18.1] - 2024-11-23 ### Changed @@ -586,7 +596,8 @@ Initial package state - Nagios state map -[Unreleased]: https://github.com/atc0005/go-nagios/compare/v0.18.1...HEAD +[Unreleased]: https://github.com/atc0005/go-nagios/compare/v0.19.0...HEAD +[v0.19.0]: https://github.com/atc0005/go-nagios/releases/tag/v0.19.0 [v0.18.1]: https://github.com/atc0005/go-nagios/releases/tag/v0.18.1 [v0.18.0]: https://github.com/atc0005/go-nagios/releases/tag/v0.18.0 [v0.17.1]: https://github.com/atc0005/go-nagios/releases/tag/v0.17.1 diff --git a/vendor/github.com/atc0005/go-nagios/README.md b/vendor/github.com/atc0005/go-nagios/README.md index 91fe837..a3603f3 100644 --- a/vendor/github.com/atc0005/go-nagios/README.md +++ b/vendor/github.com/atc0005/go-nagios/README.md @@ -60,6 +60,9 @@ such time that the API is considered stable. - Panics from client code are captured and reported - panics are surfaced as `CRITICAL` state - service output and error details are overridden to make panics prominent +- Optional support for emitting performance data metric for plugin output size + - disabled by default + - can be toggled on by client code as desired - Optional support for emitting performance data generated by plugins - if not overridden by client code *and* if using the provided `nagios.NewPlugin()` constructor, a default `time` performance data metric diff --git a/vendor/github.com/atc0005/go-nagios/nagios.go b/vendor/github.com/atc0005/go-nagios/nagios.go index 4048116..08028c4 100644 --- a/vendor/github.com/atc0005/go-nagios/nagios.go +++ b/vendor/github.com/atc0005/go-nagios/nagios.go @@ -15,6 +15,7 @@ import ( "log" "os" "runtime/debug" + "strconv" "strings" "time" ) @@ -305,6 +306,11 @@ type Plugin struct { // instead. shouldSkipOSExit bool + // shouldEmitTotalPluginSizeMetric indicates whether client code has opted + // to emit (append) a performance data metric calculating the total plugin + // output size. + shouldEmitTotalPluginSizeMetric bool + // debugLogging is the collection of debug logging options for the plugin. debugLogging debugLoggingOptions @@ -589,6 +595,13 @@ func (p *Plugin) SkipOSExit() { p.shouldSkipOSExit = true } +// EnablePluginOutputSizePerfDataMetric appends a performance data metric +// noting the total plugin output size. +func (p *Plugin) EnablePluginOutputSizePerfDataMetric() { + p.logAction("Enabling total plugin output size metric as requested") + p.shouldEmitTotalPluginSizeMetric = true +} + // SetPayloadBytes uses the given input in bytes to overwrite any existing // content in the payload buffer. It returns the length of input and a // potential error. If given empty input the payload buffer is reset without @@ -704,6 +717,10 @@ func (p Plugin) emitOutput(pluginOutput string) { p.logAction("Writing plugin output") + if p.shouldEmitTotalPluginSizeMetric { + pluginOutput = addPluginOutputSizeMetric(pluginOutput) + } + // Attempt to write to output sink. If this fails, send error to the // default abort message output target. If that fails (however unlikely), // we have bigger problems and should abort. @@ -754,6 +771,49 @@ func (p *Plugin) tryAddDefaultTimeMetric() { p.logAction("Added default time metric to collection") } +// addPluginOutputSizeMetric appends a performance data metric to the given +// input noting the total plugin output size. If the metric is already present +// the original input is returned unmodified. +func addPluginOutputSizeMetric(pluginOutput string) string { + metricLabel := "plugin_output_size" + + // Attempt to prevent adding the same metric twice. + if strings.Contains(pluginOutput, metricLabel) { + return pluginOutput + } + + pluginOutput = strings.TrimSuffix(pluginOutput, CheckOutputEOL) + + outputSizeMetric := PerformanceData{ + Label: metricLabel, + Value: "PLACEHOLDER", + UnitOfMeasurement: "B", // bytes + } + + var modifiedPluginOutput string + + // Code snippet inspired by or generated with the help of ChatGPT, OpenAI. + for { + // Calculate the current length. + length := len(modifiedPluginOutput) + + // Construct metric using updated length value. + outputSizeMetric.Value = strconv.Itoa(length) + outputSizeMetricString := outputSizeMetric.String() + CheckOutputEOL + + // Construct modified plugin output using the updated metric. + modifiedPluginOutput = pluginOutput + outputSizeMetricString + + // Break when the actual length of modified plugin output containing + // the output size metric matches the calculated length. + if len(modifiedPluginOutput) == length { + break + } + } + + return modifiedPluginOutput +} + // defaultTimeMetric is a helper function that wraps the logic used to provide // a default performance data metric that tracks plugin execution time. func defaultTimeMetric(start time.Time) PerformanceData { diff --git a/vendor/github.com/atc0005/go-nagios/testdata/plugin-output-multiline-with-optional-perf-data-included.txt b/vendor/github.com/atc0005/go-nagios/testdata/plugin-output-multiline-with-optional-perf-data-included.txt new file mode 100644 index 0000000..c78e71c --- /dev/null +++ b/vendor/github.com/atc0005/go-nagios/testdata/plugin-output-multiline-with-optional-perf-data-included.txt @@ -0,0 +1,22 @@ +OK: Datastore HUSVM-DC1-vol6 space usage (0 VMs) is 0.01% of 18.0TB with 18.0TB remaining [WARNING: 90% , CRITICAL: 95%] +**THRESHOLDS** + +* CRITICAL: 95% datastore usage +* WARNING: 90% datastore usage + +**DETAILED INFO** + +Datastore Space Summary: + +* Name: HUSVM-DC1-vol6 +* Space Used: 2.3GB (0.01%) +* Space Remaining: 18.0TB (99.99%) +* VMs: 0 + + +--- + +* vSphere environment: https://vc1.example.com:443/sdk +* Plugin User Agent: check-vmware/v0.30.6-0-g25fdcdc + + | 'time'=874ms;;;; 'plugin_output_size'=530B;;;; diff --git a/vendor/github.com/atc0005/go-nagios/testdata/plugin-output-one-line-with-optional-perf-data-included.txt b/vendor/github.com/atc0005/go-nagios/testdata/plugin-output-one-line-with-optional-perf-data-included.txt new file mode 100644 index 0000000..2807376 --- /dev/null +++ b/vendor/github.com/atc0005/go-nagios/testdata/plugin-output-one-line-with-optional-perf-data-included.txt @@ -0,0 +1 @@ +OK: Datastore HUSVM-DC1-vol6 space usage (0 VMs) is 0.01% of 18.0TB with 18.0TB remaining [WARNING: 90% , CRITICAL: 95%] | 'time'=874ms;;;; 'plugin_output_size'=171B;;;; diff --git a/vendor/modules.txt b/vendor/modules.txt index 5ded5f0..470a68e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/atc0005/go-nagios v0.18.1 +# github.com/atc0005/go-nagios v0.19.0 ## explicit; go 1.19 github.com/atc0005/go-nagios # github.com/mattn/go-colorable v0.1.13