Skip to main content

Nagios Helper Objects for Python Check Scripts

Project description

NagiosCheckHelper

This library helps with the boilerplate nagios check formating, status information, and basic evaluations when writing a Python nagios/icinga check

Installation

It's on pypi, so it's as easy as installing via pip

pip3 install NagiosCheckHelper

NagErrors Object

An object to hold the Errors that have occured.

Generally you can call it with obj.addCritical(error text) or obj.addWarning(error text) to accumulate your errors

Then call obj.printStatus() to print the formatted Errors

Then call obj.doExit() to exit your program with the proper result code.

Usage

Object Creation

No parameters, so just do a:

from NagiosCheckHelper import NagErrors
nerr = NagErrors()

Logging Errors

There are 4 functions for logging errors:

  • addRecord(eType,etext)

  • addCritical(etext)

  • addWarning(etext)

  • addUnknown(etext)

  • eType would be the type of error. One of: critical, warning, or unknown\

  • etext is the Error message (without any Error or Warning prefix, that's automatically added)

example:

from NagiosCheckHelper import NagErrors
nerr = NagErrors()
nerr.addRecord("critical", "The printer is on fire.")
nerr.addWarning("The printer is out of paper.")
nerr.addUnknown("The printer grew legs and walked out the door.")

Outputting status

There are 2 main functions for outputting status:

  • printStatus() - print out the formatted status lines
  • doExit() - Exit the program with the proper status code.

NagErrors "full" example:

A quick example that sets a couple messages and exits

from NagiosCheckHelper import NagErrors
nerr = NagErrors()
nerr.addCritical("This is a Critical Event")
nerr.addWarning("This is a Warning Event")
nerr.printStatus()
nerr.doExit()

NagEval Object

An object with common subroutines to evaluate data and cause error events based on the comparisons.

Be sure to initite it with an NagErrors Object.

Usage

Object Creation

Takes a NagErrors object to track errors, so just do a:

from NagiosCheckHelper import NagErrors, NagEval
nerr = NagErrors()
neval = NagEval(nerr)

Evaluate value against Enumerated Values

Evaluate a value based on lists of enumerated values

evalEnum(value, defaultStatus="UNKNOWN", okValues=[], warningValues=[], criticalValues=[], unknownValues=[], prefixText="", postfixText= "")

Evaluate List of values against Enumerated Values

Evaluate a list of values based on lists of enumerated values

values = ['value1', 'value2', 'value3']
evalListEnum(values, emptyStatus="UNKNOWN", unknownValueStatus="UNKNOWN", okValues=[], warningValues=[], criticalValues=[], unknownValues=[], prefixText="", postfixText= "")

Evaluate Numbers

There are 2 evaluators that will handle number ranges (asending and decending):

evalNumberAsc(value, warningAbove=None, criticalAbove=None, prefixText="", postfixText="", numberUnits="")
evalNumberDesc(value, warningBelow=None, criticalBelow=None, prefixText="", postfixText= "", numberUnits="")

Evaluate List of Numbers

There are 2 evaluators that will handle lists of numbers based on number ranges (asending and decending):

values = [5, 90, 55, 200001]
evalListNumberAsc(values, emptyStatus="UNKNOWN", warningAbove=None, criticalAbove=None, prefixText="", postfixText="", numberUnits="")
evalListNumberDesc(values, emptyStatus="UNKNOWN", warningBelow=None, criticalBelow=None, prefixText="", postfixText= "", numberUnits="")

NagEval "full" example:

A quick example that tests a value, outputs the results and exits with the proper code

from NagiosCheckHelper import NagErrors, NagEval
nerr = NagErrors()
neval = NagEval(nerr)
neval.evalNumberAsc(95, warningAbove=80, criticalAbove=90, numberUnits="%")
nerr.printStatus()
nerr.doExit()

Full Examples

These are full examples/checks that use this library and click to handle most of the boilerplate and script is mostly just defining the options and running the actual check.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

NagiosCheckHelper-0.1.3.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

NagiosCheckHelper-0.1.3-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file NagiosCheckHelper-0.1.3.tar.gz.

File metadata

  • Download URL: NagiosCheckHelper-0.1.3.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.5

File hashes

Hashes for NagiosCheckHelper-0.1.3.tar.gz
Algorithm Hash digest
SHA256 9ef3f2f8145f1939f80896ec73dbc4e1c31cca2278514e34dca4b8ca51523e0e
MD5 0c9f54be4dfb686b712f5da8bd470f86
BLAKE2b-256 1a75b4e33d982f8b0f9cca68c26a3cdc2932182bc8ea5b30abf6965b5d7e683e

See more details on using hashes here.

File details

Details for the file NagiosCheckHelper-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: NagiosCheckHelper-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.5

File hashes

Hashes for NagiosCheckHelper-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d86711e71a8fb2cdc4da7a48650f8f8e885f12db6d4f3b319f13ad3649ee61f8
MD5 efedf0a23413fb7f906406709f838f3a
BLAKE2b-256 8db8599bd3e00d486a07763b5752ed750dbcb39b9afafd46ca32337d499ee52a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page