Skip to content

A Go library for effortless struct marshalling into Icinga2-compatible format, facilitating automatic exit codes based on defined thresholds. πŸ“ŠπŸš€

License

Notifications You must be signed in to change notification settings

niklastreml/icinga-marshaler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

icinga-marshaler GitHub go.mod Go version GoDoc codecov

Small library that provides a utility function for easily marshalling any go struct into a format that icinga2 can understand. The library follows the specification mentioned here.

Example

package main

func main() {
    type Check struct {
		BasicValue          string
		FieldWithThresholds int64   `warn:"800" crit:"1024" min:"64" max:"2048"`
		FieldWithCustomName float64 `icinga:"MyCustomField"`
		EverythingTogether  int32   `icinga:"Complex" warn:"800" crit:"1024" min:"64" max:"2048"`
	}

	status := Check{
		BasicValue:          "WARN",
		FieldWithThresholds: 1024,
		FieldWithCustomName: 63.5,
		EverythingTogether:  100,
	}

	bytes := Marshal(status)
	fmt.Println(string(bytes))
}

Creates this output:

'BasicValue'=WARN 'FieldWithThresholds'=1024;800;1024;64;2048 'MyCustomField'=63.5 'Complex'=100;800;1024;64;2048

Automatic exit codes

You can get an exit code based on performance data and the Min,Max,Warn and Crit tags. This is useful if you want to exit your program with the correct exit code. You can use the ExitCode() function for this. It will compare the performance data to the thresholds and return the correct exit code. If the performance data is not a number, it will return 3 (UNKNOWN).

package main

import (
	"os"
)

func main() {
    type Check struct {
		MyField int64   `warn:"800" crit:"1024" min:"64" max:"2048"`
	}

	status := Check{
		MyField: 1200,
	}

	code := ExitCode(status)
	os.Exit(code) // exits with code 2, i.e. CRITICAL
}

About

A Go library for effortless struct marshalling into Icinga2-compatible format, facilitating automatic exit codes based on defined thresholds. πŸ“ŠπŸš€

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages