Skip to content

Commit 9072445

Browse files
authored
[rsyslog]: Remote logging with the highest rule priority (#22020)
<!-- Please make sure you've read and understood our contributing guidelines: https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md failure_prs.log skip_prs.log Make sure all your commits include a signature generated with `git commit -s` ** If this is a bug fix, make sure your description includes "fixes #xxxx", or "closes #xxxx" or "resolves #xxxx" Please provide the following information: --> #### Why I did it This fix resolves issue with missing certain types of messages while forwarding to the remote server. Basically, this moves remote syslog forwarding rules to be executed before any other instructions take place, so everything received by a local syslog instance will be forwarded to the remote machine. The fix allows remote forwarding of messages defined as: https://github.com/sonic-net/sonic-buildimage/blob/master/files/image_config/rsyslog/rsyslog.d/00-sonic.conf.j2 #### Work item tracking * N/A #### How I did it * Moved `rsyslog` remote forwarding rules to be on top of other syslog instructions #### How to verify it <!-- If PR needs to be backported, then the PR must be tested against the base branch and the earliest backport release branch and provide tested image version on these two branches. For example, if the PR is requested for master, 202211 and 202012, then the requester needs to provide test results on master and 202012. --> 1. Enable remote syslog forwarding 2. Check for message patterns defined as [00-sonic.conf.j2](https://github.com/sonic-net/sonic-buildimage/blob/master/files/image_config/rsyslog/rsyslog.d/00-sonic.conf.j2) #### Which release branch to backport (provide reason below if selected) <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 - [ ] 202205 - [ ] 202211 - [ ] 202305 #### Tested branch (Please provide the tested image version) <!-- - Please provide tested image version - e.g. - [x] 20201231.100 --> - [x] master <!-- image version 1 --> #### Description for the changelog <!-- Write a short (one line) summary that describes the changes in this pull request for inclusion in the changelog: --> * N/A #### Link to config_db schema for YANG module changes <!-- Provide a link to config_db schema for the table for which YANG model is defined Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md --> * N/A #### A picture of a cute animal (not mandatory but encouraged) ``` .---. .----------- / \ __ / ------ / / \( )/ ----- ////// ' \/ ` --- //// / // : : --- // / / /` '-- // //..\\ ====UU====UU==== '//||\\` ''`` ```
1 parent 3283497 commit 9072445

File tree

4 files changed

+52
-52
lines changed

4 files changed

+52
-52
lines changed

files/image_config/rsyslog/rsyslog.conf.j2

+28-28
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,6 @@ template(name="WelfRemoteFormat" type="string" string="%TIMESTAMP% id=firewall t
6464
:::date-year%-%timereported:::date-month%-%timereported:::date-day% %timereported:::date-hour%:%timereported:::date-minute%:%timereported\
6565
:::date-second%\" fw=\"{{ fw_name }}\" pri=%syslogpriority% msg=\"%syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\"\n")
6666

67-
#
68-
# Set the default permissions for all log files.
69-
#
70-
$FileOwner root
71-
$FileGroup adm
72-
$FileCreateMode 0640
73-
$DirCreateMode 0755
74-
$Umask 0022
75-
76-
#
77-
# Where to place spool and state files
78-
#
79-
$WorkDirectory /var/spool/rsyslog
80-
81-
#
82-
# Include all config files in /etc/rsyslog.d/
83-
#
84-
$IncludeConfig /etc/rsyslog.d/*.conf
85-
86-
#
87-
# Suppress duplicate messages and report "message repeated n times"
88-
#
89-
$RepeatedMsgReduction on
90-
91-
###############
92-
#### RULES ####
93-
###############
94-
9567
#
9668
# Remote syslog logging
9769
#
@@ -134,3 +106,31 @@ $RepeatedMsgReduction on
134106
*.{{ severity }}
135107
action(type="omfwd" Target="{{ server }}" Port="{{ port }}" Protocol="{{ proto }}" Template="{{ template }}"{{ options }})
136108
{% endfor %}
109+
110+
#
111+
# Set the default permissions for all log files.
112+
#
113+
$FileOwner root
114+
$FileGroup adm
115+
$FileCreateMode 0640
116+
$DirCreateMode 0755
117+
$Umask 0022
118+
119+
#
120+
# Where to place spool and state files
121+
#
122+
$WorkDirectory /var/spool/rsyslog
123+
124+
#
125+
# Include all config files in /etc/rsyslog.d/
126+
#
127+
$IncludeConfig /etc/rsyslog.d/*.conf
128+
129+
#
130+
# Suppress duplicate messages and report "message repeated n times"
131+
#
132+
$RepeatedMsgReduction on
133+
134+
###############
135+
#### RULES ####
136+
###############

src/sonic-config-engine/setup.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[aliases]
2+
test=pytest

src/sonic-config-engine/tests/sample_output/py3/rsyslog.conf

+11-12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ template(name="WelfRemoteFormat" type="string" string="%TIMESTAMP% id=firewall t
4949
:::date-year%-%timereported:::date-month%-%timereported:::date-day% %timereported:::date-hour%:%timereported:::date-minute%:%timereported\
5050
:::date-second%\" fw=\"kvm-host\" pri=%syslogpriority% msg=\"%syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\"\n")
5151

52+
#
53+
# Remote syslog logging
54+
#
55+
56+
# The omfwd plug-in provides the core functionality of traditional message
57+
# forwarding via UDP and plain TCP. It is a built-in module that does not need
58+
# to be loaded.
59+
60+
*.*
61+
action(type="omfwd" Target="3.3.3.3" Port="514" Protocol="udp" Template="SONiCForwardFormat")
62+
5263
#
5364
# Set the default permissions for all log files.
5465
#
@@ -76,15 +87,3 @@ $RepeatedMsgReduction on
7687
###############
7788
#### RULES ####
7889
###############
79-
80-
#
81-
# Remote syslog logging
82-
#
83-
84-
# The omfwd plug-in provides the core functionality of traditional message
85-
# forwarding via UDP and plain TCP. It is a built-in module that does not need
86-
# to be loaded.
87-
88-
*.*
89-
action(type="omfwd" Target="3.3.3.3" Port="514" Protocol="udp" Template="SONiCForwardFormat")
90-

src/sonic-config-engine/tests/sample_output/py3/rsyslog_with_docker0.conf

+11-12
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ template(name="WelfRemoteFormat" type="string" string="%TIMESTAMP% id=firewall t
5151
:::date-year%-%timereported:::date-month%-%timereported:::date-day% %timereported:::date-hour%:%timereported:::date-minute%:%timereported\
5252
:::date-second%\" fw=\"kvm-host\" pri=%syslogpriority% msg=\"%syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\"\n")
5353

54+
#
55+
# Remote syslog logging
56+
#
57+
58+
# The omfwd plug-in provides the core functionality of traditional message
59+
# forwarding via UDP and plain TCP. It is a built-in module that does not need
60+
# to be loaded.
61+
62+
*.*
63+
action(type="omfwd" Target="3.3.3.3" Port="514" Protocol="udp" Template="SONiCForwardFormat")
64+
5465
#
5566
# Set the default permissions for all log files.
5667
#
@@ -78,15 +89,3 @@ $RepeatedMsgReduction on
7889
###############
7990
#### RULES ####
8091
###############
81-
82-
#
83-
# Remote syslog logging
84-
#
85-
86-
# The omfwd plug-in provides the core functionality of traditional message
87-
# forwarding via UDP and plain TCP. It is a built-in module that does not need
88-
# to be loaded.
89-
90-
*.*
91-
action(type="omfwd" Target="3.3.3.3" Port="514" Protocol="udp" Template="SONiCForwardFormat")
92-

0 commit comments

Comments
 (0)