<?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: Need help when using variable instead of constant  in splunk query construct  within where and eval in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Need-help-when-using-variable-instead-of-constant-in-splunk/m-p/132999#M36324</link>
    <description>&lt;P&gt;How do you - as a human - determine the number of times AQ2 has been greater than AQ1 in your example table at the bottom of the post? I see no timestamp with both values set, so I can't make a comparison in my head - that's before trying to make Splunk do it for me.&lt;/P&gt;</description>
    <pubDate>Fri, 31 Jan 2014 20:42:20 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2014-01-31T20:42:20Z</dc:date>
    <item>
      <title>Need help when using variable instead of constant  in splunk query construct  within where and eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-when-using-variable-instead-of-constant-in-splunk/m-p/132998#M36323</link>
      <description>&lt;P&gt;I have a query Q1 which is used to collect avg over 10 days.Say the average is AvgQ1 100. I have another query Q2 which collects 5 min samples over 2 different weekend days for the avg. We have say a few values for avg say AvgQ2: 50,60,70,80,90,100,110,120,130,140,150 for example. I want to check how many values in this exceed the avg found above as 100. Things are okay when I have 2 queries and do in manually. But I have to automate this. So I have to use variables than hardcoded values. For example&lt;/P&gt;

&lt;P&gt;The normal way to check when values are exceeded in Q2 results above is:&lt;/P&gt;

&lt;P&gt;| stats count(eval(AvgQ2 &amp;gt;= 100)) as countoverlimit  --&amp;gt;This works when I do it manually&lt;/P&gt;

&lt;P&gt;| stats count(eval(AvgQ2 &amp;gt;= AvgQ1 )) as countoverlimt  --&amp;gt; When this is constant is treated as variable to automate it, I have issues, because splunk gives error for that construct&lt;/P&gt;

&lt;P&gt;The other way is to use different construct&lt;/P&gt;

&lt;P&gt;| where AvgQ2 &amp;gt; 100 | stats count as countoverlimit --&amp;gt; This works with hard coded value&lt;/P&gt;

&lt;P&gt;| where AvgQ2 &amp;gt; AvgQ1 | stats count as countoverlimit --&amp;gt; When this constant is treated as variable to automate it, there seem issues, since splunk gives error for that construct.&lt;/P&gt;

&lt;P&gt;Lets say when you store in a csv file and use it in Q2, it will look like this.&lt;/P&gt;

&lt;P&gt;sourcetype="yoursourcetypewiththenumbers" [| inputlookup AvgQ1.csv | fields AvgQ1 ]  --&amp;gt;   This works as usual and depends on where you use it. This will become the below and works.&lt;/P&gt;

&lt;P&gt;sourcetype="yoursourcetypewiththenumbers" 100&lt;/P&gt;

&lt;P&gt;But what if want to use this within where clause?&lt;/P&gt;

&lt;P&gt;| where AvgQ2 &amp;gt; AvgQ1 . Inside where clause if I used the above construct, it doesnt work since splunk will give error.&lt;/P&gt;

&lt;P&gt;| where AvgQ2 &amp;gt; [| inputlookup AvgQ1.csv | fields AvgQ1 ]. Also this wont work either since its within where clause&lt;/P&gt;

&lt;P&gt;The same with eval&lt;/P&gt;

&lt;P&gt;| stats count(eval(AvgQ2 &amp;gt;= [| inputlookup AvgQ1.csv | fields AvgQ1 ] )) as countoverlimt --&amp;gt; This wont work either.&lt;/P&gt;

&lt;P&gt;Other options are to store these values in 2 different csv files. Either as csv or lookup usage.&lt;/P&gt;

&lt;P&gt;Then I can also combine the results into 1 csv or lookup file to simplify it. The first line will be from Q1 result. The rest will be from Q2 result. I can reference the first value as first(AvgQ1). But I cant use this as variable in splunk eval and where constructs as above because it has a variable construct rather than hardcoded value. &lt;/P&gt;

&lt;P&gt;Here is the combined csv file with values.&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;time,AvgQ1,AvgQ2&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;t1,100,&lt;/LI&gt;
&lt;LI&gt;t2,                       ,50&lt;/LI&gt;
&lt;LI&gt;t3,                        ,60&lt;/LI&gt;
&lt;LI&gt;t4,                        ,70&lt;/LI&gt;
&lt;LI&gt;           ,                          ,&lt;/LI&gt;
&lt;LI&gt;           ,                           ,&lt;/LI&gt;
&lt;LI&gt;tx         ,               , 100&lt;/LI&gt;
&lt;LI&gt;ty         ,                , 150&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;How would the query be written to get number of times AvgQ2 values is over AvgQ1?&lt;/P&gt;

&lt;P&gt;The result should be 110,120,130,140,150 which is count of 5?&lt;/P&gt;

&lt;P&gt;Any help will be appreciated. I hope I can get this to automate.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2014 06:39:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-when-using-variable-instead-of-constant-in-splunk/m-p/132998#M36323</guid>
      <dc:creator>iTechEvent</dc:creator>
      <dc:date>2014-01-31T06:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Need help when using variable instead of constant  in splunk query construct  within where and eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-when-using-variable-instead-of-constant-in-splunk/m-p/132999#M36324</link>
      <description>&lt;P&gt;How do you - as a human - determine the number of times AQ2 has been greater than AQ1 in your example table at the bottom of the post? I see no timestamp with both values set, so I can't make a comparison in my head - that's before trying to make Splunk do it for me.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2014 20:42:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-when-using-variable-instead-of-constant-in-splunk/m-p/132999#M36324</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-01-31T20:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need help when using variable instead of constant  in splunk query construct  within where and eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-when-using-variable-instead-of-constant-in-splunk/m-p/133000#M36325</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your query 2 giving field AvgQ2, multiple events&amp;gt; | table AvgQ2 | eval joinfield=1
| join joinfield [search &amp;lt;your query 1 giving single value AvgQ1&amp;gt; | table AvgQ1 | eval joinfield=1]
| fields - joinfield | where AvgQ2 &amp;gt; AvgQ1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should give you all the AvgQ2 values which are higher than AvgQ1. To get count your can further append "| stats count".&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2014 22:59:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-when-using-variable-instead-of-constant-in-splunk/m-p/133000#M36325</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-01-31T22:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Need help when using variable instead of constant  in splunk query construct  within where and eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-when-using-variable-instead-of-constant-in-splunk/m-p/133001#M36326</link>
      <description>&lt;P&gt;I tried it and it works great. Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Sun, 02 Feb 2014 08:32:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-when-using-variable-instead-of-constant-in-splunk/m-p/133001#M36326</guid>
      <dc:creator>iTechEvent</dc:creator>
      <dc:date>2014-02-02T08:32:13Z</dc:date>
    </item>
  </channel>
</rss>

