예제 #1
0
def trigger_monitor_daemon(env_file, config_file):
    '''
    Function that runs on interval and calls the validator tool over a file
    '''
    while True:
        config = json.loads(open(config_file, "r").read())
        if triggervalidator.verifyconfiguration(config):
            print("Running verification ...")

            # Call trigger verification tool
            # [template_issues, action_issues, timing_issues]
            env = json.loads(open(env_file, "r").read())
            file_path = env["path_to_logs"] + \
                "/Cooking-Esam_transform.log"  # Hardcoded file
            log = open(file_path, 'r').read().strip().splitlines()
            result = triggervalidator.verifytriggers(log, config)
            print("ISSUES =", result)
            # Alert via email
            triggeralert.alert_issues(result[0], result[1], result[2], config,
                                      env)

            # Set interval
            # config frequency is in minutes, convert to seconds
            seconds = config["frequency"] * 60
            print("Thread will pause", seconds, "seconds")
            time.sleep(seconds)
        else:
            print(
                "Configuration file is invalid, please verify the config.json is valid."
            )
            time.sleep(120)  # Sleep for 2 minutes before re-trying
예제 #2
0
def verify_triggers(response: Response, body: str = Body(..., media_type="text/plain")):
    # Strip log form any trailing whitespaces then split on end of lines
    body_log = str(body).strip().splitlines()
    # Load the configuration and env info
    config = json.loads(open(CONFIG_FILE, "r").read())
    env = json.loads(open(ENV_FILE, "r").read())
    # Verify if configuration is valid then proceed
    if triggervalidator.verifyconfiguration(config):
        # Call trigger verification tool
        # [template_issues, action_issues, timing_issues]
        result = triggervalidator.verifytriggers(body_log, config)

        # Alert via email
        triggeralert.alert_issues(
            result[0], result[1], result[2], config, env)

        return str(result)
    else:
        # Send error status code when config is not valid
        response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
        return {"error": "Config file is invalid or corrupted"}