def test_compile(self):
     """
     Tests that the wrapper can output mib files.
     """
     input_dir = None
     output_dir = None
     try:
         input_dir = tempfile.mkdtemp()
         output_dir = tempfile.mkdtemp()
         shutil.copy('conpot/tests/data/VOGON-POEM-MIB.mib', input_dir)
         find_mibs([input_dir])
         compile_mib('VOGON-POEM-MIB', output_dir)
         self.assertIn('VOGON-POEM-MIB.py', os.listdir(output_dir))
     finally:
         shutil.rmtree(input_dir)
         shutil.rmtree(output_dir)
示例#2
0
    def xml_mib_config(self, dom, mibpaths, rawmibs_dirs):
        try:
            mibs = dom.xpath('//opc/mibs/*')
            tmp_mib_dir = tempfile.mkdtemp()
            mibpaths.append(tmp_mib_dir)
            available_mibs = find_mibs(rawmibs_dirs)

            databus = conpot_core.get_databus()
            # parse mibs and oid tables
            for mib in mibs:
                mib_name = mib.attrib['name']
                # compile the mib file if it is found and not already loaded.
                if mib_name in available_mibs and not self.cmd_responder.has_mib(mib_name):
                    compile_mib(mib_name, tmp_mib_dir)
                for symbol in mib:
                    symbol_name = symbol.attrib['name']

                    # retrieve instance from template
                    if 'instance' in symbol.attrib:
                        # convert instance to (int-)tuple
                        symbol_instance = symbol.attrib['instance'].split('.')
                        symbol_instance = tuple(map(int, symbol_instance))
                    else:
                        # use default instance (0)
                        symbol_instance = (0,)


                    # retrieve value from databus
                    value = databus.get_value(symbol.xpath('./value/text()')[0])
                    profile_map_name = symbol.xpath('./value/text()')[0]

                    # register this MIB instance to the command responder
                    self.cmd_responder.register(mib_name,
                                                symbol_name,
                                                symbol_instance,
                                                value,
                                                profile_map_name)
        finally:
            # cleanup compiled mib files
            shutil.rmtree(tmp_mib_dir)