Skip to content

Commit 5172972

Browse files
authored
Fix invalid output of syslog IPv6 servers (sonic-net#1933)
#### What I did Modify the filter function of `show runningconfiguration syslog` #### How I did it Filter by ending "]" rather than split by ":" #### How to verify it add a syslog v6 server `sudo config syslog add f587::1:1` run command `show runningconfiguration syslog` #### Previous command output (if the output of a command-line utility has changed) ``` admin@vlab-01:~$ show runningconfiguration syslog Syslog Servers ---------------- [10.0.0.5] [10.0.0.6] [f587 ``` #### New command output (if the output of a command-line utility has changed) ``` admin@vlab-01:~$ show runningconfiguration syslog Syslog Servers ---------------- [10.0.0.5] [10.0.0.6] [f587::1:1] ```
1 parent 290ff5f commit 5172972

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

show/main.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -1358,16 +1358,32 @@ def show_run_snmp(db, ctx):
13581358
@runningconfiguration.command()
13591359
@click.option('--verbose', is_flag=True, help="Enable verbose output")
13601360
def syslog(verbose):
1361-
"""Show Syslog running configuration"""
1361+
"""Show Syslog running configuration
1362+
To match below cases(port is optional):
1363+
*.* @IPv4:port
1364+
*.* @@IPv4:port
1365+
*.* @[IPv4]:port
1366+
*.* @@[IPv4]:port
1367+
*.* @[IPv6]:port
1368+
*.* @@[IPv6]:port
1369+
"""
13621370
syslog_servers = []
13631371
syslog_dict = {}
1372+
re_ipv4_1 = re.compile(r'^\*\.\* @{1,2}(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(:\d+)?')
1373+
re_ipv4_2 = re.compile(r'^\*\.\* @{1,2}\[(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\](:\d+)?')
1374+
re_ipv6 = re.compile(r'^\*\.\* @{1,2}\[([0-9a-fA-F:.]+)\](:\d+)?')
13641375
with open("/etc/rsyslog.conf") as syslog_file:
13651376
data = syslog_file.readlines()
13661377
for line in data:
1367-
if line.startswith("*.* @"):
1368-
line = line.split(":")
1369-
server = line[0][5:]
1370-
syslog_servers.append(server)
1378+
if re_ipv4_1.match(line):
1379+
server = re_ipv4_1.match(line).group(1)
1380+
elif re_ipv4_2.match(line):
1381+
server = re_ipv4_2.match(line).group(1)
1382+
elif re_ipv6.match(line):
1383+
server = re_ipv6.match(line).group(1)
1384+
else:
1385+
continue
1386+
syslog_servers.append("[{}]".format(server))
13711387
syslog_dict['Syslog Servers'] = syslog_servers
13721388
print(tabulate(syslog_dict, headers=list(syslog_dict.keys()), tablefmt="simple", stralign='left', missingval=""))
13731389

0 commit comments

Comments
 (0)