class SnapshotFile (AbstractMibInstrumController): openedQueue = [] maxQueueEntries = 15 # max number of open text and index files def __init__(self, textFile, textParser): self.__textParser = textParser self.__textFile = textFile self._db = Database(self.__textFile, self.__textParser) def indexText(self): self._db.create() return self def close(self): self._db.close() def openDb(self): if not self._db.isOpen(): if len(SnapshotFile.openedQueue) > self.maxQueueEntries: SnapshotFile.openedQueue[0].close() del SnapshotFile.openedQueue[0] SnapshotFile.openedQueue.append(self) self._db.open() def processVarBinds(self, varBinds, nextFlag=False, setFlag=False): self.openDb() rspVarBinds = [] for oid,_ in varBinds: textOid = str( univ.OctetString( oid2str(oid) ) ) if nextFlag: try: (_oid, _, _tag, _val) = self._db.lookup_next( textOid ) subtreeFlag = False except KeyError: rspVarBinds.append((oid, exval.endOfMib)) continue else: try: (_oid, subtreeFlag, _tag, _val) = self._db.lookup( textOid ) subtreeFlag, int(subtreeFlag), True except KeyError: rspVarBinds.append((oid, exval.noSuchInstance)) continue # _oid = parser.evaluateOid(_oid) # _,_,_val = parser.evaluateValue(_oid,_tag,_val) rspVarBinds.append ( ( _oid, _val ) ) return rspVarBinds def __str__(self): return str(self._db)
def database_gc(self): """ Remove database that are not up to date """ try: # We try, if we cannot this is maybe because the db is loaded and will be refreshed by its owner for conf in searchFiles(confdir.cache, lambda _,ext: ext in ['db', 'dbm'] ): if not Database.isDbUpToDate ( conf ): logger.info ( 'Cleaning obsolete database %s', conf ); os.remove(conf) continue except: logger.warning ( 'Database cannot be cleaned %s', sys.exc_info()[1] );
def __init__(self, textFile, textParser): self.__textParser = textParser self.__textFile = textFile self._db = Database(self.__textFile, self.__textParser)
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # Description: Dump the content of the index database in readable form # from agentcluster import __version__, confdir, searchFiles from agentcluster.database import Database import os import argparse import agentcluster import logging.config logger = logging.getLogger('agentcluster.dbdump') default_log_file = os.path.join ( agentcluster.__path__[0], "agentcluster-log-console.conf") logging.config.fileConfig( default_log_file ) parser = argparse.ArgumentParser(description='SNMP Cluster of agents, by Gilles Bouissac. version %s'%__version__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument( '-c', '--cache-dir', metavar='<cache-dir>', default=confdir.cache, help='Path to a directory that contain application cache. default: %(default)s' ) options = parser.parse_args() if options.cache_dir: confdir.cache = options.cache_dir; # Browses databases: db = Database( "", None ) for dbfile in searchFiles( [confdir.cache] ): db.dump_from_file(dbfile)