Splunk Search

Dashboard to query optional fields

gtonti
Explorer

My log file is:

  1. TimeStamp=20180521095103123 Service=ABC12 User=ut1234 Id=12345678 Msg=ttttttttttttt
  2. TimeStamp=20180521095103456 Service=ABC12 Id=12345678 Msg=xxxxxxxxxxxx
  3. TimeStamp=20180521095103723 Service=ABC12 User=ut1234 Msg=yyyyyyyyyyyyyyyy

I want a dashboard in which I can search for Service, User, Id.
I made three input fields with default="*".


  1. Service
  2. *


  3. User
  4. *


  5. id
  6. *

My query is:

  1. index=xxxx Service=$serviceToken$ User=$userToken$ Id=$idToken$

When I make the query I get only thee first row of the log.
I understood that it is related to fields not present in the log file.

How can I modify my dashboard/query to obtain alle the rows?

Thank you

gtonti
Explorer

Hi everybody,
I adopted this solution. I created a token using change/condition. In this scenario I changed the default value form "*" to blanck.

The input in the xml dashboard definition is:

  1. <input type="text">
  2. <label>User</label>
  3. <initialValue></initialValue>
  4. <change>
  5. <condition value="">
  6. <set token="userToken"></set>
  7. </condition>
  8. <condition>
  9. <set token="userToken">User=$value$</set>
  10. </condition>
  11. </change>
  12. </input>

the query is:
index=xxx $userToken$

what happens is:
1) if User is empty/blank the query is index=xxx
2) if User has a value the query is index=xxx User=value

duartet
Path Finder

Worked for me! Thanks

0 Karma

mayurr98
Super Champion

Try this

index=xxxx Service=$serviceToken$ Id=$idToken$ OR User=$userToken$ 

let me know if this helps!

0 Karma

gtonti
Explorer

Thank you for the reply.
It works if I leave * in all the inputs.
If I set User to ut1234 I want only two lines as response of the query (the row 1 and 3).

Thank you

0 Karma

mayurr98
Super Champion

Yes, you are right this will not work in that case. This is because you are searching User=ut1234 OR Id=*
In order to write correct search query, you would need to add only those fields which are available in all the events. OR else you would need to find a workaround

Try this

index=xxxx | fillnull value="NA" User |search  Service=$serviceToken$ Id=$idToken$  User=$userToken$ 
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...