def load_monitors(m, filename): """Load all the monitors from the config file and return a populated SimpleMonitor.""" config = EnvironmentAwareConfigParser() config.read(filename) monitors = config.sections() if "defaults" in monitors: default_config = get_config_dict(config, "defaults") monitors.remove("defaults") else: default_config = {} myhostname = gethostname().lower() main_logger.info('=== Loading monitors') for monitor in monitors: if config.has_option(monitor, "runon"): if myhostname != config.get(monitor, "runon").lower(): main_logger.warning( "Ignoring monitor %s because it's only for host %s", monitor, config.get(monitor, "runon")) continue monitor_type = config.get(monitor, "type") new_monitor = None config_options = default_config.copy() config_options.update(get_config_dict(config, monitor)) try: cls = Monitors.monitor.get_class(monitor_type) except KeyError: main_logger.error("Unknown monitor type %s; valid types are: %s", monitor_type, ', '.join(Monitors.monitor.all_types())) continue new_monitor = cls(monitor, config_options) new_monitor.set_mon_refs(m) main_logger.info("Adding %s monitor %s: %s", monitor_type, monitor, new_monitor) m.add_monitor(monitor, new_monitor) for i in list(m.monitors.keys()): m.monitors[i].post_config_setup() main_logger.info('--- Loaded %d monitors', m.count_monitors()) return m
def load_monitors(m, filename, quiet): """Load all the monitors from the config file and return a populated SimpleMonitor.""" config = EnvironmentAwareConfigParser() config.read(filename) monitors = config.sections() if "defaults" in monitors: default_config = get_config_dict(config, "defaults") monitors.remove("defaults") else: default_config = {} myhostname = gethostname().lower() for monitor in monitors: if config.has_option(monitor, "runon"): if myhostname != config.get(monitor, "runon").lower(): sys.stderr.write( "Ignoring monitor %s because it's only for host %s\n" % (monitor, config.get(monitor, "runon"))) continue type = config.get(monitor, "type") new_monitor = None config_options = default_config.copy() config_options.update(get_config_dict(config, monitor)) if type == "host": new_monitor = Monitors.network.MonitorHost(monitor, config_options) elif type == "service": new_monitor = Monitors.service.MonitorService( monitor, config_options) elif type == "tcp": new_monitor = Monitors.network.MonitorTCP(monitor, config_options) elif type == "rc": new_monitor = Monitors.service.MonitorRC(monitor, config_options) elif type == "diskspace": new_monitor = Monitors.host.MonitorDiskSpace( monitor, config_options) elif type == "http": new_monitor = Monitors.network.MonitorHTTP(monitor, config_options) elif type == "apcupsd": new_monitor = Monitors.host.MonitorApcupsd(monitor, config_options) elif type == "svc": new_monitor = Monitors.service.MonitorSvc(monitor, config_options) elif type == "backup": new_monitor = Monitors.file.MonitorBackup(monitor, config_options) elif type == "portaudit": new_monitor = Monitors.host.MonitorPortAudit( monitor, config_options) elif type == "pkgaudit": new_monitor = Monitors.host.MonitorPkgAudit( monitor, config_options) elif type == "loadavg": new_monitor = Monitors.host.MonitorLoadAvg(monitor, config_options) elif type == "eximqueue": new_monitor = Monitors.service.MonitorEximQueue( monitor, config_options) elif type == "windowsdhcp": new_monitor = Monitors.service.MonitorWindowsDHCPScope( monitor, config_options) elif type == "zap": new_monitor = Monitors.host.MonitorZap(monitor, config_options) elif type == "fail": new_monitor = Monitors.monitor.MonitorFail(monitor, config_options) elif type == "null": new_monitor = Monitors.monitor.MonitorNull(monitor, config_options) elif type == "filestat": new_monitor = Monitors.host.MonitorFileStat( monitor, config_options) elif type == "compound": new_monitor = Monitors.compound.CompoundMonitor( monitor, config_options) new_monitor.set_mon_refs(m) elif type == 'dns': new_monitor = Monitors.network.MonitorDNS(monitor, config_options) elif type == 'command': new_monitor = Monitors.host.MonitorCommand(monitor, config_options) else: sys.stderr.write("Unknown type %s for monitor %s\n" % (type, monitor)) continue if new_monitor is None: continue if not quiet: print "Adding %s monitor %s" % (type, monitor) m.add_monitor(monitor, new_monitor) for i in m.monitors.keys(): m.monitors[i].post_config_setup() return m
def load_monitors(m, filename, quiet): """Load all the monitors from the config file and return a populated SimpleMonitor.""" config = EnvironmentAwareConfigParser() config.read(filename) monitors = config.sections() if "defaults" in monitors: default_config = get_config_dict(config, "defaults") monitors.remove("defaults") else: default_config = {} myhostname = gethostname().lower() for monitor in monitors: if config.has_option(monitor, "runon"): if myhostname != config.get(monitor, "runon").lower(): sys.stderr.write("Ignoring monitor %s because it's only for host %s\n" % (monitor, config.get(monitor, "runon"))) continue type = config.get(monitor, "type") new_monitor = None config_options = default_config.copy() config_options.update(get_config_dict(config, monitor)) if type == "host": new_monitor = Monitors.network.MonitorHost(monitor, config_options) elif type == "service": new_monitor = Monitors.service.MonitorService(monitor, config_options) elif type == "tcp": new_monitor = Monitors.network.MonitorTCP(monitor, config_options) elif type == "rc": new_monitor = Monitors.service.MonitorRC(monitor, config_options) elif type == "diskspace": new_monitor = Monitors.host.MonitorDiskSpace(monitor, config_options) elif type == "http": new_monitor = Monitors.network.MonitorHTTP(monitor, config_options) elif type == "apcupsd": new_monitor = Monitors.host.MonitorApcupsd(monitor, config_options) elif type == "svc": new_monitor = Monitors.service.MonitorSvc(monitor, config_options) elif type == "backup": new_monitor = Monitors.file.MonitorBackup(monitor, config_options) elif type == "portaudit": new_monitor = Monitors.host.MonitorPortAudit(monitor, config_options) elif type == "pkgaudit": new_monitor = Monitors.host.MonitorPkgAudit(monitor, config_options) elif type == "loadavg": new_monitor = Monitors.host.MonitorLoadAvg(monitor, config_options) elif type == "eximqueue": new_monitor = Monitors.service.MonitorEximQueue(monitor, config_options) elif type == "windowsdhcp": new_monitor = Monitors.service.MonitorWindowsDHCPScope(monitor, config_options) elif type == "zap": new_monitor = Monitors.host.MonitorZap(monitor, config_options) elif type == "fail": new_monitor = Monitors.monitor.MonitorFail(monitor, config_options) elif type == "null": new_monitor = Monitors.monitor.MonitorNull(monitor, config_options) elif type == "filestat": new_monitor = Monitors.host.MonitorFileStat(monitor, config_options) elif type == "compound": new_monitor = Monitors.compound.CompoundMonitor(monitor, config_options) new_monitor.set_mon_refs(m) elif type == 'dns': new_monitor = Monitors.network.MonitorDNS(monitor, config_options) elif type == 'command': new_monitor = Monitors.host.MonitorCommand(monitor, config_options) else: sys.stderr.write("Unknown type %s for monitor %s\n" % (type, monitor)) continue if new_monitor is None: continue if not quiet: print "Adding %s monitor %s" % (type, monitor) m.add_monitor(monitor, new_monitor) for i in m.monitors.keys(): m.monitors[i].post_config_setup() return m