Splunk Dev

splunklib: how to get metric indexes with "service.indexes"

ktn01
Path Finder

"service.indexes" in splunklib for Python return by default a collection with only event indexes (no metric indexe).

Is it a way to get a collection from all metric and event indexes giving the filter parameter "datatype=all" ?

 

Thanks

Labels (3)
0 Karma
1 Solution

tpavlik_splunk
Splunk Employee
Splunk Employee

Hey there! Even though the Python SDK does not support listing indexes for datatype=all by default you can pass any keyword argument that you want which will then be used to form the request. For your case passing `datatype='all'` to the list method for the indexes collection appears to do the trick, I just tested this on my machine and metrics indexes are being returned along with logs:

from splunklib.client import connect

service = connect(
    host='localhost',
    port=8089,
    username='admin',
    password='changed!')

for index in service.indexes.list(datatype='all'):
    print(index.name)

 

View solution in original post

ktn01
Path Finder

It works fine. This is exactly what I needed.

Thanks a lot

tpavlik_splunk
Splunk Employee
Splunk Employee

Hey there! Even though the Python SDK does not support listing indexes for datatype=all by default you can pass any keyword argument that you want which will then be used to form the request. For your case passing `datatype='all'` to the list method for the indexes collection appears to do the trick, I just tested this on my machine and metrics indexes are being returned along with logs:

from splunklib.client import connect

service = connect(
    host='localhost',
    port=8089,
    username='admin',
    password='changed!')

for index in service.indexes.list(datatype='all'):
    print(index.name)

 

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...