@@ -1356,18 +1356,29 @@ def show_run_snmp(db, ctx):
1356
1356
@runningconfiguration .command ()
1357
1357
@click .option ('--verbose' , is_flag = True , help = "Enable verbose output" )
1358
1358
def syslog (verbose ):
1359
- """Show Syslog running configuration"""
1359
+ """Show Syslog running configuration
1360
+ To match below cases:
1361
+ *.* @IPv4:port
1362
+ *.* @[IPv4]:port
1363
+ *.* @[IPv6]:port
1364
+ """
1360
1365
syslog_servers = []
1361
1366
syslog_dict = {}
1367
+ re_ipv4_1 = re .compile (r'^\*\.\* @(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):\d+' )
1368
+ re_ipv4_2 = re .compile (r'^\*\.\* @\[(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\]:\d+' )
1369
+ re_ipv6 = re .compile (r'^\*\.\* @\[([0-9a-fA-F:]+)\]:\d+' )
1362
1370
with open ("/etc/rsyslog.conf" ) as syslog_file :
1363
1371
data = syslog_file .readlines ()
1364
1372
for line in data :
1365
- if line .startswith ("*.* @" ):
1366
- end = line .find ("]" )
1367
- if end == - 1 :
1368
- continue
1369
- server = line [5 :end + 1 ]
1370
- syslog_servers .append (server )
1373
+ if re_ipv4_1 .match (line ):
1374
+ server = re_ipv4_1 .match (line ).group (1 )
1375
+ if re_ipv4_2 .match (line ):
1376
+ server = re_ipv4_2 .match (line ).group (1 )
1377
+ elif re_ipv6 .match (line ):
1378
+ server = re_ipv6 .match (line ).group (1 )
1379
+ else :
1380
+ continue
1381
+ syslog_servers .append ("[{}]" .format (server ))
1371
1382
syslog_dict ['Syslog Servers' ] = syslog_servers
1372
1383
print (tabulate (syslog_dict , headers = list (syslog_dict .keys ()), tablefmt = "simple" , stralign = 'left' , missingval = "" ))
1373
1384
0 commit comments