Skip to content

Commit c40ff64

Browse files
authored
Merge pull request #4305 from c-po/syslog-T6989
syslog: T6989: convert old configuration format to "advanced"
2 parents c1cd7b4 + cf7721f commit c40ff64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+675
-417
lines changed

data/templates/rsyslog/override.conf.j2

-11
This file was deleted.
+104-60
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,122 @@
11
### Autogenerated by system_syslog.py ###
22

3-
{% if global.marker is vyos_defined %}
4-
$ModLoad immark
5-
{% if global.marker.interval is vyos_defined %}
6-
$MarkMessagePeriod {{ global.marker.interval }}
7-
{% endif %}
8-
{% endif %}
9-
{% if global.preserve_fqdn is vyos_defined %}
10-
$PreserveFQDN on
11-
{% endif %}
3+
#### MODULES ####
4+
# Load input modules for local logging and kernel logging
125

13-
{% if global.local_host_name is vyos_defined %}
14-
$LocalHostName {{ global.local_host_name }}
15-
{% endif %}
6+
# Old-style log file format with low-precision timestamps
7+
# A modern-style logfile format with high-precision timestamps and timezone info
8+
# RSYSLOG_FileFormat
9+
module(load="builtin:omfile" Template="RSYSLOG_TraditionalFileFormat")
10+
module(load="imuxsock") # provides support for local system logging
11+
module(load="imklog") # provides kernel logging support
1612

17-
# We always log to /var/log/messages
18-
$outchannel global,/var/log/messages,262144,/usr/sbin/logrotate {{ logrotate }}
19-
{% if global.facility is vyos_defined %}
20-
{% set tmp = [] %}
21-
{% for facility, facility_options in global.facility.items() %}
22-
{% set _ = tmp.append(facility.replace('all', '*') + '.' + facility_options.level.replace('all', '*')) %}
23-
{% endfor %}
24-
{{ tmp | join(';') }} :omfile:$global
13+
# Import logs from journald
14+
module(
15+
load="imjournal"
16+
StateFile="/var/spool/rsyslog/imjournal.state" # Persistent state file to track the journal cursor
17+
Ratelimit.Interval="0" # Disable rate limiting (set to "0" for no limit)
18+
RateLimit.Burst="0"
19+
)
20+
21+
###########################
22+
#### GLOBAL DIRECTIVES ####
23+
###########################
24+
# Log specific programs to auth.log, then stop further processing
25+
if (
26+
$programname == "CRON" or
27+
$programname == "sudo" or
28+
$programname == "su"
29+
) then {
30+
action(type="omfile" file="/var/log/auth.log")
31+
stop
32+
}
33+
34+
global(workDirectory="/var/spool/rsyslog")
35+
36+
###############
37+
#### RULES ####
38+
###############
39+
40+
# Send emergency messages to all logged-in users
41+
*.emerg action(type="omusrmsg" users="*")
42+
43+
{% if marker is vyos_defined %}
44+
# Load the immark module for periodic --MARK-- message capability
45+
module(load="immark" interval="{{ marker.interval }}")
46+
{% endif %}
47+
{% if preserve_fqdn is vyos_defined %}
48+
# Preserve the fully qualified domain name (FQDN) in log messages
49+
global(preserveFQDN="on")
50+
{% if preserve_fqdn.host_name is vyos_defined and preserve_fqdn.domain_name is vyos_defined %}
51+
# Set the local hostname for log messages
52+
global(localHostname="{{ preserve_fqdn.host_name }}.{{ preserve_fqdn.domain_name }}")
53+
{% endif %}
2554
{% endif %}
2655

27-
{% if file is vyos_defined %}
28-
# File based configuration section
29-
{% for file_name, file_options in file.items() %}
30-
{% set tmp = [] %}
31-
$outchannel {{ file_name }},/var/log/user/{{ file_name }},{{ file_options.archive.size }},/usr/sbin/logrotate {{ logrotate }}
32-
{% if file_options.facility is vyos_defined %}
33-
{% for facility, facility_options in file_options.facility.items() %}
34-
{% set _ = tmp.append(facility.replace('all', '*') + '.' + facility_options.level.replace('all', '*')) %}
35-
{% endfor %}
36-
{% endif %}
37-
{{ tmp | join(';') }} :omfile:${{ file }}
38-
{% endfor %}
56+
#### GLOBAL LOGGING ####
57+
{% if local.facility is vyos_defined %}
58+
{% set tmp = [] %}
59+
{% if local.facility is vyos_defined %}
60+
{% for facility, facility_options in local.facility.items() %}
61+
{% set _ = tmp.append(facility.replace('all', '*') ~ "." ~ facility_options.level.replace('all', 'debug')) %}
62+
{% endfor %}
63+
if prifilt("{{ tmp | join(',') }}") then {
64+
action(
65+
type="omfile"
66+
file="/var/log/messages"
67+
rotation.sizeLimit="524288" # 512Kib - maximum filesize before rotation
68+
rotation.sizeLimitCommand="/usr/sbin/logrotate {{ logrotate }}"
69+
)
70+
}
71+
{% endif %}
3972
{% endif %}
4073

74+
#### CONSOLE LOGGING ####
4175
{% if console.facility is vyos_defined %}
42-
# Console logging
4376
{% set tmp = [] %}
44-
{% for facility, facility_options in console.facility.items() %}
45-
{% set _ = tmp.append(facility.replace('all', '*') + '.' + facility_options.level.replace('all', '*')) %}
46-
{% endfor %}
47-
{{ tmp | join(';') }} /dev/console
77+
{% if console.facility is vyos_defined %}
78+
{% for facility, facility_options in console.facility.items() %}
79+
{% set _ = tmp.append(facility.replace('all', '*') ~ "." ~ facility_options.level.replace('all', 'debug')) %}
80+
{% endfor %}
81+
if prifilt("{{ tmp | join(',') }}") then {
82+
action(type="omfile" file="/dev/console")
83+
}
84+
{% endif %}
4885
{% endif %}
4986

50-
{% if host is vyos_defined %}
51-
# Remote logging
52-
{% for host_name, host_options in host.items() %}
87+
#### REMOTE LOGGING ####
88+
{% if remote is vyos_defined %}
89+
{% for remote_name, remote_options in remote.items() %}
5390
{% set tmp = [] %}
54-
{% if host_options.facility is vyos_defined %}
55-
{% for facility, facility_options in host_options.facility.items() %}
56-
{% set _ = tmp.append(facility.replace('all', '*') + '.' + facility_options.level.replace('all', '*')) %}
91+
{% if remote_options.facility is vyos_defined %}
92+
{% for facility, facility_options in remote_options.facility.items() %}
93+
{% set _ = tmp.append(facility.replace('all', '*') ~ "." ~ facility_options.level.replace('all', 'debug')) %}
5794
{% endfor %}
58-
{% endif %}
59-
{% if host_options.protocol is vyos_defined('tcp') %}
60-
{{ tmp | join(';') }} @@{{ '(o)' if host_options.format.octet_counted is vyos_defined }}{{ host_name | bracketize_ipv6 }}:{{ host_options.port }}{{ ';RSYSLOG_SyslogProtocol23Format' if host_options.format.include_timezone is vyos_defined }}
61-
{% else %}
62-
{{ tmp | join(';') }} @{{ host_name | bracketize_ipv6 }}:{{ host_options.port }}{{ ';RSYSLOG_SyslogProtocol23Format' if host_options.format.include_timezone is vyos_defined }}
95+
{% set _ = tmp.sort() %}
96+
# Remote syslog to {{ remote_name }}
97+
if prifilt("{{ tmp | join(',') }}") then {
98+
action(
99+
type="omfwd"
100+
# Remote syslog server where we send our logs to
101+
target="{{ remote_name | bracketize_ipv6 }}"
102+
# Port on the remote syslog server
103+
port="{{ remote_options.port }}"
104+
protocol="{{ remote_options.protocol }}"
105+
{% if remote_options.format.include_timezone is vyos_defined %}
106+
template="SyslogProtocol23Format"
107+
{% endif %}
108+
TCP_Framing="{{ 'octed-counted' if remote_options.format.octet_counted is vyos_defined else 'traditional' }}"
109+
{% if remote_options.source_address is vyos_defined %}
110+
Address="{{ remote_options.source_address }}"
111+
{% endif %}
112+
{% if remote_options.vrf is vyos_defined %}
113+
Device="{{ remote_options.vrf }}"
114+
{% endif %}
115+
)
116+
}
63117
{% endif %}
64118
{% endfor %}
65119
{% endif %}
66120

67-
{% if user is defined and user is not none %}
68-
# Log to user terminal
69-
{% for username, user_options in user.items() %}
70-
{% set tmp = [] %}
71-
{% if user_options.facility is vyos_defined %}
72-
{% for facility, facility_options in user_options.facility.items() %}
73-
{% set _ = tmp.append(facility.replace('all', '*') + '.' + facility_options.level.replace('all', '*')) %}
74-
{% endfor %}
75-
{% endif %}
76-
{{ tmp | join(';') }} :omusrmsg:{{ username }}
77-
{% endfor %}
78-
{% endif %}
121+
# Include all configuration files in /etc/rsyslog.d/
122+
include(file="/etc/rsyslog.d/*.conf")

debian/vyos-1x.install

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ etc/netplug
99
etc/opennhrp
1010
etc/modprobe.d
1111
etc/ppp
12-
etc/rsyslog.conf
1312
etc/securetty
1413
etc/security
1514
etc/skel
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<!-- include start from include/version/system-version.xml.i -->
2-
<syntaxVersion component='system' version='28'></syntaxVersion>
2+
<syntaxVersion component='system' version='29'></syntaxVersion>
33
<!-- include end -->

interface-definitions/system_syslog.xml.in

+33-85
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,17 @@
88
<priority>400</priority>
99
</properties>
1010
<children>
11-
<tagNode name="user">
11+
<node name="console">
1212
<properties>
13-
<help>Logging to specific terminal of given user</help>
14-
<completionHelp>
15-
<path>system login user</path>
16-
</completionHelp>
17-
<valueHelp>
18-
<format>txt</format>
19-
<description>Local user account</description>
20-
</valueHelp>
21-
<constraint>
22-
#include <include/constraint/login-username.xml.i>
23-
</constraint>
24-
<constraintErrorMessage>illegal characters in user</constraintErrorMessage>
13+
<help>Log to system console (/dev/console)</help>
2514
</properties>
2615
<children>
2716
#include <include/syslog-facility.xml.i>
2817
</children>
29-
</tagNode>
30-
<tagNode name="host">
18+
</node>
19+
<tagNode name="remote">
3120
<properties>
32-
<help>Logging to remote host</help>
21+
<help>Log to remote host</help>
3322
<constraint>
3423
<validator name="ip-address"/>
3524
<validator name="fqdn"/>
@@ -49,11 +38,6 @@
4938
</valueHelp>
5039
</properties>
5140
<children>
52-
#include <include/port-number.xml.i>
53-
<leafNode name="port">
54-
<defaultValue>514</defaultValue>
55-
</leafNode>
56-
#include <include/protocol-tcp-udp.xml.i>
5741
#include <include/syslog-facility.xml.i>
5842
<node name="format">
5943
<properties>
@@ -74,86 +58,50 @@
7458
</leafNode>
7559
</children>
7660
</node>
61+
#include <include/port-number.xml.i>
62+
<leafNode name="port">
63+
<defaultValue>514</defaultValue>
64+
</leafNode>
65+
#include <include/protocol-tcp-udp.xml.i>
66+
#include <include/source-address-ipv4-ipv6.xml.i>
67+
#include <include/interface/vrf.xml.i>
7768
</children>
7869
</tagNode>
79-
<node name="global">
70+
<node name="local">
8071
<properties>
81-
<help>Logging to system standard location</help>
72+
<help>Log to standard system location /var/log/messages</help>
8273
</properties>
8374
<children>
8475
#include <include/syslog-facility.xml.i>
85-
<node name="marker">
86-
<properties>
87-
<help>mark messages sent to syslog</help>
88-
</properties>
89-
<children>
90-
<leafNode name="interval">
91-
<properties>
92-
<help>time interval how often a mark message is being sent in seconds</help>
93-
<constraint>
94-
<validator name="numeric" argument="--positive"/>
95-
</constraint>
96-
</properties>
97-
<defaultValue>1200</defaultValue>
98-
</leafNode>
99-
</children>
100-
</node>
101-
<leafNode name="preserve-fqdn">
102-
<properties>
103-
<help>uses FQDN for logging</help>
104-
<valueless/>
105-
</properties>
106-
</leafNode>
10776
</children>
10877
</node>
109-
<tagNode name="file">
78+
<node name="marker">
11079
<properties>
111-
<help>Logging to a file</help>
112-
<constraint>
113-
<regex>[a-zA-Z0-9\-_.]{1,255}</regex>
114-
</constraint>
115-
<constraintErrorMessage>illegal characters in filename or filename longer than 255 characters</constraintErrorMessage>
80+
<help>Mark messages sent to syslog</help>
11681
</properties>
11782
<children>
118-
<node name="archive">
83+
<leafNode name="interval">
11984
<properties>
120-
<help>Log file size and rotation characteristics</help>
85+
<help>Mark message interval</help>
86+
<valueHelp>
87+
<format>u32:1-65535</format>
88+
<description>Time in seconds</description>
89+
</valueHelp>
90+
<constraint>
91+
<validator name="numeric" argument="--range 1-86400"/>
92+
</constraint>
93+
<constraintErrorMessage>Port number must be in range 1 to 86400</constraintErrorMessage>
12194
</properties>
122-
<children>
123-
<leafNode name="file">
124-
<properties>
125-
<help>Number of saved files</help>
126-
<constraint>
127-
<regex>[0-9]+</regex>
128-
</constraint>
129-
<constraintErrorMessage>illegal characters in number of files</constraintErrorMessage>
130-
</properties>
131-
<defaultValue>5</defaultValue>
132-
</leafNode>
133-
<leafNode name="size">
134-
<properties>
135-
<help>Size of log files in kbytes</help>
136-
<constraint>
137-
<regex>[0-9]+</regex>
138-
</constraint>
139-
<constraintErrorMessage>illegal characters in size</constraintErrorMessage>
140-
</properties>
141-
<defaultValue>256</defaultValue>
142-
</leafNode>
143-
</children>
144-
</node>
145-
#include <include/syslog-facility.xml.i>
95+
<defaultValue>1200</defaultValue>
96+
</leafNode>
14697
</children>
147-
</tagNode>
148-
<node name="console">
98+
</node>
99+
<leafNode name="preserve-fqdn">
149100
<properties>
150-
<help>logging to serial console</help>
101+
<help>Always include domain portion in hostname</help>
102+
<valueless/>
151103
</properties>
152-
<children>
153-
#include <include/syslog-facility.xml.i>
154-
</children>
155-
</node>
156-
#include <include/interface/vrf.xml.i>
104+
</leafNode>
157105
</children>
158106
</node>
159107
</children>

python/vyos/defaults.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2018-2024 VyOS maintainers and contributors <maintainers@vyos.io>
1+
# Copyright 2018-2025 VyOS maintainers and contributors <maintainers@vyos.io>
22
#
33
# This library is free software; you can redistribute it and/or
44
# modify it under the terms of the GNU Lesser General Public
@@ -40,6 +40,11 @@
4040
'ca_certificates' : '/usr/local/share/ca-certificates/vyos'
4141
}
4242

43+
systemd_services = {
44+
'rsyslog' : 'rsyslog.service',
45+
'snmpd' : 'snmpd.service',
46+
}
47+
4348
config_status = '/tmp/vyos-config-status'
4449
api_config_state = '/run/http-api-state'
4550
frr_debug_enable = '/tmp/vyos.frr.debug'

smoketest/config-tests/basic-api-service

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ set system console device ttyS0 speed '115200'
2424
set system host-name 'vyos'
2525
set system login user vyos authentication encrypted-password '$6$2Ta6TWHd/U$NmrX0x9kexCimeOcYK1MfhMpITF9ELxHcaBU/znBq.X2ukQOj61fVI2UYP/xBzP4QtiTcdkgs7WOQMHWsRymO/'
2626
set system login user vyos authentication plaintext-password ''
27-
set system syslog global facility all level 'info'
28-
set system syslog global facility local7 level 'debug'
27+
set system syslog local facility all level 'info'
28+
set system syslog local facility local7 level 'debug'

0 commit comments

Comments
 (0)