|
0 |
- |
1 |
#!/usr/bin/python2.7 |
1 |
-- |
2 |
# coding: utf-8 |
|
|
3 |
# |
4 |
# Univention Management Console module: |
5 |
# System Diagnosis UMC module |
6 |
# |
7 |
# Copyright 2017 Univention GmbH |
8 |
# |
9 |
# http://www.univention.de/ |
10 |
# |
11 |
# All rights reserved. |
12 |
# |
13 |
# The source code of this program is made available |
14 |
# under the terms of the GNU Affero General Public License version 3 |
15 |
# (GNU AGPL V3) as published by the Free Software Foundation. |
16 |
# |
17 |
# Binary versions of this program provided by Univention to you as |
18 |
# well as other copyrighted, protected or trademarked materials like |
19 |
# Logos, graphics, fonts, specific documentations and configurations, |
20 |
# cryptographic keys etc. are subject to a license agreement between |
21 |
# you and Univention and not subject to the GNU AGPL V3. |
22 |
# |
23 |
# In the case you use this program under the terms of the GNU AGPL V3, |
24 |
# the program is provided in the hope that it will be useful, |
25 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
27 |
# GNU Affero General Public License for more details. |
28 |
# |
29 |
# You should have received a copy of the GNU Affero General Public |
30 |
# License with the Debian GNU/Linux or Univention distribution in file |
31 |
# /usr/share/common-licenses/AGPL-3; if not, see |
32 |
# <http://www.gnu.org/licenses/>. |
33 |
|
34 |
import psutil |
35 |
|
36 |
import univention.config_registry |
37 |
from univention.management.console.modules.diagnostic import Warning, Critical |
38 |
|
39 |
from univention.lib.i18n import Translation |
40 |
_ = Translation('univention-management-console-module-diagnostic').translate |
41 |
|
42 |
title = _('Check free disk space') |
43 |
description = _('Enough free disk space available.') |
44 |
|
45 |
DISK_USAGE_THRESHOLD = 90 |
46 |
|
47 |
|
48 |
def mount_points(): |
49 |
for dp in psutil.disk_partitions(): |
50 |
yield dp.mountpoint |
51 |
|
52 |
|
53 |
def high_disk_usage(): |
54 |
high = ((mp, psutil.disk_usage(mp).percent) for mp in mount_points()) |
55 |
return {mp: pc for (mp, pc) in high if pc > DISK_USAGE_THRESHOLD} |
56 |
|
57 |
|
58 |
def local_repository_exists(): |
59 |
configRegistry = univention.config_registry.ConfigRegistry() |
60 |
configRegistry.load() |
61 |
return configRegistry.is_true('local/repository', False) |
62 |
|
63 |
|
64 |
def is_varlog_own_partition(): |
65 |
mp = set(mount_points()) |
66 |
return '/var' in mp or '/var/log' in mp |
67 |
|
68 |
|
69 |
def high_log_levels(): |
70 |
def is_high(variable, default): |
71 |
return lambda ucr: int(ucr.get(variable, default)) > default |
72 |
|
73 |
def is_on(variable): |
74 |
return lambda ucr: ucr.is_true(variable, False) |
75 |
|
76 |
checks = ( |
77 |
is_high('connector/debug/function', 0), |
78 |
is_high('connector/debug/level', 2), |
79 |
is_high('samba/debug/level', 33), |
80 |
is_high('directory/manager/cmd/debug/level', 0), |
81 |
is_high('dns/debug/level', 0), |
82 |
is_high('dns/dlz/debug/level', 0), |
83 |
is_high('ldap/debug/level', 0), |
84 |
is_high('listener/debug/level', 2), |
85 |
is_high('mail/postfix/ldaptable/debuglevel', 0), |
86 |
is_high('notifier/debug/level', 1), |
87 |
is_high('nscd/debug/level', 0), |
88 |
is_high('stunnel/debuglevel', 4), |
89 |
is_high('umc/module/debug/level', 2), |
90 |
is_high('umc/server/debug/level', 2), |
91 |
is_high('grub/loglevel', 0), |
92 |
is_high('mail/postfix/smtp/tls/loglevel', 0), |
93 |
is_high('mail/postfix/smtpd/tls/loglevel', 0), |
94 |
is_on('kerberos/defaults/debug'), |
95 |
is_on('mail/postfix/smtpd/debug'), |
96 |
is_on('samba4/sysvol/sync/debug'), |
97 |
is_on('aml/idp/ldap/debug'), |
98 |
is_on('saml/idp/log/debug/enabled'), |
99 |
is_on('pdate/check/boot/debug'), |
100 |
is_on('update/check/cron/debug'), |
101 |
lambda ucr: ucr.get('apache2/loglevel', 'warn') in ('notice', 'info', 'debug') |
102 |
) |
103 |
|
104 |
configRegistry = univention.config_registry.ConfigRegistry() |
105 |
configRegistry.load() |
106 |
return any(check(configRegistry) for check in checks) |
107 |
|
108 |
|
109 |
def solutions(): |
110 |
yield _('You may want to uninstall software via {appcenter:appcenter}.') |
111 |
if not is_varlog_own_partition(): |
112 |
yield _('You may want to move /var/log to another disk or storage.') |
113 |
if local_repository_exists(): |
114 |
yield _('You may want to move the local repository to another server.') |
115 |
yield _('You may want to exchange the hard drive.') |
116 |
|
117 |
|
118 |
def run(): |
119 |
high = high_disk_usage() |
120 |
tmpl = _('- Disk for mountpoint %(mp)s is %(pc)s%% full.') |
121 |
disk_errors = [tmpl % {'mp': mp, 'pc': pc} for (mp, pc) in high.iteritems()] |
122 |
|
123 |
problem_on_root = '/' in high |
124 |
problem_on_varlog = '/var/log' in high or '/var' in high or \ |
125 |
(problem_on_root and not is_varlog_own_partition()) |
126 |
|
127 |
if disk_errors: |
128 |
umc_modules = [{'module': 'appcenter', 'flavor': 'appcenter'}] |
129 |
error_descriptions = [_('Some disks are nearly full:')] |
130 |
error_descriptions.extend(disk_errors) |
131 |
|
132 |
if problem_on_root: |
133 |
error_descriptions.append('\n'.join(solutions())) |
134 |
|
135 |
if problem_on_varlog and high_log_levels(): |
136 |
lvl_errors = (_('You have configured some high log levels.'), |
137 |
_('You may want to reset them via {ucr}.')) |
138 |
umc_modules.append({'module': 'ucr'}) |
139 |
error_descriptions.append(' '.join(lvl_errors)) |
140 |
|
141 |
if problem_on_root: |
142 |
raise Critical('\n'.join(error_descriptions), umc_modules=umc_modules) |
143 |
raise Warning('\n'.join(error_descriptions), umc_modules=umc_modules) |
144 |
|
145 |
|
146 |
if __name__ == '__main__': |
147 |
from univention.management.console.modules.diagnostic import main |
148 |
main() |
2 |
.../umc/python/diagnostic/de.po | 47 +++++++++++++++++++++- |
149 |
.../umc/python/diagnostic/de.po | 47 +++++++++++++++++++++- |
3 |
1 file changed, 45 insertions(+), 2 deletions(-) |
150 |
1 file changed, 45 insertions(+), 2 deletions(-) |