Alerting

How to change the alert email result format?

svasani_splunk
Splunk Employee
Splunk Employee

How do I format the email result to display the result in following format instead of table format?

Event 1
field1: value
field2: value

Event 2
field1: value
field2: value

Event 3
field1: value
field2: value

Event 4
field1: value
field2: value

.
.
.

0 Karma
1 Solution

svasani_splunk
Splunk Employee
Splunk Employee

You can format the email result by modifying the _raw field. To number the events use accum command and for new line between fields press shift+enter in empty quotes.

Example SPL

index=apache uri_path=*
| eval event_count = 1
| accum event_count
| eval _raw="Event " . event_count . "
" . "uri_path:".uri_path."
"."Source:".source

Make sure to check Inline box and select raw in email alert settings

Email Result
alt text

View solution in original post

svasani_splunk
Splunk Employee
Splunk Employee

You can format the email result by modifying the _raw field. To number the events use accum command and for new line between fields press shift+enter in empty quotes.

Example SPL

index=apache uri_path=*
| eval event_count = 1
| accum event_count
| eval _raw="Event " . event_count . "
" . "uri_path:".uri_path."
"."Source:".source

Make sure to check Inline box and select raw in email alert settings

Email Result
alt text

jwelsh_splunk
Splunk Employee
Splunk Employee

This came from a customer that wanted a way to send the entire result set from a search inside the email message body, instead of a CSV, HTML, or PDF attachment.

More importantly, customer wanted to specify a general template that could be used to format how each row of the result set would look in the message body. AND include the result set row number in each iteration.

eval event_count_1 initializes that count.
accum event_count keeps a running total, which get's printed with each iteration through the result set.

Here's a great blog on accum: https://www.splunk.com/blog/2014/05/16/search-commands-accum.html

0 Karma

jrsoffe
Engager

Extremely helpful solution for verbose results where a table just doesn't provide the formatting capability.

0 Karma
Get Updates on the Splunk Community!

Demo Day: Strengthen Your SOC with Splunk Enterprise Security 8.1

Today’s threat landscape is more complex than ever. Security operation centers (SOCs) are overwhelmed with ...

Dashboards: Hiding charts while search is being executed and other uses for tokens

There are a couple of features of SimpleXML / Classic dashboards that can be used to enhance the user ...

Splunk Observability Cloud's AI Assistant in Action Series: Explaining Metrics and ...

This is the fourth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how ...