initial work

This commit is contained in:
Kristian Krsnik 2023-10-03 21:41:51 +02:00
parent 7d73544d0a
commit 6f5e1f59d0
Signed by: Kristian
GPG Key ID: FD1330AC9F909E85
1 changed files with 55 additions and 5 deletions

View File

@ -255,12 +255,62 @@ def loadConfig() -> tuple[dict, str]:
return config, mode
def parseArgs(args: list[str]):
import argparse
parser = argparse.ArgumentParser(
prog='outage_detector', description='Log outages and print statistics.', formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
subparsers = parser.add_subparsers()
parser_outages = subparsers.add_parser(
'outages', help='Print outages', formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser_outages.add_argument(
'log_path', type=str, default='./connection.log',
help='Path to a file with connection logs.'
)
parser_outages.add_argument(
'--time', type=int, default=3,
help='Minimum duration for a connection loss to be considered an outage.'
)
parser_log = subparsers.add_parser(
'log', help='Log the connection status.', formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser_log.add_argument(
'--config', type=str, default='./config.json',
help='Path to a config file in JSON format.'
)
parser_log.add_argument(
'--path', type=str, default='./connection.json',
help='Path to a the file where results should be appended to. Creates the file if it does not exist.'
)
parser_log.add_argument(
'--host', type=str, default='1.1.1.1',
help='IP or hostname of a server to query.'
)
parser_log.add_argument(
'--timeout', type=int, default=2,
help='Set the timeout in seconds to use for the connection test.'
)
parser_log.add_argument(
'--no-stdout', action='store_true', default=argparse.SUPPRESS,
help='A flag that disables printing to stdout.'
)
parser.parse_args(args)
def main():
config, mode = loadConfig()
if mode == 'log':
log(config)
elif mode == 'outages':
printOutages(config)
from sys import argv
parseArgs(argv[1:])
# config, mode = loadConfig()
# if mode == 'log':
# log(config)
# elif mode == 'outages':
# printOutages(config)
if __name__ == '__main__':