icinga

package module
v0.0.0-...-08535c5 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2018 License: MIT Imports: 7 Imported by: 14

README

Icinga plugin library for go

Library to implement nagios checks in Go (golang).

Usage example

The general usage pattern looks like this::

func run() Result {
    // defined thresholds according to https://nagios-plugins.org/doc/guidelines.html
    warningThresholdString := "5:"
    criticalThresholdString := "2:"

    // implemented somewhere else
    value := getActualValue()

    // check escalation
    e, err := icinga.NewEscalation(warningThresholdString, criticalThresholdString)
    if err != nil {
        fmt.Errorf("failed to initialize escalation: %v", err)
    }
    // get the escalation level
    level := e.Check(value)

    // If everything is ok and you have a service check
    if level == icinga.None {
        return icinga.NewResultOk("MyCheck")
    }

    // If the level is critical and you have a host check
    if level == icinga.Critical {
        return icinga.NewResult("MyCheck", icinga.HostStatusDown, "your message")
    }

    // the easiest way
    return icinga.NewResult("MyCheck", icinga.ServiceStatusForEscalationLevel(level), "your message")
}

Documentation

Index

Constants

View Source
const (
	// DefaultSuccessMessage the default message if the check was successful
	DefaultSuccessMessage string = "everything ok"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Range

type Range interface {
	Check(float64) bool
	CheckInt(int) bool
	CheckInt32(int32) bool
}

Range is a combination of a lower boundary, an upper boundary and a flag for inverted (@) range semantics. See [0] for more details.

func NewRange

func NewRange(value string) (Range, error)

NewRange parse a string and returns a Range object 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})

type Result

type Result interface {
	Name() string
	Status() Status
	Message() string
	Exit()
}

Result interface for service check results

func NewResult

func NewResult(name string, status Status, message string) Result

NewResult creates a new instance of Result

func NewResultOk

func NewResultOk(name string) Result

NewResultOk creates a new instance of Result and set result to ServiceStateOk

func NewResultOkMessage

func NewResultOkMessage(name string, message string) Result

NewResultOkMessage creates a new instance of Result and set result to ServiceStateOk

func NewResultUnknownMessage

func NewResultUnknownMessage(name string, message string) Result

NewResultUnknownMessage creates a new instance of Result and set result to ServiceStateOk

type Results

type Results interface {
	All() []Result
	Add(Result)
	CalculateStatus() Status
	GenerateMessage() string
	Exit()
}

Results contains multiple results for service checks

func NewResults

func NewResults() Results

NewResults creates a new instance of Results

func NewResultsWithOptions

func NewResultsWithOptions(options ResultsOptions) Results

NewResultsWithOptions creates a new instance of Results with options

type ResultsOptions

type ResultsOptions struct {
	StatusPolicy        StatusPolicy
	StatusMessagePolicy StatusMessagePolicy
}

ResultsOptions options to generate a new instance of Results

type Status

type Status int

Status defines the service status

const (
	// ServiceStatusOk 0
	ServiceStatusOk Status = iota
	// ServiceStatusWarning 1
	ServiceStatusWarning
	// ServiceStatusCritical 2
	ServiceStatusCritical
	// ServiceStatusUnknown 3
	ServiceStatusUnknown
)

func NewStatus

func NewStatus(statusString string) Status

NewStatus return a Status for a given string

func (Status) Ordinal

func (s Status) Ordinal() int

Ordinal returns the int value

func (Status) String

func (s Status) String() string

type StatusCheck

type StatusCheck interface {
	Check(float64) Status
	CheckInt(int) Status
	CheckInt32(int32) Status
	Compare(func() bool) Status
	CompareBool(value bool) Status
}

StatusCheck contains the thresholds for warning and critical escalation

func NewStatusCheck

func NewStatusCheck(warning string, critical string) (StatusCheck, error)

NewStatusCheck parse warning and critical thresholds into an StatusCheck object

func NewStatusCheckCompare

func NewStatusCheckCompare(result string) (StatusCheck, error)

NewStatusCheckCompare returns a new StatusCheck to evaluate a status based on a closure and return a Status based on result

type StatusMessagePolicy

type StatusMessagePolicy interface {
	Generate(Results) string
}

StatusMessagePolicy interface for all status policies

func NewDefaultStatusMessagePolicy

func NewDefaultStatusMessagePolicy() StatusMessagePolicy

NewDefaultStatusMessagePolicy returns a status policy that assigns relative severity in accordance with conventional Nagios plugin return codes. Statuses associated with higher return codes are more severe.

type StatusPolicy

type StatusPolicy interface {
	Calculate(Results) Status
}

StatusPolicy interface for all status policies

func NewDefaultStatusPolicy

func NewDefaultStatusPolicy() StatusPolicy

NewDefaultStatusPolicy returns a status policy that assigns relative severity in accordance with conventional Nagios plugin return codes. Statuses associated with higher return codes are more severe.

Jump to

Keyboard shortcuts

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