summaryrefslogtreecommitdiff
path: root/src/conf_mode
diff options
context:
space:
mode:
authorzsdc <taras@vyos.io>2021-12-17 16:41:50 +0200
committerzsdc <taras@vyos.io>2021-12-17 16:41:50 +0200
commit86bbab75ae414f19305970e2aa8aaeb05e6990ae (patch)
tree377b12e8f2672cf9ca9314bb8d7b261347c5f320 /src/conf_mode
parent945ab070b72ebd9f5ccfe0052ed138a93b83b297 (diff)
downloadvyos-1x-86bbab75ae414f19305970e2aa8aaeb05e6990ae.tar.gz
vyos-1x-86bbab75ae414f19305970e2aa8aaeb05e6990ae.zip
logs: T3774: Optimization for logrotate configs
* Added proper handling of default values from CLI. * Replaced rsyslog restart postrotate action to native `rsyslog-rotate` script. * Removed unnecessary checks for `None` instead `dict` - with default values the situation becomes impossible. * Fixed default value from 10 to 1 in the rsyslog CLI.
Diffstat (limited to 'src/conf_mode')
-rwxr-xr-xsrc/conf_mode/system-logs.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/conf_mode/system-logs.py b/src/conf_mode/system-logs.py
index a9f2da476..e6296656d 100755
--- a/src/conf_mode/system-logs.py
+++ b/src/conf_mode/system-logs.py
@@ -19,9 +19,11 @@ from sys import exit
from vyos import ConfigError
from vyos import airbag
from vyos.config import Config
+from vyos.configdict import dict_merge
from vyos.logger import syslog
from vyos.template import render
from vyos.util import dict_search
+from vyos.xml import defaults
airbag.enable()
# path to logrotate configs
@@ -36,7 +38,11 @@ def get_config(config=None):
conf = Config()
base = ['system', 'logs']
- logs_config = conf.get_config_dict(base, key_mangling=('-', '_'))
+ default_values = defaults(base)
+ logs_config = conf.get_config_dict(base,
+ key_mangling=('-', '_'),
+ get_first_key=True)
+ logs_config = dict_merge(default_values, logs_config)
return logs_config
@@ -48,19 +54,13 @@ def verify(logs_config):
def generate(logs_config):
# get configuration for logrotate atop
- logrotate_atop = dict_search('logs.logrotate.atop', logs_config)
- # provide an empty dictionary if there is no config
- if not logrotate_atop:
- logrotate_atop = {}
+ logrotate_atop = dict_search('logrotate.atop', logs_config)
# generate new config file for atop
syslog.debug('Adding logrotate config for atop')
render(logrotate_atop_file, 'logs/logrotate/vyos-atop.tmpl', logrotate_atop)
# get configuration for logrotate rsyslog
- logrotate_rsyslog = dict_search('logs.logrotate.messages', logs_config)
- # provide an empty dictionary if there is no config
- if not logrotate_rsyslog:
- logrotate_rsyslog = {}
+ logrotate_rsyslog = dict_search('logrotate.messages', logs_config)
# generate new config file for rsyslog
syslog.debug('Adding logrotate config for rsyslog')
render(logrotate_rsyslog_file, 'logs/logrotate/vyos-rsyslog.tmpl',