Dashboards & Visualizations

Changing Display columns depending on sourcetype

praspai
Path Finder

In Dashboard depending on sourcetype selected in the dropdown list, we want to display different fields on the dashboard. Since fields can change in the future we have created a lookup for it. So depending on source type the lookup should be queried and get the display columns. I am trying something like below but doesn't seem to work

index=test sourcetype="XXX"|table [|inputlookup SourceType-Attributes sourcetype="XXX" | fields Attribute]

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@praspai,

Can you please try the following approach?
1) As your lookup contains sourcetype and list of fields, use the sourcetype as a lable and list of fields as a value in dropdown.

2) Set tokens for sourcetype and fields which will be used in search query.

eg:

<input type="dropdown" token="sourcetype_tkn">
  <label>SourceType</label>
  <fieldForLabel>sourcetype</fieldForLabel>
  <fieldForValue>Attribute</fieldForValue>
  <search>
    <query>| inputlookup SourceType-Attributes | fields sourcetype Attribute</query>
  </search>
  <change>
    <set token="Attribute">$value$</set>
    <set token="sourcetype">$label$</set>
  </change>
</input>

3) Use token in your search
eg.

index=test sourcetype="$sourcetype$" | table $Attribute$

Can you please try below code?

<form>
  <label>Test1</label>
  <fieldset submitButton="false">
    <input type="dropdown" token="sourcetype_tkn">
      <label>SourceType</label>
      <fieldForLabel>sourcetype</fieldForLabel>
      <fieldForValue>Attribute</fieldForValue>
      <search>
        <query>| inputlookup SourceType-Attributes | fields sourcetype Attribute</query>
      </search>
      <change>
        <set token="Attribute">$value$</set>
        <set token="sourcetype">$label$</set>
      </change>
    </input>
  </fieldset>
  <row>
    <panel>
      <html>
      <b>Source Type:</b> $sourcetype$  
      <b>Attribute :</b>$Attribute$  

    </html>
    </panel>
  </row>
  <row>
    <panel>
      <table>
        <title>My Table</title>
        <search>
          <query>index="_internal"  sourcetype=$sourcetype$ | table $Attribute$</query>
          <earliest>-30d@d</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
      </table>
    </panel>
  </row>
</form>

My Sample Dashboard:

<form>
  <label>Test1</label>
  <fieldset submitButton="false">
    <input type="dropdown" token="sourcetype_tkn">
      <label>SourceType</label>
      <fieldForLabel>sourcetype</fieldForLabel>
      <fieldForValue>Attribute</fieldForValue>
      <search>
        <query>| makeresults | eval sourcetype="splunkd", Attribute="component, index, source" | append [| makeresults | eval sourcetype="splunk_web_service", Attribute="log_level, component,requestid" ] | table sourcetype Attribute</query>
        <earliest>-24h@h</earliest>
        <latest>now</latest>
      </search>
      <change>
        <set token="Attribute">$value$</set>
        <set token="sourcetype">$label$</set>
      </change>
    </input>
  </fieldset>
  <row>
    <panel>
      <html>
      <b>Source Type:</b> $sourcetype$  
      <b>Fields :</b>$Attribute$  

    </html>
    </panel>
  </row>
  <row>
    <panel>
      <table>
        <title>My Table</title>
        <search>
          <query>index="_internal"  sourcetype=$sourcetype$ | table $Attribute$</query>
          <earliest>-30d@d</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
      </table>
    </panel>
  </row>
</form>

Thanks

0 Karma

praspai
Path Finder

Hi @kamlesh_vaghela ,

thanks for the reply.

Your example works correctly. But in the case of fields from the lookup, its taking only first row to display. It's not displaying all columns mentioned in the lookup table.

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@praspai,

It should work. Can you please check whether field mentioned in lookup has 100% coverage?

0 Karma

renjith_nair
Legend

@praspai,

Try

index=nirds sourcetype="XXX"|lookup SourceType-Attributes sourcetype

provided sourcetype is a column inside the lookup.

Below is a run anywhere example. Here we select Argentina to create a dummy search and lookup against the lookup file

| inputlookup geo_attr_countries.csv|search country="Argentina"|lookup geo_attr_countries.csv country
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

praspai
Path Finder

It's not working 😞 . It just displays the events. I want to display it in the table.

0 Karma

renjith_nair
Legend

just add the table command at the last with the fieldnames |table "field list"

---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma
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!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...