def post_job_results(jobid):
    """called by Dalton Agent sending job results"""
    # no authentication or authorization so this is easily abused; anyone with jobid
    # can overwrite results if they submit first.
    redis = get_redis()

    # check and make sure job results haven't already been posted in order to prevent
    # abuse/overwriting.  This still isn't foolproof.
    if redis.exists("%s-time" % jobid) and (
        int(get_job_status(redis, jobid)) not in [STAT_CODE_RUNNING, STAT_CODE_QUEUED]
    ):
        logger.error(
            "Data for jobid %s already exists in database; not overwriting. Source IP: %s. job_status_code code: %d"
            % (jobid, request.remote_addr, int(get_job_status(redis, jobid)))
        )
        # typically this would go back to Agent who then ignores it
        return Response(
            "Error: job results already exist.",
            mimetype="text/plain",
            headers={"X-Dalton-Webapp": "Error"},
        )

    jsons = request.form.get("json_data")
    result_obj = json.loads(jsons)

    set_job_status_msg(redis, jobid, "Final Job Status: %s" % result_obj["status"])
    # get sensor hash and update ("%s-current_job" % SENSOR_HASH) with 'None'
    SENSOR_IP = request.remote_addr
    SENSOR_UID = "unknown"
    try:
        SENSOR_UID = request.args["SENSOR_UID"]
    except Exception:
        SENSOR_UID = "unknown"
    SENSOR_HASH = create_hash([SENSOR_UID, SENSOR_IP])
    redis.set(f"{SENSOR_HASH}-current_job", "")
    redis.expire(f"{SENSOR_HASH}-current_job", REDIS_EXPIRE)

    logger.info(
        "Dalton Agent %s submitted results for job %s. Result: %s",
        SENSOR_UID,
        jobid,
        result_obj["status"],
    )

    # save results to db
    if "ids" in result_obj:
        ids = result_obj["ids"]
    elif "snort" in result_obj:
        ids = result_obj["snort"]
    else:
        ids = ""
    if "performance" in result_obj:
        perf = result_obj["performance"]
    else:
        perf = ""
    if "alert" in result_obj:
        alert = result_obj["alert"]
    else:
        alert = ""
    if "error" in result_obj:
        error = result_obj["error"]
    else:
        error = ""
    if "debug" in result_obj:
        debug = result_obj["debug"]
    else:
        debug = ""
    if "total_time" in result_obj:
        time = result_obj["total_time"]
    else:
        time = ""
    # alert_detailed is base64 encoded unified2 binary data
    alert_detailed = ""
    if "alert_detailed" in result_obj:
        try:
            # write to disk and pass to u2spewfoo.py; we could do
            #  myriad other things here like modify or import that
            #  code but this works and should be compatible and
            #  incorporate any future changes/improvements to the
            #  script
            u2_file = os.path.join(
                TEMP_STORAGE_PATH, "%s_unified2_%s" % (jobid, SENSOR_HASH)
            )
            u2_fh = open(u2_file, "wb")
            u2_fh.write(base64.b64decode(result_obj["alert_detailed"]))
            u2_fh.close()
            u2spewfoo_command = "%s %s" % (U2_ANALYZER, u2_file)
            logger.debug(
                "Processing unified2 data with command: '%s'" % u2spewfoo_command
            )
            alert_detailed = subprocess.Popen(
                u2spewfoo_command,
                shell=True,
                stderr=subprocess.STDOUT,
                stdout=subprocess.PIPE,
            ).stdout.read()
            # delete u2 file
            os.unlink(u2_file)
        except Exception as e:
            logger.error("Problem parsing unified2 data from Agent.  Error: %s" % e)
            alert_detailed = ""
    else:
        alert_detailed = ""

    # other_logs only supported on Suricata for now
    if "other_logs" in result_obj:
        logger.debug("Accessing other_log data from agent POST...")
        other_logs = result_obj["other_logs"]
    else:
        other_logs = ""

    # EVE is Suricata only
    if "eve" in result_obj:
        logger.debug("Accessing EVE data from agent POST...")
        eve = result_obj["eve"]
    else:
        eve = ""

    # Use JSON logs for Zeek
    if "zeek_json" in result_obj:
        logger.debug("Accessing Zeek JSON data from agent POST...")
        zeek_json = result_obj["zeek_json"]
    else:
        zeek_json = False

    logger.debug("Saving job data to redis...")
    redis.set("%s-ids" % jobid, ids)
    redis.set("%s-perf" % jobid, perf)
    redis.set("%s-alert" % jobid, alert)
    redis.set("%s-error" % jobid, error)
    redis.set("%s-debug" % jobid, debug)
    redis.set("%s-time" % jobid, time)
    redis.set("%s-alert_detailed" % jobid, alert_detailed)
    redis.set("%s-other_logs" % jobid, other_logs)
    redis.set("%s-eve" % jobid, eve)
    if zeek_json is not None:
        redis.set("%s-zeek_json" % jobid, str(zeek_json))
    set_keys_timeout(redis, jobid)
    logger.debug("Done saving job data to redis.")

    if error:
        set_job_status_msg(
            redis,
            jobid,
            '<div style="color:red">ERROR!</div> <a href="/dalton/job/%s">Click here for details</a>'
            % jobid,
        )
    else:
        set_job_status_msg(
            redis,
            jobid,
            '<a href="/dalton/job/%s">Click here to view your results</a>' % jobid,
        )

    set_job_status(redis, jobid, STAT_CODE_DONE)
    logger.debug("Returning from post_job_results()")
    return Response("OK", mimetype="text/plain", headers={"X-Dalton-Webapp": "OK"})
called by Dalton Agent sending job results
app/dalton.py