From 751d326c7769ac18db69de8f2be39587148be209 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Sun, 16 Jul 2023 22:03:06 +0200 Subject: syslog: T2778: fix invalid handling of logrotate and default values There was no /var/log/messages handler for logrotate making rsyslog crash after a few days. In addition we had some JIna2 templating errors for hosts, user and file CLI nodes jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'facility' Looks like therey are used rarely ;) - lucky me! --- data/templates/rsyslog/rsyslog.conf.j2 | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'data/templates/rsyslog/rsyslog.conf.j2') diff --git a/data/templates/rsyslog/rsyslog.conf.j2 b/data/templates/rsyslog/rsyslog.conf.j2 index 5352fc367..dff904129 100644 --- a/data/templates/rsyslog/rsyslog.conf.j2 +++ b/data/templates/rsyslog/rsyslog.conf.j2 @@ -23,11 +23,13 @@ $outchannel global,/var/log/messages,262144,/usr/sbin/logrotate {{ logrotate }} {% if file is vyos_defined %} # File based configuration section {% for file_name, file_options in file.items() %} -$outchannel {{ file_name }},/var/log/user/{{ file_name }},{{ file_options.archive.size }},/usr/sbin/logrotate {{ logrotate }} {% set tmp = [] %} -{% for facility, facility_options in file_options.facility.items() %} -{% set _ = tmp.append(facility.replace('all', '*') + '.' + facility_options.level) %} -{% endfor %} +$outchannel {{ file_name }},/var/log/user/{{ file_name }},{{ file_options.archive.size }},/usr/sbin/logrotate {{ logrotate }} +{% if file_options.facility is vyos_defined %} +{% for facility, facility_options in file_options.facility.items() %} +{% set _ = tmp.append(facility.replace('all', '*') + '.' + facility_options.level) %} +{% endfor %} +{% endif %} {{ tmp | join(';') }} :omfile:${{ file }} {% endfor %} {% endif %} @@ -45,9 +47,11 @@ $outchannel {{ file_name }},/var/log/user/{{ file_name }},{{ file_options.archiv # Remote logging {% for host_name, host_options in host.items() %} {% set tmp = [] %} -{% for facility, facility_options in host_options.facility.items() %} -{% set _ = tmp.append(facility.replace('all', '*') + '.' + facility_options.level) %} -{% endfor %} +{% if host_options.facility is vyos_defined %} +{% for facility, facility_options in host_options.facility.items() %} +{% set _ = tmp.append(facility.replace('all', '*') + '.' + facility_options.level) %} +{% endfor %} +{% endif %} {% if host_options.protocol is vyos_defined('tcp') %} {% if host_options.format.octet_counted is vyos_defined %} {{ tmp | join(';') }} @@(o){{ host_name | bracketize_ipv6 }}:{{ host_options.port }};RSYSLOG_SyslogProtocol23Format @@ -63,9 +67,12 @@ $outchannel {{ file_name }},/var/log/user/{{ file_name }},{{ file_options.archiv {% if user is defined and user is not none %} # Log to user terminal {% for username, user_options in user.items() %} -{% for facility, facility_options in user_options.facility.items() %} -{% set _ = tmp.append(facility.replace('all', '*') + '.' + facility_options.level) %} -{% endfor %} +{% set tmp = [] %} +{% if user_options.facility is vyos_defined %} +{% for facility, facility_options in user_options.facility.items() %} +{% set _ = tmp.append(facility.replace('all', '*') + '.' + facility_options.level) %} +{% endfor %} +{% endif %} {{ tmp | join(';') }} :omusrmsg:{{ username }} {% endfor %} {% endif %} -- cgit v1.2.3