# Contians the arg parser options. import argparse import sys def get_builder_args(): """ Gets the arguments passed in to the aom_builder main call :return: parser object """ parser = argparse.ArgumentParser(description="Generates a valid yaml file for alerting on metrics. " "If you are familiar with the yaml structure for an alert" "you don't have to use this builder, it's just convenient") parser.add_argument('-q', '--query', help="The Kariosdb query string to use") parser.add_argument('-i', '--interval', type=int, default=60, help="The interval that the check will run. " "This value is in seconds") parser.add_argument('-t', '--threshold', '--upperthreshold', help="The upper threshold is the value that when reached will cause an alert " "depending on the threshold logic. " "Use in conjunction with lower threshold to define a normal band.") parser.add_argument('-b', '--lowerthreshold', help="The lower threshold is the value that when reached will cause an alert " "depending on the threshold logic" "Use in conjunction with upper threshold to define a normal band.") parser.add_argument('-m', '--measure', choices=['gt', 'lt', 'eq'], help="The measure to use to compare the " "threshold to the values of the alerts") parser.add_argument('-a', '--alert_config', help='A valid Yaml representation of your alerting block') parser.add_argument('-l', '--log_level', type=int, default=0, help="The log level for the aom_builder run. " "[0=Error, 1=Info, 2=Debug]") parser.add_argument('-p', '--port', type=int, default=8080, help="The port to run the webapp on") return args_to_dict(parser) def get_tester_service_args(): """ Gets arguments passed into aom_tester.py Returns: parser object """ parser = argparse.ArgumentParser(description="Parameters to start the alerting on metrics dummy tester service") parser.add_argument('-l', '--log_level', type=int, default=0, help="The log level for the aom_service app" "[0=Error, 1=Info, 2=Debug]") parser.add_argument('-a', '--alert_configs', default=None, help="If provided will override the folder location read from the config with the value passed " "in. Is helpful for testing and troubleshooting alerts") parser.add_argument('--hostname', help="If provided, will override the actual hostname check with this value") parser.add_argument('-p', '--port', type=int, default=8080, help="The port to run the webapp on") return args_to_dict(parser) def get_service_args(): """ Gets arguments passed into aom_service.py Returns: parser object """ parser = argparse.ArgumentParser(description="Parameters to start the alerting on metrics service") parser.add_argument('-l', '--log_level', type=int, default=0, help="The log level for the aom_service app" "[0=Error, 1=Info, 2=Debug]") parser.add_argument('-a', '--alert_configs', default=None, help="If provided will override the folder location read from the config with the value passed " "in. Is helpful for testing and troubleshooting alerts") parser.add_argument('-o', '--override', action='store_true', help="Overrides the check leader election value") parser.add_argument('--hostname', help="If provided, will override the actual hostname check with this value") parser.add_argument('-p', '--port', type=int, default=8080, help="The port to run the webapp on") return args_to_dict(parser) def args_to_dict(parsed_args): """ Converts the argument parser object to a dict Args: parsed_args: Arg parser object Returns: Dictionary of arguments """ try: arg_list = parsed_args.parse_args() # RETURN A DICT OF ARGUMENTS arg_dict = dict() for val in vars(arg_list): arg_dict[val] = getattr(arg_list, val) return arg_dict except argparse.ArgumentError: parsed_args.print_help() sys.exit(1)