nagios

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: MIT Imports: 6 Imported by: 2

README

go-nagios

This library is a small set of tools that make writing Nagios-style checks a bit easier. The goal is for the primitives that this library exports to follow the guidelines set forth in the Nagios Plugin Development Guidelines.

Installation

go get github.com/segfaultax/go-nagios

Usage

Check

The Check type represents a very barebones Nagios check. A complete example of how to use Check is in examples/check.

RangeCheck

The RangeCheck type represents a class of Nagios checks that are specifically checking ranges of numerical values. This logic is easy to implement yourself with the normal Check type, but it's repetitive to do so. RangeCheck offers a simple API for setting warning and critical ranges for your check. See a complete example in examples/rangecheck.

PerfData

The PerfData type represents Nagios performance data. Many monitoring systems (such as Nagios and Sensu) will interpret this data and store it for later querying. You can read about Nagios performance data here. Both the Check and RangeCheck types supporting adding arbitrary performance data to the check results. See the examples/ directory on how to do that.

Range

The Range type represents a Nagios threshold range.

Ref: Nagios Documentation

import "github.com/segfaultax/go-nagios"

r1 := nagios.NewRange(0, 100, false) // exclusive range outside of 0 - 100
r1.InRange(50) // false
r1.InRange(250) // true

r2 := nagios.NewRange(0, 100, true) // inclusive range between 0 - 100
r2.InRange(50) // true
r2.InRange(250) // false

Range also supports parsing a Nagios-style threshold string.

import "github.com/segfaultax/go-nagios"

r1 := nagios.ParseRange("100") // exclusive range outside of 0 - 100
r1.InRange(50) // false
r1.InRange(250) // true

r2 := nagios.ParseRange("@100") // inclusive range between 0 - 100
r1.InRange(50) // false
r1.InRange(250) // true

See the Nagios documentation for a full description of the range format specification.

Contributors

  • Michael-Keith Bernard (@segfaultax)

License

This project is released under the MIT license. See LICENSE for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StatusOK      = Status{"OK", 0}
	StatusWarn    = Status{"WARN", 1}
	StatusCrit    = Status{"CRIT", 2}
	StatusUnknown = Status{"UNKNOWN", 3}
)

Nagios return status codes

Functions

This section is empty.

Types

type Check added in v0.2.0

type Check struct {
	Status   Status
	Message  string
	PerfData []PerfData
}

Check is the core Nagios check holder

func NewCheck added in v0.2.0

func NewCheck() *Check

NewCheck initializes a new Check in an unknown state

func (*Check) AddPerfData added in v0.2.0

func (c *Check) AddPerfData(pd PerfData)

AddPerfData adds Nagios performance data to the check result

func (*Check) Critical added in v0.2.0

func (c *Check) Critical(msg string, vs ...interface{})

Critical sets the message and return status to Critical

func (*Check) Done added in v0.2.0

func (c *Check) Done()

Done prints the output of the check and exits with the appropriate code

func (*Check) OK added in v0.2.0

func (c *Check) OK(msg string, vs ...interface{})

OK sets the message and return status to OK

func (*Check) SetMessage added in v0.2.0

func (c *Check) SetMessage(msg string, vs ...interface{})

SetMessage sets check message (with sprintf formatting)

func (*Check) String added in v0.2.0

func (c *Check) String() string

func (*Check) Unknown added in v0.2.0

func (c *Check) Unknown(msg string, vs ...interface{})

Unknown sets the message and return status to Unknown

func (*Check) Warning added in v0.2.0

func (c *Check) Warning(msg string, vs ...interface{})

Warning sets the message and return status to Warning

type PerfData added in v0.2.0

type PerfData struct {
	Label string
	Value float64
	Units string
	Warn  *Range
	Crit  *Range
	Min   *float64
	Max   *float64
}

PerfData is Nagios performance data

func NewPerfData added in v0.2.0

func NewPerfData(label string, value float64, units string) PerfData

NewPerfData creates a simple Nagios Performance Data object with no ranges

func NewPerfDataWithRanges added in v0.2.0

func NewPerfDataWithRanges(label string, value float64, units string, warn, crit *Range, min, max float64) PerfData

NewPerfDataWithRanges creates a complete Nagios Performance Data object with all range information

func (PerfData) String added in v0.2.0

func (pd PerfData) String() string

type Range

type Range struct {
	Min       float64
	Max       float64
	Inclusive bool
}

Range represents a basic Nagios range object Note: Ranges are exclusive by default, eg x < min || x > max

func NewRange

func NewRange(min, max float64, inclusive bool) *Range

NewRange constructs a new Range

func ParseRange

func ParseRange(r string) (*Range, error)

ParseRange creates a Range object from a Nagios-style Range string Ref: https://nagios-plugins.org/doc/guidelines.html#THRESHOLDFORMAT

func (*Range) InRange

func (r *Range) InRange(v float64) bool

InRange checks whether a value is in range or not

func (*Range) String

func (r *Range) String() string

type RangeCheck added in v0.2.0

type RangeCheck struct {
	Check
	Warn *Range
	Crit *Range
}

RangeCheck is a kind of Nagios check with built-in warn/crit ranges

func NewRangeCheck added in v0.2.0

func NewRangeCheck(warn *Range, crit *Range) *RangeCheck

NewRangeCheck creates a new check with warning and critical ranges

func NewRangeCheckParse added in v0.2.0

func NewRangeCheckParse(warn string, crit string) (*RangeCheck, error)

NewRangeCheckParse creates a range check by parsing warning and critical as Nagios ranges

func (*RangeCheck) CheckValue added in v0.2.0

func (rc *RangeCheck) CheckValue(value float64)

CheckValue updates the status based on available ranges

type Status added in v0.2.0

type Status struct {
	Label    string
	ExitCode int
}

Status describes a Nagios exit code

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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