Splunk Search

Filter host based on patterns

richaGindodia
Path Finder

Hello All,

I have 100 hosts with two patterns client1, client2, client3..... and server1, server2, server3....
I want to list these host in two different dropdowns

Dropdown1 contains clients
Dropdown2 contains servers

How do I do it.
Please help.

Tags (4)
0 Karma
1 Solution

rsennett_splunk
Splunk Employee
Splunk Employee

You would do something like this

<form>
  <label>New_dashboard</label>
  <fieldset submitButton="false">
    <input type="dropdown" token="clients">
       <label>dropdown1(clients)</label>
      <search>
        <query>index=whatever host=client*|stats count by host</query>
        <earliest>-60m@m</earliest>
        <latest>now</latest>
      </search>
      <fieldForLabel>host</fieldForLabel>
      <fieldForValue>host</fieldForValue>
      <prefix>host="</prefix>
      <suffix>"</suffix>
    </input>
    <input type="dropdown" token="servers">
       <label>dropdown1(clients)</label>
      <search>
        <query>index=whatever host=server*|stats count by host</query>
        <earliest>-60m@m</earliest>
        <latest>now</latest>
      </search>
      <fieldForLabel>host</fieldForLabel>
      <fieldForValue>host</fieldForValue>
      <prefix>host="</prefix>
      <suffix>"</suffix>
    </input>
  </fieldset>
   <!-- The Rest of your Dashboard goes here -->
</form>

This will produce two tokens, the value of which would be "host=clientxxx" or "host=serverxxx"

With Splunk... the answer is always "YES!". It just might require more regex than you're prepared for!

View solution in original post

jmallorquin
Builder

Hi

It could be usefull if you create before a lookup file to create the list and save theses searches to run every night.

index=xxx host=cliente* |table host |outputlookup clients.csv <- ALL TIME
index=xxx host=server* |table host | outputlookup servers.csv <- ALL TIME

0 Karma

rsennett_splunk
Splunk Employee
Splunk Employee

You would do something like this

<form>
  <label>New_dashboard</label>
  <fieldset submitButton="false">
    <input type="dropdown" token="clients">
       <label>dropdown1(clients)</label>
      <search>
        <query>index=whatever host=client*|stats count by host</query>
        <earliest>-60m@m</earliest>
        <latest>now</latest>
      </search>
      <fieldForLabel>host</fieldForLabel>
      <fieldForValue>host</fieldForValue>
      <prefix>host="</prefix>
      <suffix>"</suffix>
    </input>
    <input type="dropdown" token="servers">
       <label>dropdown1(clients)</label>
      <search>
        <query>index=whatever host=server*|stats count by host</query>
        <earliest>-60m@m</earliest>
        <latest>now</latest>
      </search>
      <fieldForLabel>host</fieldForLabel>
      <fieldForValue>host</fieldForValue>
      <prefix>host="</prefix>
      <suffix>"</suffix>
    </input>
  </fieldset>
   <!-- The Rest of your Dashboard goes here -->
</form>

This will produce two tokens, the value of which would be "host=clientxxx" or "host=serverxxx"

With Splunk... the answer is always "YES!". It just might require more regex than you're prepared for!

richaGindodia
Path Finder

Thanks alot rsennett. This worked.

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 ...