1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
.. _debugging:
.. index:: debugging
Plugin Debugging
================
Debugging plugins can sometimes be complicated since there are so many classes,
which are tied together in an implicit way. I have collected some frequent
questions about debugging.
.. index::
single: verbose; traceback
An uncaught exception makes the plugin return UNKNOWN. Where is the cause?
--------------------------------------------------------------------------
When your plugin raises an exception, you may get very little output. Example::
$ check_users.py
USERS UNKNOWN: RuntimeError: error
Set the **verbose** parameter of :py:meth:`~nagiosplugin.check.Check.main`
to some value greater than zero and you will get the full traceback::
$ check_users.py -v
USERS UNKNOWN: RuntimeError: error
Traceback (most recent call last):
File "nagiosplugin/runtime.py", line 38, in wrapper
return func(*args, **kwds)
File "nagiosplugin/examples/check_users.py", line 104, in main
check.main(args.verbose, args.timeout)
File "nagiosplugin/check.py", line 110, in main
runtime.execute(self, verbose, timeout)
File "nagiosplugin/runtime.py", line 118, in execute
with_timeout(self.timeout, self.run, check)
File "nagiosplugin/platform/posix.py", line 19, in with_timeout
func(*args, **kwargs)
File "nagiosplugin/runtime.py", line 107, in run
check()
File "nagiosplugin/check.py", line 95, in __call__
self._evaluate_resource(resource)
File "nagiosplugin/check.py", line 73, in _evaluate_resource
metrics = resource.probe()
File "nagiosplugin/examples/check_users.py", line 57, in probe
self.users = self.list_users()
File "nagiosplugin/examples/check_users.py", line 34, in list_users
raise RuntimeError('error')
RuntimeError: error
A Check constructor dies with "cannot add type <...>"
-----------------------------------------------------
When you see the following exception raised from
:py:meth:`~nagiosplugin.check.Check` (or `Check.add()`)::
UNKNOWN: TypeError: ("cannot add type <class '__main__.Users'> to check", <__main__.Users object at 0x7f0c64f73f90>)
chances are high that you are trying to add an object that is not an instance
from Resource, Context, Summary, or Results or its subclasses. A common
error is to base a resource class on `object` instead of
:py:class:`~nagiosplugin.resource.Resource`.
.. index:: pdb
I'm trying to use pdb but I get a timeout after 10s
---------------------------------------------------
When using an interactive debugger like pdb on plugins, you may experience that
your debugging session is aborted with a timeout after 10 seconds. Just set the
**timeout** parameter in :py:meth:`~nagiosplugin.check.Check.main` to 0 to avoid
this.
.. vim: set spell spelllang=en:
|