Esempio n. 1
0
    def send_report(self, nag=False):
        checks = self.checks_from_all_teams()

        # Is there at least one check that has received a ping?
        if not checks.filter(last_ping__isnull=False).exists():
            return False

        # Is there at least one check that is down?
        num_down = checks.filter(status="down").count()
        if nag and num_down == 0:
            return False

        token = signing.Signer().sign(uuid.uuid4())
        path = reverse("hc-unsubscribe-reports", args=[self.user.username])
        unsub_link = "%s%s?token=%s" % (settings.SITE_ROOT, path, token)

        # Sort checks by owner. Need this because will group by owner in
        # template.
        checks = checks.order_by("user_id")

        ctx = {
            "checks": checks,
            "sort": self.sort,
            "now": timezone.now(),
            "unsub_link": unsub_link,
            "notifications_url": self.notifications_url,
            "nag": nag,
            "nag_period": self.nag_period.total_seconds(),
            "num_down": num_down
        }

        emails.report(self.user.email, ctx)
        return True
Esempio n. 2
0
    def send_report(self):
        # reset next report date first:
        now = timezone.now()
        # Set the period to a string according to the value of report time
        if self.report_time == 1:
            period = 'Daily'
        elif self.report_time == 7:
            period = 'Weekly'
        else:
            period = 'Monthly'

        # Set the next report time to the user defined time
        self.next_report_date = now + timedelta(seconds=self.report_time)
        self.save()

        token = signing.Signer().sign(uuid.uuid4())
        path = reverse("hc-unsubscribe-reports", args=[self.user.username])
        unsub_link = "%s%s?token=%s" % (settings.SITE_ROOT, path, token)

        # Pass the period to the email body
        ctx = {
            "checks": self.user.check_set.order_by("created"),
            "now": now,
            "unsub_link": unsub_link,
            "next_report_date": period
        }

        emails.report(self.user.email, ctx)
Esempio n. 3
0
    def send_report(self, nag=False):
        checks = self.checks_from_all_teams()

        # Is there at least one check that has received a ping?
        if not checks.filter(last_ping__isnull=False).exists():
            return False

        # Is there at least one check that is down?
        num_down = checks.filter(status="down").count()
        if nag and num_down == 0:
            return False

        # Sort checks by owner. Need this because will group by owner in
        # template.
        checks = checks.order_by("user_id")

        ctx = {
            "checks": checks,
            "sort": self.sort,
            "now": timezone.now(),
            "unsub_link": self.reports_unsub_url(),
            "notifications_url": self.notifications_url(),
            "nag": nag,
            "nag_period": self.nag_period.total_seconds(),
            "num_down": num_down
        }

        emails.report(self.user.email, ctx)
        return True
Esempio n. 4
0
    def send_report(self, nag=False):
        checks = self.checks_from_all_teams()

        # Is there at least one check that has received a ping?
        if not checks.filter(last_ping__isnull=False).exists():
            return False

        # Is there at least one check that is down?
        num_down = checks.filter(status="down").count()
        if nag and num_down == 0:
            return False

        # Sort checks by owner. Need this because will group by owner in
        # template.
        checks = checks.order_by("user_id")

        ctx = {
            "checks": checks,
            "sort": self.sort,
            "now": timezone.now(),
            "unsub_link": self.reports_unsub_url(),
            "notifications_url": self.notifications_url(),
            "nag": nag,
            "nag_period": self.nag_period.total_seconds(),
            "num_down": num_down
        }

        emails.report(self.user.email, ctx)
        return True
Esempio n. 5
0
    def send_report(self):
        # reset next report date first:
        days = 0
        if self.reports_allowed == 'Daily':
            days = 1
        elif self.reports_allowed == 'Weekly':
            days = 7
        elif self.reports_allowed == 'Monthly':
            days = 30

        now = timezone.now()
        self.next_report_date = now + timedelta(days=days)
        self.save()

        token = signing.Signer().sign(uuid.uuid4())
        path = reverse("hc-unsubscribe-reports", args=[self.user.username])
        unsub_link = "%s%s?token=%s" % (settings.SITE_ROOT, path, token)

        ctx = {
            "checks": self.user.check_set.order_by("created"),
            "now": now,
            "unsub_link": unsub_link,
            "duration": self.reports_allowed
        }

        emails.report(self.user.email, ctx)
Esempio n. 6
0
    def send_report(self):
        # reset next report date first:
        now = timezone.now()
        self.next_report_date = now + timedelta(days=30)
        self.save()

        token = signing.Signer().sign(uuid.uuid4())
        path = reverse("hc-unsubscribe-reports", args=[self.user.username])
        unsub_link = "%s%s?token=%s" % (settings.SITE_ROOT, path, token)

        ctx = {"checks": self.user.check_set.order_by("created"), "now": now, "unsub_link": unsub_link}

        emails.report(self.user.email, ctx)
Esempio n. 7
0
    def send_report(self, nag=False):
        checks = self.checks_from_all_projects()

        # Has there been a ping in last 6 months?
        result = checks.aggregate(models.Max("last_ping"))
        last_ping = result["last_ping__max"]

        six_months_ago = now() - timedelta(days=180)
        if last_ping is None or last_ping < six_months_ago:
            return False

        # Is there at least one check that is down?
        num_down = checks.filter(status="down").count()
        if nag and num_down == 0:
            return False

        # Sort checks by project. Need this because will group by project in
        # template.
        checks = checks.select_related("project")
        checks = checks.order_by("project_id")
        # list() executes the query, to avoid DB access while
        # rendering the template
        checks = list(checks)

        unsub_url = self.reports_unsub_url()

        headers = {
            "List-Unsubscribe": "<%s>" % unsub_url,
            "X-Bounce-Url": unsub_url,
            "List-Unsubscribe-Post": "List-Unsubscribe=One-Click",
        }

        boundaries = month_boundaries(months=3)
        # throw away the current month, keep two previous months
        boundaries.pop()

        ctx = {
            "checks": checks,
            "sort": self.sort,
            "now": now(),
            "unsub_link": unsub_url,
            "notifications_url": self.notifications_url(),
            "nag": nag,
            "nag_period": self.nag_period.total_seconds(),
            "num_down": num_down,
            "month_boundaries": boundaries,
            "monthly_or_weekly": self.reports,
        }

        emails.report(self.user.email, ctx, headers)
        return True
Esempio n. 8
0
    def send_report(self, nag=False):
        checks = self.checks_from_all_teams()

        # Has there been a ping in last 6 months?
        result = checks.aggregate(models.Max("last_ping"))
        last_ping = result["last_ping__max"]

        six_months_ago = timezone.now() - timedelta(days=180)
        if last_ping is None or last_ping < six_months_ago:
            return False

        # Is there at least one check that is down?
        num_down = checks.filter(status="down").count()
        if nag and num_down == 0:
            return False

        # Sort checks by owner. Need this because will group by owner in
        # template.
        checks = checks.select_related("user", "user__profile")
        checks = checks.order_by("user_id")
        # list() executes the query, to avoid DB access while
        # rendering the template
        checks = list(checks)

        unsub_url = self.reports_unsub_url()

        headers = {
            "List-Unsubscribe": unsub_url,
            "X-Bounce-Url": unsub_url
        }

        ctx = {
            "checks": checks,
            "sort": self.sort,
            "now": timezone.now(),
            "unsub_link": unsub_url,
            "notifications_url": self.notifications_url(),
            "nag": nag,
            "nag_period": self.nag_period.total_seconds(),
            "num_down": num_down
        }

        emails.report(self.user.email, ctx, headers)
        return True
Esempio n. 9
0
    def send_report(self):
        # reset next report date first based on frequency selected:
        # Need to move reports_freq to a single source
        reports_freq = {'monthly': 30, 'weekly': 7, 'daily': 1, 'never': 0}
        now = timezone.now()
        if self.reports_allowed in reports_freq:
            self.next_report_date = now + 
            timedelta(days=reports_freq[self.reports_allowed])
            self.save()

            token = signing.Signer().sign(uuid.uuid4())
            path = reverse("hc-unsubscribe-reports", args=[self.user.username])
            unsub_link = "%s%s?token=%s" % (settings.SITE_ROOT, path, token)

            ctx = {
                "checks": self.user.check_set.order_by("created"),
                "now": now,
                "unsub_link": unsub_link
            }

            emails.report(self.user.email, ctx)