GithubHelp home page GithubHelp logo

sebbbastien / nagiosplugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from olorin/nagiosplugin

0.0 1.0 0.0 48 KB

Package for writing Nagios/Icinga/et cetera plugins in Go (golang)

License: BSD 3-Clause "New" or "Revised" License

Makefile 0.49% Go 99.51%

nagiosplugin's Introduction

Build status

nagiosplugin

Package for writing Nagios/Icinga/et cetera plugins in Go (golang).

Documentation

See http://godoc.org/github.com/olorin/nagiosplugin.

Usage example

The general usage pattern looks like this:

func main() {
	// Initialize the check - this will return an UNKNOWN result
	// until more results are added.
	check := nagiosplugin.NewCheck()
	// If we exit early or panic() we'll still output a result.
	defer check.Finish()

	// obtain data here

	// Add an 'OK' result - if no 'worse' check results have been
	// added, this is the one that will be output.
	check.AddResult(nagiosplugin.OK, "everything looks shiny, cap'n")
	// Add some perfdata too (label, unit, value, min, max,
	// warn, crit). The math.Inf(1) will be parsed as 'no
	// maximum'.
	check.AddPerfDatum("badness", "kb", 3.14159, 0.0, math.Inf(1), 8000.0, 9000.0)

	// Parse a range from the command line and warn on a match.
	warnRange, err := nagiosplugin.ParseRange( "1:2" )
	if err != nil {
		check.AddResult(nagiosplugin.UNKNOWN, "error parsing warning range")
	}
	if warnRange.Check( 3.14159 ) {
		check.AddResult(nagiosplugin.WARNING, "Are we crashing again?")
	}
}

In the example above, multiple results were added to the check with AddResult(). The final state of the check will be determined by its most severe result. By default, result severity is ordered to match the plugin return codes documented in the Nagios plugin developer guidelines. A WARNING result is considered more severe than OK, CRITICAL more severe than WARNING, and UNKNOWN most severe of all. A status policy may be used to modify this default behaviour:

func main() {
	check := nagiosplugin.NewCheckWithOptions(nagiosplugin.CheckOptions{
		// OK -> UNKNOWN -> WARNING -> CRITICAL
		StatusPolicy: nagiosplugin.NewOUWCStatusPolicy(),
	})
	defer check.Finish()

	// Now, any WARNING or CRITICAL results added to the check will be
	// considered more severe than any UNKNOWN result.
}

Language version

Requires go >= 1.0; tested with versions up to 1.7.

nagiosplugin's People

Contributors

dominikschulz avatar moorereason avatar olorin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.