Projet

Général

Profil

Révision f8fef4cf

IDf8fef4cf736b00cc363bdf912b3d187fb5299d0f
Parent ca27b129
Enfant 0791c99e

Ajouté par Kim B. Heino il y a presque 5 ans

systemd_status: reformat docstring to perlpod format

Voir les différences:

plugins/systemd/systemd_status
1
#!/usr/bin/python3 -tt
2
# -*- coding: utf-8 -*-
1
#!/usr/bin/env python3
3 2
# pylint: disable=invalid-name
4 3
# pylint: enable=invalid-name
5 4

  
6 5
"""Munin plugin to monitor systemd service status.
7
Copyright 2018, Kim B. Heino, b@bbbs.net, Foobar Oy
8
License GPLv2+
9 6

  
10
#%# capabilities=autoconf
11
#%# family=auto
7
=head1 NAME
8

  
9
systemd_status - monitor systemd service status, including normal services,
10
mounts, hotplugs and socket activations
11

  
12
=head1 APPLICABLE SYSTEMS
13

  
14
Linux systems with systemd installed.
15

  
16
=head1 CONFIGURATION
17

  
18
No configuration is required for this plugin.
19

  
20
Warning level for systemd "failed" state is set to 0:0. If any of the services
21
enters "failed" state, Munin will emit warning.
22

  
23
=head1 AUTHOR
24

  
25
Kim B. Heino <b@bbbs.net>
26

  
27
=head1 LICENSE
28

  
29
GPLv2
30

  
31
=head1 MAGIC MARKERS
32

  
33
 #%# family=auto
34
 #%# capabilities=autoconf
35

  
36
=cut
37

  
12 38
"""
13 39

  
14 40
import os
......
49 75
    """Print runtime values."""
50 76
    # Get data
51 77
    try:
52
        output = subprocess.check_output([
53
            '/bin/systemctl',
54
            'list-units'])  # deb9/py3.5 doesn't have encoding parameter
78
        # deb9/py3.5 doesn't have encoding parameter in subprocess
79
        output = subprocess.check_output(['/bin/systemctl', 'list-units'])
55 80
    except (OSError, subprocess.CalledProcessError):
56 81
        return
82
    output = output.decode('utf-8', 'ignore')
57 83

  
58 84
    # Parse data
59 85
    states = {state: 0 for state in STATES}
60 86
    for line in output.splitlines():
61
        line = line.decode('utf-8').split()
62
        if len(line) < 4:
63
            continue
64
        if len(line[0]) < 3:  # Skip failed-bullet
65
            line = line[1:]
66
        if line[0].endswith('.scope'):  # Ignore scopes
67
            continue
68
        if re.match(r'user.*@\d+\.service', line[0]):
87
        token = line.split()
88
        if len(token) < 4:
69 89
            continue
70
        if line[3] in states:
71
            states[line[3]] = states[line[3]] + 1
90
        if len(token[0]) < 3:  # Skip failed-bullet
91
            token = token[1:]
92
        if token[0].endswith('.scope'):
93
            continue  # Ignore scopes
94
        if re.match(r'user.*@\d+\.service', token[0]):
95
            continue  # These fail randomly in older systemd
96
        if token[3] in states:
97
            states[token[3]] = states[token[3]] + 1
72 98

  
73 99
    # Output
74 100
    for state in STATES:

Formats disponibles : Unified diff