Skip to content
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

[config] Add commands for adding/removing syslog servers #609

Merged
merged 5 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Collaborator

@stephenxs stephenxs Sep 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jleveque @tsvanduyn
It seems that the function name "syslog" conflicts with the module "syslog", causing functions calling logxxx failed, like "config load_minigraph".
Is it possible to rename it, like "logserver"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephenxs / @jleveque the ticket: #635

"""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)