Nagios

pytiger.nagios.NagiosCheck – Nagios check state machine

class pytiger.nagios.NagiosCheck[source]

New in version 1.0.0.

Abstracts a basic NRPE state machine so that a check can be reduced to its payload only.

The state machine starts at STATE_UNSET indicating that the check has not yet expressed any status (if the check existed at this point, the exit code would be equivalent to Nagios ‘unknown’).

The four other states, STATE_OK, STATE_WARN, STATE_CRIT and STATE_UNKN correspond to the Nagios values ‘OK’, ‘warn’, ‘critical’ and ‘unknown’ respectively.

States are sticky and transitions follow defined rules, so (for example) a check which has asserted ‘critical’ status cannot later rescind that and assert that it is only ‘warning’ after all.

Programs must call exit() to return the correct error code. Optional messages can be queued up and will be printed by exit() for consumption by the user.

Example usage:

>>> n = NagiosCheck()
>>> n.ok('Everything is fine')
>>> n.exit()
critical(message=None)[source]

Set the current state to STATE_CRIT from any other state (indicating that the check is outside acceptable parameters and affecting service). This trumps all other states and is sticky.

exit()[source]

Print the queued messages and exit with an appropriate exit code (this is the basis for the Nagios status)

ok(message=None)[source]

If the current state is unset, set it to STATE_OK (indicating that the check is within acceptable parameters)

unknown(message=None)[source]

If the current state is unset or not worse than ‘OK’, set it to STATE_UNKN (indicating that some internal error means the check cannot be sure of the current situation).

warn(message=None)[source]

If the current state is unset or not worse than ‘warning’, set it to STATE_WARN (indicating that the check is outside acceptable parameters, but not service-affecting)

messages

List of queued messages

state

Current state of the check