check_systemd


Namecheck_systemd JSON
Version 4.1.0 PyPI version JSON
download
home_pagehttps://github.com/Josef-Friedrich/check_systemd
SummaryNagios / Icinga monitoring plugin to check systemd for failed units.
upload_time2024-03-01 17:52:38
maintainer
docs_urlNone
authorJosef Friedrich
requires_python>=3.8,<4.0
licenseLGPL-2.1-only
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: http://img.shields.io/pypi/v/check-systemd.svg
    :target: https://pypi.org/project/check-systemd
    :alt: This package on the Python Package Index

.. image:: https://github.com/Josef-Friedrich/check_systemd/actions/workflows/tests.yml/badge.svg
    :target: https://github.com/Josef-Friedrich/check_systemd/actions/workflows/tests.yml
    :alt: Tests

.. image:: https://readthedocs.org/projects/check-systemd/badge/?version=latest
    :target: https://check-systemd.readthedocs.io/en/latest/?badge=latest
    :alt: Documentation Status

check_systemd
=============

``check_systemd`` is a `Nagios <https://www.nagios.org>`__ /
`Icinga <https://icinga.com>`__ monitoring plugin to check
`systemd <https://systemd.io>`__. This Python script will report a
degraded system to your monitoring solution. It can also be used to
monitor individual systemd services (with the ``-u, --unit`` parameter)
and timers units (with the ``-t, --dead-timers`` parameter). The only
dependency the plugin needs is the Python library
`nagiosplugin <https://nagiosplugin.readthedocs.io/en/stable>`__.

Installation
------------

::

   pip install check_systemd

Packages
--------

``check_systemd`` on `repology.org <https://repology.org/project/check-systemd/related>`__.

-  archlinux
   (`package <https://aur.archlinux.org/packages/check_systemd>`__,
   `source
   code <https://aur.archlinux.org/check_systemd.git>`__):
   ``yaourt -S check_systemd``
-  Ubuntu
   (`package <https://packages.ubuntu.com/search?keywords=monitoring-plugins-systemd&searchon=names>`__,
   `source
   code <https://git.launchpad.net/ubuntu/+source/monitoring-plugins-systemd>`__):
   ``apt install monitoring-plugins-systemd``
-  Debian
   (`package <https://packages.debian.org/search?keywords=monitoring-plugins-systemd>`__,
   `source
   code <https://salsa.debian.org/python-team/packages/monitoring-plugins-systemd/-/tree/debian/master/debian>`__):
   ``apt install monitoring-plugins-systemd``
-  NixOS
   (`package <https://search.nixos.org/packages?channel=unstable&query=check_systemd>`__,
   `source
   code <https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/servers/monitoring/nagios/plugins/check_systemd.nix>`__):
   ``nix-env -iA nixos.check_systemd``
-  Fedora
   (`package <https://packages.fedoraproject.org/pkgs/nagios-plugins-systemd/nagios-plugins-systemd/>`__,
   `source code <https://src.fedoraproject.org/rpms/nagios-plugins-systemd>`__):
   ``dnf install nagios-plugins-systemd``

Command line interface
----------------------

:: 

    usage: check_systemd [-h] [-v] [-d] [-V] [-i] [-I REGEXP] [-u UNIT_NAME]
                         [--include-type UNIT_TYPE [UNIT_TYPE ...]] [-e REGEXP]
                         [--exclude-unit UNIT_NAME [UNIT_NAME ...]]
                         [--exclude-type UNIT_TYPE]
                         [--state {active,reloading,inactive,failed,activating,deactivating}]
                         [-t] [-W SECONDS] [-C SECONDS] [-n] [-w SECONDS]
                         [-c SECONDS] [--dbus | --cli] [--user] [-P | -p]

    Copyright (c) 2014-18 Andrea Briganti <kbytesys@gmail.com>
    Copyright (c) 2019-24 Josef Friedrich <josef@friedrich.rocks>

    Nagios / Icinga monitoring plugin to check systemd.

    options:
      -h, --help            show this help message and exit
      -v, --verbose         Increase output verbosity (use up to 3 times).
      -d, --debug           Increase debug verbosity (use up to 2 times): -d: info
                            -dd: debug.
      -V, --version         show program's version number and exit

    Options related to unit selection:
      By default all systemd units are checked. Use the option '-e' to exclude units
      by a regular expression. Use the option '-u' to check only one unit.

      -i, --ignore-inactive-state
                            Ignore an inactive state on a specific unit. Oneshot
                            services for example are only active while running and
                            not enabled. The rest of the time they are inactive.
                            This option has only an affect if it is used with the
                            option -u.
      -I REGEXP, --include REGEXP
                            Include systemd units to the checks. This option can be
                            applied multiple times, for example: -I mnt-data.mount
                            -I task.service. Regular expressions can be used to
                            include multiple units at once, for example: -i
                            'user@\d+\.service'. For more informations see the
                            Python documentation about regular expressions
                            (https://docs.python.org/3/library/re.html).
      -u UNIT_NAME, --unit UNIT_NAME, --include-unit UNIT_NAME
                            Name of the systemd unit that is being tested.
      --include-type UNIT_TYPE [UNIT_TYPE ...]
                            One or more unit types (for example: 'service', 'timer')
      -e REGEXP, --exclude REGEXP
                            Exclude a systemd unit from the checks. This option can
                            be applied multiple times, for example: -e mnt-
                            data.mount -e task.service. Regular expressions can be
                            used to exclude multiple units at once, for example: -e
                            'user@\d+\.service'. For more informations see the
                            Python documentation about regular expressions
                            (https://docs.python.org/3/library/re.html).
      --exclude-unit UNIT_NAME [UNIT_NAME ...]
                            Name of the systemd unit that is being tested.
      --exclude-type UNIT_TYPE
                            One or more unit types (for example: 'service', 'timer')
      --state {active,reloading,inactive,failed,activating,deactivating}, --required {active,reloading,inactive,failed,activating,deactivating}, --expected-state {active,reloading,inactive,failed,activating,deactivating}
                            Specify the active state that the systemd unit must have
                            (for example: active, inactive)

    Timers related options:
      -t, --timers, --dead-timers
                            Detect dead / inactive timers. See the corresponding
                            options '-W, --dead-timer-warning' and '-C, --dead-
                            timers-critical'. Dead timers are detected by parsing
                            the output of 'systemctl list-timers'. Dead timer rows
                            displaying 'n/a' in the NEXT and LEFT columns and the
                            time span in the column PASSED exceeds the values
                            specified with the options '-W, --dead-timer-warning'
                            and '-C, --dead-timers-critical'.
      -W SECONDS, --timers-warning SECONDS, --dead-timers-warning SECONDS
                            Time ago in seconds for dead / inactive timers to
                            trigger a warning state (by default 6 days).
      -C SECONDS, --timers-critical SECONDS, --dead-timers-critical SECONDS
                            Time ago in seconds for dead / inactive timers to
                            trigger a critical state (by default 7 days).

    Startup time related options:
      -n, --no-startup-time
                            Don’t check the startup time. Using this option the
                            options '-w, --warning' and '-c, --critical' have no
                            effect. Performance data about the startup time is
                            collected, but no critical, warning etc. states are
                            triggered.
      -w SECONDS, --warning SECONDS
                            Startup time in seconds to result in a warning status.
                            The default is 60 seconds.
      -c SECONDS, --critical SECONDS
                            Startup time in seconds to result in a critical status.
                            The default is 120 seconds.

    Monitoring data acquisition:
      --dbus                Use the systemd’s D-Bus API instead of parsing the text
                            output of various systemd related command line
                            interfaces to monitor systemd. At the moment the D-Bus
                            backend of this plugin is only partially implemented.
      --cli                 Use the text output of serveral systemd command line
                            interface (cli) binaries to gather the required data for
                            the monitoring process.
      --user                Also show user (systemctl --user) units.

    Performance data:
      -P, --performance-data
                            Attach no performance data to the plugin output.
      -p, --no-performance-data
                            Attach performance data to the plugin output.

    Performance data:
      - count_units
      - startup_time
      - units_activating
      - units_active
      - units_failed
      - units_inactive

Project pages
-------------

-  on `github.com <https://github.com/Josef-Friedrich/check_systemd>`__
-  on
   `icinga.com <https://exchange.icinga.com/joseffriedrich/check_systemd>`__
-  on
   `nagios.org <https://exchange.nagios.org/directory/Plugins/System-Metrics/Processes/check_systemd/details>`__

Behind the scenes
-----------------

To detect failed units this monitoring script runs:

.. code:: sh

   systemctl list-units --all

To get the startup time it executes:

.. code:: sh

   systemd-analyze

To find dead timers this plugin launches:

.. code:: sh

   systemctl list-timers --all

To learn how ``systemd`` produces the text output on the command line,
it is worthwhile to take a look at ``systemd``\ ’s source code. Files
relevant for text output are:
`basic/time-util.c <https://github.com/systemd/systemd/blob/main/src/basic/time-util.c>`__,
`analyze/analyze.c <https://github.com/systemd/systemd/blob/main/src/analyze/analyze.c>`__.

Testing
-------

::

   pyenv install 3.6.12
   pyenv install 3.7.9
   pyenv local 3.6.12 3.7.9
   pip3 install tox
   tox

Test a single test case:

::

   tox -e py38 -- test/test_scope_timers.py:TestScopeTimers.test_all_n_a

Deploying
---------

Edit the version number in check_systemd.py (without ``v``). Use the
``-s`` option to sign the tag (required for the Debian package).

::

   git tag -s v2.0.11
   git push --tags

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Josef-Friedrich/check_systemd",
    "name": "check_systemd",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Josef Friedrich",
    "author_email": "josef@friedrich.rocks",
    "download_url": "https://files.pythonhosted.org/packages/1c/ba/dd4507ed699deaf27d7f9b6aed6e5c84d00e9796ef56ed3c5fe215c1315f/check_systemd-4.1.0.tar.gz",
    "platform": null,
    "description": ".. image:: http://img.shields.io/pypi/v/check-systemd.svg\n    :target: https://pypi.org/project/check-systemd\n    :alt: This package on the Python Package Index\n\n.. image:: https://github.com/Josef-Friedrich/check_systemd/actions/workflows/tests.yml/badge.svg\n    :target: https://github.com/Josef-Friedrich/check_systemd/actions/workflows/tests.yml\n    :alt: Tests\n\n.. image:: https://readthedocs.org/projects/check-systemd/badge/?version=latest\n    :target: https://check-systemd.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation Status\n\ncheck_systemd\n=============\n\n``check_systemd`` is a `Nagios <https://www.nagios.org>`__ /\n`Icinga <https://icinga.com>`__ monitoring plugin to check\n`systemd <https://systemd.io>`__. This Python script will report a\ndegraded system to your monitoring solution. It can also be used to\nmonitor individual systemd services (with the ``-u, --unit`` parameter)\nand timers units (with the ``-t, --dead-timers`` parameter). The only\ndependency the plugin needs is the Python library\n`nagiosplugin <https://nagiosplugin.readthedocs.io/en/stable>`__.\n\nInstallation\n------------\n\n::\n\n   pip install check_systemd\n\nPackages\n--------\n\n``check_systemd`` on `repology.org <https://repology.org/project/check-systemd/related>`__.\n\n-  archlinux\n   (`package <https://aur.archlinux.org/packages/check_systemd>`__,\n   `source\n   code <https://aur.archlinux.org/check_systemd.git>`__):\n   ``yaourt -S check_systemd``\n-  Ubuntu\n   (`package <https://packages.ubuntu.com/search?keywords=monitoring-plugins-systemd&searchon=names>`__,\n   `source\n   code <https://git.launchpad.net/ubuntu/+source/monitoring-plugins-systemd>`__):\n   ``apt install monitoring-plugins-systemd``\n-  Debian\n   (`package <https://packages.debian.org/search?keywords=monitoring-plugins-systemd>`__,\n   `source\n   code <https://salsa.debian.org/python-team/packages/monitoring-plugins-systemd/-/tree/debian/master/debian>`__):\n   ``apt install monitoring-plugins-systemd``\n-  NixOS\n   (`package <https://search.nixos.org/packages?channel=unstable&query=check_systemd>`__,\n   `source\n   code <https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/servers/monitoring/nagios/plugins/check_systemd.nix>`__):\n   ``nix-env -iA nixos.check_systemd``\n-  Fedora\n   (`package <https://packages.fedoraproject.org/pkgs/nagios-plugins-systemd/nagios-plugins-systemd/>`__,\n   `source code <https://src.fedoraproject.org/rpms/nagios-plugins-systemd>`__):\n   ``dnf install nagios-plugins-systemd``\n\nCommand line interface\n----------------------\n\n:: \n\n    usage: check_systemd [-h] [-v] [-d] [-V] [-i] [-I REGEXP] [-u UNIT_NAME]\n                         [--include-type UNIT_TYPE [UNIT_TYPE ...]] [-e REGEXP]\n                         [--exclude-unit UNIT_NAME [UNIT_NAME ...]]\n                         [--exclude-type UNIT_TYPE]\n                         [--state {active,reloading,inactive,failed,activating,deactivating}]\n                         [-t] [-W SECONDS] [-C SECONDS] [-n] [-w SECONDS]\n                         [-c SECONDS] [--dbus | --cli] [--user] [-P | -p]\n\n    Copyright (c) 2014-18 Andrea Briganti <kbytesys@gmail.com>\n    Copyright (c) 2019-24 Josef Friedrich <josef@friedrich.rocks>\n\n    Nagios / Icinga monitoring plugin to check systemd.\n\n    options:\n      -h, --help            show this help message and exit\n      -v, --verbose         Increase output verbosity (use up to 3 times).\n      -d, --debug           Increase debug verbosity (use up to 2 times): -d: info\n                            -dd: debug.\n      -V, --version         show program's version number and exit\n\n    Options related to unit selection:\n      By default all systemd units are checked. Use the option '-e' to exclude units\n      by a regular expression. Use the option '-u' to check only one unit.\n\n      -i, --ignore-inactive-state\n                            Ignore an inactive state on a specific unit. Oneshot\n                            services for example are only active while running and\n                            not enabled. The rest of the time they are inactive.\n                            This option has only an affect if it is used with the\n                            option -u.\n      -I REGEXP, --include REGEXP\n                            Include systemd units to the checks. This option can be\n                            applied multiple times, for example: -I mnt-data.mount\n                            -I task.service. Regular expressions can be used to\n                            include multiple units at once, for example: -i\n                            'user@\\d+\\.service'. For more informations see the\n                            Python documentation about regular expressions\n                            (https://docs.python.org/3/library/re.html).\n      -u UNIT_NAME, --unit UNIT_NAME, --include-unit UNIT_NAME\n                            Name of the systemd unit that is being tested.\n      --include-type UNIT_TYPE [UNIT_TYPE ...]\n                            One or more unit types (for example: 'service', 'timer')\n      -e REGEXP, --exclude REGEXP\n                            Exclude a systemd unit from the checks. This option can\n                            be applied multiple times, for example: -e mnt-\n                            data.mount -e task.service. Regular expressions can be\n                            used to exclude multiple units at once, for example: -e\n                            'user@\\d+\\.service'. For more informations see the\n                            Python documentation about regular expressions\n                            (https://docs.python.org/3/library/re.html).\n      --exclude-unit UNIT_NAME [UNIT_NAME ...]\n                            Name of the systemd unit that is being tested.\n      --exclude-type UNIT_TYPE\n                            One or more unit types (for example: 'service', 'timer')\n      --state {active,reloading,inactive,failed,activating,deactivating}, --required {active,reloading,inactive,failed,activating,deactivating}, --expected-state {active,reloading,inactive,failed,activating,deactivating}\n                            Specify the active state that the systemd unit must have\n                            (for example: active, inactive)\n\n    Timers related options:\n      -t, --timers, --dead-timers\n                            Detect dead / inactive timers. See the corresponding\n                            options '-W, --dead-timer-warning' and '-C, --dead-\n                            timers-critical'. Dead timers are detected by parsing\n                            the output of 'systemctl list-timers'. Dead timer rows\n                            displaying 'n/a' in the NEXT and LEFT columns and the\n                            time span in the column PASSED exceeds the values\n                            specified with the options '-W, --dead-timer-warning'\n                            and '-C, --dead-timers-critical'.\n      -W SECONDS, --timers-warning SECONDS, --dead-timers-warning SECONDS\n                            Time ago in seconds for dead / inactive timers to\n                            trigger a warning state (by default 6 days).\n      -C SECONDS, --timers-critical SECONDS, --dead-timers-critical SECONDS\n                            Time ago in seconds for dead / inactive timers to\n                            trigger a critical state (by default 7 days).\n\n    Startup time related options:\n      -n, --no-startup-time\n                            Don\u2019t check the startup time. Using this option the\n                            options '-w, --warning' and '-c, --critical' have no\n                            effect. Performance data about the startup time is\n                            collected, but no critical, warning etc. states are\n                            triggered.\n      -w SECONDS, --warning SECONDS\n                            Startup time in seconds to result in a warning status.\n                            The default is 60 seconds.\n      -c SECONDS, --critical SECONDS\n                            Startup time in seconds to result in a critical status.\n                            The default is 120 seconds.\n\n    Monitoring data acquisition:\n      --dbus                Use the systemd\u2019s D-Bus API instead of parsing the text\n                            output of various systemd related command line\n                            interfaces to monitor systemd. At the moment the D-Bus\n                            backend of this plugin is only partially implemented.\n      --cli                 Use the text output of serveral systemd command line\n                            interface (cli) binaries to gather the required data for\n                            the monitoring process.\n      --user                Also show user (systemctl --user) units.\n\n    Performance data:\n      -P, --performance-data\n                            Attach no performance data to the plugin output.\n      -p, --no-performance-data\n                            Attach performance data to the plugin output.\n\n    Performance data:\n      - count_units\n      - startup_time\n      - units_activating\n      - units_active\n      - units_failed\n      - units_inactive\n\nProject pages\n-------------\n\n-  on `github.com <https://github.com/Josef-Friedrich/check_systemd>`__\n-  on\n   `icinga.com <https://exchange.icinga.com/joseffriedrich/check_systemd>`__\n-  on\n   `nagios.org <https://exchange.nagios.org/directory/Plugins/System-Metrics/Processes/check_systemd/details>`__\n\nBehind the scenes\n-----------------\n\nTo detect failed units this monitoring script runs:\n\n.. code:: sh\n\n   systemctl list-units --all\n\nTo get the startup time it executes:\n\n.. code:: sh\n\n   systemd-analyze\n\nTo find dead timers this plugin launches:\n\n.. code:: sh\n\n   systemctl list-timers --all\n\nTo learn how ``systemd`` produces the text output on the command line,\nit is worthwhile to take a look at ``systemd``\\ \u2019s source code. Files\nrelevant for text output are:\n`basic/time-util.c <https://github.com/systemd/systemd/blob/main/src/basic/time-util.c>`__,\n`analyze/analyze.c <https://github.com/systemd/systemd/blob/main/src/analyze/analyze.c>`__.\n\nTesting\n-------\n\n::\n\n   pyenv install 3.6.12\n   pyenv install 3.7.9\n   pyenv local 3.6.12 3.7.9\n   pip3 install tox\n   tox\n\nTest a single test case:\n\n::\n\n   tox -e py38 -- test/test_scope_timers.py:TestScopeTimers.test_all_n_a\n\nDeploying\n---------\n\nEdit the version number in check_systemd.py (without ``v``). Use the\n``-s`` option to sign the tag (required for the Debian package).\n\n::\n\n   git tag -s v2.0.11\n   git push --tags\n",
    "bugtrack_url": null,
    "license": "LGPL-2.1-only",
    "summary": "Nagios / Icinga monitoring plugin to check systemd for failed units.",
    "version": "4.1.0",
    "project_urls": {
        "Homepage": "https://github.com/Josef-Friedrich/check_systemd",
        "Repository": "https://github.com/Josef-Friedrich/check_systemd"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9ef3c7a483e6d2468c39f5849c12427af334f0ed53f721cfecd1e2ab37c6eaf5",
                "md5": "1f31e5c10190b9e93d0e3ce2bfd51c06",
                "sha256": "2fe4aae3c1ee53f35274cbf63a03c5a450f88c91a808a819023d94294df9e414"
            },
            "downloads": -1,
            "filename": "check_systemd-4.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1f31e5c10190b9e93d0e3ce2bfd51c06",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 27259,
            "upload_time": "2024-03-01T17:52:36",
            "upload_time_iso_8601": "2024-03-01T17:52:36.951164Z",
            "url": "https://files.pythonhosted.org/packages/9e/f3/c7a483e6d2468c39f5849c12427af334f0ed53f721cfecd1e2ab37c6eaf5/check_systemd-4.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1cbadd4507ed699deaf27d7f9b6aed6e5c84d00e9796ef56ed3c5fe215c1315f",
                "md5": "65aa2d649d8bb6f6e6ccd6f35ed4bed1",
                "sha256": "b90027879cf6f9df97ab50b11c237c14e8aca649471a18456c2fc73a30a5a7db"
            },
            "downloads": -1,
            "filename": "check_systemd-4.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "65aa2d649d8bb6f6e6ccd6f35ed4bed1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 28169,
            "upload_time": "2024-03-01T17:52:38",
            "upload_time_iso_8601": "2024-03-01T17:52:38.443986Z",
            "url": "https://files.pythonhosted.org/packages/1c/ba/dd4507ed699deaf27d7f9b6aed6e5c84d00e9796ef56ed3c5fe215c1315f/check_systemd-4.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-01 17:52:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Josef-Friedrich",
    "github_project": "check_systemd",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "check_systemd"
}
        
Elapsed time: 0.19112s