def get_occurrence_expected_expire_date(self, plan, occurrence): # get n occurrences to keep as of this occurrence and return the # last one ;) dt = date_plus_seconds(occurrence, 1) ocs = plan.schedule.next_n_occurrences(self.retain_count, dt=occurrence) return ocs[-1]
def daily_audit_report(self, audit_date): logger.info("PlanScheduleAuditor: Generating %s audit report for '%s'" % (TYPE_PLAN_AUDIT, datetime_to_string(audit_date))) audit_end_date = date_plus_seconds(audit_date, 3600 * 24) all_plans_report = PlanScheduleAuditReport() all_plans_report.audit_date = audit_date all_plans_report.audit_type = TYPE_PLAN_AUDIT total_plans = 0 failed_plan_reports = [] all_warned_audits = [] total_warnings = 0 for plan in get_mbs().plan_collection.find_iter(no_cursor_timeout=True): logger.info("PlanScheduleAuditor: Processing plan %s" % plan.id) plan_report = self._create_plan_audit_report(plan, audit_date) if plan_report.has_failures(): failed_plan_reports.append(plan_report) if plan_report.has_warnings(): # only append to warned audits if report doesn't have failures if not plan_report.has_failures(): all_warned_audits.extend(plan_report.warned_audits) total_warnings += 1 total_plans += 1 total_failures = len(failed_plan_reports) if failed_plan_reports: all_plans_report.failed_audits = failed_plan_reports if all_warned_audits: all_plans_report.warned_audits = all_warned_audits all_plans_report.total_audits = total_plans all_plans_report.total_failures = total_failures all_plans_report.total_success = total_plans - total_failures all_plans_report.total_warnings = total_warnings logger.info("PlanScheduleAuditor: Generated report:\n%s " % all_plans_report) # alert if failed audits are >= max allowed percent of total if float(total_failures) / total_plans > self.max_allowed_failures_percentage: subject = "%s Auditor Failure: Too many failures!!!" % self.name msg = "There are %s failures out of %s which is > %s%%" % (total_failures, total_plans, self.max_allowed_failures_percentage * 100) logger.error(subject) logger.error(msg) get_mbs().notifications.send_event_notification(subject, msg, priority=NotificationPriority.CRITICAL) else: logger.info("NO ALERT for %s Auditor: There are %s failures out of %s which is < %s%%" % (self.name,total_failures, total_plans, self.max_allowed_failures_percentage * 100)) return all_plans_report
def daily_audit_report(self, audit_date): logger.info("PlanAuditor: Generating %s audit report for '%s'" % (TYPE_PLAN_AUDIT, datetime_to_string(audit_date))) audit_end_date = date_plus_seconds(audit_date, 3600 * 24) all_plans_report = AuditReport() all_plans_report.audit_date = audit_date all_plans_report.audit_type = TYPE_PLAN_AUDIT total_plans = 0 failed_plan_reports = [] all_warned_audits = [] total_warnings = 0 for plan in get_mbs().plan_collection.find(): # skip recently added plans whose created date is after audit date # and their next occurrence is not in auditing range if (plan.created_date > audit_date and plan.next_occurrence and plan.next_occurrence > audit_end_date) : logger.info("PlanAuditor: Skipping auditing plan '%s' since" " its created date '%s' is later than audit date " "'%s'" % (plan.id, datetime_to_string(plan.created_date), datetime_to_string(audit_date))) continue plan_report = self._create_plan_audit_report(plan, audit_date) if plan_report.has_failures(): failed_plan_reports.append(plan_report) if plan_report.has_warnings(): # only append to warned audits if report doesn't have failures if not plan_report.has_failures(): all_warned_audits.extend(plan_report.warned_audits) total_warnings += 1 total_plans += 1 total_failures = len(failed_plan_reports) if failed_plan_reports: all_plans_report.failed_audits = failed_plan_reports if all_warned_audits: all_plans_report.warned_audits = all_warned_audits all_plans_report.total_audits = total_plans all_plans_report.total_failures = total_failures all_plans_report.total_success = total_plans - total_failures all_plans_report.total_warnings = total_warnings logger.info("PlanAuditor: Generated report:\n%s " % all_plans_report) return all_plans_report
def get_download_url(container, file_path): temp_key = random_temp_shared_key() storage_url = "https://%s/%s" % (container.conn.connection_args[0], container.conn.connection_args[2]) set_account_temp_url_key(storage_url, container.conn.token, temp_key) expire_date = date_plus_seconds(date_now(), 300) return get_temp_url(container.name, "GET", storage_url, temp_key, file_path, expire_date)
def next_natural_occurrence(self, dt=None): last_natural_occurrence = self.last_natural_occurrence(dt) frequency = self.frequency_in_seconds return date_plus_seconds(last_natural_occurrence, frequency)
def get_occurrence_expected_expire_date(self, plan, occurrence): return date_plus_seconds(occurrence, self.max_time)
def daily_audit_report(self, audit_date): logger.info( "PlanScheduleAuditor: Generating %s audit report for '%s'" % (TYPE_PLAN_AUDIT, datetime_to_string(audit_date))) audit_end_date = date_plus_seconds(audit_date, 3600 * 24) all_plans_report = PlanScheduleAuditReport() all_plans_report.audit_date = audit_date all_plans_report.audit_type = TYPE_PLAN_AUDIT total_plans = 0 failed_plan_reports = [] all_warned_audits = [] total_warnings = 0 for plan in get_mbs().plan_collection.find_iter( no_cursor_timeout=True): plan_report = self._create_plan_audit_report(plan, audit_date) if plan_report.has_failures(): failed_plan_reports.append(plan_report) if plan_report.has_warnings(): # only append to warned audits if report doesn't have failures if not plan_report.has_failures(): all_warned_audits.extend(plan_report.warned_audits) total_warnings += 1 total_plans += 1 total_failures = len(failed_plan_reports) if failed_plan_reports: all_plans_report.failed_audits = failed_plan_reports if all_warned_audits: all_plans_report.warned_audits = all_warned_audits all_plans_report.total_audits = total_plans all_plans_report.total_failures = total_failures all_plans_report.total_success = total_plans - total_failures all_plans_report.total_warnings = total_warnings logger.info("PlanScheduleAuditor: Generated report:\n%s " % all_plans_report) # alert if failed audits are >= max allowed percent of total if float(total_failures ) / total_plans > self.max_allowed_failures_percentage: subject = "%s Auditor Failure: Too many failures!!!" % self.name msg = "There are %s failures out of %s which is > %s%%" % ( total_failures, total_plans, self.max_allowed_failures_percentage * 100) logger.error(subject) logger.error(msg) get_mbs().notifications.send_event_notification( subject, msg, priority=NotificationPriority.CRITICAL) else: logger.info( "NO ALERT for %s Auditor: There are %s failures out of %s which is < %s%%" % (self.name, total_failures, total_plans, self.max_allowed_failures_percentage * 100)) return all_plans_report