check_x

package module
v0.0.0-...-0782e67 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2016 License: GPL-3.0 Imports: 11 Imported by: 22

README

Circle CI Go Report Card

check_x

Go Library to write Monitoring checks for Nagios/Icinga like checks

Usage:

func main() {
	//Set Plugin timeout, it will kill you and end properly
	check_x.StartTimeout(5 * time.Second)

	//Create a warning threshold
	warn, err := check_x.NewThreshold("10:")
	//If you don't want to handle the error, you could just pass it to the user
	check_x.ExitOnError(err)
	
	//Create a critical threshold
	crit, err := check_x.NewThreshold("@20:30")
	check_x.ExitOnError(err)

	//do your magic
	measuredValue1 := 25.0
	measuredValue2 := 5.0

	//evaluate your magic
	status1 := check_x.Evaluator{Warning: warn, Critical: warn}.Evaluate(measuredValue1)
	status2 := check_x.Evaluator{Warning: warn, Critical: warn}.Evaluate(measuredValue2)

	//see what went wrong
	worstState, err := check_x.States{status1, status2}.GetWorst()
	check_x.ExitOnError(err)

	//set some performancedata
	check_x.NewPerformanceData("foo", measuredValue1).Unit("B").Warn(warn).Crit(crit).Min(0).Max(100)
	check_x.NewPerformanceData("bar", measuredValue2).Unit("s").Min(0)

	//bring it to an end
	check_x.Exit(*worstState, "Made by check_x")
}
Critical - Made by check_x|'foo'=25B;10:;@20:30;0;100 'bar'=5s;;;0;

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//OK - returncode: 0
	OK = State{/* contains filtered or unexported fields */}
	//Warning - returncode: 1
	Warning = State{/* contains filtered or unexported fields */}
	//Critical - returncode: 2
	Critical = State{/* contains filtered or unexported fields */}
	//Unknown - returncode: 3
	Unknown = State{/* contains filtered or unexported fields */}
)
View Source
var ErrEmptyStates = errors.New("The given States do not contain a State")

ErrEmptyStates will be thrown if no State was added to the States array

View Source
var (

	//ErrFirstBiggerThenSecond this error is thrown when the first number is bigger then the second
	ErrFirstBiggerThenSecond = errors.New("First argument is bigger then second")
)

Functions

func Exit

func Exit(state State, msg string)

Exit returns with the given returncode and message and optional performancedata

func ExitOnError

func ExitOnError(err error)

ExitOnError quits with unknown and the error message if an error was passed

func LongExit

func LongExit(state State, msg, longMsg string)

LongExit returns with the given returncode and message and optional performancedata and long message

func NewPerformanceData

func NewPerformanceData(label string, value float64) *performanceData

NewPerformanceData adds a Performancedata object which can be expanded with further information

func NewPerformanceDataString

func NewPerformanceDataString(label, value string) *performanceData

NewPerformanceDataString adds a Performancedata object which can be expanded with further information

func PrintPerformanceData

func PrintPerformanceData() string

PrintPerformanceData prints all performancedata

func StartTimeout

func StartTimeout(duration time.Duration)

StartTimeout starts an timeout, which will end the program with an unknown code

Types

type Evaluator

type Evaluator struct {
	Warning  *Threshold
	Critical *Threshold
}

Evaluator stores the warning and critical thresholds

func (Evaluator) Evaluate

func (t Evaluator) Evaluate(value float64) (result State)

Evaluate returns the stored values

type State

type State struct {
	// contains filtered or unexported fields
}

State represents an nagioskind returncode

func StateFromInt

func StateFromInt(code int) State

StateFromInt creates an known state if code is 0-3, else a new State will be returned

func StateFromString

func StateFromString(name string) State

StateFromString creates an known state if string is "ok|warning|critical|unknown", else a new State will be returned

func (State) String

func (s State) String() string

String prints the name of the state

type States

type States []State

States is a list of state

func (States) GetBest

func (s States) GetBest() (*State, error)

GetBest returns the best State from the array

func (States) GetWorst

func (s States) GetWorst() (*State, error)

GetWorst returns the worst State from the array

func (States) Len

func (s States) Len() int

Len for Sort interface

func (States) Less

func (s States) Less(i, j int) bool

Less for Sort interface

func (States) Swap

func (s States) Swap(i, j int)

Swap for Sort interface

type Threshold

type Threshold struct {
	// contains filtered or unexported fields
}

Threshold contains the threshold logic: https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT

func NewThreshold

func NewThreshold(def string) (*Threshold, error)

NewThreshold constructs a new Threshold from string, returns an Threshold if possible else nil and an error

func (Threshold) IsValueOK

func (t Threshold) IsValueOK(value float64) bool

IsValueOK tests if the given value fulfills the the Thresholds false: value is critical/warning true: value is ok

func (Threshold) String

func (t Threshold) String() string

String prints the Threshold

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL