diff options
author | zsdc <taras@vyos.io> | 2021-12-13 19:28:27 +0200 |
---|---|---|
committer | zsdc <taras@vyos.io> | 2021-12-13 19:28:27 +0200 |
commit | a22ba14999a38217155a7a999f61e855d813cc41 (patch) | |
tree | 7bd215a9d09444d8b0b70e8afbf88f8412fe3f90 /src | |
parent | 89fdb4fbfa05e11a7e4ad7f169b5753b4fc60d71 (diff) | |
download | vyos-1x-a22ba14999a38217155a7a999f61e855d813cc41.tar.gz vyos-1x-a22ba14999a38217155a7a999f61e855d813cc41.zip |
logs: T3774: Improved logs config rendering
Switched to `vyos.util.dict_search()` to keep the style common with the
rest components.
Removed config file comparison - almost the same result may be reached
by removing a configuration file with each boot, we already have such a
feature in the `vyos-router`.
Diffstat (limited to 'src')
-rwxr-xr-x | src/conf_mode/system-logs.py | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/conf_mode/system-logs.py b/src/conf_mode/system-logs.py index 8eb95e543..7b5af240f 100755 --- a/src/conf_mode/system-logs.py +++ b/src/conf_mode/system-logs.py @@ -20,8 +20,8 @@ from vyos import ConfigError from vyos import airbag from vyos.config import Config from vyos.logger import syslog -from vyos.template import render_to_string -from vyos.util import read_file, write_file +from vyos.template import render +from vyos.util import dict_search airbag.enable() # path to logrotate config for atop @@ -47,17 +47,13 @@ def verify(logs_config): def generate(logs_config): # get configuration for logrotate atop - logrotate_atop = logs_config.get('logs', {}).get('logrotate', - {}).get('atop', {}) - # read current config file for atop - logrotate_atop_current = read_file(logrotate_atop_file) + logrotate_atop = dict_search('logs.logrotate.atop', logs_config) + # provide an empty dictionary if there is no config + if not logrotate_atop: + logrotate_atop = {} # generate new config file for atop - logrotate_atop_new = render_to_string('logs/logrotate/vyos-atop.tmpl', - logrotate_atop) - # update configuration files if this is necessary - if logrotate_atop_new != logrotate_atop_current: - syslog.debug('Adding logrotate config for atop') - write_file(logrotate_atop_file, logrotate_atop_new) + syslog.debug('Adding logrotate config for atop') + render(logrotate_atop_file, 'logs/logrotate/vyos-atop.tmpl', logrotate_atop) def apply(logs_config): |