-
Notifications
You must be signed in to change notification settings - Fork 672
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
Fix invalid output of syslog IPv6 servers #1933
Changes from 3 commits
ac1f573
7e4eb10
ea7efa4
f7d3f3a
8848651
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1356,16 +1356,29 @@ 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: | ||
*.* @IPv4:port | ||
*.* @[IPv4]:port | ||
*.* @[IPv6]:port | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The port is optional and the default is 514. ref: https://linux.die.net/man/5/rsyslog.conf #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can make the port optional. |
||
""" | ||
syslog_servers = [] | ||
syslog_dict = {} | ||
re_ipv4_1 = re.compile(r'^\*\.\* @(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):\d+') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for being strict when writing a regex! we can delegate the check to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Qi, according to rsyslog IPv6 support, I think we can just consider the cases of |
||
re_ipv4_2 = re.compile(r'^\*\.\* @\[(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\]:\d+') | ||
re_ipv6 = re.compile(r'^\*\.\* @\[([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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. I am checking all lines in rsyslogd.conf. |
||
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="")) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add some unit tests?