Splunk Search

If/Else Conditions in a form base on Dropdown Selection

jaywilwk
Engager

I've created a form that has a dropdown where users can select their sourcetype. Within each sourcetype, the fields are different. Is there a way for me to have the associated fields available based on the sourcetype that the user selects? If so how do I do this? Below is my form.

<form>
<label>Threat Dashboard</label>
   <fieldset autoRun="false" submitButton="true">
      <input type="text" token="src_ip">
      <label>Source IP:</label>
      <default>*</default>
    </input>
      <input type="text" token="src_port">
      <label>Source Port:</label>
      <default>*</default>
    </input>
    <input type="text" token="dst_ip">
      <label>Destination IP:</label>
      <default>*</default>
    </input>
    <input type="text" token="dst_port">
      <label>Destination Port:</label>
      <default>*</default>
    </input>
    <input type="dropdown" token="sourcetype">
      <label>Select Sourcetype:</label>
      <default>pan_traffic</default>
      <populatingSearch fieldForValue="sourcetype" fieldForLabel="sourcetype" earliest="-120m" latest="-90m">
        <![CDATA[index=* | stats count by sourcetype]]>
      </populatingSearch>
    </input>
    <input type="time" searchWhenChanged="false">
      <default>
        <earliestTime>-15m</earliestTime>
        <latestTime>now</latestTime>
      </default>
       </input>
  </fieldset>
    <row>
    <table>
      <title>Investigate Source IP: $src_ip$</title>
      <searchString>sourcetype=$sourcetype$ src_ip=$src_ip$ dst_ip=$dst_ip$ src_port=$src_port$ dst_port=$dst_port$ | table src_ip, dst_ip, action, src_port, dst_port</searchString>

    </table>
  </row>
  </form>
0 Karma
1 Solution

somesoni2
Revered Legend

Try this in you searchString for the table.

  sourcetype=$sourcetype$ src_ip=$src_ip$ dst_ip=$dst_ip$ src_port=$src_port$ dst_port=$dst_port$ | table [|stats count| eval search=case("$sourcetype$"="proxysg","src_ip, dst_ip, action","$sourcetype$"="pan_traffic","action, src_port, dst_port", 1=1,"src_ip, dst_ip, action, src_port, dst_port")  | table search]

Update:

sourcetype=$sourcetype$  [|stats count | eval src_ip="$src_ip$" | eval dst_ip="$dst_ip$" 
| eval src_port="$src_port$" | eval dst_port="$dst_port$" | eval client_ip="$src_ip$" 
| eval dest_ip="$dst_ip$" | eval port=split("$src_port$,$dst_port$",",") | mvexpand port
| eval host=port
| table [|stats count| eval search=case(
"$sourcetype$"="proxysg","client_ip,dest_ip,port",
"$sourcetype$"="pan_traffic" OR "$sourcetype$"="pan_threat","src_ip, dst_ip,src_port,dst_port", 
"$sourcetype$"="ciscoios", "host" ,
1=1,"")  | table search] | format]
| table [|stats count| eval search=case(
"$sourcetype$"="proxysg","client_ip, dest_ip, action,port",
"$sourcetype$"="pan_traffic" OR "$sourcetype$"="pan_threat","src_ip,dst_ip,action,src_port,dst_port", 
"$sourcetype$"="ciscoios", "host,action,syslog_message" ,
1=1,"*")  | table search]

View solution in original post

0 Karma

jaywilwk
Engager

yes that's right.

0 Karma

somesoni2
Revered Legend

What should be the query if you want to search proxysg logs with dropdown values? Will it be this?

sourcetype=proxy client_ip=$src_ip$ dest_ip=$dst_ip$ port=$src_ip$ OR port=$dst_ip$

0 Karma

jaywilwk
Engager

in the proxysg, there is only port, which would be for the src_port and dst_port

0 Karma

somesoni2
Revered Legend

This was the critical information missing from the question. Can you confirm the final list of sourcetype-field list and mapping to dropdown in the form.

sourcetype=pan_traffic

field dropdown

src_ip src_ip
dst_ip dst_ip
src_port src_port
dst_port dst_port

sourcetype=proxysg

field dropdown

client_ip src_ip
dest_ip dst_ip
port src_port OR dst_port????

0 Karma

jaywilwk
Engager

it seems like it's on the right track, but I'm still not getting results. I have the default sourcetype=pan_traffic in the dropdown and the fields are src_ip, dst_ip, src_port, dst_port. In proxysg, fields are client_ip, dest_ip, port.

0 Karma

somesoni2
Revered Legend

The filters in the base search also needs to be filtered based on sourcetype. Try the updated answer.

0 Karma

jaywilwk
Engager

I tried it and I didn't get anything back for the proxysg sourcetype.

0 Karma

somesoni2
Revered Legend

My bad, missed one bracket. Updated the answer. Try now.

0 Karma

jaywilwk
Engager

I tried this and I got an error in my eval command: The expression is malformed. Expected ).

0 Karma

jaywilwk
Engager

ok let's say the fields src_ip and dst_ip is only available when the user select proxysg as their sourcetype. let's say I want client_ip and dest_ip available in my search result when the user select sourcetype=pan_traffic in the drop down. So based on the sourcetype selected, I want those field available that are associated with the sourcetype.

0 Karma

somesoni2
Revered Legend

Are you saying you want to customize filters used in search and fields displayed in table based on sourcetype selected?

0 Karma
Get Updates on the Splunk Community!

Your Guide to Splunk Digital Experience Monitoring

A flawless digital experience isn't just an advantage, it's key to customer loyalty and business success. But ...

Data Management Digest – November 2025

  Welcome to the inaugural edition of Data Management Digest! As your trusted partner in data innovation, the ...

Upcoming Webinar: Unmasking Insider Threats with Slunk Enterprise Security’s UEBA

Join us on Wed, Dec 10. at 10AM PST / 1PM EST for a live webinar and demo with Splunk experts! Discover how ...