Hi Everyone,
A common issue I have been facing is how can I provide UDM fields in the automated messages in my SOAR playbooks. The current way is to type out the UDM field and use the Placeholder variable to select which fields you want to select. ie)
principal.ip="[Event.event_principal_ip]"
Which can take quite a bit of time, especially if you want to enter +10 UDM fields!
To remedy this I used the Render Template action to create a JINJA2 script that would perform the conversion automatically and format it so it can be copy/pasted directly into a UDM search for further investigation. Here is the script(be sure to select the "Include Case Data" check box):
{% set CaseData = input_json['SiemplifyEvents'] %}
{% if CaseData is defined %}
{% for event in CaseData %}
{% for item in event%}
{% if "ip" in item and "event" in item%}
{% set word = ".".join(item.split("_")) %}
{% set UDM=[] %}
{% for index in range(word|length) %}
{% if word[index] in "1234567890" %}
{% if word[index-1]=="." %}
{% do UDM.pop() %}
{% endif %}
{% elif word[index] == word[index]|upper and word[index] != "."%}
{% do UDM.append("_") %}
{% do UDM.append(word[index]|lower|safe) %}
{% else %}
{% do UDM.append(word[index]|safe) %}
{% endif %}
{% endfor %}
{% set TempName = "".join(UDM)%}
{% set UDM_Field = ".".join(TempName.split(".")[1:])|safe%}
{{UDM_Field+"=\""|safe+event[item]|safe+"\""|safe}}
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
It's not the prettiest or fastest thing ever, but it does get the job done! Of course you likely don't want every field under the sun in your report. Line 6 is the place to filter for which fields you want. In this example, I am returning all fields that have "ip" and "event" in them. This is usually good enough for a high level over view of certain values.
If you want a more specific list I would recommend copying udm fields from a sample log and using excel to get everything before the "=" (I use =leftsplit in excel).
{% set CaseData = input_json['SiemplifyEvents'] %}
{% set UDM_Filter = ["principal.ip","principal.hostname"] %}
{% if CaseData is defined %}
{% for event in CaseData %}
{% for item in event%}
{% if "ip" in item and "event" in item%}
{% set word = ".".join(item.split("_")) %}
{% set UDM=[] %}
{% for index in range(word|length) %}
{% if word[index] in "1234567890" %}
{% if word[index-1]=="." %}
{% do UDM.pop() %}
{% endif %}
{% elif word[index] == word[index]|upper and word[index] != "."%}
{% do UDM.append("_") %}
{% do UDM.append(word[index]|lower|safe) %}
{% else %}
{% do UDM.append(word[index]|safe) %}
{% endif %}
{% endfor %}
{% set TempName = "".join(UDM)%}
{% set UDM_Field = ".".join(TempName.split(".")[1:])|safe%}
{% if UDM_Field in UDM_Filter %}
{{UDM_Field+"=\""|safe+event[item]|safe+"\""|safe}}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
Solved! Go to Solution.
Thanks for the contribution Moseis!
I have done similar (but different) recently but from a different angle, I'm adding here to compliment your work above.
1 Create a string of entity types
2. Use Jinja (like you did) to create a string
(sorry it's not letting me add the code in clear text to copy)
3 The output is a simple request for 1 entity type
hash ="abcdef123" or hash = "abcdef123"
Thanks for the contribution Moseis!
I have done similar (but different) recently but from a different angle, I'm adding here to compliment your work above.
1 Create a string of entity types
2. Use Jinja (like you did) to create a string
(sorry it's not letting me add the code in clear text to copy)
3 The output is a simple request for 1 entity type
hash ="abcdef123" or hash = "abcdef123"