def _init_handlers(self, queue, cfg): ret = [] default = cfg.metricsd_default_interval handlers = cfg.metricsd_handlers if not len(handlers): ret = [(None, MetricsDHandler(queue, default))] ret[0][1].start() return ret for item in handlers: if len(item) == 2: pattern, interval, priority = item[0], item[1], 100 elif len(item) == 3: pattern, interval, priority = item else: raise ConfigError("Invalid handler specification: %s" % item) try: pattern = re.compile(pattern) except: raise ConfigError("Invalid pattern: %s" % pattern) if interval < 0: raise ConfigError("Invalid interval: %s" % interval) ret.append((pattern, interval, priority)) handlers.sort(key=lambda p: p[2]) ret = [(p, MetricsDHandler(queue, i)) for (p, i, _) in ret] ret.append((None, MetricsDHandler(queue, default))) for _, h in ret: h.start() return ret
def __init__(self, types_dbs=[]): self.types = {} self.type_ranges = {} if not types_dbs: types_dbs = filter(os.path.exists, [ "/usr/share/collectd/types.db", "/usr/local/share/collectd/types.db" ]) if not types_dbs: raise ConfigError("Unable to locate types.db") self.types_dbs = types_dbs self._load_types()
def load_auth_file(self): try: f = open(self.auth_file) except IOError as exc: raise ConfigError("Unable to load collectd's auth file: %r" % exc) self.auth_db.clear() for line in f: line = line.strip() if not line or line[0] == "#": continue user, passwd = line.split(":", 1) user = user.strip() passwd = passwd.strip() if not user or not passwd: log.warning("Found line with missing user or password") continue if user in self.auth_db: log.warning("Found multiple entries for single user") self.auth_db[user] = passwd f.close() log.info("Loaded collectd's auth file from %s", self.auth_file)
def __init__(self, cfg): sec_level = cfg.collectd_security_level if sec_level in ("sign", "SIGN", "Sign", 1): self.sec_level = 1 elif sec_level in ("encrypt", "ENCRYPT", "Encrypt", 2): self.sec_level = 2 else: self.sec_level = 0 self.auth_file = cfg.collectd_auth_file self.auth_db = {} self.cfg_mon = None if self.auth_file: self.load_auth_file() self.cfg_mon = FileMonitor(self.auth_file) if self.sec_level: if not self.auth_file: raise ConfigError("Collectd security level configured but no " "auth file specified in configuration") if not self.auth_db: log.warning("Collectd security level configured but no " "user/passwd entries loaded from auth file")