<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to get all indexes and sourcetypes? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-all-indexes-and-sourcetypes/m-p/262090#M175834</link>
    <description>&lt;P&gt;After browsing through Splunk Answers, the closest I could get is the following SPL to list all Indexes and Sourcetypes in a single table - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventcount summarize=false index=* index!=_* | dedup index | fields index 
      | map maxsearches=100 search="| metadata type=sourcetypes index=\"$index$\" | eval retention=tostring(abs(lastTime-firstTime), \"duration\") | convert ctime(firstTime) ctime(lastTime) | sort lastTime | rename totalCount AS \"TotalEvents\" firstTime AS \"FirstEvent\" lastTime AS \"LastEvent\" | eval index=\"$index$\"" | rename index as "Index" "sourcetype" as "SourceType" | fields Index  SourceType TotalEvents FirstEvent LastEvent
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to provide the users with the ability to filter by indexes and sourcetypes. Here is what I have so far - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form&amp;gt;
  &amp;lt;label&amp;gt;Splunk Indexes and SourceTypes&amp;lt;/label&amp;gt;
  &amp;lt;fieldset submitButton="false"&amp;gt;
    &amp;lt;input type="multiselect" token="index" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;Select Index&amp;lt;/label&amp;gt;
      &amp;lt;search&amp;gt;
        &amp;lt;query&amp;gt;| rest /servicesNS/-/-/data/indexes|rename "title" as index | eval dy = (frozenTimePeriodInSecs/86400) % 365 | eval retention = dy . " days" | dedup index | stats count by index&amp;lt;/query&amp;gt;
      &amp;lt;/search&amp;gt;
      &amp;lt;fieldForLabel&amp;gt;index&amp;lt;/fieldForLabel&amp;gt;
      &amp;lt;fieldForValue&amp;gt;index&amp;lt;/fieldForValue&amp;gt;
      &amp;lt;choice value="\&amp;amp;quot;$index$\&amp;amp;quot;"&amp;gt;ALL&amp;lt;/choice&amp;gt;
      &amp;lt;default&amp;gt;"\""$index$\"""&amp;lt;/default&amp;gt;
      &amp;lt;initialValue&amp;gt;\"$index$\"&amp;lt;/initialValue&amp;gt;
    &amp;lt;/input&amp;gt;
    &amp;lt;input type="multiselect" token="source_type" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;Select SourceType(s)&amp;lt;/label&amp;gt;
      &amp;lt;search&amp;gt;
        &amp;lt;query&amp;gt;| metadata type=sourcetypes index=* | stats count by sourcetype&amp;lt;/query&amp;gt;
      &amp;lt;/search&amp;gt;
      &amp;lt;fieldForLabel&amp;gt;sourcetype&amp;lt;/fieldForLabel&amp;gt;
      &amp;lt;fieldForValue&amp;gt;sourcetype&amp;lt;/fieldForValue&amp;gt;
      &amp;lt;prefix&amp;gt;(&amp;lt;/prefix&amp;gt;
      &amp;lt;suffix&amp;gt;)&amp;lt;/suffix&amp;gt;
      &amp;lt;valuePrefix&amp;gt;SourceType=&amp;lt;/valuePrefix&amp;gt;
      &amp;lt;delimiter&amp;gt; OR &amp;lt;/delimiter&amp;gt;
      &amp;lt;choice value="*"&amp;gt;ALL&amp;lt;/choice&amp;gt;
      &amp;lt;default&amp;gt;*&amp;lt;/default&amp;gt;
      &amp;lt;initialValue&amp;gt;*&amp;lt;/initialValue&amp;gt;
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| eventcount summarize=false index=* index!=_* | dedup index | fields index         | map maxsearches=100 search="| metadata type=sourcetypes index=\"$index$\" | eval retention=tostring(abs(lastTime-firstTime), \"duration\") | convert ctime(firstTime) ctime(lastTime) | sort lastTime | rename totalCount AS \"TotalEvents\" firstTime AS \"FirstEvent\" lastTime AS \"LastEvent\" | eval index=\"$index$\"" | rename index as "Index" "sourcetype" as "SourceType" | fields Index  SourceType TotalEvents FirstEvent LastEvent | search $source_type$&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-3d@d&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="count"&amp;gt;10&amp;lt;/option&amp;gt;
        &amp;lt;option name="dataOverlayMode"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;cell&amp;lt;/option&amp;gt;
        &amp;lt;option name="percentagesRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="rowNumbers"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="totalsRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="wrap"&amp;gt;true&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am unable to achieve 2 things here - &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;When I filter indexes, I want the respective sourcetypes to be filtered in the sourctypes dropdown&lt;/LI&gt;
&lt;LI&gt;Display the table with selected indexes and sourcetypes only (should be able to select multiple in both case)&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;The query seems to be slow, but it gives the expected output.&lt;/P&gt;

&lt;P&gt;Any advice? Thanks!&lt;/P&gt;</description>
    <pubDate>Fri, 27 Jan 2017 01:41:29 GMT</pubDate>
    <dc:creator>jagadeeshm</dc:creator>
    <dc:date>2017-01-27T01:41:29Z</dc:date>
    <item>
      <title>How to get all indexes and sourcetypes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-all-indexes-and-sourcetypes/m-p/262090#M175834</link>
      <description>&lt;P&gt;After browsing through Splunk Answers, the closest I could get is the following SPL to list all Indexes and Sourcetypes in a single table - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventcount summarize=false index=* index!=_* | dedup index | fields index 
      | map maxsearches=100 search="| metadata type=sourcetypes index=\"$index$\" | eval retention=tostring(abs(lastTime-firstTime), \"duration\") | convert ctime(firstTime) ctime(lastTime) | sort lastTime | rename totalCount AS \"TotalEvents\" firstTime AS \"FirstEvent\" lastTime AS \"LastEvent\" | eval index=\"$index$\"" | rename index as "Index" "sourcetype" as "SourceType" | fields Index  SourceType TotalEvents FirstEvent LastEvent
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to provide the users with the ability to filter by indexes and sourcetypes. Here is what I have so far - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form&amp;gt;
  &amp;lt;label&amp;gt;Splunk Indexes and SourceTypes&amp;lt;/label&amp;gt;
  &amp;lt;fieldset submitButton="false"&amp;gt;
    &amp;lt;input type="multiselect" token="index" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;Select Index&amp;lt;/label&amp;gt;
      &amp;lt;search&amp;gt;
        &amp;lt;query&amp;gt;| rest /servicesNS/-/-/data/indexes|rename "title" as index | eval dy = (frozenTimePeriodInSecs/86400) % 365 | eval retention = dy . " days" | dedup index | stats count by index&amp;lt;/query&amp;gt;
      &amp;lt;/search&amp;gt;
      &amp;lt;fieldForLabel&amp;gt;index&amp;lt;/fieldForLabel&amp;gt;
      &amp;lt;fieldForValue&amp;gt;index&amp;lt;/fieldForValue&amp;gt;
      &amp;lt;choice value="\&amp;amp;quot;$index$\&amp;amp;quot;"&amp;gt;ALL&amp;lt;/choice&amp;gt;
      &amp;lt;default&amp;gt;"\""$index$\"""&amp;lt;/default&amp;gt;
      &amp;lt;initialValue&amp;gt;\"$index$\"&amp;lt;/initialValue&amp;gt;
    &amp;lt;/input&amp;gt;
    &amp;lt;input type="multiselect" token="source_type" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;Select SourceType(s)&amp;lt;/label&amp;gt;
      &amp;lt;search&amp;gt;
        &amp;lt;query&amp;gt;| metadata type=sourcetypes index=* | stats count by sourcetype&amp;lt;/query&amp;gt;
      &amp;lt;/search&amp;gt;
      &amp;lt;fieldForLabel&amp;gt;sourcetype&amp;lt;/fieldForLabel&amp;gt;
      &amp;lt;fieldForValue&amp;gt;sourcetype&amp;lt;/fieldForValue&amp;gt;
      &amp;lt;prefix&amp;gt;(&amp;lt;/prefix&amp;gt;
      &amp;lt;suffix&amp;gt;)&amp;lt;/suffix&amp;gt;
      &amp;lt;valuePrefix&amp;gt;SourceType=&amp;lt;/valuePrefix&amp;gt;
      &amp;lt;delimiter&amp;gt; OR &amp;lt;/delimiter&amp;gt;
      &amp;lt;choice value="*"&amp;gt;ALL&amp;lt;/choice&amp;gt;
      &amp;lt;default&amp;gt;*&amp;lt;/default&amp;gt;
      &amp;lt;initialValue&amp;gt;*&amp;lt;/initialValue&amp;gt;
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| eventcount summarize=false index=* index!=_* | dedup index | fields index         | map maxsearches=100 search="| metadata type=sourcetypes index=\"$index$\" | eval retention=tostring(abs(lastTime-firstTime), \"duration\") | convert ctime(firstTime) ctime(lastTime) | sort lastTime | rename totalCount AS \"TotalEvents\" firstTime AS \"FirstEvent\" lastTime AS \"LastEvent\" | eval index=\"$index$\"" | rename index as "Index" "sourcetype" as "SourceType" | fields Index  SourceType TotalEvents FirstEvent LastEvent | search $source_type$&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-3d@d&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="count"&amp;gt;10&amp;lt;/option&amp;gt;
        &amp;lt;option name="dataOverlayMode"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;cell&amp;lt;/option&amp;gt;
        &amp;lt;option name="percentagesRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="rowNumbers"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="totalsRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="wrap"&amp;gt;true&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am unable to achieve 2 things here - &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;When I filter indexes, I want the respective sourcetypes to be filtered in the sourctypes dropdown&lt;/LI&gt;
&lt;LI&gt;Display the table with selected indexes and sourcetypes only (should be able to select multiple in both case)&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;The query seems to be slow, but it gives the expected output.&lt;/P&gt;

&lt;P&gt;Any advice? Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2017 01:41:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-all-indexes-and-sourcetypes/m-p/262090#M175834</guid>
      <dc:creator>jagadeeshm</dc:creator>
      <dc:date>2017-01-27T01:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to get all indexes and sourcetypes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-all-indexes-and-sourcetypes/m-p/262091#M175835</link>
      <description>&lt;P&gt;Here is my final version with the following -&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;Default option is show "All" indexes and sourcetypes&lt;/LI&gt;
&lt;LI&gt;Selecting specific indexes will filter sourcetypes&lt;/LI&gt;
&lt;LI&gt;Submit button to filter the table based on the selected indexes and sourcetypes.&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Note # Tips are welcome to improve the performance of the SPL.&lt;/P&gt;

&lt;P&gt;Hope that saves a few hours for someone.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form&amp;gt;
  &amp;lt;label&amp;gt;Splunk Indexes and SourceTypes&amp;lt;/label&amp;gt;
  &amp;lt;fieldset submitButton="true"&amp;gt;
    &amp;lt;input type="multiselect" token="index_selected"&amp;gt;
      &amp;lt;label&amp;gt;Select Index&amp;lt;/label&amp;gt;
      &amp;lt;search&amp;gt;
        &amp;lt;query&amp;gt;| rest /servicesNS/-/-/data/indexes|rename "title" as index | search (index!=_* AND index!="cim_*") | stats count by index&amp;lt;/query&amp;gt;
      &amp;lt;/search&amp;gt;
      &amp;lt;fieldForLabel&amp;gt;index&amp;lt;/fieldForLabel&amp;gt;
      &amp;lt;fieldForValue&amp;gt;index&amp;lt;/fieldForValue&amp;gt;
      &amp;lt;choice value="*"&amp;gt;All&amp;lt;/choice&amp;gt;
      &amp;lt;default&amp;gt;*&amp;lt;/default&amp;gt;
      &amp;lt;initialValue&amp;gt;*&amp;lt;/initialValue&amp;gt;
      &amp;lt;valuePrefix&amp;gt;index=&amp;lt;/valuePrefix&amp;gt;
      &amp;lt;delimiter&amp;gt; OR &amp;lt;/delimiter&amp;gt;
    &amp;lt;/input&amp;gt;
    &amp;lt;input type="multiselect" token="sourcetype_selected"&amp;gt;
      &amp;lt;label&amp;gt;Select SouceType(s)&amp;lt;/label&amp;gt;
      &amp;lt;choice value="*"&amp;gt;All&amp;lt;/choice&amp;gt;
      &amp;lt;search&amp;gt;
        &amp;lt;query&amp;gt;| metadata type=sourcetypes $index_selected$ | rename sourcetype as SourceType | stats count by SourceType&amp;lt;/query&amp;gt;
        &amp;lt;earliest&amp;gt;0&amp;lt;/earliest&amp;gt;
      &amp;lt;/search&amp;gt;
      &amp;lt;fieldForLabel&amp;gt;SourceType&amp;lt;/fieldForLabel&amp;gt;
      &amp;lt;fieldForValue&amp;gt;SourceType&amp;lt;/fieldForValue&amp;gt;
      &amp;lt;default&amp;gt;*&amp;lt;/default&amp;gt;
      &amp;lt;prefix&amp;gt;(&amp;lt;/prefix&amp;gt;
      &amp;lt;suffix&amp;gt;)&amp;lt;/suffix&amp;gt;
      &amp;lt;initialValue&amp;gt;*&amp;lt;/initialValue&amp;gt;
      &amp;lt;valuePrefix&amp;gt;SourceType=&amp;lt;/valuePrefix&amp;gt;
      &amp;lt;delimiter&amp;gt; OR &amp;lt;/delimiter&amp;gt;
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| eventcount summarize=false index=* index!=_* | dedup index | fields index         | map maxsearches=100 search="| metadata type=sourcetypes index=\"$$index$$\" | eval retention=tostring(abs(lastTime-firstTime), \"duration\") | convert ctime(firstTime) ctime(lastTime) | sort lastTime | rename totalCount AS \"TotalEvents\" firstTime AS \"FirstEvent\" lastTime AS \"LastEvent\" | eval index=\"$$index$$\"" | rename  "sourcetype" as "SourceType" | fields index  SourceType TotalEvents FirstEvent LastEvent |search $index_selected$ | search $sourcetype_selected$&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-3d@d&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="count"&amp;gt;100&amp;lt;/option&amp;gt;
        &amp;lt;option name="dataOverlayMode"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;cell&amp;lt;/option&amp;gt;
        &amp;lt;option name="percentagesRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="rowNumbers"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="totalsRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="wrap"&amp;gt;true&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Jan 2017 04:50:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-all-indexes-and-sourcetypes/m-p/262091#M175835</guid>
      <dc:creator>jagadeeshm</dc:creator>
      <dc:date>2017-01-27T04:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to get all indexes and sourcetypes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-all-indexes-and-sourcetypes/m-p/262092#M175836</link>
      <description>&lt;P&gt;Hey @Jagadeeshm,&lt;/P&gt;

&lt;P&gt;You could also use a rest end point to get all the indexes, then map over them to get metadata for each:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | rest services/data/indexes | fields title
 | map maxsearches=50 search="| metadata type=sourcetypes index=$title$ | eval index=\"$title$\""
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Jan 2017 17:33:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-all-indexes-and-sourcetypes/m-p/262092#M175836</guid>
      <dc:creator>aljohnson_splun</dc:creator>
      <dc:date>2017-01-27T17:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to get all indexes and sourcetypes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-all-indexes-and-sourcetypes/m-p/262093#M175837</link>
      <description>&lt;P&gt;You could also use tstats for this purpose, for example:&lt;BR /&gt;
| tstats count where index=* groupby index&lt;BR /&gt;
(I think you could even leave the where clause out if you wish)&lt;/P&gt;

&lt;P&gt;| tstats count where index=* groupby index, sourcetype&lt;/P&gt;

&lt;P&gt;Or similar...I've also done searches such as:&lt;BR /&gt;
| tstats count, min(_time), max(_time) where index=* groupby index, sourcetype, source&lt;/P&gt;

&lt;P&gt;Just an alternative...&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:34:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-all-indexes-and-sourcetypes/m-p/262093#M175837</guid>
      <dc:creator>gjanders</dc:creator>
      <dc:date>2020-09-29T12:34:20Z</dc:date>
    </item>
  </channel>
</rss>

