<?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 write lookup file for splunk query in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374285#M110016</link>
    <description>&lt;P&gt;I have a requirement to use lookups instead of queries in Splunk Dashboards.&lt;/P&gt;

&lt;P&gt;How can I get them and how to convert them to lookups using queries.&lt;/P&gt;

&lt;P&gt;For example::&lt;/P&gt;

&lt;P&gt;Query : &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="gcp_prod_ecomm_webstoreui" "[ACCESS]" ("/catalog/*.jsp" OR "/product/" OR "/search.jsp*" OR "Cavisson") NOT("alive") NOT “dlr=true”
| rex field=MESSAGE "\d{2}:\d{2}:\d{2}\s(?&amp;lt;page_response_time&amp;gt;[0-9.]*)\s(?&amp;lt;method&amp;gt;.[A-Z]+)\s(?&amp;lt;Request&amp;gt;.[a-zA-Z0-9-:/^%?+&amp;amp;()\"=+_.-]*)\s(?&amp;lt;Request1&amp;gt;.[a-zA-Z0-9-:/^%?+&amp;amp;()\"=+_.-]*)\s(?&amp;lt;StatusCode&amp;gt;[0-9]+)" 
| eval RequestFormat=case(Request like "%catalog%", "Catalog Page", Request like "%product%", "Product Page", Request like "%search%", "Search Page") 
| timechart span=1m avg(page_response_time) by RequestFormat
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 24 Mar 2018 04:37:10 GMT</pubDate>
    <dc:creator>asplunk789</dc:creator>
    <dc:date>2018-03-24T04:37:10Z</dc:date>
    <item>
      <title>How to write lookup file for splunk query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374285#M110016</link>
      <description>&lt;P&gt;I have a requirement to use lookups instead of queries in Splunk Dashboards.&lt;/P&gt;

&lt;P&gt;How can I get them and how to convert them to lookups using queries.&lt;/P&gt;

&lt;P&gt;For example::&lt;/P&gt;

&lt;P&gt;Query : &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="gcp_prod_ecomm_webstoreui" "[ACCESS]" ("/catalog/*.jsp" OR "/product/" OR "/search.jsp*" OR "Cavisson") NOT("alive") NOT “dlr=true”
| rex field=MESSAGE "\d{2}:\d{2}:\d{2}\s(?&amp;lt;page_response_time&amp;gt;[0-9.]*)\s(?&amp;lt;method&amp;gt;.[A-Z]+)\s(?&amp;lt;Request&amp;gt;.[a-zA-Z0-9-:/^%?+&amp;amp;()\"=+_.-]*)\s(?&amp;lt;Request1&amp;gt;.[a-zA-Z0-9-:/^%?+&amp;amp;()\"=+_.-]*)\s(?&amp;lt;StatusCode&amp;gt;[0-9]+)" 
| eval RequestFormat=case(Request like "%catalog%", "Catalog Page", Request like "%product%", "Product Page", Request like "%search%", "Search Page") 
| timechart span=1m avg(page_response_time) by RequestFormat
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 24 Mar 2018 04:37:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374285#M110016</guid>
      <dc:creator>asplunk789</dc:creator>
      <dc:date>2018-03-24T04:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to write lookup file for splunk query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374286#M110017</link>
      <description>&lt;P&gt;@splunk789 do you need to create lookup for Request values like &lt;CODE&gt;Catalog Page&lt;/CODE&gt;, &lt;CODE&gt;Product Page&lt;/CODE&gt; and &lt;CODE&gt;Search Page&lt;/CODE&gt; etc or for entire query?&lt;/P&gt;

&lt;P&gt;You can save entire query as a &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/Knowledge/Searchmacroexamples"&gt;Macro Knowledge Object&lt;/A&gt; in Splunk, if you need to matain/re-use queries.&lt;/P&gt;

&lt;P&gt;If you really need to run the Splunk Query from Lookup file could you tell what is the use case?&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 06:46:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374286#M110017</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-03-24T06:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to write lookup file for splunk query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374287#M110018</link>
      <description>&lt;P&gt;@niketnilay, Thanks for the reply. &lt;/P&gt;

&lt;P&gt;My requirement is to optimize the dashboard which is having queries. Need to use lookups and optimize them for a better performance of Splunk search. So, how can I use the lookup in (XML Source ) the place of noraml search query (inputlookup snbuireesponsetime.csv)&lt;/P&gt;</description>
      <pubDate>Sun, 25 Mar 2018 23:02:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374287#M110018</guid>
      <dc:creator>asplunk789</dc:creator>
      <dc:date>2018-03-25T23:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to write lookup file for splunk query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374288#M110019</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE&gt;      index="gcp_prod_ecomm_webstoreui"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;"[ACCESS]" ("/catalog/&lt;EM&gt;.jsp" OR&lt;BR /&gt;
"/product/" OR "/search.jsp&lt;/EM&gt;" OR&lt;BR /&gt;
"Cavisson") NOT("alive") NOT&lt;BR /&gt;
“dlr=true”  | rex field=MESSAGE&lt;BR /&gt;
"\d{2}:\d{2}:\d{2}\s(?&amp;lt;page_response_time&amp;gt;[0-9.]&lt;EM&gt;)\s(?&amp;lt;method&amp;gt;.[A-Z]+)\s(?&amp;lt;Request&amp;gt;.[a-zA-Z0-9-:/^%?+&amp;amp;()\"=+_.-]&lt;/EM&gt;)\s(?&amp;lt;Request1&amp;gt;.[a-zA-Z0-9-:/^%?+&amp;amp;()\"=+_.-]*)\s(?&amp;lt;StatusCode&amp;gt;[0-9]+)"  | eval RequestFormat=case(Request like&lt;BR /&gt;
"%catalog%", "Catalog Page", Request&lt;BR /&gt;
like "%product%", "Product Page",&lt;BR /&gt;
Request like "%search%", "Search&lt;BR /&gt;
Page")  | timechart span=1m&lt;BR /&gt;
avg(page_response_time) by&lt;BR /&gt;
RequestFormat usenull=f&lt;BR /&gt;
useother=f&lt;BR /&gt;
          -15m&lt;BR /&gt;
          now&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:41:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374288#M110019</guid>
      <dc:creator>asplunk789</dc:creator>
      <dc:date>2020-09-29T18:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to write lookup file for splunk query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374289#M110020</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/102648"&gt;@asplunk789&lt;/a&gt;, following is a search based on lookup file &lt;CODE&gt;search_queries.csv&lt;/CODE&gt; with two columns &lt;CODE&gt;Name&lt;/CODE&gt; of the search and &lt;CODE&gt;Search&lt;/CODE&gt; with the Splunk Search Query. The dropdown token &lt;CODE&gt;$tokSearchQuery$&lt;/CODE&gt; has been passed directly to the &lt;CODE&gt;&amp;lt;search&amp;gt;&amp;lt;query&amp;gt;&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;PS: For better management of Search Queries insert, update, delete you should explore &lt;CODE&gt;KV Store Implementation&lt;/CODE&gt; in Splunk instead of lookups.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;panel&amp;gt;
  &amp;lt;title&amp;gt;Search Based on Lookup&amp;lt;/title&amp;gt;
  &amp;lt;input type="dropdown" token="tokSearchQuery" searchWhenChanged="true"&amp;gt;
    &amp;lt;label&amp;gt;Select Search Query (from lookup)&amp;lt;/label&amp;gt;
    &amp;lt;fieldForLabel&amp;gt;Name&amp;lt;/fieldForLabel&amp;gt;
    &amp;lt;fieldForValue&amp;gt;Search&amp;lt;/fieldForValue&amp;gt;
    &amp;lt;search&amp;gt;
      &amp;lt;query&amp;gt;| inputlookup search_queries.csv | table Name Search&amp;lt;/query&amp;gt;
    &amp;lt;/search&amp;gt;
  &amp;lt;/input&amp;gt;
  &amp;lt;chart&amp;gt;
    &amp;lt;search&amp;gt;
      &amp;lt;query&amp;gt;$tokSearchQuery$&amp;lt;/query&amp;gt;
      &amp;lt;earliest&amp;gt;$tokTime.earliest$&amp;lt;/earliest&amp;gt;
      &amp;lt;latest&amp;gt;$tokTime.latest$&amp;lt;/latest&amp;gt;
    &amp;lt;/search&amp;gt;
    &amp;lt;option name="charting.chart.showDataLabels"&amp;gt;minmax&amp;lt;/option&amp;gt;
    &amp;lt;option name="charting.chart.stackMode"&amp;gt;stacked&amp;lt;/option&amp;gt;
    &amp;lt;option name="refresh.display"&amp;gt;progressbar&amp;lt;/option&amp;gt;
  &amp;lt;/chart&amp;gt;
&amp;lt;/panel&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere example with &lt;CODE&gt;makeresults&lt;/CODE&gt; instead of inputlookup. The same result from &lt;CODE&gt;makeresults&lt;/CODE&gt; has been pushed to lookup file through the &lt;CODE&gt;outputlookup&lt;/CODE&gt; command.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;panel&amp;gt;
  &amp;lt;title&amp;gt;Search Based on Dummy Query to Simulate Fetching from Lookup&amp;lt;/title&amp;gt;
  &amp;lt;input type="dropdown" token="tokSearchQueryDummyTesting" searchWhenChanged="true"&amp;gt;
    &amp;lt;label&amp;gt;Select Search Query (dummy through makeresults)&amp;lt;/label&amp;gt;
    &amp;lt;fieldForLabel&amp;gt;Name&amp;lt;/fieldForLabel&amp;gt;
    &amp;lt;fieldForValue&amp;gt;Search&amp;lt;/fieldForValue&amp;gt;
    &amp;lt;search&amp;gt;
      &amp;lt;query&amp;gt;| makeresults
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;| eval Search="index=_internal sourcetype=splunkd component=\"ExecProcessor\" log_level!=\"INFO\" | timechart sum(date_second) as response_time by log_level",Name="Execprocessor Errors"&lt;BR /&gt;
| append [| makeresults&lt;BR /&gt;
| eval Search="index=_internal sourcetype=splunkd component=\"Search*\" log_level!=\"INFO\" | timechart sum(date_second) as response_time by log_level",Name="Search Components Errors"]&lt;BR /&gt;
| append [| makeresults&lt;BR /&gt;
| eval Search="index=_internal sourcetype=splunkd component=\"*\" log_level!=\"INFO\" | timechart sum(date_second) as response_time by log_level",Name="All Errors"]&lt;BR /&gt;
| table Name Search&lt;BR /&gt;
          &lt;EARLIEST&gt;-24h@h&lt;/EARLIEST&gt;&lt;BR /&gt;
          &lt;LATEST&gt;now&lt;/LATEST&gt;&lt;BR /&gt;
        &lt;BR /&gt;
      &lt;BR /&gt;
      &lt;CHART&gt;&lt;BR /&gt;
        &lt;SEARCH&gt;&lt;BR /&gt;
          &lt;QUERY&gt;$tokSearchQueryDummyTesting$&lt;/QUERY&gt;&lt;BR /&gt;
          &lt;EARLIEST&gt;$tokTime.earliest$&lt;/EARLIEST&gt;&lt;BR /&gt;
          &lt;LATEST&gt;$tokTime.latest$&lt;/LATEST&gt;&lt;BR /&gt;
        &lt;/SEARCH&gt;&lt;BR /&gt;
        minmax&lt;BR /&gt;
        stacked&lt;BR /&gt;
        progressbar&lt;BR /&gt;
      &lt;/CHART&gt;&lt;BR /&gt;
    &lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/231574-searchqueryfromlookupfile.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;Following is the complete dashboard code for screenshot above:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form&amp;gt;
  &amp;lt;label&amp;gt;Run Search from Lookup&amp;lt;/label&amp;gt;
  &amp;lt;fieldset submitButton="false"&amp;gt;
    &amp;lt;input type="time" token="tokTime" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;Select Time&amp;lt;/label&amp;gt;
      &amp;lt;default&amp;gt;
        &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
        &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
      &amp;lt;/default&amp;gt;
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;Search Based on Dummy Query to Simulate Fetching from Lookup&amp;lt;/title&amp;gt;
      &amp;lt;input type="dropdown" token="tokSearchQueryDummyTesting" searchWhenChanged="true"&amp;gt;
        &amp;lt;label&amp;gt;Select Search Query (dummy through makeresults)&amp;lt;/label&amp;gt;
        &amp;lt;fieldForLabel&amp;gt;Name&amp;lt;/fieldForLabel&amp;gt;
        &amp;lt;fieldForValue&amp;gt;Search&amp;lt;/fieldForValue&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| makeresults
| eval Search="index=_internal sourcetype=splunkd component=\"ExecProcessor\" log_level!=\"INFO\" | timechart sum(date_second) as response_time by log_level",Name="Execprocessor Errors"
| append [| makeresults
| eval Search="index=_internal sourcetype=splunkd component=\"Search*\" log_level!=\"INFO\" | timechart sum(date_second) as response_time by log_level",Name="Search Components Errors"]
| append [| makeresults
| eval Search="index=_internal sourcetype=splunkd component=\"*\" log_level!=\"INFO\" | timechart sum(date_second) as response_time by log_level",Name="All Errors"]
| table Name Search&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
      &amp;lt;/input&amp;gt;
      &amp;lt;chart&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;$tokSearchQueryDummyTesting$&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;$tokTime.earliest$&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;$tokTime.latest$&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="charting.chart.showDataLabels"&amp;gt;minmax&amp;lt;/option&amp;gt;
        &amp;lt;option name="charting.chart.stackMode"&amp;gt;stacked&amp;lt;/option&amp;gt;
        &amp;lt;option name="refresh.display"&amp;gt;progressbar&amp;lt;/option&amp;gt;
      &amp;lt;/chart&amp;gt;
    &amp;lt;/panel&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;Search Based on Lookup&amp;lt;/title&amp;gt;
      &amp;lt;input type="dropdown" token="tokSearchQuery" searchWhenChanged="true"&amp;gt;
        &amp;lt;label&amp;gt;Select Search Query (from lookup)&amp;lt;/label&amp;gt;
        &amp;lt;fieldForLabel&amp;gt;Name&amp;lt;/fieldForLabel&amp;gt;
        &amp;lt;fieldForValue&amp;gt;Search&amp;lt;/fieldForValue&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| inputlookup search_queries.csv | table Name Search&amp;lt;/query&amp;gt;
        &amp;lt;/search&amp;gt;
      &amp;lt;/input&amp;gt;
      &amp;lt;chart&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;$tokSearchQuery$&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;$tokTime.earliest$&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;$tokTime.latest$&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="charting.chart.showDataLabels"&amp;gt;minmax&amp;lt;/option&amp;gt;
        &amp;lt;option name="charting.chart.stackMode"&amp;gt;stacked&amp;lt;/option&amp;gt;
        &amp;lt;option name="refresh.display"&amp;gt;progressbar&amp;lt;/option&amp;gt;
      &amp;lt;/chart&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:41:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374289#M110020</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-29T18:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to write lookup file for splunk query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374290#M110021</link>
      <description>&lt;P&gt;Hi, if you concern is performance issue. You may wish to consider in optimizing your searches. Here are some of the pointers.&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Avoid extracting fields in search (rex). Try to extract the field first using props and transforms.&lt;/LI&gt;
&lt;LI&gt;Avoid using keyword searches like "[ACCESS]". Use key-value pair instead if the fields are extracted.&lt;/LI&gt;
&lt;LI&gt;Specify the sourcetype in your search. The index may contains multiple sourcetypes depending on your setup.&lt;/LI&gt;
&lt;LI&gt;Use automatic lookup for your "Request" field to lookup the type of request. Prerequisite that the request field must be present during searching.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;You may also like to watch this past .conf video for some recommendation in optimizing your searches.&lt;BR /&gt;
&lt;A href="https://conf.splunk.com/files/2016/recordings/search-optimization.mp4"&gt;https://conf.splunk.com/files/2016/recordings/search-optimization.mp4&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;For your case, it is not recommended to write the result into lookup and the present it again on dashboard from lookup. &lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 03:26:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374290#M110021</guid>
      <dc:creator>Kendrick821</dc:creator>
      <dc:date>2018-03-26T03:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to write lookup file for splunk query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374291#M110022</link>
      <description>&lt;P&gt;Hi Nike,&lt;/P&gt;

&lt;P&gt;The above solution works good.&lt;BR /&gt;
But I have will have to have two drop downs inside the panel "Search Based on Lookup".&lt;BR /&gt;
as Name and Subname and the corresponding query has to be executed.&lt;BR /&gt;
This is because the Name has many subnames under it.&lt;BR /&gt;
Could you kindly help me with it.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 06:02:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374291#M110022</guid>
      <dc:creator>Deepz2612</dc:creator>
      <dc:date>2019-02-26T06:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to write lookup file for splunk query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374292#M110023</link>
      <description>&lt;P&gt;Hi Nike,&lt;/P&gt;

&lt;P&gt;The above solution works good.&lt;BR /&gt;
But I have will have to have two drop downs inside the panel "Search Based on Lookup".&lt;BR /&gt;
as Name and Subname and the corresponding query has to be executed.&lt;BR /&gt;
This is because the Name has many subnames under it.&lt;BR /&gt;
Could you kindly help me with it.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 06:09:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-lookup-file-for-splunk-query/m-p/374292#M110023</guid>
      <dc:creator>deepikasounda</dc:creator>
      <dc:date>2019-02-27T06:09:35Z</dc:date>
    </item>
  </channel>
</rss>

