def get_engine_version(path):
    """returns the version of the engine given full path to binary (e.g. Suricata, Snort)."""
    global SENSOR_ENGINE_VERSION_ORIG
    engine = "unknown"
    version = "unknown"
    try:
        binary_name = os.path.basename(path).lower()
        if "zeek" in binary_name:
            command = f"{path} --version"
        elif "snort" in binary_name or "suricata" in binary_name:
            command = f"{path} -V"
        process = subprocess.Popen(
            command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
        )
        stdout, stderr = process.communicate()
        regex = re.compile(
            r"(Version|(Suricata|zeek) version)\s+(?P<version>\d+[\d\x2E\x2D\5FA-Za-z]*)"
        )
        if stderr:
            # apparently 'Snort -V' outputs to stderr....
            output = stderr
        else:
            output = stdout
        # get engine from output
        if "Suricata" in output.decode("utf-8"):
            engine = "suricata"
        elif "Snort" in output.decode("utf-8"):
            engine = "snort"
        elif "zeek" in output.decode("utf-8"):
            engine = "zeek"
        else:
            # use filename of binary
            engine = os.path.basename(path).lower()
            logger.warn(
                "Could not determine engine name, using '%s' from IDS_BINARY path"
                % engine
            )

        # get version from output
        result = regex.search(output.decode("utf-8"))
        if result:
            version = result.group("version")

        SENSOR_ENGINE_VERSION_ORIG = version

        # if Suricata version 4, see if Rust is enabled and add to version string
        if "suricata" in engine and version.split(".")[0] == "4":
            process = subprocess.Popen(
                '%s --build-info | grep "Rust support"' % path,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                shell=True,
            )
            stdout, stderr = process.communicate()
            if "yes" in str(stdout):
                # rust support exists
                version = "rust_%s" % version
    except Exception as e:
        logger.warn("Exception in get_engine_version(): %s" % e)
        pass
    logger.debug(
        "Using IDS binary '%s': engine: '%s', version '%s'" % (path, engine, version)
    )
    return (engine, version)
returns the version of the engine given full path to binary (e.g. Suricata, Snort).
dalton-agent/dalton-agent.py