Exemplo n.º 1
0
def controller():
    inputs = "ccc16:hhh21"
    #splitter = inputs[1].split(":")
    splitter = inputs.split(":")
    username = splitter[0]
    password = splitter[1]
    connection = "mongodb+srv://" + username + ":" + password + "@scte.cfbun.mongodb.net/Configurations?retryWrites=true&w=majority"
    client = pymongo.MongoClient(connection)
    db = client.test
    print(db)
    col = client["Configurations"]
    x = col["Adspace"]
    z = col["BackendConfigs"]

    for network in z.distinct("network_id"):
        print(network)
        for j in z.find({"network_id": network}):
            pass
        print(j)
        for message in x.find({"NetworkId": network}):
            print(message)
            q = queue.Queue()
            t = threading.Thread(target=neovalidator2.getfrommongo(),
                                 args=(network, j, message, q)).start()
            t.join()
            print("t end")
            result = q.get()
            neoalert.alert_issues(result[0], str(result[1]), str(result[2]), j)
Exemplo n.º 2
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"}
Exemplo n.º 3
0
def getfrommongo():
    
    for config in z.find({"network_id" : "MSNBC-4000"}):
        pass

    #for nodes in x.find({"_id" :ObjectId('60b80a323b77502dce74aae1')}, {"0"}):
        #pass

    #for j in z.distinct({"network_id"}):
        #for nodes in x.find({"NetworkId": j}):
            #pass

    for nodes in x.find({"NetworkId": "MSNBC-1590.dfw.1080"}):
        decode_input = Cue(nodes["inputBase64"])
        decode_output = Cue(nodes["OutputBase64"])
        action = nodes["Action"].strip()
        uuid = nodes["Uuid"]
        result = log_verify(decode_input, decode_output, action, uuid, config)
        neoalert.alert_issues(result[0], result[1], result[2], uuid, config)
Exemplo n.º 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