Alerting

Send an e-mail to a variable located in your results

cburr2012
Path Finder

Hello all,

I have a query that is locating users that are logging in to our exchange server. I have an alert set up that sends the username to a static e-mail address.

I would like to make that static e-mail address dynamic based on the results pulled from the table.

i.e.: index=exchange these_terms_here --> yields --> johndoe@google.com

Instead of alerting ME that johndoe@google.com has logged in, I want to alert johndoe@google.com that he has logged in.

I was thinking that Splunk uses Splunk Alert: $name$, so I could just call my field from the search results $email$, but that appears to be local to the create alert function.

Other than a Python script, thoughts? I will do it w/ Python if there are no local-to-Splunk options. Thanks!

Tags (4)
0 Karma
1 Solution

yannK
Splunk Employee
Splunk Employee

The basic alerting doesn't allow dynamic email destination.
If you want to go this way, use scripted alerts, and write a script that :

  • have your search result contain the email in it
    • takes the arguments from the alert
    • open the result file, look for the email the results
    • sent the email (or call the email script sendemail.py) with the new arguments.

see http://docs.splunk.com/Documentation/Splunk/4.3.3/admin/ConfigureScriptedAlerts

View solution in original post

troywollenslege
Path Finder

Did you ever create a script to do this? Willing to share?

0 Karma

troywollenslege
Path Finder

Splunk says you can upload just scripts to their site.. maybe here?

https://www.splunk.com/index.php?module=roles&func=showloginform&artid=splunkbase&redirecturl=http:/...

Built something useful with Splunk? Want to share it?
Why not package it into an app and upload it?

Uploads don't have to be complex. Even one useful script, saved search, or view can help others in the Splunk Community!

0 Karma

cburr2012
Path Finder

Yes, I did create a script to do this. After some trial and error, it is working. I will find a way to share this.

0 Karma

ramgnisiv
Path Finder

6 yrs later, i have the same problem. Does someone have a script they can share?

0 Karma

fulldanad
Path Finder

Hi

FYI, we did it with the following SPL request :

| inputlookup lookup_FILTER_EMAIL.csv
| map search="search index=xxx

| search filter=$FILTER$

| eval mail=$EMAIL$
| sendemail to=\"$EMAIL$\" subject=\"test $FILTER$\" sendresults=false sendcsv=true " maxsearches=20

0 Karma

gjanders
SplunkTrust
SplunkTrust
0 Karma

fulldanad
Path Finder

Hi,

Were you able to share the script somewhere ?

Rgds
Dan

0 Karma

yannK
Splunk Employee
Splunk Employee

The basic alerting doesn't allow dynamic email destination.
If you want to go this way, use scripted alerts, and write a script that :

  • have your search result contain the email in it
    • takes the arguments from the alert
    • open the result file, look for the email the results
    • sent the email (or call the email script sendemail.py) with the new arguments.

see http://docs.splunk.com/Documentation/Splunk/4.3.3/admin/ConfigureScriptedAlerts

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Observability Simplified: Combining User Experience, Application Performance & ...

Tech Talk Observability Simplified: Combining User Experience, Application Performance & Network ...

Event Series May & June: From Network Visibility to Service Intelligence

Unifying the Network: Moving from Alert Noise to Service Intelligence with Splunk ITSI In today’s hybrid ...

Global Splunk User Group Events: May + June 2026

Your Splunk Community Awaits: Discover Upcoming User Group Events Worldwide    Staying ahead in the fast-paced ...