From 4e1755d4f2fc45509d6a9dbc90498c81bcf7015d Mon Sep 17 00:00:00 2001 From: Rajendra Dendukuri Date: Mon, 30 Nov 2020 22:19:12 -0800 Subject: [PATCH] Added 'config core' and 'show cores' CLI commands Signed-off-by: Rajendra Dendukuri --- config/main.py | 27 +++++++++++++++++++ show/main.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/config/main.py b/config/main.py index b832c45cb9..07e867777f 100755 --- a/config/main.py +++ b/config/main.py @@ -1901,6 +1901,33 @@ def shutdown(): """Shut down BGP session(s)""" pass +@config.group(cls=clicommon.AbbreviationGroup) +def core(): + """ Configure coredump """ + if os.geteuid() != 0: + exit("Root privileges are required for this operation") + pass + +@core.command() +@click.argument('disable', required=False) +def disable(disable): + """Administratively Disable coredump generation""" + config_db = ConfigDBConnector() + config_db.connect() + table = "COREDUMP" + key = "config" + config_db.set_entry(table, key, {"enabled": "false"}) + +@core.command() +@click.argument('enable', required=False) +def enable(enable): + """Administratively Enable coredump generation""" + config_db = ConfigDBConnector() + config_db.connect() + table = "COREDUMP" + key = "config" + config_db.set_entry(table, key, {"enabled": "true"}) + @config.group(cls=clicommon.AbbreviationGroup) def kdump(): """ Configure kdump """ diff --git a/show/main.py b/show/main.py index 6fb8beb9fd..c0aea3d056 100755 --- a/show/main.py +++ b/show/main.py @@ -1423,6 +1423,76 @@ def system_memory(verbose): cmd = "free -m" run_command(cmd, display_cmd=verbose) +# +# 'coredumpctl' group ("show cores") +# + +@cli.group(cls=clicommon.AliasedGroup) +def cores(): + """Show core dump events encountered""" + pass + +# 'config' subcommand ("show cores config") +@cores.command('config') +@click.option('--verbose', is_flag=True, help="Enable verbose output") +def core_config(verbose): + """ Show coredump configuration """ + # Default admin mode + admin_mode = True + # Obtain config from Config DB + config_db = ConfigDBConnector() + if config_db is not None: + config_db.connect() + table_data = config_db.get_table('COREDUMP') + if table_data is not None: + config_data = table_data.get('config') + if config_data is not None: + admin_mode = config_data.get('enabled') + if admin_mode is not None and admin_mode.lower() == 'false': + admin_mode = False + + # Core dump administrative mode + if admin_mode: + click.echo('Coredump : %s' % 'Enabled') + else: + click.echo('Coredump : %s' % 'Disabled') + +# 'list' subcommand ("show cores list") +@cores.command('list') +@click.argument('pattern', required=False) +@click.option('--verbose', is_flag=True, help="Enable verbose output") +def core_list(verbose, pattern): + """ List available coredumps """ + + if not os.geteuid()==0: + click.echo("Note: To list all the core files please run the command with root privileges\n") + + if os.path.exists("/usr/bin/coredumpctl"): + cmd = "coredumpctl list" + if pattern is not None: + cmd = cmd + " " + pattern + run_command(cmd, display_cmd=verbose) + else: + exit("Note: Install systemd-coredump package to run this command") + +# 'info' subcommand ("show cores info") +@cores.command('info') +@click.argument('pattern', required=False) +@click.option('--verbose', is_flag=True, help="Enable verbose output") +def core_info(verbose, pattern): + """ Show information about one or more coredumps """ + + if not os.geteuid()==0: + click.echo("Note: To view all the core files please run the command with root privileges\n") + + if os.path.exists("/usr/bin/coredumpctl"): + cmd = "coredumpctl info" + if pattern is not None: + cmd = cmd + " " + pattern + run_command(cmd, display_cmd=verbose) + else: + exit("Note: Install systemd-coredump package to run this command") + # # 'kdump command ("show kdump ...") #