def test_009_normalizer_multiple_version(self): """ Verify we can can deal with a normalizer with more than one version. """ fdir = tempfile.mkdtemp() shutil.copyfile(os.path.join(self.normalizer_path, 'postfix.xml'), os.path.join(fdir, 'postfix.xml')) # Change normalizer version in fdir path xml = parse(os.path.join(fdir, 'postfix.xml')) xmln = xml.getroot() xmln.set('version', '1.0') xml.write(os.path.join(fdir, 'postfix.xml')) ln = LogNormalizer([self.normalizer_path, fdir]) self.assertEquals(XMLfromstring(ln.get_normalizer_source('postfix-0.99')).getroottree().getroot().get('version'), '0.99') self.assertEquals(XMLfromstring(ln.get_normalizer_source('postfix-1.0')).getroottree().getroot().get('version'), '1.0') shutil.rmtree(fdir)
def update_normalizer(self, raw_xml_contents, name=None, dir_path=None): """used to add or update a normalizer. @param raw_xml_contents: XML description of normalizer as flat XML. It must comply to the DTD. @param name: if set, the XML description will be saved as name.xml. If left blank, name will be fetched from the XML description. @param dir_path: the path to the directory where to copy the given normalizer. """ path = self.normalizers_paths[0] if dir_path: if dir_path in self.normalizers_paths: path = dir_path xmlconf = XMLfromstring(raw_xml_contents).getroottree() if not self.dtd.validate(xmlconf): raise ValueError, "This definition file does not follow the normalizers DTD :\n\n%s" % \ self.dtd.error_log.filter_from_errors() if not name: name = xmlconf.getroot().get('name') if not name.endswith('.xml'): name += '.xml' xmlconf.write(open(os.path.join(path, name), 'w'), encoding='utf8', method='xml', pretty_print=True) self.reload()
def test_008_normalizer_multiple_paths(self): """ Verify we can can deal with multiple normalizer paths. """ fdir = tempfile.mkdtemp() sdir = tempfile.mkdtemp() for f in os.listdir(self.normalizer_path): path_f = os.path.join(self.normalizer_path, f) if os.path.isfile(path_f): shutil.copyfile(path_f, os.path.join(fdir, f)) shutil.move(os.path.join(fdir, 'postfix.xml'), os.path.join(sdir, 'postfix.xml')) ln = LogNormalizer([fdir, sdir]) source = ln.get_normalizer_source('postfix-0.99') self.assertEquals( XMLfromstring(source).getroottree().getroot().get('name'), 'postfix') self.assertTrue( ln.get_normalizer_path('postfix-0.99').__contains__( os.path.basename(sdir))) self.assertTrue( ln.get_normalizer_path('syslog-1.0').__contains__( os.path.basename(fdir))) xml_src = ln.get_normalizer_source('syslog-1.0') os.unlink(os.path.join(fdir, 'syslog.xml')) ln.reload() self.assertRaises(ValueError, ln.get_normalizer_path, 'syslog-1.0') ln.update_normalizer(xml_src, dir_path=sdir) self.assertTrue( ln.get_normalizer_path('syslog-1.0').__contains__( os.path.basename(sdir))) shutil.rmtree(fdir) shutil.rmtree(sdir)
def test_007_normalizer_getsource(self): """ Verify we can retreive XML source of a normalizer. """ ln = LogNormalizer(self.normalizer_path) source = ln.get_normalizer_source('syslog-0.99') self.assertEquals(XMLfromstring(source).getroottree().getroot().get('name'), 'syslog')