result

package
v1.0.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: GPL-2.0 Imports: 4 Imported by: 15

Documentation

Overview

Package result provides types and functions to organize results in a check plugin

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Overall

type Overall struct {
	// default summary (first line of output) if everything is ok. Has to be set in a plugin
	OKSummary string
	// The results that are associated with this overall
	PartialResults []*PartialResult
	// contains filtered or unexported fields
}

Overall is a singleton for a monitoring plugin that has several partial results (or sub-results)

Design decisions: A check plugin has a single Overall (singleton), each partial thing which is tested, gets its own subcheck.

The results of these may be relevant to the overall status in the end or not, e.g. if a plugin tries two different methods for something and one suffices, but one fails, the whole check might be OK and only the subcheck Warning or Critical.

Example (WithSubchecks)
var overall Overall

example_perfdata := check.Perfdata{Label: "pd_test", Value: 5, Uom: "s"}
pd_list := check.PerfdataList{}
pd_list.Add(&example_perfdata)

subcheck := &PartialResult{
	Output:   "Subcheck1 Test",
	Perfdata: pd_list,
}

subcheck.SetState(check.OK)

overall.AddSubcheck(subcheck)
overall.Add(check.OK, "bla")

fmt.Println(overall.GetOutput())
Output:
states: ok=2
\_ [OK] Subcheck1 Test
\_ [OK] bla
|pd_test=5s
Example (WithVerticalbar)
var overall Overall

overall.OKSummary = "unit|test"

example_perfdata := check.Perfdata{Label: "pd_test", Value: 5, Uom: "s"}
pd_list := check.PerfdataList{}
pd_list.Add(&example_perfdata)

subcheck := &PartialResult{
	Output:   "vertical|bar",
	Perfdata: pd_list,
}

subcheck.SetState(check.OK)

overall.AddSubcheck(subcheck)
overall.Add(check.OK, "another|bar")

fmt.Println(overall.GetOutput())
Output:
unit test
\_ [OK] vertical bar
\_ [OK] another bar
|pd_test=5s

func (*Overall) Add

func (o *Overall) Add(state check.Status, output string)

Add adds a return state explicitly. Add is concurrency-safe

Example
overall := Overall{}
overall.Add(check.OK, "One element is good")
overall.Add(check.Critical, "The other is critical")

fmt.Printf("%s", overall.GetOutput())

func (*Overall) AddSubcheck added in v0.4.0

func (o *Overall) AddSubcheck(subcheck *PartialResult)

AddSubcheck adds a PartialResult to the Overall. AddSubcheck is concurrency-safe

func (*Overall) GetOutput

func (o *Overall) GetOutput() string

GetOutput returns a text representation of the current outputs of the Overall. GetOutput is concurrency-safe

Example
overall := Overall{}
overall.Add(check.OK, "One element is good")
overall.Add(check.Critical, "The other is critical")

fmt.Println(overall.GetOutput())
Output:
The other is critical
\_ [OK] One element is good
\_ [CRITICAL] The other is critical

func (*Overall) GetStatus

func (o *Overall) GetStatus() check.Status

GetStatus returns the current state (ok, warning, critical, unknown) of the Overall. GetStatus is concurrency-safe

Example
overall := Overall{}
overall.Add(check.OK, "One element is good")
overall.Add(check.Critical, "The other is critical")

fmt.Println(overall.GetStatus())
Output:
CRITICAL

type PartialResult added in v0.4.0

type PartialResult struct {
	Perfdata       check.PerfdataList
	PartialResults []*PartialResult
	Output         string
	// contains filtered or unexported fields
}

PartialResult represents a sub-result for an Overall struct

func NewPartialResult added in v0.6.2

func NewPartialResult() *PartialResult

NewPartialResult initializer with defaults. It is recommended to use NewPartialResult. The default compared to the nil object is the default state is set to Unknown.

func (*PartialResult) AddSubcheck added in v0.4.0

func (s *PartialResult) AddSubcheck(subcheck *PartialResult)

AddSubcheck adds a PartialResult to the PartialResult

func (*PartialResult) GetStatus added in v0.5.0

func (s *PartialResult) GetStatus() check.Status

GetStatus returns the current state (ok, warning, critical, unknown) of the PartialResult

func (*PartialResult) SetDefaultState added in v0.5.0

func (s *PartialResult) SetDefaultState(state check.Status)

SetDefaultState sets a new default state for a PartialResult

func (*PartialResult) SetState added in v0.5.0

func (s *PartialResult) SetState(state check.Status)

SetState sets a state for a PartialResult

func (*PartialResult) String added in v0.4.0

func (s *PartialResult) String() string

String returns the status and output of the PartialResult

Jump to

Keyboard shortcuts

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