Skip to content

Commit 4d052dc

Browse files
author
Frederick Ross
committed
Add Indexes.default method to fetch name of default index.
1 parent b13e4d7 commit 4d052dc

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎splunklib/client.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def fired_alerts(self):
379379
@property
380380
def indexes(self):
381381
"""The indexes of this Splunk instance."""
382-
return Collection(self, PATH_INDEXES, item=Index)
382+
return Indexes(self, PATH_INDEXES, item=Index)
383383

384384
@property
385385
def info(self):
@@ -1443,6 +1443,11 @@ def count(self):
14431443
"""Returns the count of triggered alerts."""
14441444
return int(self.content.get('triggered_alert_count', 0))
14451445

1446+
class Indexes(Collection):
1447+
def default(self):
1448+
index = self['_audit']
1449+
return index['defaultDatabase']
1450+
14461451
class Index(Entity):
14471452
"""This class is an index class used to access specific operations."""
14481453
def __init__(self, service, path, **kwargs):
@@ -1840,8 +1845,7 @@ def oneshot(self, path, **kwargs):
18401845
raise
18411846

18421847

1843-
1844-
class Job(Entity):
1848+
class Job(Entity):
18451849
"""This class represents a search job."""
18461850
def __init__(self, service, sid, **kwargs):
18471851
path = PATH_JOBS + sid

‎tests/test_index.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class IndexWithoutRestart(IndexTest):
4545
def test_integrity(self):
4646
self.check_entity(self.index)
4747

48+
def test_default(self):
49+
default = self.service.indexes.default()
50+
self.assertTrue(isinstance(default, str))
51+
4852
def test_disable_enable(self):
4953
self.index.disable()
5054
self.index.refresh()

0 commit comments

Comments
 (0)