<?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: How to create time dependent thresholds from lookup? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-time-dependent-thresholds-from-lookup/m-p/397082#M115272</link>
    <description>&lt;P&gt;I would concatenate the date_hour and date_wday fields to use as a key for your lookup.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[YOUR BASE SEARCH HERE]
| eval day_hour=date_hour . "_" . date_wday 
| table _time day_hour
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This would create a field called day_hour that looks like the following:  9_monday.&lt;/P&gt;

&lt;P&gt;Your CSV would then look like the following:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;day_hour,threshold&lt;/STRONG&gt;&lt;BR /&gt;
9_monday,50000&lt;BR /&gt;
10_monday,60000&lt;BR /&gt;
11_monday,50000&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 00:46:58 GMT</pubDate>
    <dc:creator>kmorris_splunk</dc:creator>
    <dc:date>2020-09-30T00:46:58Z</dc:date>
    <item>
      <title>How to create time dependent thresholds from lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-time-dependent-thresholds-from-lookup/m-p/397081#M115271</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have a question on using lookups in a search. I want to achieve that I have a scheduled search to compare to a threshold value that varies in time and is stored in a lookup. I've got a threshold value for every hour on every weekday (7*24 threshold values).&lt;/P&gt;

&lt;P&gt;For now I've got the threshold statically in the query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=index1
| stats dc(Response) as value
| eval threshold=50000
| eval state=(case(value &amp;lt; threshold*0.25, "critical", value &amp;gt;= threshold*0.5, "normal", (value&amp;gt;=threshold*0.25 AND value &amp;lt; threshold*0.5), "warning"))
| table value, state
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The CSV basically looks like this:&lt;BR /&gt;
time (weekday &amp;amp; hour), threshold &lt;/P&gt;

&lt;P&gt;How should I format the weekday and hour in the csv and how do I use the lookup in the search to get the threshold value that is applicable for the current time on the current weekday?&lt;/P&gt;

&lt;P&gt;Thanks, kind regards,&lt;BR /&gt;
Willem Jongeneel&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 10:48:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-time-dependent-thresholds-from-lookup/m-p/397081#M115271</guid>
      <dc:creator>willemjongeneel</dc:creator>
      <dc:date>2019-06-03T10:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to create time dependent thresholds from lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-time-dependent-thresholds-from-lookup/m-p/397082#M115272</link>
      <description>&lt;P&gt;I would concatenate the date_hour and date_wday fields to use as a key for your lookup.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[YOUR BASE SEARCH HERE]
| eval day_hour=date_hour . "_" . date_wday 
| table _time day_hour
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This would create a field called day_hour that looks like the following:  9_monday.&lt;/P&gt;

&lt;P&gt;Your CSV would then look like the following:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;day_hour,threshold&lt;/STRONG&gt;&lt;BR /&gt;
9_monday,50000&lt;BR /&gt;
10_monday,60000&lt;BR /&gt;
11_monday,50000&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:46:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-time-dependent-thresholds-from-lookup/m-p/397082#M115272</guid>
      <dc:creator>kmorris_splunk</dc:creator>
      <dc:date>2020-09-30T00:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to create time dependent thresholds from lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-time-dependent-thresholds-from-lookup/m-p/397083#M115273</link>
      <description>&lt;P&gt;Hi @willemjongeneel,&lt;/P&gt;

&lt;P&gt;You can have weekday our in the following format... &lt;BR /&gt;
e.g.&lt;BR /&gt;
&lt;CODE&gt;Mon19&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Let's say you have following lookup file&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;threshold   weekdayhour
5000         Mon19
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can convert &lt;CODE&gt;_time&lt;/CODE&gt; in your lookup format and get threshold value from lookup as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1 
| eval weekdayhour=strftime(_time, "%a%H") 
| lookup threshold_weekday.csv weekdayhour output threshold
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For information on time format variables: &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.6/SearchReference/Commontimeformatvariables"&gt;Link&lt;/A&gt;&lt;BR /&gt;
Hope this helps.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 13:51:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-time-dependent-thresholds-from-lookup/m-p/397083#M115273</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2019-06-03T13:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to create time dependent thresholds from lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-time-dependent-thresholds-from-lookup/m-p/397084#M115274</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/35330"&gt;@kmorris_splunk&lt;/a&gt;, &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/156506"&gt;@harshpatel&lt;/a&gt; &lt;/P&gt;

&lt;P&gt;I've tried your suggestions. I have time like this: &lt;BR /&gt;
| eval tijd = strftime(_time,"%w%H") &lt;/P&gt;

&lt;P&gt;And my CSV looks like this (tijd goes from 000 to 623):&lt;/P&gt;

&lt;P&gt;threshold,tijd&lt;BR /&gt;
50000,000&lt;BR /&gt;
50000,001&lt;BR /&gt;
50000,002&lt;BR /&gt;
50000,003&lt;BR /&gt;
50000,004&lt;BR /&gt;
50000,005&lt;BR /&gt;
50000,006&lt;/P&gt;

&lt;P&gt;What I want to achieve is to get a distinct count of fieldvalues and compare that to the threshold that is applicable to the time the search starts. Complete search:&lt;/P&gt;

&lt;P&gt;index="index1" &lt;BR /&gt;
| eval tijd = strftime(_time,"%w%H") &lt;BR /&gt;
| lookup threshold.csv tijd output threshold&lt;BR /&gt;
| stats dc(Request) as value&lt;BR /&gt;
| eval State=(case(value &amp;lt; threshold*0.25, "critical", value &amp;gt;= threshold*0.5, "normal", (value &amp;gt;= threshold*0.25 AND value &amp;lt; threshold*0.5), "warning"))&lt;BR /&gt;
| table value, threshold, State&lt;/P&gt;

&lt;P&gt;I do not get the result I want, when I try this search I only get a value of the distinct count, but not for threshold or State. I also tried the "makeresults count=1" option. Can you advise on how to change my search? &lt;/P&gt;

&lt;P&gt;Thanks in advance!&lt;/P&gt;

&lt;P&gt;Kind regards,&lt;BR /&gt;
Willem Jongeneel&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:47:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-time-dependent-thresholds-from-lookup/m-p/397084#M115274</guid>
      <dc:creator>willemjongeneel</dc:creator>
      <dc:date>2020-09-30T00:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to create time dependent thresholds from lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-time-dependent-thresholds-from-lookup/m-p/397085#M115275</link>
      <description>&lt;P&gt;Hi @willemjongeneel,&lt;/P&gt;

&lt;P&gt;After you stats command only available fields will be "value". If you need other fields (let's say threshold) as well you can do something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="index1" 
| eval tijd = strftime(_time,"%w%H") 
| lookup threshold.csv tijd output threshold
| stats dc(Request) as value, values(threshold) as threshold
| eval State=(case(value &amp;lt; threshold*0.25, "critical", value &amp;gt;= threshold*0.5, "normal", (value &amp;gt;= threshold*0.25 AND value &amp;lt; threshold*0.5), "warning"))
| table value, threshold, State
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 12:01:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-time-dependent-thresholds-from-lookup/m-p/397085#M115275</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2019-06-04T12:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to create time dependent thresholds from lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-time-dependent-thresholds-from-lookup/m-p/397086#M115276</link>
      <description>&lt;P&gt;Hi @harshpatel &lt;/P&gt;

&lt;P&gt;Thank you, this is what I needed. &lt;/P&gt;

&lt;P&gt;Kind regards,&lt;BR /&gt;
Willem Jongeneel&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 13:20:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-time-dependent-thresholds-from-lookup/m-p/397086#M115276</guid>
      <dc:creator>willemjongeneel</dc:creator>
      <dc:date>2019-06-04T13:20:06Z</dc:date>
    </item>
  </channel>
</rss>

