Core API

The core API consists of all functions and classes which are called in a plugin’s main function. A typical main function is decorated with guarded() and creates a Check object. The check instance is fed with instances of Resource, Context, or Summary (respective custom subclasses). Finally, control is passed to the check’s main() method.

Note

All classes that plugin authors typically need are imported into the nagiosplugin name space. For example, use

import nagiosplugin
# ...
check = nagiosplugin.Check()

to get a Check instance.

nagiosplugin.check

Example: Skeleton main function

The following pseudo code outlines how Check is typically used in the main function of a plugin:

def main():
   check = nagiosplugin.Check(MyResource1(...), MyResource2(...),
                              MyContext1(...), MyContext2(...),
                              MySummary(...))
   check.main()

nagiosplugin.resource

nagiosplugin.context

Example ScalarContext usage

Configure a ScalarContext with warning and critical ranges found in ArgumentParser’s result object args and add it to a check:

c = Check(..., ScalarContext('metric', args.warning, args.critical), ...)

nagiosplugin.summary

nagiosplugin.runtime