Skip to content

Commit

Permalink
Fix invalid output of syslog IPv6 servers (#1933)
Browse files Browse the repository at this point in the history
#### 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]
```
  • Loading branch information
wen587 committed Dec 3, 2021
1 parent 290ff5f commit 5172972
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1358,16 +1358,32 @@ def show_run_snmp(db, ctx):
@runningconfiguration.command()
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def syslog(verbose):
"""Show Syslog running configuration"""
"""Show Syslog running configuration
To match below cases(port is optional):
*.* @IPv4:port
*.* @@IPv4:port
*.* @[IPv4]:port
*.* @@[IPv4]:port
*.* @[IPv6]:port
*.* @@[IPv6]:port
"""
syslog_servers = []
syslog_dict = {}
re_ipv4_1 = re.compile(r'^\*\.\* @{1,2}(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(:\d+)?')
re_ipv4_2 = re.compile(r'^\*\.\* @{1,2}\[(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\](:\d+)?')
re_ipv6 = re.compile(r'^\*\.\* @{1,2}\[([0-9a-fA-F:.]+)\](:\d+)?')
with open("/etc/rsyslog.conf") as syslog_file:
data = syslog_file.readlines()
for line in data:
if line.startswith("*.* @"):
line = line.split(":")
server = line[0][5:]
syslog_servers.append(server)
if re_ipv4_1.match(line):
server = re_ipv4_1.match(line).group(1)
elif re_ipv4_2.match(line):
server = re_ipv4_2.match(line).group(1)
elif re_ipv6.match(line):
server = re_ipv6.match(line).group(1)
else:
continue
syslog_servers.append("[{}]".format(server))
syslog_dict['Syslog Servers'] = syslog_servers
print(tabulate(syslog_dict, headers=list(syslog_dict.keys()), tablefmt="simple", stralign='left', missingval=""))

Expand Down

0 comments on commit 5172972

Please sign in to comment.