From 397f0aa4997da7a4f04d780bc976f57ee588457b Mon Sep 17 00:00:00 2001 From: Lowell Alleman Date: Fri, 12 Mar 2021 21:31:23 -0500 Subject: [PATCH 1/3] Capture 'app' context for modinput input_items - Update modularinput XML parsing to capture the 'app' tag for configuration stanza elements. This value is stored in the input dict under '__app' to avoid potential naming collisions with user defined parameters. - Updated unittest --- splunklib/modularinput/utils.py | 4 +++- .../modularinput/data/conf_with_2_inputs.xml | Bin 2332 -> 2384 bytes .../data/conf_with_invalid_inputs.xml | Bin 1332 -> 1358 bytes tests/modularinput/test_input_definition.py | 2 ++ 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/splunklib/modularinput/utils.py b/splunklib/modularinput/utils.py index 853694a0d..d731b5d55 100644 --- a/splunklib/modularinput/utils.py +++ b/splunklib/modularinput/utils.py @@ -66,7 +66,9 @@ def parse_xml_data(parent_node, child_node_tag): for child in parent_node: if child.tag == child_node_tag: if child_node_tag == "stanza": - data[child.get("name")] = {} + data[child.get("name")] = { + "__app": child.get("app", None) + } for param in child: data[child.get("name")][param.get("name")] = parse_parameters(param) elif "item" == parent_node.tag: diff --git a/tests/modularinput/data/conf_with_2_inputs.xml b/tests/modularinput/data/conf_with_2_inputs.xml index 95c44bb2a1ed46f31edf644cb1e35f2cff33b70c..bcfd8120471ce77d767d959a79d55e7f4193478e 100644 GIT binary patch delta 69 zcmbOubU|nXKeM<3Ln1=~5ZW>*F%&bT0(nIY$qX5rd6-`_qDba4R5HXv6i?=14&Cg@ HdYKsj6H^a) delta 37 ncmca0G)HIyKl5Z|4w=dEEK-}}nKv=QIFsXQuLn1=~5ZW>*F%&bT0(nIY$qX4lo*e_% Date: Fri, 12 Mar 2021 22:23:53 -0500 Subject: [PATCH 2/3] Simplified variable handing in parse_xml_data --- splunklib/modularinput/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/splunklib/modularinput/utils.py b/splunklib/modularinput/utils.py index d731b5d55..3d42b6326 100644 --- a/splunklib/modularinput/utils.py +++ b/splunklib/modularinput/utils.py @@ -64,13 +64,14 @@ def parse_parameters(param_node): def parse_xml_data(parent_node, child_node_tag): data = {} for child in parent_node: + child_name = child.get("name") if child.tag == child_node_tag: if child_node_tag == "stanza": - data[child.get("name")] = { + data[child_name] = { "__app": child.get("app", None) } for param in child: - data[child.get("name")][param.get("name")] = parse_parameters(param) + data[child_name][param.get("name")] = parse_parameters(param) elif "item" == parent_node.tag: - data[child.get("name")] = parse_parameters(child) + data[child_name] = parse_parameters(child) return data From 0f65cd7da44e87ee2c9d5fce151c191c26c37889 Mon Sep 17 00:00:00 2001 From: Lowell Alleman Date: Fri, 12 Mar 2021 22:25:35 -0500 Subject: [PATCH 3/3] Add 'app' input example into github_fork.py --- examples/github_forks/bin/github_forks.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/github_forks/bin/github_forks.py b/examples/github_forks/bin/github_forks.py index 5ffa4e409..46b42a81b 100755 --- a/examples/github_forks/bin/github_forks.py +++ b/examples/github_forks/bin/github_forks.py @@ -130,6 +130,10 @@ def stream_events(self, inputs, ew): owner = input_item["owner"] repo_name = input_item["repo_name"] + # Hint: API auth required?, get a secret from passwords.conf + # self.service.namespace["app"] = input_item["__app"] + # api_token = self.service.storage_passwords["github_api_token"].clear_password + # Get the fork count from the Github API jsondata = _get_github_repos(owner, repo_name) fork_count = jsondata["forks_count"]