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!

New Year, New Changes for Splunk Certifications

As we embrace a new year, we’re making a small but important update to the Splunk Certification ...

Stay Connected: Your Guide to January Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...

[Puzzles] Solve, Learn, Repeat: Reprocessing XML into Fixed-Length Events

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