Esempio n. 1
0
    def __init__(self, new_graphite_root=None, carbon_conf_file=None):
        """
        Build the storage directory and prepare for Start. The storage directory
        is in the GRAPHITE_ROOT folder which is used by all of the carbon daemons.
        GRAPHITE_ROOT can be modified as shown by:
            os.environ["GRAPHITE_ROOT"] = some_storage_directory
        """

        log.debug("Initialising Carbon..")

        # If an overriding graphite_root is provided: set os.environ['GRAPHITE_ROOT']
        if new_graphite_root is not None:
            os.environ["GRAPHITE_ROOT"] = normalize_path(new_graphite_root)

        # Log current GRAPHITE_ROOT
        log.debug("GRAPHITE_ROOT = %s" % os.environ['GRAPHITE_ROOT'])

        # If the path to the carbon.conf file is supplied: use it
        if carbon_conf_file is not None:
            self.carbon_config_file = normalize_path(carbon_conf_file)
        else:
            # otherwise build the path using GRAPHITE_ROOT
            self.carbon_config_file = os.path.join(os.environ['GRAPHITE_ROOT'], 'conf','carbon.conf')

        #read config file, used mostly to get the port its running on
        self.configuration = SafeConfigParser()
        self.configuration.read(self.carbon_config_file)

        self.application_service = service.MultiService()
        self.reactor_thread = None
Esempio n. 2
0
    def __init__(self, gentry_settings_file=None):

        log.debug('Initialising Gentry..')

        if gentry_settings_file is None:
            os.environ['DJANGO_SETTINGS_MODULE'] = 'gentry.settings'
        else:
            n = 'j5_warden_gentry_settings'
            os.environ['DJANGO_SETTINGS_MODULE'] = n
            if not sys.modules.has_key(n):
                imp.load_source(
                    n, warden_utils.normalize_path(gentry_settings_file))

        log.debug('$DJANGO_SETTINGS_MODULE = %s' %
                  os.environ['DJANGO_SETTINGS_MODULE'])
        from django.conf import settings

        dbfile = settings.DATABASES['default']['NAME']
        #exists
        try:
            with open(dbfile) as f:
                pass
            management.execute_from_command_line(['manage.py', 'migrate'])
        except:
            raise IOError(
                'Gentry Database was not found at "%s". Please use warden-setup to initialise it.'
                % dbfile)

        self.thread = self.GentryServerThread()
Esempio n. 3
0
    def __init__(self, new_graphite_root=None, carbon_conf_file=None):
        """
        Build the storage directory and prepare for Start. The storage directory
        is in the GRAPHITE_ROOT folder which is used by all of the carbon daemons.
        GRAPHITE_ROOT can be modified as shown by:
            os.environ["GRAPHITE_ROOT"] = some_storage_directory
        """

        log.debug("Initialising Carbon..")

        # If an overriding graphite_root is provided: set os.environ['GRAPHITE_ROOT']
        if new_graphite_root is not None:
            os.environ["GRAPHITE_ROOT"] = normalize_path(new_graphite_root)

        # Log current GRAPHITE_ROOT
        log.debug("GRAPHITE_ROOT = %s" % os.environ['GRAPHITE_ROOT'])

        # If the path to the carbon.conf file is supplied: use it
        if carbon_conf_file is not None:
            self.carbon_config_file = normalize_path(carbon_conf_file)
        else:
            # otherwise build the path using GRAPHITE_ROOT
            self.carbon_config_file = os.path.join(os.environ['GRAPHITE_ROOT'],
                                                   'conf', 'carbon.conf')

        #read config file, used mostly to get the port its running on
        self.configuration = SafeConfigParser()
        self.configuration.read(self.carbon_config_file)

        self.application_service = service.MultiService()
        self.reactor_thread = None
Esempio n. 4
0
 def stop(self):
     if self.thread.isAlive():
         log.debug("Stopping Diamond..")
         self.thread.stop()
         self.thread.join()
         log.debug("Stopped Diamond.")
     else:
         log.error("Can't stop Diamond if it has not started.")
 def _attach_files(self, mail):
     attached_files = 0
     log.debug("Scanning for files..")
     for path in self._walk_directory(settings.WHISPER_STORAGE_PATH):
         attachment = self.create_attachment(path, self._path_to_metric_filename(path))
         if attachment:
             mail.attach(attachment)
             attached_files += 1
     log.debug("Found %d files for sending." % attached_files)
     return attached_files
Esempio n. 6
0
    def stop(self):
        if self.reactor_thread.isAlive():
            log.debug("Stopping Carbon..")

            self.application_service.stopService()

            self.reactor_thread.die()
            self.reactor_thread.join()

            log.debug("Stopped Carbon.")
        else:
            log.error("Can't stop Carbon/Twistd if it has not started.")
Esempio n. 7
0
    def stop(self):
        if self.reactor_thread.isAlive():
            log.debug("Stopping Carbon..")

            self.application_service.stopService()

            self.reactor_thread.die()
            self.reactor_thread.join()

            log.debug("Stopped Carbon.")
        else:
            log.error("Can't stop Carbon/Twistd if it has not started.")
Esempio n. 8
0
    def __init__(self,
                 diamond_root=None,
                 diamond_conf_file=None,
                 diamond_stdout_lvl=None):
        self.thread = None
        self.config = None

        log.debug('Initialising Diamond..')

        if diamond_root is not None:
            diamond_root = normalize_path(diamond_root)
            os.environ['DIAMOND_ROOT'] = diamond_root
            log.debug('$DIAMOND_ROOT=%s' % os.environ['DIAMOND_ROOT'])
        else:
            diamond_root = os.environ['DIAMOND_ROOT']

        if diamond_conf_file is None:
            diamond_conf_file = os.path.join(diamond_root, 'diamond.conf')

        diamond_conf_file = normalize_path(diamond_conf_file)

        if os.path.exists(diamond_conf_file):
            self.config = configobj.ConfigObj(diamond_conf_file)
            self.config['configfile'] = diamond_conf_file
        else:
            print >> sys.stderr, "ERROR: Config file: %s does not exist." % diamond_conf_file
            sys.exit(1)

        if diamond_stdout_lvl is None:
            diamond_stdout_lvl = logging.ERROR

        self.log_diamond = logging.getLogger('diamond')
        self.log_diamond.setLevel(logging.DEBUG)
        self.log_diamond.propagate = False

        #       LOG to STDOUT
        formatter = logging.Formatter(
            '[%(asctime)s][%(levelname)s][%(message)s]')
        streamHandler = logging.StreamHandler(sys.stdout)
        streamHandler.setFormatter(formatter)
        streamHandler.setLevel(diamond_stdout_lvl)

        # LOG to File
        fileHandler = logging.FileHandler(
            os.path.join(diamond_root, 'diamond.log'))
        fileHandler.setFormatter(formatter)
        fileHandler.setLevel(logging.DEBUG)

        self.log_diamond.addHandler(streamHandler)
        self.log_diamond.addHandler(fileHandler)
        self.log_diamond.disabled = False
Esempio n. 9
0
    def _startup(self):
        """
        Start the warden instance
        Carbon, Diamond and Gentry are started in order, and this method will only exit once all are bound to their
        correct ports
        """

        log.info('Starting Warden..')
        try:
            self.carbon.start()
            self._wait_for_start(self.carbon)
            log.debug('1. Carbon Started')

            self.diamond.start()
            self._wait_for_start(self.diamond)
            log.debug('2. Diamond Started')

            self.gentry.start()
            self._wait_for_start(self.gentry)
            log.debug('3. Gentry Started')

            if self.configuration.getboolean('smtp_forwarder', 'enabled'):
                self.smtpforward.start()
                log.debug('4. Graphite SMTP forwarder Started')

            # blocking
            log.info('Started Warden.')
            self.startuptime = self.shutdowntime = datetime.datetime.now()

        except Exception, e:
            raise StartupException(e)
Esempio n. 10
0
    def _startup(self):
        """
        Start the warden instance
        Carbon, Diamond and Gentry are started in order, and this method will only exit once all are bound to their
        correct ports
        """

        log.info('Starting Warden..')
        try:
            self.carbon.start()
            self._wait_for_start(self.carbon)
            log.debug('1. Carbon Started')

            self.diamond.start()
            self._wait_for_start(self.diamond)
            log.debug('2. Diamond Started')

            self.gentry.start()
            self._wait_for_start(self.gentry)
            log.debug('3. Gentry Started')

            if self.configuration.getboolean('smtp_forwarder', 'enabled'):
                self.smtpforward.start()
                log.debug('4. Graphite SMTP forwarder Started')

            # blocking
            log.info('Started Warden.')
            self.startuptime = self.shutdowntime = datetime.datetime.now()

        except Exception, e:
            raise StartupException(e)
Esempio n. 11
0
    def __init__(self, gentry_settings_file=None):

        log.debug('Initialising Gentry..')

        if gentry_settings_file is None:
            os.environ['DJANGO_SETTINGS_MODULE'] = 'gentry.settings'
        else:
            n = 'j5_warden_gentry_settings'
            os.environ['DJANGO_SETTINGS_MODULE'] = n
            if not sys.modules.has_key(n):
                imp.load_source(n, warden_utils.normalize_path(gentry_settings_file))

        log.debug('$DJANGO_SETTINGS_MODULE = %s' % os.environ['DJANGO_SETTINGS_MODULE'])
        from django.conf import settings

        # hook loggers
        import graphite.logger
        self.graphitelog = graphite.logger.log

        # FILE HANDLERS STDOUT
        self.graphitelog.metricAccessLogger.addHandler(self.make_and_return_filehandler('metricAccessLogger', os.path.expanduser('~/.graphite/metric_access.log')))
        self.graphitelog.cacheLogger.addHandler(self.make_and_return_filehandler('cacheLogger',  os.path.expanduser('~/.graphite/.graphite/cache.log')))
        self.graphitelog.renderingLogger.addHandler(self.make_and_return_filehandler('renderingLogger',  os.path.expanduser('~/.graphite/.graphite/rendering.log')))
        self.graphitelog.infoLogger.addHandler(self.make_and_return_filehandler('infoLogger',  os.path.expanduser('~/.graphite/.graphite/info.log')))
        self.graphitelog.exceptionLogger.addHandler(self.make_and_return_filehandler('exceptionLogger',  os.path.expanduser('~/.graphite/.graphite/exception.log')))

        # STREAM HANDLERS STDOUT
        self.graphitelog.metricAccessLogger.addHandler(self.make_and_return_streamhandler('metricAccessLogger'))
        self.graphitelog.cacheLogger.addHandler(self.make_and_return_streamhandler('cacheLogger'))
        self.graphitelog.renderingLogger.addHandler(self.make_and_return_streamhandler('renderingLogger'))
        self.graphitelog.infoLogger.addHandler(self.make_and_return_streamhandler('infoLogger'))
        self.graphitelog.exceptionLogger.addHandler(self.make_and_return_streamhandler('exceptionLogger'))

        self.graphitelog.infoLogger.propagate = False
        self.graphitelog.exceptionLogger.propagate = False
        self.graphitelog.cacheLogger.propagate = False
        self.graphitelog.metricAccessLogger.propagate = False
        self.graphitelog.renderingLogger.propagate = False

        dbfile = settings.DATABASES['default']['NAME']
        #exists
        try:
            with open(dbfile) as f: pass
            management.execute_from_command_line(['manage.py', 'migrate'])
        except:
            raise IOError('Gentry Database was not found at "%s". Please use warden-setup to initialise it.' % dbfile)

        self.thread = self.GentryServerThread()
Esempio n. 12
0
    def __init__(self, diamond_root=None, diamond_conf_file=None, diamond_stdout_lvl=None):
        self.thread = None
        self.config = None

        log.debug('Initialising Diamond..')

        if diamond_root is not None:
            diamond_root = normalize_path(diamond_root)
            os.environ['DIAMOND_ROOT'] = diamond_root
            log.debug('$DIAMOND_ROOT=%s' % os.environ['DIAMOND_ROOT'])
        else:
            diamond_root = os.environ['DIAMOND_ROOT']

        if diamond_conf_file is None:
            diamond_conf_file = os.path.join(diamond_root, 'diamond.conf')

        diamond_conf_file = normalize_path(diamond_conf_file)

        if os.path.exists(diamond_conf_file):
            self.config = configobj.ConfigObj(diamond_conf_file)
            self.config['configfile'] = diamond_conf_file
        else:
            print >> sys.stderr, "ERROR: Config file: %s does not exist." % diamond_conf_file
            sys.exit(1)

        if diamond_stdout_lvl is None:
            diamond_stdout_lvl = logging.ERROR

        self.log_diamond = logging.getLogger('diamond')
        self.log_diamond.setLevel(logging.DEBUG)
        self.log_diamond.propagate = False

        #       LOG to STDOUT
        formatter = logging.Formatter('[%(asctime)s][%(levelname)s][%(message)s]')
        streamHandler = logging.StreamHandler(sys.stdout)
        streamHandler.setFormatter(formatter)
        streamHandler.setLevel(diamond_stdout_lvl)

        # LOG to File
        fileHandler = logging.FileHandler(os.path.join(diamond_root,'diamond.log'))
        fileHandler.setFormatter(formatter)
        fileHandler.setLevel(logging.DEBUG)

        self.log_diamond.addHandler(streamHandler)
        self.log_diamond.addHandler(fileHandler)
        self.log_diamond.disabled = False
Esempio n. 13
0
    def __init__(self, gentry_settings_file=None):

        log.debug('Initialising Gentry..')

        os.environ['DJANGO_SETTINGS_MODULE'] = 'gentry.settings'

        log.debug('$DJANGO_SETTINGS_MODULE = %s' % os.environ['DJANGO_SETTINGS_MODULE'])
        from django.conf import settings

        dbfile = settings.DATABASES['default']['NAME']
        #exists
        try:
            with open(dbfile) as f: pass
            management.execute_from_command_line(['manage.py', 'migrate'])
        except:
            raise IOError('Gentry Database was not found at "%s". Please use warden-setup to initialise it.' % dbfile)

        self.thread = self.GentryServerThread()
Esempio n. 14
0
    def start(self):
        log.debug("Starting Carbon..")

        twistd_options = ["--no_save", "--nodaemon", 'carbon-combined']

        if self.carbon_config_file is not None:
            twistd_options.append('--config=' + self.carbon_config_file)

        config = ServerOptions()
        config.parseOptions(twistd_options)
        config.subCommand = 'carbon-combined'

        # Hacky stuff to get carbon logging to the proper place
        from carbon.conf import settings as c_sett
        from carbon import log as c_log

        log_dir = os.path.join(os.environ['GRAPHITE_ROOT'], 'storage', 'log','carbon')
        if not os.path.exists(log_dir):
            os.makedirs(log_dir)

        c_log.logToStdout()
        c_log.logToDir(log_dir)

        # Change these if you want big logs
        c_sett.LOG_UPDATES = False
        c_sett.LOG_CACHE_HITS = True



        plg = config.loadedPlugins[config.subCommand]
        self.application_service = plg.makeService(config.subOptions)

        if reactor.running:
            raise Exception('Reactor is already running.')

        self.application_service.startService()
        self.reactor_thread = self.ReactorThread()
        self.reactor_thread.start()

        log.debug("Started Carbon.")
Esempio n. 15
0
    def start(self):
        log.debug("Starting Carbon..")

        twistd_options = ["--no_save", "--nodaemon", 'carbon-combined']

        if self.carbon_config_file is not None:
            twistd_options.append('--config=' + self.carbon_config_file)

        config = ServerOptions()
        config.parseOptions(twistd_options)
        config.subCommand = 'carbon-combined'

        # Hacky stuff to get carbon logging to the proper place
        from carbon.conf import settings as c_sett
        from carbon import log as c_log

        log_dir = os.path.join(os.environ['GRAPHITE_ROOT'], 'storage', 'log',
                               'carbon')
        if not os.path.exists(log_dir):
            os.makedirs(log_dir)

        c_log.logToStdout()
        c_log.logToDir(log_dir)

        # Change these if you want big logs
        c_sett.LOG_UPDATES = False
        c_sett.LOG_CACHE_HITS = True

        plg = config.loadedPlugins[config.subCommand]
        self.application_service = plg.makeService(config.subOptions)

        if reactor.running:
            raise Exception('Reactor is already running.')

        self.application_service.startService()
        self.reactor_thread = self.ReactorThread()
        self.reactor_thread.start()

        log.debug("Started Carbon.")
Esempio n. 16
0
    def __init__(self, gentry_settings_file=None):

        log.debug('Initialising Gentry..')

        os.environ['DJANGO_SETTINGS_MODULE'] = 'gentry.settings'

        log.debug('$DJANGO_SETTINGS_MODULE = %s' %
                  os.environ['DJANGO_SETTINGS_MODULE'])
        from django.conf import settings

        dbfile = settings.DATABASES['default']['NAME']
        #exists
        try:
            with open(dbfile) as f:
                pass
            management.execute_from_command_line(['manage.py', 'migrate'])
        except:
            raise IOError(
                'Gentry Database was not found at "%s". Please use warden-setup to initialise it.'
                % dbfile)

        self.thread = self.GentryServerThread()
    def start(self):

        while True:
            for generator_cls in BaseMailGenerator.generator_registry:
                generator = generator_cls()
                mail = generator.create_mail()

                if mail:
                    conn = SMTP()
                    try:
                        log.debug("Connecting..")
                        conn.connect(settings.EMAIL_HOST)
                        conn.set_debuglevel(False)

                        if settings.EMAIL_USE_TLS:
                            log.debug("Starting TLS..")
                            conn.starttls()

                        log.debug("Logging in..")
                        conn.login(settings.EMAIL_USERNAME, settings.EMAIL_PASSWORD)
                        log.debug("Sending mail..")
                        conn.sendmail(mail['From'], mail['To'], mail.as_string())
                        log.debug("Sent.")
                    except smtplib.SMTPRecipientsRefused:
                        log.error("Receipient confused.")
                    except smtplib.SMTPHeloError:
                        log.error("Server didn't respond properly to HELO.")
                    except smtplib.SMTPSenderRefused:
                        log.error("Sender refused.")
                    except smtplib.SMTPDataError:
                        log.error("Unexpected error code.")
                    except Exception as exc:
                        log.exception(exc)
                    finally:
                        if hasattr(conn, 'sock') and conn.sock:
                            conn.quit()

            time.sleep(self.SLEEP_INTERVAL)
Esempio n. 18
0
    def __init__(self, gentry_settings_file=None):

        log.debug('Initialising Gentry..')

        if gentry_settings_file is None:
            os.environ['DJANGO_SETTINGS_MODULE'] = 'gentry.settings'
        else:
            n = 'j5_warden_gentry_settings'
            os.environ['DJANGO_SETTINGS_MODULE'] = n
            if not sys.modules.has_key(n):
                imp.load_source(n, warden_utils.normalize_path(gentry_settings_file))

        log.debug('$DJANGO_SETTINGS_MODULE = %s' % os.environ['DJANGO_SETTINGS_MODULE'])
        from django.conf import settings

        dbfile = settings.DATABASES['default']['NAME']
        #exists
        try:
            with open(dbfile) as f: pass
            management.execute_from_command_line(['manage.py', 'migrate'])
        except:
            raise IOError('Gentry Database was not found at "%s". Please use warden-setup to initialise it.' % dbfile)

        self.thread = self.GentryServerThread()
Esempio n. 19
0
    def _shutdown(self):
        """
        Shutdown in order, some threading may be wrong here, make sure of inidividual .join()
        """
        self.shutdowntime = datetime.datetime.now()

        elapsed = self.shutdowntime - self.startuptime
        log.info('Warden was active for %s' % str(elapsed))

        log.info('Shutting down Warden..')

        if self.configuration.getboolean('smtp_forwarder', 'enabled'):
            try:
                self.smtpforward.stop()
                log.debug('4. Graphite SMTP forwarder stopped')
            except Exception:
                log.exception(
                    'An error occured while shutting down Graphite SMTP forwarder'
                )

        try:
            self.gentry.stop()
            log.debug('3. Gentry Stopped.')
        except Exception:
            log.exception("An error occured while shutting down Gentry")

        try:
            self.diamond.stop()
            log.debug('2. Diamond Stopped.')
        except Exception:
            log.exception("An error occured while shutting down Diamond")

        try:
            self.carbon.stop()
            log.debug('1. Carbon Stopped.')
        except Exception:
            log.exception("An error occured while shutting down Carbon")

        log.info('Shut down Warden.')
Esempio n. 20
0
    def _shutdown(self):
        """
        Shutdown in order, some threading may be wrong here, make sure of inidividual .join()
        """
        self.shutdowntime = datetime.datetime.now()

        elapsed = self.shutdowntime - self.startuptime
        log.info('Warden was active for %s' % str(elapsed))

        log.info('Shutting down Warden..')

        if self.configuration.getboolean('smtp_forwarder', 'enabled'):
            try:
                self.smtpforward.stop()
                log.debug('4. Graphite SMTP forwarder stopped')
            except Exception:
                log.exception('An error occured while shutting down Graphite SMTP forwarder')

        try:
            self.gentry.stop()
            log.debug('3. Gentry Stopped.')
        except Exception:
            log.exception("An error occured while shutting down Gentry")

        try:
            self.diamond.stop()
            log.debug('2. Diamond Stopped.')
        except Exception:
            log.exception("An error occured while shutting down Diamond")

        try:
            self.carbon.stop()
            log.debug('1. Carbon Stopped.')
        except Exception:
            log.exception("An error occured while shutting down Carbon")

        log.info('Shut down Warden.')
Esempio n. 21
0
 def stop(self):
     log.debug("Shutting down CherryPy server...")
     self.server.stop()
Esempio n. 22
0
 def run(self):
     log.debug("Starting CherryPy server on %s:%s with key '%s'" %
               (self.host, self.port, self.key))
     self.server.start()
Esempio n. 23
0
    def __init__(self, gentry_settings_file=None):

        log.debug('Initialising Gentry..')

        if gentry_settings_file is None:
            os.environ['DJANGO_SETTINGS_MODULE'] = 'gentry.settings'
        else:
            n = 'j5_warden_gentry_settings'
            os.environ['DJANGO_SETTINGS_MODULE'] = n
            if not sys.modules.has_key(n):
                imp.load_source(
                    n, warden_utils.normalize_path(gentry_settings_file))

        log.debug('$DJANGO_SETTINGS_MODULE = %s' %
                  os.environ['DJANGO_SETTINGS_MODULE'])
        from django.conf import settings

        # hook loggers
        import graphite.logger
        self.graphitelog = graphite.logger.log

        # FILE HANDLERS STDOUT
        self.graphitelog.metricAccessLogger.addHandler(
            self.make_and_return_filehandler(
                'metricAccessLogger',
                os.path.expanduser('~/.graphite/metric_access.log')))
        self.graphitelog.cacheLogger.addHandler(
            self.make_and_return_filehandler(
                'cacheLogger',
                os.path.expanduser('~/.graphite/.graphite/cache.log')))
        self.graphitelog.renderingLogger.addHandler(
            self.make_and_return_filehandler(
                'renderingLogger',
                os.path.expanduser('~/.graphite/.graphite/rendering.log')))
        self.graphitelog.infoLogger.addHandler(
            self.make_and_return_filehandler(
                'infoLogger',
                os.path.expanduser('~/.graphite/.graphite/info.log')))
        self.graphitelog.exceptionLogger.addHandler(
            self.make_and_return_filehandler(
                'exceptionLogger',
                os.path.expanduser('~/.graphite/.graphite/exception.log')))

        # STREAM HANDLERS STDOUT
        self.graphitelog.metricAccessLogger.addHandler(
            self.make_and_return_streamhandler('metricAccessLogger'))
        self.graphitelog.cacheLogger.addHandler(
            self.make_and_return_streamhandler('cacheLogger'))
        self.graphitelog.renderingLogger.addHandler(
            self.make_and_return_streamhandler('renderingLogger'))
        self.graphitelog.infoLogger.addHandler(
            self.make_and_return_streamhandler('infoLogger'))
        self.graphitelog.exceptionLogger.addHandler(
            self.make_and_return_streamhandler('exceptionLogger'))

        self.graphitelog.infoLogger.propagate = False
        self.graphitelog.exceptionLogger.propagate = False
        self.graphitelog.cacheLogger.propagate = False
        self.graphitelog.metricAccessLogger.propagate = False
        self.graphitelog.renderingLogger.propagate = False

        dbfile = settings.DATABASES['default']['NAME']
        #exists
        try:
            with open(dbfile) as f:
                pass
            management.execute_from_command_line(['manage.py', 'migrate'])
        except:
            raise IOError(
                'Gentry Database was not found at "%s". Please use warden-setup to initialise it.'
                % dbfile)

        self.thread = self.GentryServerThread()
Esempio n. 24
0
    def start(self):
        log.debug("Starting Diamond..")
        self.thread = self.DiamondThread(self.config)
        self.thread.start()

        log.debug("Started Diamond.")
Esempio n. 25
0
 def stop(self):
     log.debug("Shutting down CherryPy server...")
     self.server.stop()
Esempio n. 26
0
 def run(self):
     log.debug("Starting CherryPy server on %s:%s with key '%s'" % (self.host, self.port, self.key))
     self.server.start()
Esempio n. 27
0
 def start(self):
     log.debug('Starting Graphite SMTP forwader...')
     self.dispatcherThread.start()
     log.debug('Started Graphite SMTP forwader.')
Esempio n. 28
0
 def stop(self):
     log.debug('Stopping Graphite SMTP forwader...')
     self.dispatcherThread.stop()
     log.debug('Stopped Graphite SMTP forwader.')
Esempio n. 29
0
        def run(self):
            self.running = True

            self.configuration = self.load_config()

            self.SLEEP_TIME = int(self.configuration['send_interval'])
            self.last_poll_time = time.time()

            log.debug('SMTP dispatch will occur in %s' % str(self.prettiertime(self.SLEEP_TIME)))

            while self.running:
                if (time.time()-self.last_poll_time) < self.SLEEP_TIME:
                    time.sleep(1)
                    continue
                                                    # this overrides the value in the gentry_settings_module

                conn = SMTP()
                try:
                    log.debug('Connecting...')
                    conn.connect(self.configuration['email_host'])
                    conn.set_debuglevel(False)

                    if self.configuration['email_use_tls']:
                        conn.starttls()

                    log.debug('Logging in..')
                    conn.login(self.configuration['email_username'], self.configuration['email_password'])
                    max_mail_size = int(conn.esmtp_features['size'])

                    for generator_cls in BaseMailGenerator.generator_registry:
                        generator = generator_cls(self.configuration, max_mail_size)
                        mails = generator.get_mail_list()

                        for mail in mails:
                            if mail:

                                bytes = len(mail.as_string())
                                if bytes < 1024:
                                    sizestr = str(bytes) + "b"
                                elif bytes < 1048576:
                                    sizestr = "%.2f Kb" % (bytes/1024.0)
                                else:
                                    sizestr = "%.2f Mb" % ((bytes/1024.0)/1024.0)

                                log.debug('%s: Sending mail to: %s Size: %s' % (generator.__class__.__name__, mail['To'],sizestr))

                                start_time = time.time()
                                conn.sendmail(mail['From'], mail['To'], mail.as_string())
                                log.debug('Sent mail in %d seconds.' % (time.time()-start_time))

                    self.last_poll_time = time.time()

                    self.configuration = self.load_config()
                    self.SLEEP_TIME = int(self.configuration['send_interval'])

                    log.debug('Next SMTP dispatch will occur in %s' % str(self.prettiertime(self.SLEEP_TIME)))

                except smtplib.SMTPRecipientsRefused:
                    log.error('STMPRecipientsRefused')
                except smtplib.SMTPHeloError:
                    log.error('SMTPHeloError')
                except smtplib.SMTPSenderRefused:
                    log.exception('SMTPSenderRefused')
                except smtplib.SMTPDataError:
                    log.error('SMTPDataError')
                except Exception:
                    log.exception('An exception occured when sending mail')
                finally:
                    # Did it fail to send
                    if time.time() - self.last_poll_time > self.SLEEP_TIME:
                        self.last_poll_time = time.time() + (60 * 10) - self.SLEEP_TIME
                        log.debug('Next SMTP dispatch will occur in %s' % str(self.prettiertime(60*10)))

                    if hasattr(conn, 'sock') and conn.sock:
                        conn.quit()