From 4a83ffbba5a9d35401181bd66459db1b97ee648c Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Mon, 29 Jun 2026 16:06:33 +0200 Subject: [PATCH] Fix some docs --- README.md | 22 ++++++++++++---------- perfdata.go | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c608150..47cdf96 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ See the [documentation on pkg.go.dev](https://pkg.go.dev/github.com/NETWAYS/go-c ## Simple Example -go-check includes everything to quickly create a CLI monitoring plugin: +With the `NewConfig` constructor you can quickly create a CLI monitoring plugin: ```go package main @@ -39,6 +39,8 @@ func main() { } ``` +However, the go-check library does not require you to use the `Config` type. + ## Return Codes The library provides predefined return or exit codes: @@ -92,6 +94,9 @@ check.ExitError(err) // UNKNOWN, 3 ``` +You can use `defer check.CatchPanic()` to ensure a check plugin will always exit with a proper code, +even if the code panics. + ## Timeout Handling HandleTimeout is a helper for a goroutine, to wait for signals and timeout, and exit with a proper code. @@ -133,7 +138,7 @@ pl.Add(&check.Perfdata{ Label: "process.cpu.percent", Value: 25, Uom: "%", - Warn: &check.Threshold{Lower: check.NegInf, Upper: 50 }, + Warn: &check.Threshold{Lower: check.NegInf, Upper: 50}, Crit: &check.Threshold{Lower: check.NegInf, Upper: 90}, Min: 0, Max: 100}) @@ -163,13 +168,10 @@ An `Overall` can contain multiple subchecks. The final exit of the `Overall` wil o := Overall{} o.Add(0, "Something is OK") -pr := PartialResult{ - Output: "My Subcheck", -} +pr := NewPartialResult() -if err := pr.SetState(check.OK); err != nil { - fmt.Printf(%s, err) -} +pr.SetOutput("Something happened") +pr.SetState(check.OK) o.AddSubcheck(pr) @@ -177,14 +179,14 @@ fmt.Println(o.GetOutput()) // states: ok=1 // [OK] Something is OK -// \_ [OK] My Subcheck +// \_ [OK] Something happened ``` Overall is concurrency-safe. ## Human-readable bytes -`ParseBytes` is a helper that can be used to parse string containering IEC or SI bytes into the number of bytes. +`ParseBytes` is a helper that can be used to parse string containing IEC or SI bytes into the number of bytes. ```go b, err := ParseBytes("2MiB") diff --git a/perfdata.go b/perfdata.go index ed92d03..a9b52f5 100644 --- a/perfdata.go +++ b/perfdata.go @@ -10,7 +10,7 @@ import ( const PerfdataSeparatorSymbol = "|" // PerfdataList can store multiple perfdata and implements the fmt.Stringer interface -// to provide formated output for the performance data +// to provide formatted output for the performance data type PerfdataList []*Perfdata // String returns string representations of all Perfdata added to the list