GridFieldSetup
Automation used to more easily populate a grid field. This is necessary when you want to assign certain values as static or if you have context paths that you will assign to different values as well. Instead of a value you can enter `TIMESTAMP` to get the current timestamp in ISO format. For example: `!GridFieldSetup keys=ip,src,timestamp val1=${AWS.EC2.Instances.NetworkInterfaces.PrivateIpAddress} val2="AWS" val3="TIMESTAMP" gridfiled="gridfield"`.
python · Common Scripts
Source
import demistomock as demisto # noqa: F401 from CommonServerPython import * # noqa: F401 def grid_field_setup(keys: list[str], vals: dict, res_list: list) -> list[str]: """Returns a list of dictionaries based on the key/values provided. :type keys: ``str`` :type vals: ``dict`` :type res_list: ``list`` :param keys: comma separated values used for keys (columns) :param vals: dictionary of the value assigned to keys :param res_list: list of current entries in gridfield (or blank list) :return: list of dictionaries """ temp = {} for i, key in enumerate(keys, start=1): if vals[f"val{i}"] == "TIMESTAMP": temp[key] = datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%fZ") else: temp[key] = vals[f"val{i}"] res_list.append(temp) return res_list """ COMMAND FUNCTION """ def grid_field_setup_command(args: dict[str, str]) -> CommandResults: keys = argToList(args.pop("keys", [])) overwrite = args.pop("overwrite", False) gridfield = args.pop("gridfield", None) # logic here to check if empty result and set default list fields = demisto.incidents()[0].get("CustomFields") if not fields: raise ValueError("no Custom Fields present") orig = fields.get(gridfield) if not orig or argToBoolean(overwrite): orig = [] # dictionary or all vals vals = {k: v for k, v in args.items() if k.startswith("val")} # error is keys and value numbers don't align if len(keys) != len(vals): raise ValueError("number of keys and values needs to be the same") # Call the standalone function and get the raw response result = grid_field_setup(keys, vals, orig) results = demisto.executeCommand("setIncident", {gridfield: result}) return results """ MAIN FUNCTION """ def main(): try: return_results(grid_field_setup_command(demisto.args())) except Exception as ex: return_error(f"Failed to execute GridFieldSetup. Error: {ex!s}") """ ENTRY POINT """ if __name__ in ("__main__", "__builtin__", "builtins"): main()
README
Automation used to more easily populate a grid field. This is necessary when you want to assign certain values as static or if you have context paths that you will assign to different values as well. Instead of a value you can enter TIMESTAMP to get the current timestamp in ISO format. For example:
!GridFieldSetup keys=ip,src,timestamp val1=${AWS.EC2.Instances.NetworkInterfaces.PrivateIpAddress} val2="AWS" val3="TIMESTAMP" gridfiled="gridfield"
Script Data
| Name | Description |
|---|---|
| Script Type | python3 |
| Tags | Utility |
| Cortex XSOAR Version | 6.5.0 |
Inputs
| Argument Name | Description |
|---|---|
| keys | columns for the grid field in comma separated format |
| val1 | A value for the 1st key. (Can be a string or context path or TIMESTAMP to get the current timestamp in ISO format.) |
| val2 | A value for the 2nd key. (Can be a string or context path or TIMESTAMP to get the current timestamp in ISO format.) |
| val3 | A value for the 3rd key. (Can be a string or context path or TIMESTAMP to get the current timestamp in ISO format.) |
| val4 | A value for the 4th key. (Can be a string or context path or TIMESTAMP to get the current timestamp in ISO format.) |
| val5 | A value for the 5th key. (Can be a string or context path or TIMESTAMP to get the current timestamp in ISO format.) |
| val6 | A value for the 6th key. (Can be a string or context path or TIMESTAMP to get the current timestamp in ISO format.) |
| val7 | A value for the 7th key. (Can be a string or context path or TIMESTAMP to get the current timestamp in ISO format.) |
| val8 | A value for the 8th key. (Can be a string or context path or TIMESTAMP to get the current timestamp in ISO format.) |
| val9 | A value for the 9th key. (Can be a string or context path or TIMESTAMP to get the current timestamp in ISO format.) |
| val10 | A value for the 10th key. (Can be a string or context path or TIMESTAMP to get the current timestamp in ISO format.) |
| gridfield | Grid field to populate |
| overwrite | whether to overwrite what is in the gridfield or not (default is to append) |
Outputs
There are no outputs for this script.
Script Examples
Example command
!GridFieldSetup keys=url,verified val1="https://xsoar.pan.dev/" val2="verified" gridfield="urlsslverification"
Context Example
{}
Human Readable Output
Field URL SSL Verification Old Value [{“url”:”https://www.paloaltonetworks.com”,”verified”:”verified”}] New Value [{“url”:”https://www.paloaltonetworks.com”,”verified”:”verified”},{“url”:”https://xsoar.pan.dev/”,”verified”:”verified”}]
Example command
!GridFieldSetup keys=url,verified val1="https://www.paloaltonetworks.com" val2="verified" gridfield="urlsslverification" overwrite=true
Context Example
{}
Human Readable Output
Field URL SSL Verification Old Value [{“url”:”https://xsoar.pan.dev/”,”verified”:”verified”},{“url”:”https://xsoar.pan.dev/”,”verified”:”verified”}] New Value [{“url”:”https://www.paloaltonetworks.com”,”verified”:”verified”}]