Skip to content

Commit

Permalink
Redirect help output from stderr to stdout
Browse files Browse the repository at this point in the history
Send output to stdout so that Nagios XI (and presumably similar
systems) can poll plugins from this project for their help
output and display within the admin web UI.

refs GH-246
  • Loading branch information
atc0005 committed Dec 17, 2021
1 parent 9a3bfe6 commit 9c9cbc8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ const myAppURL string = "https://github.com/atc0005/check-mail"
// Usage is a custom override for the default Help text provided by the flag
// package. Here we prepend some additional metadata to the existing output.
var Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "%s %s\n%s\n\n", myAppName, version, myAppURL)

// Override default of stderr as destination for help output. This allows
// Nagios XI and similar monitoring systems to call plugins with the
// `--help` flag and have it display within the Admin web UI.
flag.CommandLine.SetOutput(os.Stdout)

fmt.Fprintln(flag.CommandLine.Output(), "\n"+Version()+"\n")
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
}
Expand Down

0 comments on commit 9c9cbc8

Please sign in to comment.