diff --git a/config/main.py b/config/main.py index caf74b08d0..59b899a818 100755 --- a/config/main.py +++ b/config/main.py @@ -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='', 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='', 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() diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index a37be1df64..e03bbcea2e 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -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 +- 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 +- 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)