示例#1
0
def setup_scheduler():
    """Sets up the APScheduler"""
    log = logging.getLogger('apscheduler')

    try:
        accounts = Account.query.filter(Account.third_party == False).filter(
            Account.active == True).all()  # noqa
        accounts = [account.name for account in accounts]
        for account in accounts:
            app.logger.debug("Scheduler adding account {}".format(account))
            rep = Reporter(account=account)
            delay = app.config.get('REPORTER_START_DELAY', 10)

            for period in rep.get_intervals(account):
                scheduler.add_interval_job(run_change_reporter,
                                           minutes=period,
                                           start_date=datetime.now() +
                                           timedelta(seconds=delay),
                                           args=[[account], period])
            auditors = []
            for monitor in all_monitors(account):
                auditors.extend(monitor.auditors)
            scheduler.add_cron_job(_audit_changes,
                                   hour=10,
                                   day_of_week="mon-fri",
                                   args=[account, auditors, True])

        # Clear out old exceptions:
        scheduler.add_cron_job(_clear_old_exceptions, hour=3, minute=0)

    except Exception as e:
        app.logger.warn("Scheduler Exception: {}".format(e))
        app.logger.warn(traceback.format_exc())
        store_exception("scheduler", None, e)
示例#2
0
def setup_scheduler():
    """Sets up the APScheduler"""
    log = logging.getLogger('apscheduler')
    log.setLevel(app.config.get('LOG_LEVEL'))
    log.addHandler(handler)

    try:
        accounts = Account.query.filter(Account.third_party == False).filter(
            Account.active == True).all()
        accounts = [account.name for account in accounts]
        for account in accounts:
            print "Scheduler adding account {}".format(account)
            scheduler.add_interval_job(run_change_reporter,
                                       minutes=interval,
                                       start_date=datetime.now() +
                                       timedelta(seconds=2),
                                       args=[account])
            for monitor in all_monitors():
                if monitor.has_auditor():
                    scheduler.add_cron_job(_audit_changes,
                                           hour=10,
                                           day_of_week="mon-fri",
                                           args=[account, monitor, True])

    except Exception as e:
        app.logger.warn("Scheduler Exception: {}".format(e))
        app.logger.warn(traceback.format_exc())
示例#3
0
    def __init__(self, account=None, alert_accounts=None, debug=False):
        self.account_watchers = {}
        self.account_alerters = {}
        if not alert_accounts:
            alert_accounts = [account]

        self.account_watchers[account] = []
        for monitor in all_monitors(account, debug):
            self.account_watchers[account].append((monitor))

        if account in alert_accounts:
            self.account_alerters[account] = Alerter(watchers_auditors=self.account_watchers[account], account=account)
示例#4
0
def run_account(account):
    """
    This should be refactored into Reporter.
    Runs the watchers/auditors for each account.
    Does not run the alerter.
    Times the operations and logs those results.
    """
    app.logger.info("Starting work on account {}.".format(account))
    time1 = time.time()
    for monitor in all_monitors():
        find_changes(account, monitor)
        app.logger.info("Account {} is done with {}".format(
            account, monitor.index))
    time2 = time.time()
    app.logger.info('Run Account %s took %0.1f s' % (account, (time2 - time1)))
示例#5
0
    def __init__(self, accounts=None, alert_accounts=None, debug=False):
        self.account_watchers = {}
        self.account_alerters = {}
        if not alert_accounts:
            alert_accounts = accounts
        for account in accounts:
            self.account_watchers[account] = []
            for monitor in all_monitors():
                watcher = monitor.watcher_class(accounts=[account],
                                                debug=debug)
                auditor = monitor.auditor_class(
                    accounts=[account],
                    debug=debug) if monitor.has_auditor() else None
                self.account_watchers[account].append((watcher, auditor))

            if account in alert_accounts:
                self.account_alerters[account] = Alerter(
                    watchers_auditors=self.account_watchers[account],
                    account=account)
示例#6
0
 def __init__(self, account=None, debug=False):
     self.all_monitors = all_monitors(account, debug)
     self.account_alerter = Alerter(watchers_auditors=self.all_monitors,
                                    account=account)
示例#7
0
def __prep_monitor_names__(monitor_names):
    if monitor_names == 'all':
        return [monitor.index for monitor in all_monitors()]
    else:
        return monitor_names.split(',')