Context and Outputs
Overview#
The Context is a map (dictionary) / JSON object that is created for each incident and is used to store structured results from the integration commands and automation scripts. The Context keys are strings and the values can be strings, numbers, objects, and arrays.
The main use of the Context is to pass data between playbook tasks, one task stores its output in the Context and the other task reads that output from the Context and uses it.
Let's look at a real world example that can show you how the Context is used:
For example ThreatStream integration has the command threatstream-analysis-report. The command returns the report of a file or URL that was submitted to the sandbox.
The response from the REST API#
Integration YML#
In the integration YAML file, the command outputs are defined as such: BrandName.Object.PropertyName
For each output entry, you have three fields; Context Path, Description and Type. Their uses are as follows:
- Context Path - This is a Dot Notation representation of the path to access the Context.
- Description - A short description of what this Context entry represents.
- Type - Indicating the type of value that is located at the path. Enables Cortex XSOAR to format the data correctly.
Use json-to-outputs command in
demisto-sdk tool to convert JSON into yml.
Example: demisto-sdk json-to-outputs -c threatstream-analysis-report -p ThreatStream.Analysis
In the code#
note
- The code must match the context path outputs specified in the YAML file.
- You can output the API response as is to the context as a raw value, under the brand name key. There is no need to modify the API response and map it to human-readable keys. You might still see old integrations in which this type of mapping is performed, but this is not a requirement.
- Avoid using dot and space characters in the context path keys.
Context Use Cases#
Important Note
When setting integration_name
with the vendor value, make sure it matches the name of the integration as defined in the yml file.
Return Data (common case)#
YAML Definition
Markdown
Results#
id name 100 alert1 200 alert2
Context Data - The way it is stored in the incident context data
Return results with custom markdown#
Markdown
This is the Header#
Table Title#
id name 100 alert1 200 alert2
Return Data that has multiple unique identifier fields#
note
Key fields are used to determine whether the data will be updated or added as new. More info
Return File#
Note: potentially malicious file - e.g. email attachment
YAML Definition
Return Info File#
Note: non malicious files - e.g. reports
YAML Definition
Return IP reputation#
For an integration usage example of how the code implements the indicator reputation command, see AutofocusV2 integration.
Context Data - The way it is stored in the incident context data
YAML Definition
Markdown
Results#
asn confidence indicator 12345 95 5.5.5.5
Return Domain reputation#
For an integration usage example of how the code implements the indicator reputation command, see AutofocusV2 integration.
YAML Definition
Context Data - The way it is stored in the incident context data
Return URL reputation#
For an integration usage example of how the code implements the indicator reputation command, see AutofocusV2 integration.
YAML Definition
Context Data - The way it is stored in the incident context data
Return File/Hash reputation#
For an integration usage example of how the code implements the indicator reputation command, see AutofocusV2 integration or CrowdsrikeMalquery.
YAML Definition
Context Data - The way it is stored in the incident context data
Return CVE reputation#
For an integration usage example of how the code implements the indicator reputation command, see CVESearchV2.
YAML Definition
Context Data - The way it is stored in the incident context data
Return Custom Indicators#
For more information, see CustomIndicatorDemo. For a usage example of the CustomIndicator helper class, see CustomIndicatorDemo .
Context Data - The way it is stored in the incident context data
YAML Definition
Return Multiple Indicators#
For an integration usage example of how the code implements the indicator reputation command, see MispV3.
In case you need to return multiple indicators (i.e. IPs) in the same call, you should return a list of CommandResults
, as shown in the following example.
Context Data - The way it is stored in the incident context data
YAML Definition
Markdown
Results#
asn confidence indicator 12345 95 5.5.5.5 54321 73 4.4.4.4
DT (Cortex XSOAR Transform Language)#
In the above example, we observe the entry context using (val.ReportID == obj.ReportID)
. This works to tie together related entry context objects. In this instance, we are using the value of the ReportID key as the unique identifier to search through the existing context and link related objects. This prevents data from being overwritten as well as further enriches an existing entry with more information. Learn more about linking context here.