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
|
.. _auxiliary-classes:
Auxiliary Classes
=================
nagiosplugin's auxiliary classes are not strictly required to write checks, but
simplify common tasks and provide convenient access to functionality that is
regularly needed by plugin authors.
.. note::
All classes that plugin authors typically need are imported directly into the
:mod:`nagiosplugin` name space. For example, use ::
import nagiosplugin
# ...
with nagiosplugin.Cookie(path) as cookie:
# ...
to get a cookie.
nagiosplugin.cookie
-------------------
.. automodule:: nagiosplugin.cookie
:no-members:
.. autoclass:: Cookie
.. automethod:: __enter__
.. topic:: Cookie example
Increment a connection count saved in the cookie by `self.new_conns`::
with nagiosplugin.Cookie(self.statefile) as cookie:
cookie['connections'] = cookie.get('connections', 0) + self.new_conns
Note that the new content is committed automatically when exiting the `with`
block.
nagiosplugin.logtail
--------------------
.. automodule:: nagiosplugin.logtail
:no-members:
.. autoclass:: LogTail
.. automethod:: __enter__
.. topic:: LogTail example
Calls `process()` for each new line in a log file::
cookie = nagiosplugin.Cookie(self.statefile)
with nagiosplugin.LogTail(self.logfile, cookie) as newlines:
for line in newlines:
process(line.decode())
.. vim: set spell spelllang=en:
|