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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...