Exemple #1
0
    def __init__(self, name, config, opts):
        self.name = name
        self.config = config
        self.opts = opts
        self.runing = False

        self.processes = {}

        init_logging(config.syslog_facility,
                     level=config.syslog_priority,
                     debug=opts.debug)

        self.log = get_logger(name)
        # save the location of the calling script for later use
        # (os.path.abspath uses current directory and daemonize does a cd /)
        self.caller_path = os.path.abspath(__main__.__file__)

        if not self.opts.debug:
            exc_handler = setup_exc_handler(name, config)
            exc_handler.install()

            daemonize(name,
                      config.pid_dir,
                      log_stdout_stderr=config.syslog_facility)

        os.umask(0022)

        try:
            esxsnmp.sql.setup_db(config.db_uri)
        except Exception, e:
            self.log.error("Problem setting up database: %s" % e)
            raise
Exemple #2
0
    def __init__(self):
        self.db = tsdb.TSDB(CONFIG.tsdb_root, mode="r")
        self.session = esxsnmp.sql.Session()

        self.log = get_logger("newdb.power")

        self.begin = None
        self.end = None
Exemple #3
0
    def __init__(self):
        self.db = tsdb.TSDB(CONFIG.tsdb_root, mode="r")
        self.session = esxsnmp.sql.Session()

        self.log = get_logger("newdb.power")

        self.begin = None
        self.end = None
Exemple #4
0
    def __init__(self):
        self.db = tsdb.TSDB(CONFIG.tsdb_root, mode="r")
        if CONFIG.agg_tsdb_root:
            self.agg_db = tsdb.TSDB(CONFIG.agg_tsdb_root, mode="r")
        else:
            self.agg_db = None

        self.session = esxsnmp.sql.Session()

        self.log = get_logger("newdb")
Exemple #5
0
    def __init__(self):
        self.db = tsdb.TSDB(CONFIG.tsdb_root, mode="r")
        if CONFIG.agg_tsdb_root:
            self.agg_db = tsdb.TSDB(CONFIG.agg_tsdb_root, mode="r")
        else:
            self.agg_db = None

        self.session = esxsnmp.sql.Session()

        self.log = get_logger("newdb")
Exemple #6
0
    def __init__(self, config, qname):
        self.log = get_logger("espersistd.%s" % qname)
        self.config = config
        self.qname = qname
        self.running = False

        self.persistq = MemcachedPersistQueue(qname, config.espersistd_uri)

        self.data_count = 0
        self.last_stats = time.time()
Exemple #7
0
    def __init__(self, qprefix, qtype, uri, num_workers):
        self.qprefix = qprefix
        self.qtype = qtype
        self.num_workers = num_workers
        self.cur_worker = 1
        self.queues = {}
        self.worker_map = {}
        self.log = get_logger('MultiWorkerQueue')

        for i in range(1, num_workers + 1):
            name = "%s_%d" % (qprefix, i)
            self.queues[name] = qtype(name, uri)
Exemple #8
0
    def __init__(self, config):
        self.config = config
        self.sinks = []
        self.log = get_logger("espersist.client")

        if not self.config.espoll_persist_uri:
            self.log.warning(
                "espoll_persist_uri not defined: all data will be discarded")
            return

        for uri in config.espoll_persist_uri:
            (kind, kind_uri) = uri.split(':', 1)
            sink = eval('%s(config, "%s")' % (kind, kind_uri))
            self.sinks.append(sink)
Exemple #9
0
    def __init__(self, config, uri):
        self.queues = {}
        self.config = config
        self.uri = uri
        self.log = get_logger("MemcachedPersistHandler")

        for qname in config.persist_queues:
            num_workers = self.config.persist_queues[qname][1]
            if num_workers > 1:
                self.queues[qname] = MultiWorkerQueue(qname,
                                                      MemcachedPersistQueue,
                                                      uri, num_workers)
            else:
                self.queues[qname] = MemcachedPersistQueue(qname, uri)
Exemple #10
0
    def __init__(self, qname, memcached_uri):
        super(MemcachedPersistQueue, self).__init__(qname)

        self.log = get_logger("MemcachedPersistQueue_%s" % self.qname)

        self.mc = memcache.Client([memcached_uri])

        self.last_added = '%s_%s_last_added' % (self.PREFIX, self.qname)
        la = self.mc.get(self.last_added)
        if not la:
            self.mc.set(self.last_added, 0)

        self.last_read = '%s_%s_last_read' % (self.PREFIX, self.qname)
        lr = self.mc.get(self.last_read)
        if not lr:
            self.mc.set(self.last_read, 0)
Exemple #11
0
    def __init__(self, name, opts, args, config):
        self.name = name
        self.opts = opts
        self.args = args
        self.config = config

        self.hostname = socket.gethostname()

        self.log = get_logger(self.name)

        self.running = False
        self.last_reload = time.time()
        self.last_penalty_empty = time.time()

        self.reload_interval = 30
        self.penalty_interval = 300

        try:
            esxsnmp.sql.setup_db(self.config.db_uri)
        except Exception, e:
            self.log.error("Problem setting up database: %s" % e)
            raise
Exemple #12
0
    def __init__(self, name, opts, args, config):
        self.name = name
        self.opts = opts
        self.args = args
        self.config = config

        self.hostname = socket.gethostname()

        self.log = get_logger(self.name)

        self.running = False
        self.last_reload = time.time()
        self.last_penalty_empty = time.time()

        self.reload_interval = 30
        self.penalty_interval = 300

        try:
            esxsnmp.sql.setup_db(self.config.db_uri)
        except Exception, e:
            self.log.error("Problem setting up database: %s" % e)
            raise
Exemple #13
0
    def __init__(self, config=None, name="AsyncSNMPPoller", maxrepetitions=25):
        self.maxrepetitions = maxrepetitions
        self.name = name
        self.config = config

        self.reqmap = {}

        self.sessions = SNMPManager(local_dir="/usr/local/share/snmp",
                                    threaded_processor=True)

        self.log = get_logger(self.name)

        if self.config:
            for mib_dir in self.config.mib_dirs:
                self.log.info("add mib dir %s" % mib_dir)
                self.sessions.add_mib_dir(mib_dir)
            self.sessions.refresh_mibs()

            for mib in self.config.mibs:
                self.log.info("add mib %s" % mib)
                self.sessions.read_module(mib)

        self.sessions.bind('response', '1', None, self._callback)
        self.sessions.bind('timeout', '1', None, self._errback)
Exemple #14
0
    def __init__(self, config, device, oidset, poller, persistq):
        self.config = config
        self.device = device
        self.oidset = oidset
        self.poller = poller
        self.persistq = persistq

        self.name = "espolld." + self.device.name + "." + self.oidset.name

        self.next_poll = int(time.time() - 1)
        self.oids = self.oidset.oids
        # in some pollers we poll oids beyond the ones which are used
        # for that poller, so we make a copy in poll_oids
        self.poll_oids = [o.name for o in self.oids]
        self.running = True
        self.log = get_logger(self.name)

        self.poller_args = {}
        if self.oidset.poller_args is not None:
            for arg in self.oidset.poller_args.split():
                (var, val) = arg.split('=')
                self.poller_args[var] = val

        self.polling_round = 0
Exemple #15
0
    def __init__(self, config=None, name="AsyncSNMPPoller", maxrepetitions=25):
        self.maxrepetitions = maxrepetitions
        self.name = name
        self.config = config

        self.reqmap = {}

        self.sessions = SNMPManager(local_dir="/usr/local/share/snmp",
                threaded_processor=True)

        self.log = get_logger(self.name)

        if self.config:
            for mib_dir in self.config.mib_dirs:
                self.log.info("add mib dir %s" % mib_dir)
                self.sessions.add_mib_dir(mib_dir)
            self.sessions.refresh_mibs()

            for mib in self.config.mibs:
                self.log.info("add mib %s" % mib)
                self.sessions.read_module(mib)

        self.sessions.bind('response', '1', None, self._callback)
        self.sessions.bind('timeout', '1', None, self._errback)
Exemple #16
0
    def __init__(self, config, device, oidset, poller, persistq):
        self.config = config
        self.device = device
        self.oidset = oidset
        self.poller = poller
        self.persistq = persistq

        self.name = "espolld." + self.device.name + "." + self.oidset.name

        self.next_poll = int(time.time() - 1)
        self.oids = self.oidset.oids
        # in some pollers we poll oids beyond the ones which are used
        # for that poller, so we make a copy in poll_oids
        self.poll_oids = [o.name for o in self.oids]
        self.running = True
        self.log = get_logger(self.name)

        self.poller_args = {}
        if self.oidset.poller_args is not None:
            for arg in self.oidset.poller_args.split():
                (var, val) = arg.split('=')
                self.poller_args[var] = val

        self.polling_round = 0
Exemple #17
0
    def __init__(self):
        self.session = esxsnmp.sql.Session()

        self.log = get_logger("newdb.alusapref")
Exemple #18
0
    """Entry point for espolld."""
    argv = sys.argv
    oparse = get_opt_parser(default_config_file=get_config_path())
    (opts, args) = oparse.parse_args(args=argv)

    try:
        config = get_config(opts.config_file, opts)
    except ConfigError, e:
        print e
        sys.exit(1)

    name = "espolld"

    init_logging(config.syslog_facility, level=config.syslog_priority,
            debug=opts.debug)
    log = get_logger(name)

    setproctitle(name)

    if not opts.debug:
        exc_handler = setup_exc_handler(name, config)
        exc_handler.install()

        daemonize(name, config.pid_dir,
                log_stdout_stderr=config.syslog_facility)

    os.umask(0022)

    try:
        poller = PollManager(name, opts, args, config)
Exemple #19
0
    def __init__(self):
        self.session = esxsnmp.sql.Session()

        self.log = get_logger("newdb.alusapref")
Exemple #20
0
    (opts, args) = oparse.parse_args(args=argv)

    opts.config_file = os.path.abspath(opts.config_file)

    try:
        config = get_config(opts.config_file, opts)
    except ConfigError, e:
        print >> sys.stderr, e
        sys.exit(1)

    name = "espersistd.%s" % opts.role

    if opts.qname:
        name += ".%s" % opts.qname

    log = get_logger(name)

    if opts.role == 'manager':
        try:
            PersistManager(name, config, opts).run()
        except Exception, e:
            log.error("Problem with manager module: %s" % e)
            sys.exit(1)
    elif opts.role == 'worker':
        worker(name, config, opts)
        sys.exit(0)
        try:
            worker(name, config, opts)
        except Exception, e:
            log.error("Problem with worker module: %s" % e, exc_info=True)
            raise e