Skip to content

Commit 07bd868

Browse files
tsvanduynjleveque
authored andcommitted
[config] Add commands for adding/removing syslog servers (sonic-net#609)
1 parent 3d008ea commit 07bd868

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

config/main.py

+48
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,54 @@ def naming_mode_alias():
13121312
"""Set CLI interface naming mode to ALIAS (Vendor port alias)"""
13131313
set_interface_naming_mode('alias')
13141314

1315+
#
1316+
# 'syslog' group ('config syslog ...')
1317+
#
1318+
@config.group()
1319+
@click.pass_context
1320+
def syslog(ctx):
1321+
"""Syslog server configuration tasks"""
1322+
config_db = ConfigDBConnector()
1323+
config_db.connect()
1324+
ctx.obj = {'db': config_db}
1325+
pass
1326+
1327+
@syslog.command('add')
1328+
@click.argument('syslog_ip_address', metavar='<syslog_ip_address>', required=True)
1329+
@click.pass_context
1330+
def add_syslog_server(ctx, syslog_ip_address):
1331+
""" Add syslog server IP """
1332+
if not is_ipaddress(syslog_ip_address):
1333+
ctx.fail('Invalid ip address')
1334+
db = ctx.obj['db']
1335+
syslog_servers = db.get_table("SYSLOG_SERVER")
1336+
if syslog_ip_address in syslog_servers:
1337+
click.echo("Syslog server {} is already configured".format(syslog_ip_address))
1338+
return
1339+
else:
1340+
db.set_entry('SYSLOG_SERVER', syslog_ip_address, {'NULL': 'NULL'})
1341+
click.echo("Syslog server {} added to configuration".format(syslog_ip_address))
1342+
try:
1343+
click.echo("Restarting rsyslog-config service...")
1344+
run_command("systemctl restart rsyslog-config", display_cmd=False)
1345+
except SystemExit as e:
1346+
ctx.fail("Restart service rsyslog-config failed with error {}".format(e))
1347+
1348+
@syslog.command('del')
1349+
@click.argument('syslog_ip_address', metavar='<syslog_ip_address>', required=True)
1350+
@click.pass_context
1351+
def del_syslog_server(ctx, syslog_ip_address):
1352+
""" Delete syslog server IP """
1353+
if not is_ipaddress(syslog_ip_address):
1354+
ctx.fail('Invalid IP address')
1355+
db = ctx.obj['db']
1356+
db.set_entry('SYSLOG_SERVER', '{}'.format(syslog_ip_address), None)
1357+
click.echo("Syslog server {} removed from configuration".format(syslog_ip_address))
1358+
try:
1359+
click.echo("Restarting rsyslog-config service...")
1360+
run_command("systemctl restart rsyslog-config", display_cmd=False)
1361+
except SystemExit as e:
1362+
ctx.fail("Restart service rsyslog-config failed with error {}".format(e))
13151363

13161364
if __name__ == '__main__':
13171365
config()

doc/Command-Reference.md

+31
Original file line numberDiff line numberDiff line change
@@ -4079,4 +4079,35 @@ This command displays the routing policy that takes precedence over the other ro
40794079
Exit routemap
40804080
```
40814081

4082+
# Syslog Server Configuration Commands
4083+
4084+
This sub-section of commands is used to add or remove the configured syslog servers.
4085+
4086+
**config syslog add**
4087+
4088+
This command is used to add a SYSLOG server to the syslog server list. Note that more that one syslog server can be added in the device.
4089+
4090+
- Usage: config syslog add <ip-address>
4091+
- Example:
4092+
```
4093+
admin@str-s6000-acs-11:~$ sudo config syslog add 1.1.1.1
4094+
Syslog server 1.1.1.1 added to configuration
4095+
Restarting rsyslog-config service...
4096+
admin@str-s6000-acs-11:~$
4097+
```
4098+
4099+
**config syslog delete**
4100+
4101+
This command is used to delete the syslog server configured.
4102+
4103+
- Usage: config syslog del <ip-address>
4104+
- Example:
4105+
```
4106+
admin@str-s6000-acs-11:~$ sudo config syslog del 1.1.1.1
4107+
Syslog server 1.1.1.1 removed from configuration
4108+
Restarting rsyslog-config service...
4109+
admin@str-s6000-acs-11:~$
4110+
```
4111+
4112+
40824113
Go Back To [Beginning of the document](#SONiC-COMMAND-LINE-INTERFACE-GUIDE) or [Beginning of this section](#Quagga-BGP-Show-Commands)

0 commit comments

Comments
 (0)