nagios

package
v0.0.0-...-3645f34 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PerfDataOutputDelimiter = "|"
	PerfDataLabelDelimiter  = "="
	PerfDataValueDelimiter  = ";"
)
View Source
const (
	ThresholdDelimiter = ":"
)

Variables

This section is empty.

Functions

func Compact

func Compact(s []string) []string

Compact removes any empty string from the provided array

Types

type Alert

type Alert func(float64) bool

Alert is a comparison functor for the given value

func False

func False() Alert

True create an alert instance which always fails

func GreaterEqualThan

func GreaterEqualThan(cmp float64) Alert

GreaterEqualThan create an alert instance acting on the given value as boundary. Any compared value must be greater than or equal to the comparison in order to pass

func GreaterThan

func GreaterThan(cmp float64) Alert

GreaterThan create an alert instance acting on the given value as boundary. Any compared value must be greater than the comparison in order to pass

func LessEqualThan

func LessEqualThan(cmp float64) Alert

LessEqualThan create an alert instance acting on the given value as boundary. Any compared value must be less than or equal to the comparison in order to pass

func LessThan

func LessThan(cmp float64) Alert

LessThan create an alert instance acting on the given value as boundary. Any compared value must be less than the comparison in order to pass

func True

func True() Alert

True create an alert instance which always passes

type ExitCode

type ExitCode int

Nagios plugin exit state

const (
	OK ExitCode = iota
	WARNING
	CRITICAL
	UNKNOWN
	DEPENDENT
)

func (ExitCode) String

func (i ExitCode) String() string

type PerfData

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

PerfData holds a single performand data metric and its context (thresholds, limits, ...)

func NewPerfData

func NewPerfData(label string, value *PerfValue, warn, crit *Threshold, min, max int) *PerfData

NewPerfData creates a new instance with the given performance metric, thresholds, and limits

func NewScopedPerfData

func NewScopedPerfData(label string, value *PerfValue, min, max int) *PerfData

NewScopedPerfData creates a new instance with the given performance metric and limits

func NewThresholdPerfData

func NewThresholdPerfData(label string, value *PerfValue, warn, crit *Threshold) *PerfData

NewThresholdPerfData creates a new instance with the given performance metric and thresholds

func NewUndefinedPerfData

func NewUndefinedPerfData(label string) *PerfData

NewUndefinedPerfData creates a new instance with the semantic of the value being undefined

func NewValuePerfData

func NewValuePerfData(label string, value *PerfValue) *PerfData

NewValuePerfData creates a new instance with the given performance metric

func ParsePerfData

func ParsePerfData(s string) (*PerfData, error)

ParsePerfDataOutput parses the given string for a single performance metric in the Nagios PerfData format

func ParsePerfDataOutput

func ParsePerfDataOutput(s string) ([]PerfData, error)

ParsePerfDataOutput parses the given string for performance metrics in the Nagios PerfData format

func (*PerfData) Critical

func (d *PerfData) Critical() string

Warning returns the critical threshold

func (*PerfData) CriticalAlert

func (d *PerfData) CriticalAlert() bool

CriticalAlert compares the value against the critical threshold. If either of those is not available, the function returns false.

func (*PerfData) Equal

func (d *PerfData) Equal(o *PerfData) bool

Equal comparse the internal fields with those of o

func (*PerfData) Float

func (d *PerfData) Float() float64

Float parses the Value() for numeric data or returns 0 otherwise.

func (*PerfData) Label

func (d *PerfData) Label() string

Label returns the peformance data label

func (*PerfData) Max

func (d *PerfData) Max() (result int)

Max returns the upper peformance data limit

func (*PerfData) Min

func (d *PerfData) Min() (result int)

Min returns the lower peformance data limit

func (*PerfData) QuotedLabel

func (d *PerfData) QuotedLabel() string

QuotedLabel returns the peformance data label; quoted if it contains any spaces

func (*PerfData) String

func (d *PerfData) String() string

String formats the internal data using the Nagios performance data notation

func (*PerfData) Value

func (d *PerfData) Value() string

Value returns the current peformance data value, or U if no such information is available

func (*PerfData) Warning

func (d *PerfData) Warning() string

Warning returns the warning threshold

func (*PerfData) WarningAlert

func (d *PerfData) WarningAlert() bool

WarningAlert compares the value against the warning threshold. If either of those is not available, the function returns false.

type PerfValue

type PerfValue struct {
	Value float64
	Undef bool
	Unit  string
}

PerfValue represents a performance metric value

func NewFloatValue

func NewFloatValue(f float64) *PerfValue

NewFloatValue creates a new numeric performance value without any unit of measurement

func NewPercentValue

func NewPercentValue(f float64) *PerfValue

NewPercentValue creates a new numeric peformance value using percent as the unit of measurement

func NewUndefinedValue

func NewUndefinedValue() *PerfValue

NewUndefinedValue creates a new undefined peformance value

func NewUnitValue

func NewUnitValue(f float64, u string) *PerfValue

NewUnitValue creates a new numeric peformance value using the provided unit of measurement

func ParsePerfValue

func ParsePerfValue(s string) (*PerfValue, error)

ParsePerfValue parses the given string for a performance metric value

func (*PerfValue) Equal

func (v *PerfValue) Equal(o *PerfValue) bool

Equal comparse the internal fields with those of o

func (*PerfValue) String

func (v *PerfValue) String() string

String renders the performance value according to its internal representation. An undefined value simple yields U, otherwise the numeric value and optional unit of measurement are concatenated and returned

type Plugin

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

Plugin represents a Nagios plugin execution definition

func NewArgumentPlugin

func NewArgumentPlugin(command string, arguments ...string) *Plugin

NewArgumentPlugin creates a new plugin instance using the given command and commandline arguments

func NewPlugin

func NewPlugin(command string, arguments, environment []string) *Plugin

NewPlugin creates a new plugin instance using the given command, commandline arguments, and environment variables. The environment variables are expected to be an array of key/value pairs, joined by =

func (*Plugin) Run

func (p *Plugin) Run(ctx context.Context) (*PluginResult, error)

Run is a wrapper to exec.Command. Any error is the result of the command not being able to be executed. The returned PluginResult contains any command output on STDERR as error.

func (*Plugin) String

func (p *Plugin) String() string

String creates a rudimentary commandline representation, using the command and its arguments

type PluginResult

type PluginResult struct {
	Status   ExitCode
	Error    error
	Output   string
	Trailer  []string
	PerfData []PerfData
}

PluginResult contains the summary of a Nagios plugin execution

func (*PluginResult) String

func (r *PluginResult) String() string

String renders the plugin result in a Nagios compatible way

type PluginResultDecoder

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

PluginResultDecoder is a decoder implementation for Nagios plugin output

func NewPluginResultDecoder

func NewPluginResultDecoder(r io.Reader) *PluginResultDecoder

NewPluginResultDecoder creates a new decoder instance using the give reader as data source

func (*PluginResultDecoder) Decode

func (d *PluginResultDecoder) Decode(result *PluginResult) error

Decode uses a scanner to drain the internal reader of any data. Processed information are fed back into the given result instance.

type Threshold

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

Threshold is a boundary definition for peformance metrics

func NewGreaterThreshold

func NewGreaterThreshold(minValue float64) *Threshold

NewGreaterThreshold creates a threshold instance, alerting on any metric greater then the given boundary

func NewInsideThreshold

func NewInsideThreshold(lowerLimit, upperLimit float64) *Threshold

NewInsideThreshold creates a threshold instance, alerting on any metric inside of the given boundaries

func NewLesserThreshold

func NewLesserThreshold(maxValue float64) *Threshold

NewLesserThreshold creates a threshold instance, alerting on any metric less then the given boundary

func NewOutsideThreshold

func NewOutsideThreshold(lowerLimit, upperLimit float64) *Threshold

NewOutsideThreshold creates a threshold instance, alerting on any metric outside of the given boundaries

func NewThreshold

func NewThreshold(minValue float64) *Threshold

NewThreshold creates a threshold instance, alerting on any metric less than zero or greater then the given boundary

func ParseThreshold

func ParseThreshold(s string) (*Threshold, error)

ParseThreshold parses the given value for alert boundaries

func (*Threshold) Alert

func (t *Threshold) Alert(value float64) bool

Alert compares the given value against the internal boundaries

func (*Threshold) Equal

func (t *Threshold) Equal(o *Threshold) bool

Equal comparse the internal fields with those of o

func (*Threshold) String

func (t *Threshold) String() string

String renders the threshold in a Nagios compatible format

Jump to

Keyboard shortcuts

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