Monday, 15 September 2014

how to use python to parse ossec rules xml -



how to use python to parse ossec rules xml -

i have ossec rules xml file, content this:

<var name="sensitive_directory">^/root|^/proc|^/etc|^/$</var> <var name="bad_words_ops">failure|error|bad |fatal|failed|illegal |denied|refused|unauthorized</var> <group name="local,ops,syslog,sudo,pam,"> <rule id="101000" level="4"> <if_sid>5715</if_sid> <srcip>!10.83.60.54</srcip> <srcip>!10.83.60.55</srcip> <description>except ips approved.</description> </rule> </group>

i trying utilize python parse xml, error:

xml.etree.elementtree.parseerror: junk after document element: line 10, column 0

here code using:

xml.etree import elementtree def read_xml(text): root = elementtree.fromstring(text) lst_node = root.getiterator("person") print lst_node if __name__ == '__main__': read_xml(open("test.xml").read())

wrap xml tag this

import xml.etree.elementtree et def read_xml(text): root = et.fromstring('<root>'+text+'</root>') # wrap root tag el in root.iter('srcip'): # changed tag srcip since sample hasn't got "player" print el.text if __name__ == '__main__': read_xml(open("yourfile.xml", "r").read()) !10.83.60.54 !10.83.60.55

python xml

No comments:

Post a Comment