Skip to content

Commit

Permalink
[config] Add commands for adding/removing syslog servers (sonic-net#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsvanduyn authored and jleveque committed Aug 19, 2019
1 parent 3d008ea commit 07bd868
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
48 changes: 48 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,54 @@ def naming_mode_alias():
"""Set CLI interface naming mode to ALIAS (Vendor port alias)"""
set_interface_naming_mode('alias')

#
# 'syslog' group ('config syslog ...')
#
@config.group()
@click.pass_context
def syslog(ctx):
"""Syslog server configuration tasks"""
config_db = ConfigDBConnector()
config_db.connect()
ctx.obj = {'db': config_db}
pass

@syslog.command('add')
@click.argument('syslog_ip_address', metavar='<syslog_ip_address>', required=True)
@click.pass_context
def add_syslog_server(ctx, syslog_ip_address):
""" Add syslog server IP """
if not is_ipaddress(syslog_ip_address):
ctx.fail('Invalid ip address')
db = ctx.obj['db']
syslog_servers = db.get_table("SYSLOG_SERVER")
if syslog_ip_address in syslog_servers:
click.echo("Syslog server {} is already configured".format(syslog_ip_address))
return
else:
db.set_entry('SYSLOG_SERVER', syslog_ip_address, {'NULL': 'NULL'})
click.echo("Syslog server {} added to configuration".format(syslog_ip_address))
try:
click.echo("Restarting rsyslog-config service...")
run_command("systemctl restart rsyslog-config", display_cmd=False)
except SystemExit as e:
ctx.fail("Restart service rsyslog-config failed with error {}".format(e))

@syslog.command('del')
@click.argument('syslog_ip_address', metavar='<syslog_ip_address>', required=True)
@click.pass_context
def del_syslog_server(ctx, syslog_ip_address):
""" Delete syslog server IP """
if not is_ipaddress(syslog_ip_address):
ctx.fail('Invalid IP address')
db = ctx.obj['db']
db.set_entry('SYSLOG_SERVER', '{}'.format(syslog_ip_address), None)
click.echo("Syslog server {} removed from configuration".format(syslog_ip_address))
try:
click.echo("Restarting rsyslog-config service...")
run_command("systemctl restart rsyslog-config", display_cmd=False)
except SystemExit as e:
ctx.fail("Restart service rsyslog-config failed with error {}".format(e))

if __name__ == '__main__':
config()
31 changes: 31 additions & 0 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -4079,4 +4079,35 @@ This command displays the routing policy that takes precedence over the other ro
Exit routemap
```

# Syslog Server Configuration Commands

This sub-section of commands is used to add or remove the configured syslog servers.

**config syslog add**

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.

- Usage: config syslog add <ip-address>
- Example:
```
admin@str-s6000-acs-11:~$ sudo config syslog add 1.1.1.1
Syslog server 1.1.1.1 added to configuration
Restarting rsyslog-config service...
admin@str-s6000-acs-11:~$
```

**config syslog delete**

This command is used to delete the syslog server configured.

- Usage: config syslog del <ip-address>
- Example:
```
admin@str-s6000-acs-11:~$ sudo config syslog del 1.1.1.1
Syslog server 1.1.1.1 removed from configuration
Restarting rsyslog-config service...
admin@str-s6000-acs-11:~$
```


Go Back To [Beginning of the document](#SONiC-COMMAND-LINE-INTERFACE-GUIDE) or [Beginning of this section](#Quagga-BGP-Show-Commands)

0 comments on commit 07bd868

Please sign in to comment.