result

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: GPL-2.0 Imports: 5 Imported by: 6

Documentation

Overview

result tries to

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WorstState

func WorstState(states ...int) int

Determines the worst state from a list of states

Helps combining an overall states, only based on a few numbers for various checks.

Order of preference: Critical, Unknown, Warning, Ok

Types

type Overall

type Overall struct {
	Summary string

	Outputs        []string // Deprecate this in a future version
	PartialResults []PartialResult
	// contains filtered or unexported fields
}

Overall is a singleton for a monitoring pluging 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 := perfdata.Perfdata{Label: "pd_test", Value: 5, Uom: "s"}
pd_list := perfdata.PerfdataList{}
pd_list.Add(&example_perfdata)

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

subcheck.SetState(check.OK)

overall.AddSubcheck(subcheck)
overall.Add(0, "bla")

fmt.Println(overall.GetOutput())
Output:

states: ok=1
[OK] bla
\_ [OK] Subcheck1 Test
|pd_test=5s

func (*Overall) Add

func (o *Overall) Add(state int, output string)

Add adds a return state explicitly

Hint: This will set stateSetExplicitly to true

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

fmt.Printf("%#v\n", overall)
Output:

result.Overall{oks:1, warnings:0, criticals:1, unknowns:0, Summary:"", stateSetExplicitly:true, Outputs:[]string{"[OK] One element is good", "[CRITICAL] The other is critical"}, PartialResults:[]result.PartialResult(nil)}

func (*Overall) AddSubcheck added in v0.4.0

func (o *Overall) AddSubcheck(subcheck PartialResult)

AddSubcheck adds a PartialResult to the Overall

func (*Overall) GetOutput

func (o *Overall) GetOutput() string

GetOutput returns a text representation of the current outputs of the Overall

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

fmt.Println(overall.GetOutput())
Output:

states: critical=1 ok=1
[OK] One element is good
[CRITICAL] The other is critical

func (*Overall) GetStatus

func (o *Overall) GetStatus() int

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

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

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

2

func (*Overall) GetSummary

func (o *Overall) GetSummary() string

GetSummary returns a text representation of the current state of the Overall nolint: funlen

type PartialResult added in v0.4.0

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

PartialResult represents a sub-result for an Overall struct

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() int

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

func (*PartialResult) SetDefaultState added in v0.5.0

func (s *PartialResult) SetDefaultState(state int) error

SetDefaultState sets a new default state for a PartialResult

func (*PartialResult) SetState added in v0.5.0

func (s *PartialResult) SetState(state int) error

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