Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[syslog] Adjust runningconfiguration syslog command #2843

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ####
###############