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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...