Add custom fields to your Splunk SOAR (Cloud) playbook
You can define and use your own custom fields for events, either globally or for specific event types, in a Splunk SOAR (Cloud) playbook. For example, you might add a custom field named Department and assign it a list of values for each department in your organization (for example, IT Ops, Sales, and Business).
Using custom fields in playbooks requires special coding.
Plan your naming convention carefully. Custom field names described here require additional special handling:
- names containing characters other than letters, numbers, or underscores (_)
- names starting with a space
Update and read custom field values
To update custom field values in containers, use the following code examples with the container.update API :
Update a custom field value
Example code to update a custom field value from a container.
outputs = {}
# Write your custom code here...
container = {"id": container_id}
update = {
"custom_fields": {
field_name: field_value,
},
}
# Make the HTTP request
success, message = phantom.update(container, update)
assert success, message
# Return a JSON-serializable object
assert json.dumps(outputs) # Will raise an exception if the :outputs: object is not JSON-serializable
return outputs
Read a custom field value
While not technically an update function, reading a custom field value also uses the container.update API.
Example code to read (get) a custom field value from a container.
outputs = {}
# Write your custom code here...
container = phantom.get_container(container_id)
custom_fields = container.get("custom_fields", {})
outputs["field_found"] = field_name in custom_fields
outputs["field_value"] = custom_fields.get(field_name)
# Return a JSON-serializable object
assert json.dumps(outputs) # Will raise an exception if the :outputs: object is not JSON-serializable
return outputs