mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
systemd_status: reformat docstring to perlpod format
This commit is contained in:
parent
ca27b12937
commit
f8fef4cf73
1 changed files with 45 additions and 19 deletions
|
@ -1,14 +1,40 @@
|
|||
#!/usr/bin/python3 -tt
|
||||
# -*- coding: utf-8 -*-
|
||||
#!/usr/bin/env python3
|
||||
# pylint: disable=invalid-name
|
||||
# pylint: enable=invalid-name
|
||||
|
||||
"""Munin plugin to monitor systemd service status.
|
||||
Copyright 2018, Kim B. Heino, b@bbbs.net, Foobar Oy
|
||||
License GPLv2+
|
||||
|
||||
#%# capabilities=autoconf
|
||||
#%# family=auto
|
||||
=head1 NAME
|
||||
|
||||
systemd_status - monitor systemd service status, including normal services,
|
||||
mounts, hotplugs and socket activations
|
||||
|
||||
=head1 APPLICABLE SYSTEMS
|
||||
|
||||
Linux systems with systemd installed.
|
||||
|
||||
=head1 CONFIGURATION
|
||||
|
||||
No configuration is required for this plugin.
|
||||
|
||||
Warning level for systemd "failed" state is set to 0:0. If any of the services
|
||||
enters "failed" state, Munin will emit warning.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Kim B. Heino <b@bbbs.net>
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
GPLv2
|
||||
|
||||
=head1 MAGIC MARKERS
|
||||
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
=cut
|
||||
|
||||
"""
|
||||
|
||||
import os
|
||||
|
@ -49,26 +75,26 @@ def fetch():
|
|||
"""Print runtime values."""
|
||||
# Get data
|
||||
try:
|
||||
output = subprocess.check_output([
|
||||
'/bin/systemctl',
|
||||
'list-units']) # deb9/py3.5 doesn't have encoding parameter
|
||||
# deb9/py3.5 doesn't have encoding parameter in subprocess
|
||||
output = subprocess.check_output(['/bin/systemctl', 'list-units'])
|
||||
except (OSError, subprocess.CalledProcessError):
|
||||
return
|
||||
output = output.decode('utf-8', 'ignore')
|
||||
|
||||
# Parse data
|
||||
states = {state: 0 for state in STATES}
|
||||
for line in output.splitlines():
|
||||
line = line.decode('utf-8').split()
|
||||
if len(line) < 4:
|
||||
token = line.split()
|
||||
if len(token) < 4:
|
||||
continue
|
||||
if len(line[0]) < 3: # Skip failed-bullet
|
||||
line = line[1:]
|
||||
if line[0].endswith('.scope'): # Ignore scopes
|
||||
continue
|
||||
if re.match(r'user.*@\d+\.service', line[0]):
|
||||
continue
|
||||
if line[3] in states:
|
||||
states[line[3]] = states[line[3]] + 1
|
||||
if len(token[0]) < 3: # Skip failed-bullet
|
||||
token = token[1:]
|
||||
if token[0].endswith('.scope'):
|
||||
continue # Ignore scopes
|
||||
if re.match(r'user.*@\d+\.service', token[0]):
|
||||
continue # These fail randomly in older systemd
|
||||
if token[3] in states:
|
||||
states[token[3]] = states[token[3]] + 1
|
||||
|
||||
# Output
|
||||
for state in STATES:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue