Developing for Splunk Enterprise

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)

 

View solution in original post

.conf21 Now Fully Virtual!
Register for FREE Today!

We've made .conf21 totally virtual and totally FREE! Our completely online experience will run from 10/19 through 10/20 with some additional events, too!