ExecuteCommandAt

A wrapper script for the executeCommandAt command to be used in playbooks or the war-room.

python · Common Scripts

Source

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


def execute_command_at(command: Any, incident_ids: list, arguments: dict | str) -> Any:
    # ensure that incident ids is a comma-separated list
    csv_incident_ids = ",".join(map(str, incident_ids))

    arguments_dict_error_msg = "Failed to execute ExecuteCommandAt. Argument 'arguments' must be in a dict format"

    if isinstance(arguments, list):
        raise DemistoException(arguments_dict_error_msg)

    if isinstance(arguments, str):
        try:
            arguments = json.loads(arguments)
        except Exception as ex:
            raise DemistoException(f"Failed to parse Argument 'arguments' {ex}")

        if not isinstance(arguments, dict):
            raise DemistoException(arguments_dict_error_msg)

    return execute_command("executeCommandAt", {"command": command, "incidents": csv_incident_ids, "arguments": arguments})


def main() -> None:
    try:
        args = demisto.args()
        incident_ids: list = argToList(args.get("incident_ids"))
        command = args.get("command")
        arguments = args.get("arguments", {})

        return_results(execute_command_at(command, incident_ids, arguments))

    except Exception as ex:
        return_error(f"Failed to execute ExecuteCommandAt. Error: {ex}")


if __name__ in ("__main__", "__builtin__", "builtins"):
    main()

README

A wrapper script for the executeCommandAt command to be used in playbooks or the war-room

Script Data


Name Description
Script Type python3
Cortex XSOAR Version 6.0.0

Inputs


Argument Name Description
incident_ids The incident ids to run the command on. Can be passed in as CSV format for multiple.
command The command name to run
arguments The arguments to pass into the command. The format should be like: {"argument_name": "argument_value"}

Outputs


There are no outputs for this script.

Usage Notes


Executing commands on another incident

```war room
// single incident example:
!ExecuteCommandAt command=”Print” incident_ids=”" arguments=`{"value":"hello world"}`

// multiple incident example:
!ExecuteCommandAt command=”Print” incident_ids=”," arguments=`{"value":"hello world"}` ```