blob: 3284cbc69142e055355a06628ad7119e02dc74d0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#!/usr/bin/python3
"""Msec plugin for log file handling"""
# main plugin class name
PLUGIN = "log"
import re
import gettext
# configuration
import config
# localization
try:
gettext.install('msec', str=1)
except IOError:
_ = str
class log:
# configuration variables
# logrotate file
LOGROTATE = '/etc/logrotate.conf'
# pam
LOGROTATE_ROTATE = re.compile('^rotate\s*(\d+)$')
def __init__(self, log=None, configfiles=None, root=None):
# initializing plugin
self.log = log
self.configfiles = configfiles
self.root = root
# configuring entry in global settings
config.SETTINGS['LOG_RETENTION'] = ("log.log_retention", ['*'])
# insert entry into system security settings
config.SETTINGS_SYSTEM.append('LOG_RETENTION')
def log_retention(self, arg):
'''Define the default retention period for logs, in weeks. Some countries require that the log files should be kept for 12 months, other do not have such strict requirements. This variable defines the number of past log files that should be kept by logrotate on the system.'''
# verify parameter validity
try:
retention = int(arg)
except:
self.log.error(_('Invalid retention period: "%s"') % arg)
return
logrotate = self.configfiles.get_config_file(self.LOGROTATE)
val = logrotate.get_match(self.LOGROTATE_ROTATE, '@1')
if val != arg:
self.log.info(_("Setting log retention period to %d weeks") % retention)
logrotate.replace_line_matching(self.LOGROTATE_ROTATE, ("rotate %d" % retention))
|