Documentation ¶
Index ¶
- Constants
- Variables
- func BaseExit(rc int)
- func BoundaryToString(value float64) (s string)
- func CatchPanic()
- func DumpBenchmark()
- func DumpBenchmarkWhen(criteria bool)
- func Exit(rc int, output string, args ...interface{})
- func ExitError(err error)
- func ExitRaw(rc int, output ...string)
- func Exitf(rc int, output string, args ...interface{})
- func HandleTimeout(timeout int)
- func InitBenchmark(message string)
- func RecordBenchmark(message string)
- func StatusText(status int) string
- type Benchmark
- type BenchmarkEvent
- type Config
- type Threshold
Examples ¶
Constants ¶
const ( // OK means everything is fine OK = 0 // Warning means there is a problem the admin should review Warning = 1 // Critical means there is a problem that requires immediate action Critical = 2 // Unknown means the status can not be determined, probably due to an error or something missing Unknown = 3 )
Variables ¶
var ( PosInf = math.Inf(1) NegInf = math.Inf(-1) )
var AllowExit = true
AllowExit lets you disable the call to os.Exit() in ExitXxx() functions of this package.
This should be used carefully and most likely only for testing.
var PrintStack = true
PrintStack prints the error stack when recovering from a panic with CatchPanic()
Functions ¶
func BoundaryToString ¶
Convert a threshold bound to its string representation
func CatchPanic ¶
func CatchPanic()
CatchPanic is a general function for defer, to capture any panic that occurred during runtime of a check
The function will recover from the condition and exit with a proper UNKNOWN status, while showing error and the call stack.
Example ¶
defer CatchPanic() panic("something bad happened")
Output: UNKNOWN - Golang encountered a panic: something bad happened would exit with code 3
func DumpBenchmarkWhen ¶
func DumpBenchmarkWhen(criteria bool)
Dump the Benchmark when criteria is met, to be used with defer and a boolean variable
func Exit ¶
Exit prints the plugin output and exits the program
Deprecated, please use Exitf or ExitRaw.
Example ¶
Exitf(OK, "Everything is fine - value=%d", 42)
Output: OK - Everything is fine - value=42 would exit with code 0
func ExitError ¶
func ExitError(err error)
ExitError exists with an Unknown state while reporting the error
Example ¶
err := fmt.Errorf("connection to %s has been timed out", "localhost:12345") ExitError(err)
Output: UNKNOWN - connection to localhost:12345 has been timed out (*errors.errorString) would exit with code 3
func ExitRaw ¶ added in v0.2.0
ExitRaw prints the plugin output with the state prefixed and exits the program.
Example:
OK - everything is fine
Example ¶
ExitRaw(OK, "Everything is fine")
Output: OK - Everything is fine would exit with code 0
func Exitf ¶ added in v0.2.0
Exitf prints the plugin output using formatting and exits the program.
Output is the formatting string, and the rest of the arguments help adding values.
Also see fmt package: https://golang.org/pkg/fmt
Example ¶
Exitf(OK, "Everything is fine - value=%d", 42)
Output: OK - Everything is fine - value=42 would exit with code 0
func HandleTimeout ¶
func HandleTimeout(timeout int)
Helper for a goroutine, to wait for signals and timeout, and exit with a proper code
func InitBenchmark ¶
func InitBenchmark(message string)
Initialize a Benchmark for the running program as static instance
Example ¶
noinspection GoBoolExpressions
debug := true /* flags.Debug */ if debug { InitBenchmark("Start plugin") defer DumpBenchmarkWhen(debug /* flags.Debug */) } time.Sleep(1 * time.Second) RecordBenchmark("Connecting to service") time.Sleep(2 * time.Second) RecordBenchmark("Connection open")
Output:
func RecordBenchmark ¶
func RecordBenchmark(message string)
Recording timing and memory for the current program
func StatusText ¶
StatusText returns the string corresponding to a state
Example ¶
fmt.Println(StatusText(OK), StatusText(Warning), StatusText(Critical), StatusText(Unknown))
Output: OK WARNING CRITICAL UNKNOWN
Types ¶
type Benchmark ¶
type Benchmark struct {
Events []*BenchmarkEvent
}
Benchmark records multiple events and provides functionality to dump the recorded events
var ActiveBenchmark *Benchmark
func NewBenchmark ¶
NewBenchmark starts a new benchmark and records the message as event
Example ¶
bench := NewBenchmark("Start plugin") defer bench.DumpWhen(true /* flags.Debug */) time.Sleep(1 * time.Second) bench.Record("Connecting to service") time.Sleep(2 * time.Second) bench.Record("Connection open")
Output:
type BenchmarkEvent ¶
type BenchmarkEvent struct { Time *time.Time Offset *time.Duration Message string TotalAlloc uint64 HeapAlloc uint64 }
BenchmarkEvent represents a single event during a benchmark with the time it occurred
type Config ¶
type Config struct { Name string Readme string Version string Timeout int Verbose bool Debug bool PrintVersion bool DefaultFlags bool DefaultHelper bool FlagSet *flag.FlagSet }
Example ¶
config := NewConfig() config.Name = "check_test" config.Readme = `Test Plugin` config.Version = "1.0.0" _ = config.FlagSet.StringP("hostname", "H", "localhost", "Hostname to check") config.ParseArguments() // Some checking should be done here Exitf(OK, "Everything is fine - answer=%d", 42)
Output: OK - Everything is fine - answer=42 would exit with code 0
func (*Config) EnableTimeoutHandler ¶
func (c *Config) EnableTimeoutHandler()
Start the timeout and signal handler in a goroutine
func (*Config) ParseArguments ¶
func (c *Config) ParseArguments()
func (*Config) ParseArray ¶
func (*Config) SetupLogging ¶
func (c *Config) SetupLogging()
type Threshold ¶
Defining a threshold for any numeric value
Format: [@]start:end
Threshold Generate an alert if x... 10 < 0 or > 10, (outside the range of {0 .. 10}) 10: < 10, (outside {10 .. ∞}) ~:10 > 10, (outside the range of {-∞ .. 10}) 10:20 < 10 or > 20, (outside the range of {10 .. 20}) @10:20 ≥ 10 and ≤ 20, (inside the range of {10 .. 20})
Reference: https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT
func (Threshold) DoesViolate ¶
Compares a value against the threshold, and returns true if the value violates the threshold.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
http
|
|
mock
Helper package to add more functions to httpmock (github.com/jarcoal/httpmock) Features: - RegisterQueryMapResponder form query based based on a QueryMap - ActivateRecorder to record HTTP requests during the development of tests and examples
|
Helper package to add more functions to httpmock (github.com/jarcoal/httpmock) Features: - RegisterQueryMapResponder form query based based on a QueryMap - ActivateRecorder to record HTTP requests during the development of tests and examples |
result tries to
|
result tries to |