File: core.rst

package info (click to toggle)
nagiosplugin 1.3.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 948 kB
  • sloc: python: 1,857; makefile: 139; sh: 8
file content (107 lines) | stat: -rw-r--r-- 2,797 bytes parent folder | download | duplicates (2)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
.. _core-api:

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
:func:`~nagiosplugin.runtime.guarded` and creates a
:class:`~nagiosplugin.check.Check` object. The check instance is fed with
instances of :class:`~nagiosplugin.resource.Resource`,
:class:`~nagiosplugin.context.Context`, or
:class:`~nagiosplugin.summary.Summary` (respective custom subclasses). Finally,
control is passed to the check's :meth:`~nagiosplugin.check.Check.main` method.

.. note::

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

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

   to get a :class:`~nagiosplugin.check.Check` instance.


nagiosplugin.check
------------------

.. automodule:: nagiosplugin.check
   :no-members:

.. autoclass:: Check

   .. automethod:: __call__

   .. attribute:: name

      Short name which is used to prefix the check's status output (as commonly
      found in plugins shipped with Nagios). It defaults to the uppercased class
      name of the first resource added. However, plugin authors may override
      this by assigning an user-defined name. If this attribute is None, status
      output will not be prefixed with a check name.

   .. attribute:: results

      :class:`~nagiosplugin.result.Results` container that allows accessing the
      :class:`~nagiosplugin.result.Result` objects generated during the
      evaluation.

.. topic:: Example: Skeleton main function

   The following pseudo code outlines how :class:`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
---------------------

.. automodule:: nagiosplugin.resource
   :no-members:

.. autoclass:: Resource


nagiosplugin.context
--------------------

.. automodule:: nagiosplugin.context
   :no-members:

.. autoclass:: Context

.. autoclass:: ScalarContext

.. topic:: 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
--------------------

.. automodule:: nagiosplugin.summary
   :no-members:

.. autoclass:: Summary


nagiosplugin.runtime
--------------------

.. automodule:: nagiosplugin.runtime
   :no-members:

.. autofunction:: guarded(*args, verbose=None)

.. vim: set spell spelllang=en: