Example #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
Example #2
0
def write_configuration(body=Body(..., media_type="application/json")):
    if triggervalidator.verifyconfiguration(body):
        open(CONFIG_FILE, "w").write(json.dumps(body))
        return json.loads(open(CONFIG_FILE, "r").read())
    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"}
Example #3
0
def verifylogs(response: Response,
               body: str = Body(..., media_type="text/plain")):
    f = open("./logs/" + body, "r")
    #f = reversed(f)
    #f = open("./logs/test1.log", "r")
    #for now the log file itself is hardcoded, but can be easily automated once,
    #other splice command types has been implemented

    r = requests.get('http://127.0.0.1:8000/networks')
    string = ""

    # for i in r:
    #     print(type(i))
    #     string= str(i)
    # print(string)
    # index = str(string)
    # list_i = index.split(",")
    for nodes in x.find({"_id": 1}):
        #print(nodes)
        pass

    body_log = str(f.read()).strip().splitlines()
    #below is an one of the ways to reverse read
    #body_log = body_log[::-1]
    #config = json.loads(open(CONFIG_FILE, "r").read())
    config = nodes
    env = json.loads(open(ENV_FILE, "r").read())
    #config loop required
    if triggervalidator.verifyconfiguration(config):
        #for item in reversed(body_log):
        for item in body_log:
            #print(item)
            #please read the comments above devi_func in neovalidator
            #on why there is an nested for-loop reading in reverse
            for itex in reversed(body_log):
                neovalidator.devi_func(itex, config)
            result = neovalidator.logverify(item, config)
            print(result)
            # triggeralert.alert_issues(
            #     result[0], result[1], result[2], config, env)
            neoalert.alert_issues(result[0], str(result[1]), str(result[2]),
                                  config)
        #print("action dict outside loop before clear : " + str(neovalidator.action_dict))
        neovalidator.action_dict_clear()
        print("action dict outside loop after clear : " +
              str(neovalidator.action_dict))
        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"}
Example #4
0
def trigger_monitor_daemon(env_file, config_file):
    '''
    Function that runs on interval and calls the validator tool over a file
    '''
    #for nodes in x.find({"_id":1}):

    #t = threading.Thread(target=neovalidator.logverify(body_log, config), args=(10,))

    #t.start()

    #t.join()

    while True:
        translator.network_translate()
        f = open("./logs/only-insert.log", "r")
        for nodes in x.find({"_id": 1}):
            pass
        body_log = str(f.read()).strip().splitlines()
        #config = json.loads(open(config_file, "r").read())
        config = nodes
        env = json.loads(open(ENV_FILE, "r").read())
        if triggervalidator.verifyconfiguration(config):
            print("Running verification ...")

            # Call trigger verification tool
            for item in body_log:
                for itex in reversed(body_log):
                    neovalidator.devi_func(itex, config)
                result = neovalidator.logverify(item, config)
                neoalert.alert_issues(result[0], str(result[1]),
                                      str(result[2]), config)
            neovalidator.action_dict_clear()
            # 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
Example #5
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"}