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!

Earn a $35 Gift Card for Answering our Splunk Admins & App Developer Survey

Survey for Splunk Admins and App Developers is open now! | Earn a $35 gift card!      Hello there,  Splunk ...

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...