Skip to content

Commit 659ba24

Browse files
authored
[syslog] Adjust runningconfiguration syslog command (sonic-net#2843)
#### What I did Adjust `show runningconfiguration syslog` command according to the new syslog configuration file #### How I did it Fix regex to match the target syslog server #### How to verify it Run the next command in sonic shell: ``` show runningconfiguration syslog ```
1 parent 46fba26 commit 659ba24

File tree

3 files changed

+103
-2
lines changed

3 files changed

+103
-2
lines changed

show/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1686,7 +1686,7 @@ def syslog(verbose):
16861686
header = ["Syslog Servers"]
16871687
body = []
16881688

1689-
re_syslog = re.compile(r'^\*\.\* action\(.*target=\"{1}(.+?)\"{1}.*\)')
1689+
re_syslog = re.compile(r'^action\(type=\"omfwd\" Target=\"{1}(.+?)\"{1}.*\)')
16901690

16911691
try:
16921692
with open("/etc/rsyslog.conf") as syslog_file:

tests/show_test.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from unittest import mock
88
from click.testing import CliRunner
99
from utilities_common import constants
10-
from unittest.mock import call, MagicMock, patch
10+
from unittest.mock import call, MagicMock, patch, mock_open
1111

1212
EXPECTED_BASE_COMMAND = 'sudo '
1313
EXPECTED_BASE_COMMAND_LIST = ['sudo']
@@ -988,3 +988,27 @@ def test_show_ztp(self, mock_run_command):
988988
def teardown(self):
989989
print('TEAR DOWN')
990990

991+
992+
class TestShowRunningconfiguration(object):
993+
@classmethod
994+
def setup_class(cls):
995+
print('SETUP')
996+
os.environ['UTILITIES_UNIT_TESTING'] = '1'
997+
998+
@patch('show.main.run_command')
999+
@patch('builtins.open', mock_open(
1000+
read_data=open('tests/syslog_input/rsyslog.conf').read()))
1001+
def test_rc_syslog(self, mock_rc):
1002+
runner = CliRunner()
1003+
1004+
result = runner.invoke(
1005+
show.cli.commands['runningconfiguration'].commands['syslog'])
1006+
print(result.exit_code)
1007+
print(result.output)
1008+
1009+
assert result.exit_code == 0
1010+
assert '[1.1.1.1]' in result.output
1011+
1012+
@classmethod
1013+
def teardown_class(cls):
1014+
print('TEARDOWN')

tests/syslog_input/rsyslog.conf

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
###############################################################################
2+
# Managed by Ansible
3+
# file: ansible/roles/acs/templates/rsyslog.conf.j2
4+
###############################################################################
5+
#
6+
# /etc/rsyslog.conf Configuration file for rsyslog.
7+
#
8+
# For more information see
9+
# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
10+
11+
12+
#################
13+
#### MODULES ####
14+
#################
15+
16+
$ModLoad imuxsock # provides support for local system logging
17+
$ModLoad imklog # provides kernel logging support
18+
#$ModLoad immark # provides --MARK-- message capability
19+
20+
# provides UDP syslog reception
21+
$ModLoad imudp
22+
$UDPServerAddress 127.0.0.1 #bind to localhost before udp server run
23+
$UDPServerRun 514
24+
25+
# provides TCP syslog reception
26+
#$ModLoad imtcp
27+
#$InputTCPServerRun 514
28+
29+
30+
###########################
31+
#### GLOBAL DIRECTIVES ####
32+
###########################
33+
#
34+
# Use traditional timestamp format.
35+
# To enable high precision timestamps, comment out the following line.
36+
#
37+
#$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
38+
39+
# Define a custom template
40+
$template SONiCFileFormat,"%timegenerated%.%timegenerated:::date-subseconds% %HOSTNAME% %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
41+
$ActionFileDefaultTemplate SONiCFileFormat
42+
43+
template(name="WelfRemoteFormat" type="string" string="%TIMESTAMP% id=firewall time=\"%timereported\
44+
:::date-year%-%timereported:::date-month%-%timereported:::date-day% %timereported:::date-hour%:%timereported:::date-minute%:%timereported\
45+
:::date-second%\" fw=\"sonic\" pri=%syslogpriority% msg=\"%syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\"\n")
46+
47+
#Set remote syslog server
48+
*.notice
49+
action(type="omfwd" Target="1.1.1.1" Port="514" Protocol="udp" Device="eth0" Template="SONiCFileFormat")
50+
51+
#
52+
# Set the default permissions for all log files.
53+
#
54+
$FileOwner root
55+
$FileGroup adm
56+
$FileCreateMode 0640
57+
$DirCreateMode 0755
58+
$Umask 0022
59+
60+
#
61+
# Where to place spool and state files
62+
#
63+
$WorkDirectory /var/spool/rsyslog
64+
65+
#
66+
# Include all config files in /etc/rsyslog.d/
67+
#
68+
$IncludeConfig /etc/rsyslog.d/*.conf
69+
70+
#
71+
# Suppress duplicate messages and report "message repeated n times"
72+
#
73+
$RepeatedMsgReduction on
74+
75+
###############
76+
#### RULES ####
77+
###############

0 commit comments

Comments
 (0)