<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to send e-mail alert that contains a variable in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/How-to-send-e-mail-alert-that-contains-a-variable/m-p/547159#M10400</link>
    <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Given a set of logs like below:&lt;/P&gt;&lt;P&gt;Mar 2 12:56:34 10.1.2.3 router-01: 2021 Mar 2 12:56:34.628 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Cleared for timeout&lt;BR /&gt;Mar 2 12:52:30 10.1.2.3 router-01: 2021 Mar 2 12:52:30.562 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Occurred for timeout&lt;BR /&gt;Mar 2 11:13:59 10.1.2.3 router-01: 2021 Mar 2 11:13:59.912 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Cleared for timeout&lt;BR /&gt;Mar 2 11:13:55 10.1.2.3 router-01: 2021 Mar 2 11:13:55.912 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Occurred for timeout&lt;BR /&gt;Mar 2 10:52:29 10.1.2.3 router-01: 2021 Mar 2 10:52:29.848 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Cleared for timeout&lt;BR /&gt;Mar 2 10:52:25 10.1.2.3 router-01: 2021 Mar 2 10:52:25.850 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Occurred for timeout&lt;BR /&gt;Mar 2 10:26:04 10.1.2.3 router-01: 2021 Mar 2 10:26:04.843 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Cleared for timeout&lt;BR /&gt;Mar 2 10:26:00 10.1.2.3 router-01: 2021 Mar 2 10:26:00.838 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Occurred for timeout&lt;BR /&gt;Mar 2 10:09:19 10.1.2.3 router-01: 2021 Mar 2 10:09:19.918 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Cleared for timeout&lt;/P&gt;&lt;P&gt;with our setup for the above as:&amp;nbsp;&lt;/P&gt;&lt;P&gt;index=syslog&amp;nbsp; sourcetype=Cisco AND "IP SLA:"&lt;/P&gt;&lt;P&gt;I am trying to send an e-mail alert that will send only the LAST event for "Threshold Cleared" and more importantly, a variable that computes (time delta) from the last "Occurred" to the last "Cleared" event, in this case 244 seconds (12:56:34 - 12:52:30).&lt;/P&gt;&lt;P&gt;I have some knowledge of subsearches but only as part of another inline search and can't get my head on how to assign the result as a "variable" and then subsequently include that variable in an e-mail alert.&lt;/P&gt;&lt;P&gt;Basically the email alert I want to construct is:&lt;/P&gt;&lt;P&gt;"Latest IP SLA threshold has cleared at 12:56:34 PM.&amp;nbsp; &amp;nbsp;Event duration was 244 seconds"&lt;/P&gt;&lt;P&gt;Any suggestions on the syntax will be much appreciated.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Apr 2021 07:17:48 GMT</pubDate>
    <dc:creator>rleyba828</dc:creator>
    <dc:date>2021-04-08T07:17:48Z</dc:date>
    <item>
      <title>How to send e-mail alert that contains a variable</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-send-e-mail-alert-that-contains-a-variable/m-p/547159#M10400</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Given a set of logs like below:&lt;/P&gt;&lt;P&gt;Mar 2 12:56:34 10.1.2.3 router-01: 2021 Mar 2 12:56:34.628 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Cleared for timeout&lt;BR /&gt;Mar 2 12:52:30 10.1.2.3 router-01: 2021 Mar 2 12:52:30.562 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Occurred for timeout&lt;BR /&gt;Mar 2 11:13:59 10.1.2.3 router-01: 2021 Mar 2 11:13:59.912 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Cleared for timeout&lt;BR /&gt;Mar 2 11:13:55 10.1.2.3 router-01: 2021 Mar 2 11:13:55.912 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Occurred for timeout&lt;BR /&gt;Mar 2 10:52:29 10.1.2.3 router-01: 2021 Mar 2 10:52:29.848 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Cleared for timeout&lt;BR /&gt;Mar 2 10:52:25 10.1.2.3 router-01: 2021 Mar 2 10:52:25.850 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Occurred for timeout&lt;BR /&gt;Mar 2 10:26:04 10.1.2.3 router-01: 2021 Mar 2 10:26:04.843 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Cleared for timeout&lt;BR /&gt;Mar 2 10:26:00 10.1.2.3 router-01: 2021 Mar 2 10:26:00.838 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Occurred for timeout&lt;BR /&gt;Mar 2 10:09:19 10.1.2.3 router-01: 2021 Mar 2 10:09:19.918 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Cleared for timeout&lt;/P&gt;&lt;P&gt;with our setup for the above as:&amp;nbsp;&lt;/P&gt;&lt;P&gt;index=syslog&amp;nbsp; sourcetype=Cisco AND "IP SLA:"&lt;/P&gt;&lt;P&gt;I am trying to send an e-mail alert that will send only the LAST event for "Threshold Cleared" and more importantly, a variable that computes (time delta) from the last "Occurred" to the last "Cleared" event, in this case 244 seconds (12:56:34 - 12:52:30).&lt;/P&gt;&lt;P&gt;I have some knowledge of subsearches but only as part of another inline search and can't get my head on how to assign the result as a "variable" and then subsequently include that variable in an e-mail alert.&lt;/P&gt;&lt;P&gt;Basically the email alert I want to construct is:&lt;/P&gt;&lt;P&gt;"Latest IP SLA threshold has cleared at 12:56:34 PM.&amp;nbsp; &amp;nbsp;Event duration was 244 seconds"&lt;/P&gt;&lt;P&gt;Any suggestions on the syntax will be much appreciated.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 07:17:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-send-e-mail-alert-that-contains-a-variable/m-p/547159#M10400</guid>
      <dc:creator>rleyba828</dc:creator>
      <dc:date>2021-04-08T07:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to send e-mail alert that contains a variable</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-send-e-mail-alert-that-contains-a-variable/m-p/547166#M10401</link>
      <description>&lt;P&gt;See this example search with your data&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="Mar 2 12:56:34 10.1.2.3 router-01: 2021 Mar 2 12:56:34.628 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Cleared for timeout
Mar 2 12:52:30 10.1.2.3 router-01: 2021 Mar 2 12:52:30.562 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Occurred for timeout
Mar 2 11:13:59 10.1.2.3 router-01: 2021 Mar 2 11:13:59.912 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Cleared for timeout
Mar 2 11:13:55 10.1.2.3 router-01: 2021 Mar 2 11:13:55.912 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Occurred for timeout
Mar 2 10:52:29 10.1.2.3 router-01: 2021 Mar 2 10:52:29.848 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Cleared for timeout
Mar 2 10:52:25 10.1.2.3 router-01: 2021 Mar 2 10:52:25.850 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Occurred for timeout
Mar 2 10:26:04 10.1.2.3 router-01: 2021 Mar 2 10:26:04.843 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Cleared for timeout
Mar 2 10:26:00 10.1.2.3 router-01: 2021 Mar 2 10:26:00.838 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Occurred for timeout
Mar 2 10:09:19 10.1.2.3 router-01: 2021 Mar 2 10:09:19.918 AEST: %SLA_SENDER-3-IPSLATHRESHOLD: IP SLA: Threshold Cleared for timeout"
| multikv noheader=t
| rex field=_raw ".*router-01: (?&amp;lt;date&amp;gt;\d+ \w{3} \d+ \d+:\d+:\d+\.\d+)"
| eval _time=strptime(date, "%Y %b %d %H:%M:%S")
| table _time _raw
| rex field=_raw ".*(?&amp;lt;state&amp;gt;Cleared|Occurred)"
| streamstats range(_time) as duration latest(eval(if(state="Cleared", _time, null))) as latest reset_before="("state==\"Cleared\"")"
| where !isnull(latest) AND state="Occurred"
| head 1
| eval l=strftime(latest, "%l:%M:%S %p")
| eval message="Latest IP SLA threshold has cleared at ".l.".  Event duration was ".round(duration)." seconds"
| table message&lt;/LI-CODE&gt;&lt;P&gt;I've assumed that it's just a stream of on/off events, but you may need to modify the search as needed. In practice you only need the most recent 3 events as they should contain either&amp;nbsp;&lt;/P&gt;&lt;P&gt;cleared, occurred, cleared&amp;nbsp;&lt;/P&gt;&lt;P&gt;or&amp;nbsp;&lt;/P&gt;&lt;P&gt;occurred,cleared, occurred&lt;/P&gt;&lt;P&gt;so you could do a head 3 at the start.&lt;/P&gt;&lt;P&gt;but basically the streamstats is your tool.&lt;/P&gt;&lt;P&gt;Hope this helps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 08:50:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-send-e-mail-alert-that-contains-a-variable/m-p/547166#M10401</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-04-08T08:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to send e-mail alert that contains a variable</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-send-e-mail-alert-that-contains-a-variable/m-p/547281#M10406</link>
      <description>&lt;P&gt;HI bowesmana,&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; Many thanks for this....I'll adapt your query string a bit to see if fits some other variations of how the logs arrive, but essentially, it is the structure/combination of SPL commands that you provided that should make it work.&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 23:09:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-send-e-mail-alert-that-contains-a-variable/m-p/547281#M10406</guid>
      <dc:creator>rleyba828</dc:creator>
      <dc:date>2021-04-08T23:09:47Z</dc:date>
    </item>
  </channel>
</rss>

