<?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 Re: Using Stats and Eval (and adding timestamps) in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-Stats-and-Eval-and-adding-timestamps/m-p/73856#M18537</link>
    <description>&lt;P&gt;We are close, it is :&lt;/P&gt;

&lt;P&gt;eval  searchStartTime=relative_time(now(), "-5m")&lt;/P&gt;

&lt;P&gt;other eval commandes:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Sep 2012 23:59:39 GMT</pubDate>
    <dc:creator>melting</dc:creator>
    <dc:date>2012-09-27T23:59:39Z</dc:date>
    <item>
      <title>Using Stats and Eval (and adding timestamps)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Stats-and-Eval-and-adding-timestamps/m-p/73852#M18533</link>
      <description>&lt;P&gt;I am monitoring myserver logs file created by BEA using a universal forwarder on the BEA instance. &lt;/P&gt;

&lt;P&gt;I want to create an alert that log indicates a failure to connect to CISCO. &lt;/P&gt;

&lt;P&gt;The search string in my alert looks like this. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="myserver" | search "Could not open connection with host: cisco1.cisco.net and port: 101" | stats count as connectionFailure  WHERE connectionFailure&amp;gt;0 | eval hourTimeStamp= date_hour.":".date_minute.":".date_second | fields hourTimeStamp,connectionFailure 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note that date_hour, date_minute and date_second are all populated.&lt;/P&gt;

&lt;P&gt;However this search does not seem to be working and i reckon its because I am not using eval and stats in the right manner&lt;/P&gt;

&lt;P&gt;Any suggestions on how to better this ? &lt;/P&gt;

&lt;P&gt;The goal of the Alert is to do two things&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
i) Run this search every 5 minutes so that connectionFailures are detected (count how many)&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
ii) TimeStamp the event.&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
If I get the search, I can set the alert myself. &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:31:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Stats-and-Eval-and-adding-timestamps/m-p/73852#M18533</guid>
      <dc:creator>asarolkar</dc:creator>
      <dc:date>2020-09-28T12:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using Stats and Eval (and adding timestamps)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Stats-and-Eval-and-adding-timestamps/m-p/73853#M18534</link>
      <description>&lt;P&gt;It is unclear what you need the timestamp for... Splunk knows the time period of the search and you do not need to create a timestamp. But I included a field that contains the time that the search started minus 5 minutes.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="myserver"  "Could not open connection with host: cisco1.cisco.net and port: 101" 
| stats count as connectionFailure
| eval searchStartTime=relative_time(now(),"-5m")
| fieldFormat searchStart = strftime(searchStartTime,"$H:$M:$S")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Sep 2012 23:12:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Stats-and-Eval-and-adding-timestamps/m-p/73853#M18534</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-09-27T23:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using Stats and Eval (and adding timestamps)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Stats-and-Eval-and-adding-timestamps/m-p/73854#M18535</link>
      <description>&lt;P&gt;It looks like you are trying to use eval for concatentation, that would look like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval hourTimeStamp= date_hour + ":" + date_minute + ":" +date_second |
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Sep 2012 23:19:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Stats-and-Eval-and-adding-timestamps/m-p/73854#M18535</guid>
      <dc:creator>melting</dc:creator>
      <dc:date>2012-09-27T23:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using Stats and Eval (and adding timestamps)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Stats-and-Eval-and-adding-timestamps/m-p/73855#M18536</link>
      <description>&lt;P&gt;| eval searchStartTime=relativetime(now,"-5,")&lt;/P&gt;

&lt;P&gt;are you sure this is allowed ? Splunk says it does not know of a relativetime() method&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2012 23:24:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Stats-and-Eval-and-adding-timestamps/m-p/73855#M18536</guid>
      <dc:creator>asarolkar</dc:creator>
      <dc:date>2012-09-27T23:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using Stats and Eval (and adding timestamps)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Stats-and-Eval-and-adding-timestamps/m-p/73856#M18537</link>
      <description>&lt;P&gt;We are close, it is :&lt;/P&gt;

&lt;P&gt;eval  searchStartTime=relative_time(now(), "-5m")&lt;/P&gt;

&lt;P&gt;other eval commandes:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2012 23:59:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Stats-and-Eval-and-adding-timestamps/m-p/73856#M18537</guid>
      <dc:creator>melting</dc:creator>
      <dc:date>2012-09-27T23:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using Stats and Eval (and adding timestamps)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Stats-and-Eval-and-adding-timestamps/m-p/73857#M18538</link>
      <description>&lt;P&gt;Sorry - melting saw my error... my typing really stunk on that one...&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2012 04:34:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Stats-and-Eval-and-adding-timestamps/m-p/73857#M18538</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-09-28T04:34:05Z</dc:date>
    </item>
  </channel>
</rss>

