Exemple #1
0
    def _prune_all_missed_extracts(self):
        """We might have missed some extracts, for example if the
           tabcmd failed, things took too long, etc.
           If so, remove the missed extracts from our tables.
           If multiple rows with the same parentid and empty fileid
           exist (unarchived), keep only the most recent row.
        """

        total_rowcount = 0

        for obj_class in [WorkbookExtractEntry, DataSourceExtractEntry]:
            stmt = ("delete from %s where " + \
                    "(parentid, sid) not in " + \
                    "(select parentid, max(sid) " + \
                    "from %s where fileid is null " + \
                    "group by parentid) " + \
                    "and fileid is null;") % (obj_class.__tablename__,
                                                  obj_class.__tablename__)

            connection = meta.get_connection()
            result = connection.execute(stmt)
            connection.close()

            if result.rowcount:
                logger.debug("refresh _prune_missed_extracts for %s pruned %d",
                             obj_class.__tablename__, result.rowcount)

                total_rowcount += result.rowcount

        return total_rowcount
Exemple #2
0
    def _prune(self):
        """Keep only the the ones in the last email-lookback-minutes
           period."""

        email_lookback_minutes = self.system[SystemKeys.EMAIL_LOOKBACK_MINUTES]
        stmt = ("DELETE from email_sent "
                "where creation_time < NOW() - INTERVAL '%d MINUTES'") % \
                (email_lookback_minutes,)

        connection = meta.get_connection()
        result = connection.execute(stmt)
        connection.close()

        logger.debug("email limit manager: pruned %d", result.rowcount)
Exemple #3
0
    def prune(self):
        """Prune/remove old rows from the metrics table."""

        metric_save_days = self.system[SystemKeys.METRIC_SAVE_DAYS]
        logger.debug("metrics: prune save %d days", metric_save_days)

        stmt = ("DELETE FROM metrics " + \
                "WHERE creation_time < NOW() - INTERVAL '%d DAYS'") % \
               (metric_save_days,)

        connection = meta.get_connection()
        result = connection.execute(stmt)
        connection.close()

        logger.debug("metrics: pruned %d rows", result.rowcount)
        return {'status': "OK", 'pruned': result.rowcount}
Exemple #4
0
    def _prune_missed_revisions(self):
        """Remove rows from workbook_updates that we didn't manage to
           archive.  It may be due to bad credentials, failed tabcmd, etc.
           Returns:
                count of updates pruned.
        """

        stmt = "delete from workbook_updates where " + \
                "(workbookid, timestamp) not in "+ \
                    "(select workbookid, max(timestamp) "+ \
                    "from workbook_updates where url='' " + \
                    "group by workbookid) " + \
                    "and url='';"

        connection = meta.get_connection()
        result = connection.execute(stmt)
        connection.close()

        if result.rowcount:
            logger.debug("workbooks _prune_missed_revisions pruned %d",
                           result.rowcount)

        return result.rowcount
Exemple #5
0
    def check(self, metric='cpu'):
        # pylint: disable=too-many-locals
        if metric != 'cpu':
            return {'error': 'Unknown metric: %s' % metric}

        cpu_load_warn = self.system[SystemKeys.CPU_LOAD_WARN]
        cpu_load_error = self.system[SystemKeys.CPU_LOAD_ERROR]
        cpu_period_warn = self.system[SystemKeys.CPU_PERIOD_WARN]
        cpu_period_error = self.system[SystemKeys.CPU_PERIOD_ERROR]

        connection = meta.get_connection()

        results = []

        agents = self.server.agentmanager.all_agents()
        for key in agents.keys():
            agent = agents[key]

            self.process_level_check(agent, connection, 'cpu')
            self.process_level_check(agent, connection, 'memory')

            error_report = self._cpu_above_threshold(connection, agent,
                                                     cpu_load_error,
                                                     cpu_period_error)
            logger.debug("metrics: error_report '%s': %s", agent.displayname,
                         str(error_report))

            if error_report['above'] != 'yes':
                warn_report = self._cpu_above_threshold(
                    connection, agent, cpu_load_warn, cpu_period_warn)

                logger.debug("metrics: warn_report '%s': %s",
                             agent.displayname, str(warn_report))
                if error_report['above'] == 'unknown' and \
                                warn_report['above'] == 'unknown':
                    results.append({"displayname": agent.displayname,
                                    "status": "unknown",
                                    "info": ("No data yet: " + \
                                             "error/warning %d/%d seconds") % \
                                            (cpu_period_error, cpu_period_warn)})
                    continue

            if error_report['above'] == 'yes':
                color = 'red'
                report_value = error_report['value']
                description = "%d > %d" % (report_value, cpu_load_error)
            elif warn_report['above'] == 'yes':
                color = 'yellow'
                report_value = warn_report['value']
                description = "%d > %d" % (report_value, cpu_load_warn)
            else:
                color = 'green'
                if error_report['above'] != 'unknown':
                    report_value = error_report['value']
                else:
                    report_value = warn_report['value']
                description = "%d" % report_value

            result = self._report('cpu', connection, agent, color,
                                  report_value, description, None,
                                  cpu_load_error, cpu_load_warn,
                                  cpu_period_error / 60, cpu_period_warn / 60)
            results.append(result)

        connection.close()

        if not len(results):
            return {'status': 'OK', 'info': 'No agents connected.'}
        return {'status': 'OK', 'info': results}