RunDockerCommand

This command will allow you to run commands against a local Docker Container. You can run commands like wc for instance with word count, or other types of commands that you want on the docker container. We recommend for tools that you want to use that are not part of the default Docker container, to cope this Automation script and then create a customer docker container with /docker_image_create with a custom docker container to add any command level tool to Demisto and output the results directly to the context.

python · Common Scripts

Source

import subprocess

import demistomock as demisto  # noqa: F401
from CommonServerPython import *  # noqa: F401


def main():
    ret = []
    sysargs = None

    cmdarg = demisto.args()["cmd"]
    if "sysargs" in demisto.args():
        sysargs = demisto.args()["sysargs"]

    if sysargs is None:
        output = None
        try:
            cmd_list = cmdarg.split()
            output = subprocess.check_output(cmd_list, shell=False)
        except subprocess.CalledProcessError as e:
            output = e.output
        ret.append(output)
    else:
        ret.append(subprocess.check_output([cmdarg, sysargs]))

    ret = [r.decode("utf-8") for r in ret]  # type:ignore[union-attr]
    ec = {"Command": cmdarg, "Results": ret[0]}

    demisto.results(
        {
            "Type": entryTypes["note"],
            "ContentsFormat": formats["json"],
            "Contents": ret,
            "HumanReadable": ret[0],
            "EntryContext": {"CommandResults": ec},
        }
    )


if __name__ in ("__main__", "__builtin__", "builtins"):
    main()
    sys.exit(0)

README

Allows you to run commands against a local Docker container. A command such as wc with word count, or other types of commands that you want on the docker container.

We recommend for tools that you want to use that are not part of the default Docker container, to cope this Automation script and then create a customer docker container with /docker_image_create with a custom docker container to add any command level tool to Cortex XSOAR and output the results directly to the context.

Script Data


Name Description
Script Type python
Tags Utilities

Inputs


Argument Name Description
cmd The command to enter.
sysargs The sysargs to enter.

Outputs


Path Description Type
CommandResults.Command Contains the command line tool name and arguments that were run. Unknown
CommandResults.Results Returns the results as a single string of the results. The results of the command will need to be parsed into the preferred format. Use commands such as ExtractRegex or create your own follow on automation script that will parse the results into your preferred format. Unknown