Splunk Search

Splunk 6.5.0: How to edit my dashboard to set an in-page contextual drilldown with multiple conditions from a table?

jwahlgren
Engager

Hi fellow Splunkers 🙂

I have a table containing various fields such as sourcetype and username etc. I want to enable the user to always drilldown on sourcetype and user + what ever field is clicked on. Here is how my code looks like now

  <panel>
      <table id="master">
        <title>Test</title>
        <search>
          <query>main search... | bucket _time span=5m | stats count by sourcetype,_time,user,app,action,host,src,dest</query>
          <earliest>$s_time.earliest$</earliest>
          <latest>$s_time.latest$</latest>
        </search>
        <option name="dataOverlayMode">heatmap</option>
        <option name="drilldown">cell</option>
        <option name="percentagesRow">false</option>
        <option name="rowNumbers">true</option>
        <option name="totalsRow">true</option>
        <drilldown>
          <set token="s_sourcetype">$row.sourcetype$</set>
          <set token="s_user">$click.value2$</set>
        </drilldown>
      </table>
    </panel>
  </row>
  <row>
    <panel>
      <event id="detail" depends="$s_sourcetype$">
        <title>Detailed events by sourcetype $s_event_source$ and username $s_user$</title>
        <search>
          <query>main search... | search (sourcetype="$s_sourcetype$" user="$s_user$" host="$s_host$" src="$s_src$" dest="$s_dest$")</query>
          <earliest>$s_time.earliest$</earliest>
          <latest>$s_time.latest$</latest>
        </search>
        <option name="count">20</option>
        <option name="maxLines">5</option>
        <option name="rowNumbers">1</option>
        <option name="type">list</option>
      </event>
    </panel>

For now this works just fine if I only click on the user field in the master table. It will pass the token to the second panel and show results in an event list with the title e.g. "Detailed events by sourcetype WinEventLog:Security and username admin"

But, if a user clicks any of the other fields, like "host", it will show: "Detailed events by sourcetype WinEventLog:Security and username 127.0.0.1" and pass the host token to the user token. I tried to follow the "Contextual example with multiple conditions" at Splunk docs (can't post link) and that is simple with just sourcetype and log_level fields, however I want to select value in table and not by column name as this will search for user=user. With my example I'm not able to figure out how to do this.

Any suggestions?

0 Karma
1 Solution

jeffland
SplunkTrust
SplunkTrust

You can set your token to more than just $click.value2$, for example like this

<drilldown>
  <set token="s_sourcetype">$row.sourcetype$</set>
  <set token="s_user">"$click.name2$"="$click.value2$"</set>
  <set token="s_host">$row.host$</set>
</drilldown>

With a search like this:

 <search>
   <query>main search... | search (sourcetype="$s_sourcetype$" host="$s_host$" $s_user$)</query>

you should be good to go for any clicked column, as the token itself will always contain the clicked column name and the clicked value.

On a side note, try to move your search parameters to as early as possible within your search. Since you are using fields like sourcetype and host which are always present, you can at least move those two to the front of the search:

<query>sourcetype="$s_sourcetype$" host="$s_host$" ...main search... | search ($s_user$)</query>

If, like in the above example, the only options for the fields the user can click on are also present in the data you want to drill down into, then you can move the last token to the front as well. Fields which will not work with this method are obviously ones that you evaluate within the search, for example:

...some searching | eval newField=if(something, "a", "b") | search newField="$token$"

In this example, you won't be able to move the search for newField="$token$" before doing the eval.

The reason behind this is simple: when you do a search like this:

source=A OR source=B | some searching | search source=B

then splunk initially fetches all events for source A from disk even though they are never used.
This "moving search elements to the front of the search" is something that splunk will optimize internally beginning with 6.5 (which is what you're on), so you don't need to do it - I just added it for your information and understanding of splunk, and I'd still consider it a good practice.

View solution in original post

jeffland
SplunkTrust
SplunkTrust

You can set your token to more than just $click.value2$, for example like this

<drilldown>
  <set token="s_sourcetype">$row.sourcetype$</set>
  <set token="s_user">"$click.name2$"="$click.value2$"</set>
  <set token="s_host">$row.host$</set>
</drilldown>

With a search like this:

 <search>
   <query>main search... | search (sourcetype="$s_sourcetype$" host="$s_host$" $s_user$)</query>

you should be good to go for any clicked column, as the token itself will always contain the clicked column name and the clicked value.

On a side note, try to move your search parameters to as early as possible within your search. Since you are using fields like sourcetype and host which are always present, you can at least move those two to the front of the search:

<query>sourcetype="$s_sourcetype$" host="$s_host$" ...main search... | search ($s_user$)</query>

If, like in the above example, the only options for the fields the user can click on are also present in the data you want to drill down into, then you can move the last token to the front as well. Fields which will not work with this method are obviously ones that you evaluate within the search, for example:

...some searching | eval newField=if(something, "a", "b") | search newField="$token$"

In this example, you won't be able to move the search for newField="$token$" before doing the eval.

The reason behind this is simple: when you do a search like this:

source=A OR source=B | some searching | search source=B

then splunk initially fetches all events for source A from disk even though they are never used.
This "moving search elements to the front of the search" is something that splunk will optimize internally beginning with 6.5 (which is what you're on), so you don't need to do it - I just added it for your information and understanding of splunk, and I'd still consider it a good practice.

jwahlgren
Engager

Thank you for the detailed answer, I was able to fix the issue with the help of your instructions.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...