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 parse_confs(self,conf_dir): try: agents = {} for conf in searchFiles(conf_dir, lambda _,ext: ext=='agent'): conf = os.path.abspath(conf) # Records this new agent placeholder agents[conf] = Any( **{"sum":0, "current_sum":md5sum(conf), "handle":None} ); except Exception: logger.error ( 'Exception parsing conf %s', sys.exc_info()[1] ); logger.debug ( "", exc_info=True ); return; return agents
# 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)