-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #330 from atc0005/i324-add-plugin-output-size-metric
Add plugin output size metric
- Loading branch information
Showing
6 changed files
with
266 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2020 Adam Chalkley | ||
// | ||
// https://github.com/atc0005/go-nagios | ||
// | ||
// Licensed under the MIT License. See LICENSE file in the project root for | ||
// full license information. | ||
|
||
package nagios_test | ||
|
||
import ( | ||
"github.com/atc0005/go-nagios" | ||
) | ||
|
||
// Ignore this. This is just to satisfy the "whole file" example requirements | ||
// per https://go.dev/blog/examples. | ||
var _ = "https://github.com/atc0005/go-nagios" | ||
|
||
// This example demonstrates enabling the plugin output size metric. This | ||
// optional metric is disabled by default. | ||
func Example_enablePluginOutputSizeMetric() { | ||
// First, create an instance of the Plugin type. By default this value is | ||
// configured to indicate a successful execution. This should be | ||
// overridden by client code to indicate the final plugin state to Nagios | ||
// when the plugin exits. | ||
var plugin = nagios.NewPlugin() | ||
|
||
// Second, immediately defer ReturnCheckResults() so that it runs as the | ||
// last step in your client code. If you do not defer ReturnCheckResults() | ||
// immediately any other deferred functions in your client code will not | ||
// run. | ||
// | ||
// Avoid calling os.Exit() directly from your code. If you do, this | ||
// library is unable to function properly; this library expects that it | ||
// will handle calling os.Exit() with the required exit code (and | ||
// specifically formatted output). | ||
// | ||
// For handling error cases, the approach is roughly the same, only you | ||
// call return explicitly to end execution of the client code and allow | ||
// deferred functions to run. | ||
defer plugin.ReturnCheckResults() | ||
|
||
// Enable emitting a plugin output size metric. This optional metric is | ||
// disabled by default. | ||
plugin.EnablePluginOutputSizePerfDataMetric() | ||
|
||
// more stuff here involving performing the actual service check | ||
|
||
plugin.ServiceOutput = "one-line summary of plugin results " //nolint:goconst | ||
plugin.LongServiceOutput = "more detailed output from plugin here" //nolint:goconst | ||
|
||
// more stuff here involving wrapping up the service check | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
testdata/plugin-output-multiline-with-optional-perf-data-included.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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;;;; |
1 change: 1 addition & 0 deletions
1
testdata/plugin-output-one-line-with-optional-perf-data-included.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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;;;; |