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!

Splunk Enterprise Security 8.0.2 Availability: On cloud and On-premise!

A few months ago, we released Splunk Enterprise Security 8.0 for our cloud customers. Today, we are excited to ...

Logs to Metrics

Logs and Metrics Logs are generally unstructured text or structured events emitted by applications and written ...

Developer Spotlight with Paul Stout

Welcome to our very first developer spotlight release series where we'll feature some awesome Splunk ...