def run_check()

in src/queuealerter.py [0:0]


def run_check(config: list):
    if os.environ.get("SERVICE_KEY") is None or os.environ.get("SERVICE_KEY")=="":
        raise ValueError("You must specify SERVICE_KEY to indicate the PagerDuty service key to send alerts to")

    rmqpath = os.environ.get("RABBITMQ_CONFIG_PATH")
    if rmqpath is None or rmqpath == "":
        raise ValueError("You must specify RABBITMQ_CONFIG_PATH to indicate where the rabbitmq_client_uri file is located")

    no_ssl = os.environ.get("RABBITMQ_NO_SSL")
    if no_ssl is None:
        use_ssl = True
    else:
        use_ssl = no_ssl.lower() != "true"

    rmqconfig = RabbitMQConfig.load_from_files(rmqpath, use_ssl)
    for entry in config:
        current_messages = get_queued_message_count(entry["queue"], rmqconfig)
        logger.info("Currently there are {0} messages on the {1} queue".format(current_messages, entry["queue"]))
        if current_messages > entry["threshold"]:
            logger.warning("{0} is over the threshold of {1} so alerting...".format(entry["queue"], entry["threshold"]))
            msg = "The queue {0} currently has {1} messages which exceeds the alert threshold. Please investigate.".format(entry["queue"], current_messages)
            notify_pagerduty(msg, "trigger", "queuesize-{0}".format(entry["queue"]), current_messages)