Skip to content

Commit fba0947

Browse files
author
Frederick Ross
committed
Modular input kind bindings.
1 parent f609849 commit fba0947

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

splunklib/client.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def messages(self):
402402
def modular_input_kinds(self):
403403
"""Returns a collection of the modular input kinds on this Splunk instance."""
404404
if self.splunk_version[0] >= 5:
405-
return ReadOnlyCollection(self, PATH_MODULAR_INPUTS, item=Entity)
405+
return ReadOnlyCollection(self, PATH_MODULAR_INPUTS, item=ModularInputKind)
406406
else:
407407
raise IllegalOperationException("Modular inputs are not supported before Splunk version 5.")
408408

@@ -2295,13 +2295,24 @@ def value(self):
22952295
return self[self.name]
22962296

22972297
class ModularInputKind(Entity):
2298+
def __contains__(self, name):
2299+
args = self.state.content['endpoints']['args']
2300+
if name in args:
2301+
return True
2302+
else:
2303+
return Entity.__contains__(self, name)
2304+
22982305
def __getitem__(self, name):
2299-
args = self['endpoint']['args']
2306+
args = self.state.content['endpoint']['args']
23002307
if name in args:
23012308
return args['item']
23022309
else:
23032310
return Entity.__getitem__(self, name)
23042311

2312+
@property
2313+
def arguments(self):
2314+
return self.state.content['endpoint']['args']
2315+
23052316
def update(self, **kwargs):
23062317
"""Raises an error. Modular input kinds are read only."""
23072318
raise IllegalOperationException("Modular input kinds cannot be updated via the REST API.")

tests/test_modular_input_kinds.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,28 @@
1818
import splunklib.client as client
1919

2020
class ModularInputKindTestCase(testlib.TestCase):
21-
pass
21+
def test_list_arguments(self):
22+
test1 = self.service.modular_input_kinds['test1']
23+
24+
expected_args = set(["name", "resname", "key_id", "no_description", "empty_description",
25+
"arg_required_on_edit", "not_required_on_edit", "required_on_create",
26+
"not_required_on_create", "number_field", "string_field", "boolean_field"])
27+
found_args = set(test1.arguments.keys())
28+
29+
self.assertEqual(expected_args, found_args)
30+
31+
def test_update_raises_exception(self):
32+
test1 = self.service.modular_input_kinds['test1']
33+
self.assertRaises(client.IllegalOperationException, test1.update, a="b")
34+
35+
def check_modular_input_kind(self, m):
36+
if m.name == 'test1':
37+
self.assertEqual('Test "Input" - 1', m['title'])
38+
self.assertEqual("xml", m['streaming_mode'])
39+
elif m.name == 'test2':
40+
self.assertEqual('test2', m['title'])
41+
self.assertEqual('simple', m['streaming_mode'])
42+
43+
def test_list_modular_inputs(self):
44+
for m in self.service.modular_input_kinds:
45+
self.check_modular_input_kind(m)

0 commit comments

Comments
 (0)