File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414 import xml .etree .cElementTree as ET
1515except ImportError as ie :
1616 import xml .etree .ElementTree as ET
17- from tests . modularinput . modularinput_testlib import parse_xml_data
17+ from utils import parse_xml_data
1818
1919class InputDefinition :
2020 """InputDefinition encodes the XML defining inputs that Splunk passes to
Original file line number Diff line number Diff line change @@ -44,4 +44,27 @@ def xml_compare(expected, found):
4444 if (expected .text is None or expected .text .strip () == "" ) and (found .text is None or found .text .strip () == "" ):
4545 return True
4646 else :
47- return expected .tag == found .tag and expected .text == found .text and expected .attrib == found .attrib
47+ return expected .tag == found .tag and expected .text == found .text and expected .attrib == found .attrib
48+
49+ def parse_parameters (paramNode ):
50+ if paramNode .tag == "param" :
51+ return paramNode .text
52+ elif paramNode .tag == "param_list" :
53+ parameters = []
54+ for mvp in paramNode :
55+ parameters .append (mvp .text )
56+ return parameters
57+ else :
58+ raise ValueError ("Invalid configuration scheme, %s tag unexpected." % paramNode .tag )
59+
60+ def parse_xml_data (parent_node , child_node_tag ):
61+ data = {}
62+ for child in parent_node :
63+ if child .tag == child_node_tag :
64+ if child_node_tag == "stanza" :
65+ data [child .get ("name" )] = {}
66+ for param in child :
67+ data [child .get ("name" )][param .get ("name" )] = parse_parameters (param )
68+ elif "item" == parent_node .tag :
69+ data [child .get ("name" )] = parse_parameters (child )
70+ return data
Original file line number Diff line number Diff line change 1717 import xml .etree .cElementTree as ET
1818except ImportError as ie :
1919 import xml .etree .ElementTree as ET
20- from tests . modularinput . modularinput_testlib import parse_xml_data
20+ from utils import parse_xml_data
2121
2222class ValidationDefinition (object ):
2323 """This class represents the XML sent by Splunk for external validation of a new modular input.
Original file line number Diff line number Diff line change 2424
2525sys .path .insert (0 , os .path .join ('../../splunklib' , '..' ))
2626
27- from splunklib .modularinput .utils import xml_compare
28-
29- # utility functions
30-
31- def parse_parameters (paramNode ):
32- if paramNode .tag == "param" :
33- return paramNode .text
34- elif paramNode .tag == "param_list" :
35- parameters = []
36- for mvp in paramNode :
37- parameters .append (mvp .text )
38- return parameters
39- else :
40- raise ValueError ("Invalid configuration scheme, %s tag unexpected." % paramNode .tag )
41-
42- def parse_xml_data (parent_node , child_node_tag ):
43- data = {}
44- for child in parent_node :
45- if child .tag == child_node_tag :
46- if child_node_tag == "stanza" :
47- data [child .get ("name" )] = {}
48- for param in child :
49- data [child .get ("name" )][param .get ("name" )] = parse_parameters (param )
50- elif "item" == parent_node .tag :
51- data [child .get ("name" )] = parse_parameters (child )
52- return data
27+ from splunklib .modularinput .utils import xml_compare , parse_xml_data , parse_parameters
You can’t perform that action at this time.
0 commit comments