Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -163,28 +168,25 @@ 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)

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")
Expand Down
2 changes: 1 addition & 1 deletion perfdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading