Alerting

How to get fields from second search to my alert email?

poddraj
Explorer

Hi,
I have below scenario where I have query 1 which triggers the condition for my alert to fire if it fires then I want to send the O/P of 2nd query to send in email as tabular data. In that email subject I want to include the time duration of my 2nd query

index=dte_fios sourcetype=dte2_Fios FT=*FT Error_Code!=0000 earliest=04/20/2020:11:00:00 latest=04/20/2020:13:00:00
| bin _time span=15m
| stats count as Total, count(eval(Error_Code!="0000")) AS Failure by FT,_time
| eval Failurepercent=round(Failure/Total*100)
| table _time,FT,Total,Failure,Failurepercent
| lookup ftthresholdlkp FT
| eval alert=case(some condition)
| where alert=1
| map search="search index=dte_fios sourcetype=dte2_Fios FT=$FT$ earliest=04/20/2020:12:45:00 latest=04/20/2020:13:00:00 | eval STime=strftime(earliest,"%m/%d %H:%M") , ETime=strftime(latest,"%m/%d %H:%M")| eval AlertType=if($Failurepercent$>50,"RED","AMBER")|table _time,WPID,MGRID,Host,System,DIP_Command,CID,DTE_Command,FT,OSS,Error_Code,Error_Msg"

I am trying to send Subject of mail as "AMBER ALERT: Below are the failure from 04/20 12:45 TO 04/20 13:00 GMT GMT" to get I used $result.earliest$ $result.latest$ but they are coming as blank in my subject then I used eval command to create 2 fields STIME & ETime but if I add that in map search it is not returning any rows at all and also my AlertType is also not working
Can someone help me out here how can achieve above subject using my query

Labels (2)
Tags (2)
0 Karma

skoelpin
SplunkTrust
SplunkTrust

I've created a solution that does exactly this. I was able to do it with the Automatic Splunk Search app

  1. Build an alert and make sure it's outputting your time fields you want to pass
  2. Make it fire the "Automatic Search" alert action
  3. The alert action will house a second query which will build the report and accept tokens from the first search
  4. The tokens represent time, you simply pass these time modifiers in the second search which also has a | send_email command

https://splunkbase.splunk.com/app/3837/

0 Karma

poddraj
Explorer

Any suggestion on this question pls?

0 Karma
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!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...