From f0e3d3ef8f9dad895f7b6bc1768630f0ef17912e Mon Sep 17 00:00:00 2001 From: David Timber Date: Sun, 15 May 2022 21:31:54 +0800 Subject: Add boot-report subcmd ... - Fix palhm-dnssec-check.sh - Make "tasks" config optional so that PALHM can be used only for boot-report --- src/palhm.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'src/palhm.py') diff --git a/src/palhm.py b/src/palhm.py index 474f0a0..f008736 100755 --- a/src/palhm.py +++ b/src/palhm.py @@ -7,6 +7,7 @@ from abc import ABC, abstractmethod from getopt import getopt import palhm +from palhm.exceptions import InvalidConfigError class ProgConf: @@ -113,6 +114,23 @@ class ModsCmd (Cmd): "Usage: " + sys.argv[0] + " mods" + ''' Prints the available modules to stdout.''') +class BootReportCmd (Cmd): + def __init__ (self, *args, **kwargs): + pass + + def do_cmd (self): + ProgConf.alloc_ctx() + + if ProgConf.ctx.boot_report is None: + raise InvalidConfigError("'boot-report' not configured") + + return ProgConf.ctx.boot_report.do_send(ProgConf.ctx) + + def print_help (): + print( +"Usage: " + sys.argv[0] + " boot-report" + ''' +Send mail of boot report to recipients configured.''') + class HelpCmd (Cmd): def __init__ (self, optlist, args): self.optlist = optlist @@ -138,11 +156,12 @@ Options: -f FILE Load config from FILE instead of the hard-coded default Config: ''' + ProgConf.conf + ''' Commands: - run run a task - config load config and print the contents - help [CMD] print this message and exit normally if [CMD] is not specified. - Print usage of [CMD] otherwise - mods list available modules''') + run run a task + config load config and print the contents + help [CMD] print this message and exit normally if [CMD] is not specified. + Print usage of [CMD] otherwise + mods list available modules + boot-report mail boot report''') return 0 @@ -150,7 +169,8 @@ CmdMap = { "config": ConfigCmd, "run": RunCmd, "help": HelpCmd, - "mods": ModsCmd + "mods": ModsCmd, + "boot-report": BootReportCmd } optlist, args = getopt(sys.argv[1:], "qvf:") -- cgit v1.2.3-70-g09d2