check_systemd 2.0.2__tar.gz → 2.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- check_systemd-2.0.4/MANIFEST.in +3 -0
- check_systemd-2.0.4/PKG-INFO +86 -0
- check_systemd-2.0.4/README.md +65 -0
- check_systemd-2.0.4/check_systemd.egg-info/PKG-INFO +86 -0
- {check_systemd-2.0.2 → check_systemd-2.0.4}/check_systemd.egg-info/SOURCES.txt +1 -0
- check_systemd-2.0.4/check_systemd.egg-info/entry_points.txt +3 -0
- check_systemd-2.0.4/check_systemd.py +367 -0
- {check_systemd-2.0.2 → check_systemd-2.0.4}/setup.py +9 -2
- check_systemd-2.0.2/MANIFEST.in +0 -2
- check_systemd-2.0.2/PKG-INFO +0 -33
- check_systemd-2.0.2/README.md +0 -12
- check_systemd-2.0.2/check_systemd.egg-info/PKG-INFO +0 -33
- check_systemd-2.0.2/check_systemd.py +0 -146
- {check_systemd-2.0.2 → check_systemd-2.0.4}/LICENSE +0 -0
- {check_systemd-2.0.2 → check_systemd-2.0.4}/check_systemd.egg-info/dependency_links.txt +0 -0
- {check_systemd-2.0.2 → check_systemd-2.0.4}/check_systemd.egg-info/requires.txt +0 -0
- {check_systemd-2.0.2 → check_systemd-2.0.4}/check_systemd.egg-info/top_level.txt +0 -0
- {check_systemd-2.0.2 → check_systemd-2.0.4}/setup.cfg +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: check_systemd
|
|
3
|
+
Version: 2.0.4
|
|
4
|
+
Summary: Nagios / Icinga monitoring plugin to check systemd for failed units.
|
|
5
|
+
Home-page: https://github.com/Josef-Friedrich/check_systemd
|
|
6
|
+
Author: Josef Friedrich
|
|
7
|
+
Author-email: josef@friedrich.rocks
|
|
8
|
+
License: GNU LGPL v2
|
|
9
|
+
Description: [](https://pypi.python.org/pypi/check_systemd)
|
|
10
|
+
[](https://travis-ci.org/Josef-Friedrich/check_systemd)
|
|
11
|
+
|
|
12
|
+
# check_systemd
|
|
13
|
+
|
|
14
|
+
Nagios / Icinga monitoring plugin to check systemd for failed units.
|
|
15
|
+
|
|
16
|
+
This Python script will report a degraded system to Nagios / Icinage.
|
|
17
|
+
It requires only the nagiosplugin library.
|
|
18
|
+
|
|
19
|
+
You can also test a single service with -s parameter.
|
|
20
|
+
|
|
21
|
+
Released under GNU GPLv2 License.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
pip3 install check_systemd
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Command line interface
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
usage: nosetests [-h] [-c SECONDS] [-e UNIT | -u UNIT] [-v] [-V] [-w SECONDS]
|
|
33
|
+
|
|
34
|
+
Copyright (c) 2014-18 Andrea Briganti a.k.a 'Kbyte' <kbytesys@gmail.com>
|
|
35
|
+
Copyright (c) 2019 Josef Friedrich <josef@friedrich.rocks>
|
|
36
|
+
|
|
37
|
+
Nagios / Icinga monitoring plugin to check systemd for failed units.
|
|
38
|
+
|
|
39
|
+
optional arguments:
|
|
40
|
+
-h, --help show this help message and exit
|
|
41
|
+
-c SECONDS, --critical SECONDS
|
|
42
|
+
Startup time in seconds to result in critical status.
|
|
43
|
+
-e UNIT, --exclude UNIT
|
|
44
|
+
Exclude a systemd unit from the checks. This option
|
|
45
|
+
can be applied multiple times. For example: -e mnt-
|
|
46
|
+
data.mount -e task.service.
|
|
47
|
+
-u UNIT, --unit UNIT Name of the systemd unit that is beeing tested.
|
|
48
|
+
-v, --verbose Increase output verbosity (use up to 3 times).
|
|
49
|
+
-V, --version show program's version number and exit
|
|
50
|
+
-w SECONDS, --warning SECONDS
|
|
51
|
+
Startup time in seconds to result in warning status.
|
|
52
|
+
|
|
53
|
+
Performance data:
|
|
54
|
+
- count_units
|
|
55
|
+
- startup_time
|
|
56
|
+
- units_activating
|
|
57
|
+
- units_active
|
|
58
|
+
- units_failed
|
|
59
|
+
- units_inactive
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Project pages
|
|
64
|
+
|
|
65
|
+
* https://github.com/Josef-Friedrich/check_systemd
|
|
66
|
+
* https://exchange.icinga.com/joseffriedrich/check_systemd
|
|
67
|
+
|
|
68
|
+
## Testing
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
pip3 install tox
|
|
72
|
+
tox
|
|
73
|
+
```
|
|
74
|
+
Keywords: nagios,systemd
|
|
75
|
+
Platform: UNKNOWN
|
|
76
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
77
|
+
Classifier: Environment :: Plugins
|
|
78
|
+
Classifier: Intended Audience :: System Administrators
|
|
79
|
+
Classifier: License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)
|
|
80
|
+
Classifier: Programming Language :: Python
|
|
81
|
+
Classifier: Programming Language :: Python :: 3
|
|
82
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
83
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
84
|
+
Classifier: Topic :: System :: Networking :: Monitoring
|
|
85
|
+
Requires-Python: >=3.6
|
|
86
|
+
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[](https://pypi.python.org/pypi/check_systemd)
|
|
2
|
+
[](https://travis-ci.org/Josef-Friedrich/check_systemd)
|
|
3
|
+
|
|
4
|
+
# check_systemd
|
|
5
|
+
|
|
6
|
+
Nagios / Icinga monitoring plugin to check systemd for failed units.
|
|
7
|
+
|
|
8
|
+
This Python script will report a degraded system to Nagios / Icinage.
|
|
9
|
+
It requires only the nagiosplugin library.
|
|
10
|
+
|
|
11
|
+
You can also test a single service with -s parameter.
|
|
12
|
+
|
|
13
|
+
Released under GNU GPLv2 License.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
pip3 install check_systemd
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Command line interface
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
usage: nosetests [-h] [-c SECONDS] [-e UNIT | -u UNIT] [-v] [-V] [-w SECONDS]
|
|
25
|
+
|
|
26
|
+
Copyright (c) 2014-18 Andrea Briganti a.k.a 'Kbyte' <kbytesys@gmail.com>
|
|
27
|
+
Copyright (c) 2019 Josef Friedrich <josef@friedrich.rocks>
|
|
28
|
+
|
|
29
|
+
Nagios / Icinga monitoring plugin to check systemd for failed units.
|
|
30
|
+
|
|
31
|
+
optional arguments:
|
|
32
|
+
-h, --help show this help message and exit
|
|
33
|
+
-c SECONDS, --critical SECONDS
|
|
34
|
+
Startup time in seconds to result in critical status.
|
|
35
|
+
-e UNIT, --exclude UNIT
|
|
36
|
+
Exclude a systemd unit from the checks. This option
|
|
37
|
+
can be applied multiple times. For example: -e mnt-
|
|
38
|
+
data.mount -e task.service.
|
|
39
|
+
-u UNIT, --unit UNIT Name of the systemd unit that is beeing tested.
|
|
40
|
+
-v, --verbose Increase output verbosity (use up to 3 times).
|
|
41
|
+
-V, --version show program's version number and exit
|
|
42
|
+
-w SECONDS, --warning SECONDS
|
|
43
|
+
Startup time in seconds to result in warning status.
|
|
44
|
+
|
|
45
|
+
Performance data:
|
|
46
|
+
- count_units
|
|
47
|
+
- startup_time
|
|
48
|
+
- units_activating
|
|
49
|
+
- units_active
|
|
50
|
+
- units_failed
|
|
51
|
+
- units_inactive
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Project pages
|
|
56
|
+
|
|
57
|
+
* https://github.com/Josef-Friedrich/check_systemd
|
|
58
|
+
* https://exchange.icinga.com/joseffriedrich/check_systemd
|
|
59
|
+
|
|
60
|
+
## Testing
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
pip3 install tox
|
|
64
|
+
tox
|
|
65
|
+
```
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: check-systemd
|
|
3
|
+
Version: 2.0.4
|
|
4
|
+
Summary: Nagios / Icinga monitoring plugin to check systemd for failed units.
|
|
5
|
+
Home-page: https://github.com/Josef-Friedrich/check_systemd
|
|
6
|
+
Author: Josef Friedrich
|
|
7
|
+
Author-email: josef@friedrich.rocks
|
|
8
|
+
License: GNU LGPL v2
|
|
9
|
+
Description: [](https://pypi.python.org/pypi/check_systemd)
|
|
10
|
+
[](https://travis-ci.org/Josef-Friedrich/check_systemd)
|
|
11
|
+
|
|
12
|
+
# check_systemd
|
|
13
|
+
|
|
14
|
+
Nagios / Icinga monitoring plugin to check systemd for failed units.
|
|
15
|
+
|
|
16
|
+
This Python script will report a degraded system to Nagios / Icinage.
|
|
17
|
+
It requires only the nagiosplugin library.
|
|
18
|
+
|
|
19
|
+
You can also test a single service with -s parameter.
|
|
20
|
+
|
|
21
|
+
Released under GNU GPLv2 License.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
pip3 install check_systemd
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Command line interface
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
usage: nosetests [-h] [-c SECONDS] [-e UNIT | -u UNIT] [-v] [-V] [-w SECONDS]
|
|
33
|
+
|
|
34
|
+
Copyright (c) 2014-18 Andrea Briganti a.k.a 'Kbyte' <kbytesys@gmail.com>
|
|
35
|
+
Copyright (c) 2019 Josef Friedrich <josef@friedrich.rocks>
|
|
36
|
+
|
|
37
|
+
Nagios / Icinga monitoring plugin to check systemd for failed units.
|
|
38
|
+
|
|
39
|
+
optional arguments:
|
|
40
|
+
-h, --help show this help message and exit
|
|
41
|
+
-c SECONDS, --critical SECONDS
|
|
42
|
+
Startup time in seconds to result in critical status.
|
|
43
|
+
-e UNIT, --exclude UNIT
|
|
44
|
+
Exclude a systemd unit from the checks. This option
|
|
45
|
+
can be applied multiple times. For example: -e mnt-
|
|
46
|
+
data.mount -e task.service.
|
|
47
|
+
-u UNIT, --unit UNIT Name of the systemd unit that is beeing tested.
|
|
48
|
+
-v, --verbose Increase output verbosity (use up to 3 times).
|
|
49
|
+
-V, --version show program's version number and exit
|
|
50
|
+
-w SECONDS, --warning SECONDS
|
|
51
|
+
Startup time in seconds to result in warning status.
|
|
52
|
+
|
|
53
|
+
Performance data:
|
|
54
|
+
- count_units
|
|
55
|
+
- startup_time
|
|
56
|
+
- units_activating
|
|
57
|
+
- units_active
|
|
58
|
+
- units_failed
|
|
59
|
+
- units_inactive
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Project pages
|
|
64
|
+
|
|
65
|
+
* https://github.com/Josef-Friedrich/check_systemd
|
|
66
|
+
* https://exchange.icinga.com/joseffriedrich/check_systemd
|
|
67
|
+
|
|
68
|
+
## Testing
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
pip3 install tox
|
|
72
|
+
tox
|
|
73
|
+
```
|
|
74
|
+
Keywords: nagios,systemd
|
|
75
|
+
Platform: UNKNOWN
|
|
76
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
77
|
+
Classifier: Environment :: Plugins
|
|
78
|
+
Classifier: Intended Audience :: System Administrators
|
|
79
|
+
Classifier: License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)
|
|
80
|
+
Classifier: Programming Language :: Python
|
|
81
|
+
Classifier: Programming Language :: Python :: 3
|
|
82
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
83
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
84
|
+
Classifier: Topic :: System :: Networking :: Monitoring
|
|
85
|
+
Requires-Python: >=3.6
|
|
86
|
+
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
You can redistribute it and/or modify it under the terms of the GNU General
|
|
5
|
+
Public License as published by the Free Software Foundation, either version 2
|
|
6
|
+
of the License.
|
|
7
|
+
Copyright 2014-18 Andrea Briganti a.k.a 'Kbyte'
|
|
8
|
+
Copyright 2019 Josef Friedrich
|
|
9
|
+
"""
|
|
10
|
+
import io
|
|
11
|
+
import subprocess
|
|
12
|
+
import argparse
|
|
13
|
+
import re
|
|
14
|
+
|
|
15
|
+
import nagiosplugin
|
|
16
|
+
from nagiosplugin import Metric
|
|
17
|
+
|
|
18
|
+
__version__ = '2.0.4'
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SystemdctlListUnitsResource(nagiosplugin.Resource):
|
|
22
|
+
"""
|
|
23
|
+
:param list excludes: A list of systemd unit names.
|
|
24
|
+
"""
|
|
25
|
+
name = 'SYSTEMD'
|
|
26
|
+
|
|
27
|
+
def __init__(self, excludes=[]):
|
|
28
|
+
self.excludes = excludes
|
|
29
|
+
|
|
30
|
+
def probe(self):
|
|
31
|
+
"""Query system state and return metrics.
|
|
32
|
+
|
|
33
|
+
:return: generator that emits
|
|
34
|
+
:class:`~nagiosplugin.metric.Metric` objects
|
|
35
|
+
"""
|
|
36
|
+
# We don’t use `systemctl --failed --no-legend`, because we want to
|
|
37
|
+
# collect performance data of all units.
|
|
38
|
+
try:
|
|
39
|
+
p = subprocess.Popen(['systemctl', 'list-units', '--all',
|
|
40
|
+
'--no-legend'],
|
|
41
|
+
stderr=subprocess.PIPE,
|
|
42
|
+
stdin=subprocess.PIPE,
|
|
43
|
+
stdout=subprocess.PIPE)
|
|
44
|
+
stdout, stderr = p.communicate()
|
|
45
|
+
except OSError as e:
|
|
46
|
+
raise nagiosplugin.CheckError(e)
|
|
47
|
+
|
|
48
|
+
if stderr:
|
|
49
|
+
raise nagiosplugin.CheckError(stderr)
|
|
50
|
+
|
|
51
|
+
# Dictionary to store all units according their active state.
|
|
52
|
+
units = {
|
|
53
|
+
'failed': [],
|
|
54
|
+
'active': [],
|
|
55
|
+
'activating': [],
|
|
56
|
+
'inactive': [],
|
|
57
|
+
}
|
|
58
|
+
if stdout:
|
|
59
|
+
# Output of `systemctl list-units --all --no-legend`:
|
|
60
|
+
# UNIT LOAD ACTIVE SUB JOB DESCRIPTION
|
|
61
|
+
# foobar.service loaded active waiting Description text
|
|
62
|
+
count_units = 0
|
|
63
|
+
for line in io.StringIO(stdout.decode('utf-8')):
|
|
64
|
+
split_line = line.split()
|
|
65
|
+
# foobar.service
|
|
66
|
+
unit = split_line[0]
|
|
67
|
+
# failed
|
|
68
|
+
active = split_line[2]
|
|
69
|
+
# Only count not excludes units.
|
|
70
|
+
if unit not in self.excludes:
|
|
71
|
+
units[active].append(unit)
|
|
72
|
+
count_units += 1
|
|
73
|
+
|
|
74
|
+
for unit in units['failed']:
|
|
75
|
+
if unit not in self.excludes:
|
|
76
|
+
yield Metric(name=unit, value='failed', context='unit')
|
|
77
|
+
|
|
78
|
+
for active, unit_names in units.items():
|
|
79
|
+
yield Metric(name='units_{}'.format(active),
|
|
80
|
+
value=len(units[active]),
|
|
81
|
+
context='performance_data')
|
|
82
|
+
|
|
83
|
+
yield Metric(name='count_units', value=count_units,
|
|
84
|
+
context='performance_data')
|
|
85
|
+
|
|
86
|
+
if len(units['failed']) == 0:
|
|
87
|
+
yield Metric(name='all', value=None, context='unit')
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def format_timespan_to_seconds(fmt_timespan):
|
|
91
|
+
"""Convert a timespan format string into secondes.
|
|
92
|
+
|
|
93
|
+
:param str fmt_timespan: for example `2.345s` or `3min 45.234s`
|
|
94
|
+
|
|
95
|
+
:return: The seconds
|
|
96
|
+
:rtype: float
|
|
97
|
+
"""
|
|
98
|
+
seconds = {
|
|
99
|
+
'y': 365 * 24 * 60 * 60,
|
|
100
|
+
'month': 30 * 24 * 60 * 60,
|
|
101
|
+
'w': 7 * 24 * 60 * 60,
|
|
102
|
+
'd': 24 * 60 * 60,
|
|
103
|
+
'h': 60 * 60,
|
|
104
|
+
'min': 60,
|
|
105
|
+
's': 1,
|
|
106
|
+
}
|
|
107
|
+
result = 0
|
|
108
|
+
for span in fmt_timespan.split():
|
|
109
|
+
match = re.search(r'([\d\.]+)([a-z]+)', span)
|
|
110
|
+
value = match.group(1)
|
|
111
|
+
unit = match.group(2)
|
|
112
|
+
result += float(value) * seconds[unit]
|
|
113
|
+
return round(float(result), 3)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class SystemdAnalyseResource(nagiosplugin.Resource):
|
|
117
|
+
|
|
118
|
+
name = 'SYSTEMD'
|
|
119
|
+
|
|
120
|
+
def probe(self):
|
|
121
|
+
"""Query system state and return metrics.
|
|
122
|
+
|
|
123
|
+
:return: generator that emits
|
|
124
|
+
:class:`~nagiosplugin.metric.Metric` objects
|
|
125
|
+
"""
|
|
126
|
+
try:
|
|
127
|
+
p = subprocess.Popen(['systemd-analyze'],
|
|
128
|
+
stderr=subprocess.PIPE,
|
|
129
|
+
stdin=subprocess.PIPE,
|
|
130
|
+
stdout=subprocess.PIPE)
|
|
131
|
+
stdout, stderr = p.communicate()
|
|
132
|
+
except OSError as e:
|
|
133
|
+
raise nagiosplugin.CheckError(e)
|
|
134
|
+
|
|
135
|
+
if stderr:
|
|
136
|
+
raise nagiosplugin.CheckError(stderr)
|
|
137
|
+
|
|
138
|
+
if stdout:
|
|
139
|
+
stdout = stdout.decode('utf-8')
|
|
140
|
+
# First line:
|
|
141
|
+
# Startup finished in 1.672s (kernel) + 21.378s (userspace) =
|
|
142
|
+
# 23.050s
|
|
143
|
+
|
|
144
|
+
# On raspian no second line
|
|
145
|
+
# Second line:
|
|
146
|
+
# graphical.target reached after 1min 2.154s in userspace
|
|
147
|
+
match = re.search(r'reached after (.+) in userspace', stdout)
|
|
148
|
+
|
|
149
|
+
if not match:
|
|
150
|
+
match = re.search(r' = (.+)\n', stdout)
|
|
151
|
+
|
|
152
|
+
yield Metric(name='startup_time',
|
|
153
|
+
value=format_timespan_to_seconds(match.group(1)),
|
|
154
|
+
context='startup_time')
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class SystemctlIsActiveResource(nagiosplugin.Resource):
|
|
158
|
+
|
|
159
|
+
name = 'SYSTEMD'
|
|
160
|
+
|
|
161
|
+
def __init__(self, *args, **kwargs):
|
|
162
|
+
self.unit = kwargs.pop('unit')
|
|
163
|
+
super(nagiosplugin.Resource, self).__init__(*args, **kwargs)
|
|
164
|
+
|
|
165
|
+
def probe(self):
|
|
166
|
+
"""Query system state and return metrics.
|
|
167
|
+
|
|
168
|
+
:return: generator that emits
|
|
169
|
+
:class:`~nagiosplugin.metric.Metric` objects
|
|
170
|
+
"""
|
|
171
|
+
# Execute `systemctl is-active <service>` and get output
|
|
172
|
+
# - active
|
|
173
|
+
# - inactive (by unkown unit file)
|
|
174
|
+
# - failed
|
|
175
|
+
try:
|
|
176
|
+
p = subprocess.Popen(['systemctl', 'is-active', self.unit],
|
|
177
|
+
stderr=subprocess.PIPE,
|
|
178
|
+
stdin=subprocess.PIPE,
|
|
179
|
+
stdout=subprocess.PIPE)
|
|
180
|
+
stdout, stderr = p.communicate()
|
|
181
|
+
except OSError as e:
|
|
182
|
+
raise nagiosplugin.CheckError(e)
|
|
183
|
+
|
|
184
|
+
if stderr:
|
|
185
|
+
raise nagiosplugin.CheckError(stderr)
|
|
186
|
+
if stdout:
|
|
187
|
+
for line in io.StringIO(stdout.decode('utf-8')):
|
|
188
|
+
active = line.strip()
|
|
189
|
+
yield Metric(name=self.unit, value=active, context='unit')
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
class UnitContext(nagiosplugin.Context):
|
|
193
|
+
|
|
194
|
+
def __init__(self):
|
|
195
|
+
super(UnitContext, self).__init__('unit')
|
|
196
|
+
|
|
197
|
+
def evaluate(self, metric, resource):
|
|
198
|
+
"""Determines state of a given metric.
|
|
199
|
+
|
|
200
|
+
:param metric: associated metric that is to be evaluated
|
|
201
|
+
:param resource: resource that produced the associated metric
|
|
202
|
+
(may optionally be consulted)
|
|
203
|
+
:returns: :class:`~.result.Result`
|
|
204
|
+
"""
|
|
205
|
+
hint = '%s: %s' % (metric.name, metric.value) \
|
|
206
|
+
if metric.value else metric.name
|
|
207
|
+
if metric.value and metric.value != 'active':
|
|
208
|
+
return self.result_cls(nagiosplugin.Critical, metric=metric,
|
|
209
|
+
hint=hint)
|
|
210
|
+
else:
|
|
211
|
+
return self.result_cls(nagiosplugin.Ok, metric=metric, hint=hint)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
class PerformanceDataContext(nagiosplugin.Context):
|
|
215
|
+
|
|
216
|
+
def __init__(self):
|
|
217
|
+
super(PerformanceDataContext, self).__init__('performance_data')
|
|
218
|
+
|
|
219
|
+
def performance(self, metric, resource):
|
|
220
|
+
"""Derives performance data from a given metric.
|
|
221
|
+
|
|
222
|
+
:param metric: associated metric from which performance data are
|
|
223
|
+
derived
|
|
224
|
+
:param resource: resource that produced the associated metric
|
|
225
|
+
(may optionally be consulted)
|
|
226
|
+
|
|
227
|
+
:returns: :class:`Perfdata` object
|
|
228
|
+
"""
|
|
229
|
+
return nagiosplugin.Performance(label=metric.name, value=metric.value)
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
class SystemdSummary(nagiosplugin.Summary):
|
|
233
|
+
|
|
234
|
+
def ok(self, results):
|
|
235
|
+
"""Formats status line when overall state is ok.
|
|
236
|
+
|
|
237
|
+
:param results: :class:`~nagiosplugin.result.Results` container
|
|
238
|
+
:returns: status line
|
|
239
|
+
"""
|
|
240
|
+
for result in results.most_significant:
|
|
241
|
+
if isinstance(result.context, UnitContext):
|
|
242
|
+
return '{0}'.format(result)
|
|
243
|
+
return 'all'
|
|
244
|
+
|
|
245
|
+
def problem(self, results):
|
|
246
|
+
"""Formats status line when overall state is not ok.
|
|
247
|
+
|
|
248
|
+
:param results: :class:`~.result.Results` container
|
|
249
|
+
:returns: status line
|
|
250
|
+
"""
|
|
251
|
+
summary = []
|
|
252
|
+
for result in results.most_significant:
|
|
253
|
+
if result.context.name in ['startup_time', 'unit']:
|
|
254
|
+
summary.append(result)
|
|
255
|
+
return ', '.join(['{0}'.format(result) for result in summary])
|
|
256
|
+
|
|
257
|
+
def verbose(self, results):
|
|
258
|
+
"""Provides extra lines if verbose plugin execution is requested.
|
|
259
|
+
|
|
260
|
+
:param results: :class:`~.result.Results` container
|
|
261
|
+
:returns: list of strings
|
|
262
|
+
"""
|
|
263
|
+
summary = []
|
|
264
|
+
for result in results.most_significant:
|
|
265
|
+
if result.context.name in ['startup_time', 'unit']:
|
|
266
|
+
summary.append('{0}: {1}'.format(result.state, result))
|
|
267
|
+
return summary
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def get_argparser():
|
|
271
|
+
parser = argparse.ArgumentParser(
|
|
272
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
273
|
+
description= # noqa: E251
|
|
274
|
+
'Copyright (c) 2014-18 Andrea Briganti a.k.a \'Kbyte\' <kbytesys@gmail.com>\n' # noqa: E501
|
|
275
|
+
'Copyright (c) 2019 Josef Friedrich <josef@friedrich.rocks>\n'
|
|
276
|
+
'\n'
|
|
277
|
+
'Nagios / Icinga monitoring plugin to check systemd for failed units.\n', # noqa: E501
|
|
278
|
+
epilog= # noqa: E251
|
|
279
|
+
'Performance data:\n'
|
|
280
|
+
' - count_units\n'
|
|
281
|
+
' - startup_time\n'
|
|
282
|
+
' - units_activating\n'
|
|
283
|
+
' - units_active\n'
|
|
284
|
+
' - units_failed\n'
|
|
285
|
+
' - units_inactive\n',
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
exclusive_group = parser.add_mutually_exclusive_group()
|
|
289
|
+
|
|
290
|
+
parser.add_argument(
|
|
291
|
+
'-c', '--critical',
|
|
292
|
+
metavar='SECONDS',
|
|
293
|
+
default=120,
|
|
294
|
+
help='Startup time in seconds to result in critical status.',
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
exclusive_group.add_argument(
|
|
298
|
+
'-e', '--exclude',
|
|
299
|
+
metavar='UNIT',
|
|
300
|
+
action='append',
|
|
301
|
+
default=[],
|
|
302
|
+
help='Exclude a systemd unit from the checks. This option can be '
|
|
303
|
+
'applied multiple times. For example: -e mnt-data.mount -e '
|
|
304
|
+
'task.service.',
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
exclusive_group.add_argument(
|
|
308
|
+
'-u', '--unit',
|
|
309
|
+
type=str,
|
|
310
|
+
dest='unit',
|
|
311
|
+
help='Name of the systemd unit that is beeing tested.',
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
parser.add_argument(
|
|
315
|
+
'-v', '--verbose',
|
|
316
|
+
action='count',
|
|
317
|
+
default=0,
|
|
318
|
+
help='Increase output verbosity (use up to 3 times).'
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
parser.add_argument(
|
|
322
|
+
'-V', '--version',
|
|
323
|
+
action='version',
|
|
324
|
+
version='%(prog)s {}'.format(__version__),
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
parser.add_argument(
|
|
328
|
+
'-w', '--warning',
|
|
329
|
+
default=60,
|
|
330
|
+
metavar='SECONDS',
|
|
331
|
+
help='Startup time in seconds to result in warning status.',
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
return parser
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
@nagiosplugin.guarded
|
|
338
|
+
def main():
|
|
339
|
+
args = get_argparser().parse_args()
|
|
340
|
+
|
|
341
|
+
objects = []
|
|
342
|
+
|
|
343
|
+
if args.unit:
|
|
344
|
+
objects.append(SystemctlIsActiveResource(unit=args.unit))
|
|
345
|
+
else:
|
|
346
|
+
objects += [
|
|
347
|
+
SystemdctlListUnitsResource(excludes=args.exclude),
|
|
348
|
+
PerformanceDataContext(),
|
|
349
|
+
SystemdAnalyseResource(),
|
|
350
|
+
]
|
|
351
|
+
|
|
352
|
+
objects += [
|
|
353
|
+
UnitContext(),
|
|
354
|
+
nagiosplugin.ScalarContext(
|
|
355
|
+
name='startup_time',
|
|
356
|
+
warning=args.warning,
|
|
357
|
+
critical=args.critical,
|
|
358
|
+
),
|
|
359
|
+
SystemdSummary()
|
|
360
|
+
]
|
|
361
|
+
|
|
362
|
+
check = nagiosplugin.Check(*objects)
|
|
363
|
+
check.main(args.verbose)
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
if __name__ == '__main__':
|
|
367
|
+
main()
|
|
@@ -31,7 +31,8 @@ setup(
|
|
|
31
31
|
install_requires=[
|
|
32
32
|
'nagiosplugin>=1.2',
|
|
33
33
|
],
|
|
34
|
-
description='
|
|
34
|
+
description='Nagios / Icinga monitoring plugin to check systemd for '
|
|
35
|
+
'failed units.',
|
|
35
36
|
long_description=read('README.md'),
|
|
36
37
|
long_description_content_type='text/markdown',
|
|
37
38
|
author='Josef Friedrich',
|
|
@@ -39,6 +40,7 @@ setup(
|
|
|
39
40
|
url='https://github.com/Josef-Friedrich/check_systemd',
|
|
40
41
|
keywords=['nagios', 'systemd'],
|
|
41
42
|
license='GNU LGPL v2',
|
|
43
|
+
python_requires='>=3.6',
|
|
42
44
|
classifiers=[
|
|
43
45
|
'Development Status :: 5 - Production/Stable',
|
|
44
46
|
'Environment :: Plugins',
|
|
@@ -46,9 +48,14 @@ setup(
|
|
|
46
48
|
'License :: OSI Approved :: GNU Lesser General Public License v2 '
|
|
47
49
|
'(LGPLv2)',
|
|
48
50
|
'Programming Language :: Python',
|
|
49
|
-
'Programming Language :: Python :: 2',
|
|
50
51
|
'Programming Language :: Python :: 3',
|
|
52
|
+
'Programming Language :: Python :: 3.6',
|
|
51
53
|
'Operating System :: POSIX :: Linux',
|
|
52
54
|
'Topic :: System :: Networking :: Monitoring'
|
|
53
55
|
],
|
|
56
|
+
entry_points={
|
|
57
|
+
'console_scripts': [
|
|
58
|
+
'check_systemd = check_systemd:main',
|
|
59
|
+
],
|
|
60
|
+
},
|
|
54
61
|
)
|
check_systemd-2.0.2/MANIFEST.in
DELETED
check_systemd-2.0.2/PKG-INFO
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: check_systemd
|
|
3
|
-
Version: 2.0.2
|
|
4
|
-
Summary: A simple nagios plugin that detects failed systemd units.
|
|
5
|
-
Home-page: https://github.com/Josef-Friedrich/check_systemd
|
|
6
|
-
Author: Josef Friedrich
|
|
7
|
-
Author-email: josef@friedrich.rocks
|
|
8
|
-
License: GNU LGPL v2
|
|
9
|
-
Description: [](https://pypi.python.org/pypi/check_systemd)
|
|
10
|
-
[](https://travis-ci.org/Josef-Friedrich/check_systemd)
|
|
11
|
-
|
|
12
|
-
# check_systemd
|
|
13
|
-
|
|
14
|
-
Simple and easy nagios check for systemd status.
|
|
15
|
-
|
|
16
|
-
This Python script will report a degraded system to nagios and requires only the nagiosplugin library.
|
|
17
|
-
|
|
18
|
-
You can also test a single service with -s parameter.
|
|
19
|
-
|
|
20
|
-
Released under GNU GPLv2 License.
|
|
21
|
-
|
|
22
|
-
Keywords: nagios,systemd
|
|
23
|
-
Platform: UNKNOWN
|
|
24
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
25
|
-
Classifier: Environment :: Plugins
|
|
26
|
-
Classifier: Intended Audience :: System Administrators
|
|
27
|
-
Classifier: License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)
|
|
28
|
-
Classifier: Programming Language :: Python
|
|
29
|
-
Classifier: Programming Language :: Python :: 2
|
|
30
|
-
Classifier: Programming Language :: Python :: 3
|
|
31
|
-
Classifier: Operating System :: POSIX :: Linux
|
|
32
|
-
Classifier: Topic :: System :: Networking :: Monitoring
|
|
33
|
-
Description-Content-Type: text/markdown
|
check_systemd-2.0.2/README.md
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
[](https://pypi.python.org/pypi/check_systemd)
|
|
2
|
-
[](https://travis-ci.org/Josef-Friedrich/check_systemd)
|
|
3
|
-
|
|
4
|
-
# check_systemd
|
|
5
|
-
|
|
6
|
-
Simple and easy nagios check for systemd status.
|
|
7
|
-
|
|
8
|
-
This Python script will report a degraded system to nagios and requires only the nagiosplugin library.
|
|
9
|
-
|
|
10
|
-
You can also test a single service with -s parameter.
|
|
11
|
-
|
|
12
|
-
Released under GNU GPLv2 License.
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: check-systemd
|
|
3
|
-
Version: 2.0.2
|
|
4
|
-
Summary: A simple nagios plugin that detects failed systemd units.
|
|
5
|
-
Home-page: https://github.com/Josef-Friedrich/check_systemd
|
|
6
|
-
Author: Josef Friedrich
|
|
7
|
-
Author-email: josef@friedrich.rocks
|
|
8
|
-
License: GNU LGPL v2
|
|
9
|
-
Description: [](https://pypi.python.org/pypi/check_systemd)
|
|
10
|
-
[](https://travis-ci.org/Josef-Friedrich/check_systemd)
|
|
11
|
-
|
|
12
|
-
# check_systemd
|
|
13
|
-
|
|
14
|
-
Simple and easy nagios check for systemd status.
|
|
15
|
-
|
|
16
|
-
This Python script will report a degraded system to nagios and requires only the nagiosplugin library.
|
|
17
|
-
|
|
18
|
-
You can also test a single service with -s parameter.
|
|
19
|
-
|
|
20
|
-
Released under GNU GPLv2 License.
|
|
21
|
-
|
|
22
|
-
Keywords: nagios,systemd
|
|
23
|
-
Platform: UNKNOWN
|
|
24
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
25
|
-
Classifier: Environment :: Plugins
|
|
26
|
-
Classifier: Intended Audience :: System Administrators
|
|
27
|
-
Classifier: License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)
|
|
28
|
-
Classifier: Programming Language :: Python
|
|
29
|
-
Classifier: Programming Language :: Python :: 2
|
|
30
|
-
Classifier: Programming Language :: Python :: 3
|
|
31
|
-
Classifier: Operating System :: POSIX :: Linux
|
|
32
|
-
Classifier: Topic :: System :: Networking :: Monitoring
|
|
33
|
-
Description-Content-Type: text/markdown
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
"""
|
|
3
|
-
You can redistribute it and/or modify it under the terms of the GNU General
|
|
4
|
-
Public License as published by the Free Software Foundation, either version 2
|
|
5
|
-
of the License.
|
|
6
|
-
Copyright Andrea Briganti a.k.a 'Kbyte'
|
|
7
|
-
"""
|
|
8
|
-
import io
|
|
9
|
-
import subprocess
|
|
10
|
-
import argparse
|
|
11
|
-
|
|
12
|
-
import nagiosplugin
|
|
13
|
-
|
|
14
|
-
__version__ = '2.0.2'
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class SystemdStatus(nagiosplugin.Resource):
|
|
18
|
-
"""
|
|
19
|
-
:param list excludes: A list of systemd unit names.
|
|
20
|
-
"""
|
|
21
|
-
name = 'SYSTEMD'
|
|
22
|
-
|
|
23
|
-
def __init__(self, excludes=[]):
|
|
24
|
-
self.excludes = excludes
|
|
25
|
-
|
|
26
|
-
def probe(self):
|
|
27
|
-
# Execute systemctl --failed --no-legend and get output
|
|
28
|
-
try:
|
|
29
|
-
p = subprocess.Popen(['systemctl', '--failed', '--no-legend'],
|
|
30
|
-
stderr=subprocess.PIPE,
|
|
31
|
-
stdin=subprocess.PIPE,
|
|
32
|
-
stdout=subprocess.PIPE)
|
|
33
|
-
stdout, stderr = p.communicate()
|
|
34
|
-
except OSError as e:
|
|
35
|
-
raise nagiosplugin.CheckError(e)
|
|
36
|
-
|
|
37
|
-
if stderr:
|
|
38
|
-
raise nagiosplugin.CheckError(stderr)
|
|
39
|
-
|
|
40
|
-
if stdout:
|
|
41
|
-
for line in io.StringIO(stdout.decode('utf-8')):
|
|
42
|
-
split_line = line.split()
|
|
43
|
-
unit = split_line[0]
|
|
44
|
-
active = split_line[2]
|
|
45
|
-
if unit not in self.excludes:
|
|
46
|
-
yield nagiosplugin.Metric(unit, active, context='systemd')
|
|
47
|
-
|
|
48
|
-
yield nagiosplugin.Metric('all', None, context='systemd')
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
class ServiceStatus(nagiosplugin.Resource):
|
|
52
|
-
name = 'SYSTEMD'
|
|
53
|
-
|
|
54
|
-
def __init__(self, *args, **kwargs):
|
|
55
|
-
self.service = kwargs.pop('service')
|
|
56
|
-
super(nagiosplugin.Resource, self).__init__(*args, **kwargs)
|
|
57
|
-
|
|
58
|
-
def probe(self):
|
|
59
|
-
# Execute systemctl is-active and get output
|
|
60
|
-
try:
|
|
61
|
-
p = subprocess.Popen(['systemctl', 'is-active', self.service],
|
|
62
|
-
stderr=subprocess.PIPE,
|
|
63
|
-
stdin=subprocess.PIPE,
|
|
64
|
-
stdout=subprocess.PIPE)
|
|
65
|
-
stdout, stderr = p.communicate()
|
|
66
|
-
except OSError as e:
|
|
67
|
-
raise nagiosplugin.CheckError(e)
|
|
68
|
-
|
|
69
|
-
if stderr:
|
|
70
|
-
raise nagiosplugin.CheckError(stderr)
|
|
71
|
-
if stdout:
|
|
72
|
-
for line in io.StringIO(stdout.decode('utf-8')):
|
|
73
|
-
yield nagiosplugin.Metric(self.service, line.strip(),
|
|
74
|
-
context='systemd')
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
class SystemdContext(nagiosplugin.Context):
|
|
78
|
-
|
|
79
|
-
def __init__(self):
|
|
80
|
-
super(SystemdContext, self).__init__('systemd')
|
|
81
|
-
|
|
82
|
-
def evaluate(self, metric, resource):
|
|
83
|
-
hint = '%s: %s' % (metric.name, metric.value) \
|
|
84
|
-
if metric.value else metric.name
|
|
85
|
-
if metric.value and metric.value != 'active':
|
|
86
|
-
return self.result_cls(nagiosplugin.Critical, metric=metric,
|
|
87
|
-
hint=hint)
|
|
88
|
-
else:
|
|
89
|
-
return self.result_cls(nagiosplugin.Ok, metric=metric, hint=hint)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
class SystemdSummary(nagiosplugin.Summary):
|
|
93
|
-
|
|
94
|
-
def problem(self, results):
|
|
95
|
-
return ', '.join(['{0}'.format(result)
|
|
96
|
-
for result in results.most_significant])
|
|
97
|
-
|
|
98
|
-
def verbose(self, results):
|
|
99
|
-
return ['{0}: {1}'.format(result.state, result) for result in results]
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
def main():
|
|
103
|
-
parser = argparse.ArgumentParser()
|
|
104
|
-
exclusive_group = parser.add_mutually_exclusive_group()
|
|
105
|
-
|
|
106
|
-
exclusive_group.add_argument(
|
|
107
|
-
'-e', '--exclude',
|
|
108
|
-
metavar='UNIT',
|
|
109
|
-
action='append',
|
|
110
|
-
default=[],
|
|
111
|
-
help='Exclude a systemd unit from the checks. This option can be '
|
|
112
|
-
'applied multiple times. For example: -e mnt-data.mount -e '
|
|
113
|
-
'task.service'
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
exclusive_group.add_argument(
|
|
117
|
-
'-s', '--service',
|
|
118
|
-
type=str,
|
|
119
|
-
dest='service',
|
|
120
|
-
help='Name of the Service that is beeing tested'
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
parser.add_argument(
|
|
124
|
-
'-v', '--verbose',
|
|
125
|
-
action='count',
|
|
126
|
-
default=0,
|
|
127
|
-
help='Increase output verbosity (use up to 3 times)'
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
args = parser.parse_args()
|
|
131
|
-
|
|
132
|
-
if args.service is None:
|
|
133
|
-
check = nagiosplugin.Check(
|
|
134
|
-
SystemdStatus(excludes=args.exclude),
|
|
135
|
-
SystemdContext(),
|
|
136
|
-
SystemdSummary())
|
|
137
|
-
else:
|
|
138
|
-
check = nagiosplugin.Check(
|
|
139
|
-
ServiceStatus(service=args.service),
|
|
140
|
-
SystemdContext(),
|
|
141
|
-
SystemdSummary())
|
|
142
|
-
check.main(args.verbose)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if __name__ == '__main__':
|
|
146
|
-
main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|