From a921796e0f2b2f47b9ca9de9da417acb86f5e95b Mon Sep 17 00:00:00 2001 From: Yevhen Fastiuk Date: Mon, 22 May 2023 22:39:57 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=93=BA=20show:=20adjust=20syslog=20ru?= =?UTF-8?q?nningconfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yevhen Fastiuk --- show/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/main.py b/show/main.py index 21b284b92b..b4a7e40544 100755 --- a/show/main.py +++ b/show/main.py @@ -1686,7 +1686,7 @@ def syslog(verbose): header = ["Syslog Servers"] body = [] - re_syslog = re.compile(r'^\*\.\* action\(.*target=\"{1}(.+?)\"{1}.*\)') + re_syslog = re.compile(r'^action\(type=\"omfwd\" Target=\"{1}(.+?)\"{1}.*\)') try: with open("/etc/rsyslog.conf") as syslog_file: From 033248a7726f8fbeb1e7eea1022694cc9ffb606d Mon Sep 17 00:00:00 2001 From: Yevhen Fastiuk Date: Tue, 23 May 2023 10:22:29 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A7=AA=20unit=20test:=20Add=20running?= =?UTF-8?q?config=20syslog=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yevhen Fastiuk --- tests/show_test.py | 26 ++++++++++- tests/syslog_input/rsyslog.conf | 77 +++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 tests/syslog_input/rsyslog.conf diff --git a/tests/show_test.py b/tests/show_test.py index 21af60d8c0..5b55c15896 100644 --- a/tests/show_test.py +++ b/tests/show_test.py @@ -7,7 +7,7 @@ from unittest import mock from click.testing import CliRunner from utilities_common import constants -from unittest.mock import call, MagicMock, patch +from unittest.mock import call, MagicMock, patch, mock_open EXPECTED_BASE_COMMAND = 'sudo ' EXPECTED_BASE_COMMAND_LIST = ['sudo'] @@ -988,3 +988,27 @@ def test_show_ztp(self, mock_run_command): def teardown(self): print('TEAR DOWN') + +class TestShowRunningconfiguration(object): + @classmethod + def setup_class(cls): + print('SETUP') + os.environ['UTILITIES_UNIT_TESTING'] = '1' + + @patch('show.main.run_command') + @patch('builtins.open', mock_open( + read_data=open('tests/syslog_input/rsyslog.conf').read())) + def test_rc_syslog(self, mock_rc): + runner = CliRunner() + + result = runner.invoke( + show.cli.commands['runningconfiguration'].commands['syslog']) + print(result.exit_code) + print(result.output) + + assert result.exit_code == 0 + assert '[1.1.1.1]' in result.output + + @classmethod + def teardown_class(cls): + print('TEARDOWN') diff --git a/tests/syslog_input/rsyslog.conf b/tests/syslog_input/rsyslog.conf new file mode 100644 index 0000000000..b2a269a816 --- /dev/null +++ b/tests/syslog_input/rsyslog.conf @@ -0,0 +1,77 @@ +############################################################################### +# Managed by Ansible +# file: ansible/roles/acs/templates/rsyslog.conf.j2 +############################################################################### +# +# /etc/rsyslog.conf Configuration file for rsyslog. +# +# For more information see +# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html + + +################# +#### MODULES #### +################# + +$ModLoad imuxsock # provides support for local system logging +$ModLoad imklog # provides kernel logging support +#$ModLoad immark # provides --MARK-- message capability + +# provides UDP syslog reception +$ModLoad imudp +$UDPServerAddress 127.0.0.1 #bind to localhost before udp server run +$UDPServerRun 514 + +# provides TCP syslog reception +#$ModLoad imtcp +#$InputTCPServerRun 514 + + +########################### +#### GLOBAL DIRECTIVES #### +########################### +# +# Use traditional timestamp format. +# To enable high precision timestamps, comment out the following line. +# +#$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat + +# Define a custom template +$template SONiCFileFormat,"%timegenerated%.%timegenerated:::date-subseconds% %HOSTNAME% %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n" +$ActionFileDefaultTemplate SONiCFileFormat + +template(name="WelfRemoteFormat" type="string" string="%TIMESTAMP% id=firewall time=\"%timereported\ +:::date-year%-%timereported:::date-month%-%timereported:::date-day% %timereported:::date-hour%:%timereported:::date-minute%:%timereported\ +:::date-second%\" fw=\"sonic\" pri=%syslogpriority% msg=\"%syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\"\n") + +#Set remote syslog server +*.notice +action(type="omfwd" Target="1.1.1.1" Port="514" Protocol="udp" Device="eth0" Template="SONiCFileFormat") + +# +# Set the default permissions for all log files. +# +$FileOwner root +$FileGroup adm +$FileCreateMode 0640 +$DirCreateMode 0755 +$Umask 0022 + +# +# Where to place spool and state files +# +$WorkDirectory /var/spool/rsyslog + +# +# Include all config files in /etc/rsyslog.d/ +# +$IncludeConfig /etc/rsyslog.d/*.conf + +# +# Suppress duplicate messages and report "message repeated n times" +# +$RepeatedMsgReduction on + +############### +#### RULES #### +############### \ No newline at end of file