Splunk Search

Using Lookup Table

alan20854
Path Finder

Hi,

I am using a lookup table to populate 3 dropdown menus: Source, Service, and Method, where each selection of the previous dropdown creates the set of options for the next dropdown.

However, in the dropdown options for Service and Method, I am using a word description of the service/method code, e.g. Vendor Web Service in lieu of VNDR_WS. In my .csv file, the first three columns are source, service, and then method, and then I have two more columns with the corresponding serviceCode and methodCode.

How do I incorporate the last two columns into my search query? I would just like to search for something like serviceCode = $serviceCode$ methodCode=$methodCode$

0 Karma
1 Solution

somesoni2
Revered Legend

Use like this

dropdown service

<search>
     <query>| inputlookup Lookup.csv | search source="$source1$" | stats count by service serviceCode | table service serviceCode</query>
   </search>
   <fieldForLabel>service</fieldForLabel>
   <fieldForValue>serviceCode</fieldForValue>

dropdown method

 <search>
     <query>| inputlookup Lookup.csv | search (source = "$source1$" AND serviceCode = "$service1$")| stats count by method methodCode| table method methodCode</query>
     <earliest>0</earliest>
   </search>
   <fieldForLabel>method</fieldForLabel>
   <fieldForValue>methodCode</fieldForValue>

Panel Search

| inputlookup Lookup.csv | $serviceCode$ = search (source = "$source1$" AND serviceCode = "$service1$" AND methodCode = "$method1$") |sort -_time | head 1

View solution in original post

snoobzilla
Builder

Perfect used case for label/value functionality... I partially changed below. Basically you need to carry changes into your search.

 <input type="dropdown" token="source1" searchWhenChanged="true">
   <label>Source</label>
   <search>
     <query>| inputlookup Lookup.csv | stats count by source | table source</query>
   </search>
   <fieldForLabel>source</fieldForLabel>
   <fieldForValue>source</fieldForValue>
 </input>
 <input type="dropdown" token="service1" searchWhenChanged="true">
   <label>Service</label>
   <search>
     <query>| inputlookup Lookup.csv | search source="$source1$" | stats count by service | table service ServiceCode</query>
   </search>
   <fieldForLabel>service</fieldForLabel>
   <fieldForValue>ServiceCode</fieldForValue>
 </input>
 <input type="dropdown" token="method1" searchWhenChanged="true">
   <label>Method/Operation</label>
   <search>
     <query>| inputlookup Lookup.csv | search (source = "$source1$" AND service = "$service1$")| stats count by method | table method MethodCode</query>
     <earliest>0</earliest>
   </search>
   <fieldForLabel>method</fieldForLabel>
   <fieldForValue>MethodCode</fieldForValue>
 </input>
 <input type="time" token="time" searchWhenChanged="true">
   <label>Last Transaction Time</label>
   <default>
     <earliest>@d</earliest>
     <latest>now</latest>
   </default>
 </input>


 <panel>
   <event>
     <title>Most Recent Event</title>
     <search>
       <query>| inputlookup Lookup.csv | $serviceCode$ = search (source = "$source1$" AND service = "$service1$" AND method = "$method1$") |sort -_time | head 1
       <earliest>$time.earliest$</earliest>
       <latest>$time.latest$</latest>
     </search>
     <fields>["host","source","sourcetype"]</fields>
   </event>
 </panel>
0 Karma

somesoni2
Revered Legend

Use like this

dropdown service

<search>
     <query>| inputlookup Lookup.csv | search source="$source1$" | stats count by service serviceCode | table service serviceCode</query>
   </search>
   <fieldForLabel>service</fieldForLabel>
   <fieldForValue>serviceCode</fieldForValue>

dropdown method

 <search>
     <query>| inputlookup Lookup.csv | search (source = "$source1$" AND serviceCode = "$service1$")| stats count by method methodCode| table method methodCode</query>
     <earliest>0</earliest>
   </search>
   <fieldForLabel>method</fieldForLabel>
   <fieldForValue>methodCode</fieldForValue>

Panel Search

| inputlookup Lookup.csv | $serviceCode$ = search (source = "$source1$" AND serviceCode = "$service1$" AND methodCode = "$method1$") |sort -_time | head 1

alan20854
Path Finder

Thanks for the help!

0 Karma

snoobzilla
Builder

Yeah, what he said.

0 Karma

alan20854
Path Finder

Here is my XML:

<input type="dropdown" token="source1" searchWhenChanged="true">
  <label>Source</label>
  <search>
    <query>| inputlookup Lookup.csv | stats count by source | table source</query>
  </search>
  <fieldForLabel>source</fieldForLabel>
  <fieldForValue>source</fieldForValue>
</input>
<input type="dropdown" token="service1" searchWhenChanged="true">
  <label>Service</label>
  <search>
    <query>| inputlookup Lookup.csv | search source="$source1$" | stats count by service | table service</query>
  </search>
  <fieldForLabel>service</fieldForLabel>
  <fieldForValue>service</fieldForValue>
</input>
<input type="dropdown" token="method1" searchWhenChanged="true">
  <label>Method/Operation</label>
  <search>
    <query>| inputlookup Lookup.csv | search (source = "$source1$" AND service = "$service1$")| stats count by method | table method</query>
    <earliest>0</earliest>
  </search>
  <fieldForLabel>method</fieldForLabel>
  <fieldForValue>method</fieldForValue>
</input>
<input type="time" token="time" searchWhenChanged="true">
  <label>Last Transaction Time</label>
  <default>
    <earliest>@d</earliest>
    <latest>now</latest>
  </default>
</input>


<panel>
  <event>
    <title>Most Recent Event</title>
    <search>
      <query>| inputlookup Lookup.csv | $serviceCode$ = search (source = "$source1$" AND service = "$service1$" AND method = "$method1$") |sort -_time | head 1
      <earliest>$time.earliest$</earliest>
      <latest>$time.latest$</latest>
    </search>
    <fields>["host","source","sourcetype"]</fields>
  </event>
</panel>
0 Karma
Get Updates on the Splunk Community!

Security Professional: Sharpen Your Defenses with These .conf25 Sessions

Sooooooooooo, guess what. .conf25 is almost here, and if you're on the Security Learning Path, this is your ...

First Steps with Splunk SOAR

Our first step was to gather a list of the playbooks we wanted and to sort them by priority.  Once this list ...

How To Build a Self-Service Observability Practice with Splunk Observability Cloud

If you’ve read our previous post on self-service observability, you already know what it is and why it ...