Skip to content

Commit

Permalink
[syslog] Adjust runningconfiguration syslog command (sonic-net#2843)
Browse files Browse the repository at this point in the history
#### 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
```
  • Loading branch information
fastiuk authored and pdhruv-marvell committed Aug 23, 2023
1 parent 0d7fc5b commit 3f86cf3
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 2 deletions.
2 changes: 1 addition & 1 deletion show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 25 additions & 1 deletion tests/show_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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')
77 changes: 77 additions & 0 deletions tests/syslog_input/rsyslog.conf
Original file line number Diff line number Diff line change
@@ -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 ####
###############

0 comments on commit 3f86cf3

Please sign in to comment.