Categorygithub.com/inexio/go-monitoringplugin
modulepackage
1.0.13
Repository: https://github.com/inexio/go-monitoringplugin.git
Documentation: pkg.go.dev

# README

go-monitoringplugin

Go Report Card GitHub license GoDoc doc

Description

Golang package for writing monitoring check plugins for nagios, icinga2, zabbix, checkmk, etc. The package complies with the Monitoring Plugins Development Guidelines.

Example / Usage

package main

import (
	monitoringplugin "github.com/inexio/go-monitoringplugin"
)

func main() {
	//Creating response with a default ok message that will be displayed when the checks exits with status ok
	response := monitoringplugin.NewResponse("everything checked!")

	//Set output delimiter (default is \n)
	//response.SetOutputDelimiter(" / ")

	//updating check plugin status and adding message to the ouput (status only changes if the new status is worse than the current one)
	response.UpdateStatus(monitoringplugin.OK, "something is ok!") //check status stays ok
	response.UpdateStatus(monitoringplugin.CRITICAL, "something else is critical!") //check status updates to critical
	response.UpdateStatus(monitoringplugin.WARNING, "something else is warning!") //check status stays critical, but message will be added to the output


	//adding performance data
	err := response.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("response_time", 10, "s").SetWarn(10).SetCrit(20).SetMin(0))
	if err != nil {
		//error handling
	}
	err = response.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("memory_usage", 50, "%").SetWarn(80).SetCrit(90).SetMin(0).SetMax(100))
	if err != nil {
		//error handling
	}

	response.OutputAndExit()
	/* exits program with exit code 2 and outputs:
	CRITICAL: something is ok!
	something else is critical!
	something else is warning! | 'response_time'=10s;10;20;0; 'memory_usage'=50%;80;90;0;100
	*/
}

# Functions

NewPerformanceDataPoint creates a new PerformanceDataPoint.
NewResponse creates a new Response and sets the default OK message to the given string.
NewThresholds creates a new threshold.
StatusCode2Text is used to map the status code to a string.
String2StatusCode returns the status code for a string.

# Constants

CRITICAL check plugin status = CRITICAL.
InvalidCharacterRemove removes invalid character in the output message.
InvalidCharacterRemoveMessage removes the message with the invalid character.
InvalidCharacterReplace replaces invalid character in the output message with another character.
InvalidCharacterReplaceWithError replaces the whole message with an error message if an invalid character is found.
InvalidCharacterReplaceWithErrorAndSetUNKNOWN replaces the whole message with an error message if an invalid character is found.
OK check plugin status = OK.
UNKNOWN check plugin status = UNKNOWN.
WARNING check plugin status = WARNING.

# Structs

OutputMessage represents a message of the response.
PerformanceDataPoint contains all information of one PerformanceDataPoint.
Response is the main type that is responsible for the check plugin Response.
ResponseInfo has all available information for a response.
Thresholds contains all threshold values.

# Type aliases

InvalidCharacterBehavior specifies how the monitoringplugin should behave if an invalid character is found in the output message.