def __init__(self, home): """ Load configuration object """ AutoConf.autoconf(home) self.configuration = AutoConf.get_warden_conf() # Setup logger # this is the stdout log level loglevel = getattr( logging, self.configuration.get('warden', {}).get('loglevel', 'INFO')) log.setLevel(loglevel) self.startuptime = None self.shutdowntime = None self.smtp_forwarder_enabled = str( self.configuration.get('smtp_forwarder', {}).get('enabled', '')).lower() in ('true', 't', '1', 'yes', 'y') log.info('Initialising Warden..') try: # initialise Carbon, daemon services are setup here, but the event reactor is not yet run self.carbon = CarbonManager() # initialise Gentry, this will also perform database manipulation for Sentry self.gentry = GentryManager() # initialise Diamond, not much is required here self.diamond = DiamondManager() if self.smtp_forwarder_enabled: self.smtpforward = SMTPForwarderManager( dict(self.configuration.get('smtp_forwarder', {}))) except Exception: log.exception("An error occured during initialisation.") sys.exit(1)
def __init__( self, warden_configuration_file, new_graphite_root=None, # does the graphite root variable need to be changed carbon_config_path=None, # where are the carbon config files diamond_config_path=None, # where is the diamond config file gentry_settings_path=None, # the name of the gentry settings module start_stmp_forwarder=True, smtp_forwarder_config_path=None, ): """ Load configuration object """ # Otherwise there may be a config argument if warden_configuration_file is None: log.critical( 'No Warden configuration file supplied! Please use the "warden_configuration_file" parameter.' ) sys.exit() warden_configuration_file = os.path.abspath( os.path.expanduser(warden_configuration_file)) try: with open(warden_configuration_file) as f: pass except IOError: log.error( 'The warden config file specified ("%s") does not exist!' % warden_configuration_file) raise self.configuration = ConfigParser.RawConfigParser() self.configuration.read(warden_configuration_file) # Setup logger # this is the stdout log level loglevel = getattr(logging, self.configuration.get('warden', 'loglevel')) log.setLevel(loglevel) self.startuptime = None self.shutdowntime = None # pull new config values into configuration object if new_graphite_root is not None: self.configuration.set('carbon', 'graphite_root', str(new_graphite_root)) if carbon_config_path is not None: self.configuration.set('carbon', 'configuration', str(carbon_config_path)) if diamond_config_path is not None: self.configuration.set('diamond', 'configuration', str(diamond_config_path)) if gentry_settings_path is not None: self.configuration.set('gentry', 'gentry_settings_py_path', str(gentry_settings_path)) if start_stmp_forwarder is False: self.configuration.set('smtp_forwarder', 'enabled', str(start_stmp_forwarder)) if smtp_forwarder_config_path is not None: self.configuration.set('smtp_forwarder', 'configuration', str(smtp_forwarder_config_path)) log.info('Initialising Warden..') try: # initialise Carbon, daemon services are setup here, but the event reactor is not yet run self.carbon = CarbonManager( self.configuration.get('carbon', 'graphite_root'), self.configuration.get('carbon', 'configuration')) # initialise Gentry, this will also perform database manipulation for Sentry self.gentry = GentryManager( self.configuration.get('gentry', 'gentry_settings_py_path')) # initialise Diamond, not much is required here self.diamond = DiamondManager( self.configuration.get('diamond', 'diamond_root'), self.configuration.get('diamond', 'configuration'), getattr(logging, self.configuration.get('diamond', 'loglevel'))) if self.configuration.getboolean('smtp_forwarder', 'enabled'): self.smtpforward = SMTPForwarderManager( dict(self.configuration.items('smtp_forwarder'))) except Exception: log.exception("An error occured during initialisation.") sys.exit(1)