result

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 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 {
	// 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

subcheck := NewPartialResult()
subcheck.SetOutput("Subcheck1 Test")

example_perfdata := check.Perfdata{Label: "pd_test", Value: 5, Uom: "s"}
subcheck.AddPerfdata(&example_perfdata)

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"

subcheck := &PartialResult{
	output: "vertical|bar",
}

example_perfdata := check.Perfdata{Label: "pd_test", Value: 5, Uom: "s"}
subcheck.AddPerfdata(&example_perfdata)

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

func (*Overall) SetOKSummary added in v1.0.0

func (o *Overall) SetOKSummary(summary string)

SetOKSummary sets the summary to the given string

type PartialResult added in v0.4.0

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

PartialResult represents a sub-result for an Overall struct. Note that, a PartialResult must not be used on its own but always with an Overall.

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) AddPerfdata added in v1.0.0

func (s *PartialResult) AddPerfdata(perfdata *check.Perfdata)

AddPerfdata adds a Perfdata point to the PartialResult

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) SetOutput added in v1.0.0

func (s *PartialResult) SetOutput(output string)

SetOutput sets the output of this PartialResult to the given string

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