Skip to content

Commit 8bff44e

Browse files
author
Shakeel Mohamed
committed
Merge branch 'feature/typeProperty' into develop
2 parents ad080f9 + dae7924 commit 8bff44e

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

splunklib/client.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,18 @@ def _parse_atom_entry(entry):
237237

238238
# Filter some of the noise out of the content record
239239
content = record((k, v) for k, v in content.iteritems()
240-
if k not in ['eai:acl', 'eai:attributes', 'type'])
240+
if k not in ['eai:acl', 'eai:attributes'])
241+
242+
if isinstance(content['type'], list):
243+
content['type'] = [t for t in content['type'] if t != 'text/xml']
244+
# Unset type if it was only 'text/xml'
245+
if len(content['type']) == 0:
246+
content.pop('type', None)
247+
# Flatten 1 element list
248+
if len(content['type']) == 1:
249+
content['type'] = content['type'][0]
250+
else:
251+
content.pop('type', None)
241252

242253
return record({
243254
'title': title,
@@ -521,7 +532,7 @@ def restart(self, timeout=None):
521532
# This message will be deleted once the server actually restarts.
522533
self.messages.create(name="restart_required", **msg)
523534
result = self.post("server/control/restart")
524-
if timeout is None:
535+
if timeout is None:
525536
return result
526537
start = datetime.now()
527538
diff = timedelta(seconds=timeout)
@@ -1610,7 +1621,7 @@ def get(self, name="", owner=None, app=None, sharing=None, **query):
16101621
name = UrlEncoded(name, encode_slash=True)
16111622
return super(Collection, self).get(name, owner, app, sharing, **query)
16121623

1613-
1624+
16141625

16151626

16161627
class ConfigurationFile(Collection):
@@ -1790,7 +1801,7 @@ def create(self, password, username, realm=None):
17901801
storage_password = StoragePassword(self.service, self._entity_path(state), state=state, skip_refresh=True)
17911802

17921803
return storage_password
1793-
1804+
17941805
def delete(self, username, realm=None):
17951806
"""Delete a storage password by username and/or realm.
17961807
@@ -1961,7 +1972,7 @@ def clean(self, timeout=60):
19611972
:return: The :class:`Index`.
19621973
"""
19631974
self.refresh()
1964-
1975+
19651976
tds = self['maxTotalDataSizeMB']
19661977
ftp = self['frozenTimePeriodInSecs']
19671978
was_disabled_initially = self.disabled
@@ -1980,7 +1991,7 @@ def clean(self, timeout=60):
19801991
while self.content.totalEventCount != '0' and datetime.now() < start+diff:
19811992
sleep(1)
19821993
self.refresh()
1983-
1994+
19841995
if self.content.totalEventCount != '0':
19851996
raise OperationError, "Cleaning index %s took longer than %s seconds; timing out." %\
19861997
(self.name, timeout)
@@ -2925,7 +2936,7 @@ def export(self, query, **params):
29252936
raise TypeError("Cannot specify an exec_mode to export.")
29262937
params['segmentation'] = params.get('segmentation', 'none')
29272938
return self.post(path_segment="export",
2928-
search=query,
2939+
search=query,
29292940
**params).body
29302941

29312942
def itemmeta(self):
@@ -2988,7 +2999,7 @@ def oneshot(self, query, **params):
29882999
raise TypeError("Cannot specify an exec_mode to oneshot.")
29893000
params['segmentation'] = params.get('segmentation', 'none')
29903001
return self.post(search=query,
2991-
exec_mode="oneshot",
3002+
exec_mode="oneshot",
29923003
**params).body
29933004

29943005

tests/test_service.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ def test_restart(self):
103103
self.service.restart(timeout=120)
104104
service.login() # Make sure we are awake
105105

106+
def test_read_outputs_with_type(self):
107+
name = testlib.tmpname()
108+
service = client.connect(**self.opts.kwargs)
109+
service.post('data/outputs/tcp/syslog', name=name, type='tcp')
110+
entity = client.Entity(service, 'data/outputs/tcp/syslog/' + name)
111+
self.assertTrue('tcp', entity.content.type)
112+
113+
if service.restart_required:
114+
self.restartSplunk()
115+
service = client.connect(**self.opts.kwargs)
116+
client.Entity(service, 'data/outputs/tcp/syslog/' + name).delete()
117+
if service.restart_required:
118+
self.restartSplunk()
119+
106120
def test_splunk_version(self):
107121
service = client.connect(**self.opts.kwargs)
108122
v = service.splunk_version

0 commit comments

Comments
 (0)