Пример #1
0
def notify(flip_id, stdout):
    flip = Flip.objects.get(id=flip_id)

    check = flip.owner
    # Set the historic status here but *don't save it*.
    # It would be nicer to pass the status explicitly, as a separate parameter.
    check.status = flip.new_status
    # And just to make sure it doesn't get saved by a future coding accident:
    setattr(check, "save", None)

    stdout.write(SENDING_TMPL % (flip.new_status, check.code))

    # Set dates for followup nags
    if flip.new_status == "down":
        check.project.set_next_nag_date()

    # Send notifications
    send_start = timezone.now()
    errors = flip.send_alerts()
    for ch, error in errors:
        stdout.write("ERROR: %s %s %s\n" % (ch.kind, ch.value, error))

    # If sending took more than 5s, log it
    send_time = timezone.now() - send_start
    if send_time.total_seconds() > 5:
        stdout.write(SEND_TIME_TMPL % (send_time.total_seconds(), check.code))

    statsd.timing("hc.sendalerts.dwellTime", send_start - flip.created)
    statsd.timing("hc.sendalerts.sendTime", send_time)
Пример #2
0
def notify(flip_id, stdout):
    flip = Flip.objects.get(id=flip_id)

    check = flip.owner
    # Set the historic status here but *don't save it*.
    # It would be nicer to pass the status explicitly, as a separate parameter.
    check.status = flip.new_status
    # And just to make sure it doesn't get saved by a future coding accident:
    setattr(check, "save", None)

    stdout.write(SENDING_TMPL % (flip.new_status, check.code))

    # Set or clear dates for followup nags
    check.project.update_next_nag_dates()

    # Send notifications
    send_start = timezone.now()

    for ch, error, secs in flip.send_alerts():
        label = "OK"
        if error:
            label = "ERROR"
        elif secs > 5:
            label = "SLOW"

        s = " * %-5s %4.1fs %-10s %s %s\n" % (label, secs, ch.kind, ch.code,
                                              error)
        stdout.write(s)

    send_time = timezone.now() - send_start
    stdout.write(SEND_TIME_TMPL % (send_time.total_seconds(), check.code))

    statsd.timing("hc.sendalerts.dwellTime", send_start - flip.created)
    statsd.timing("hc.sendalerts.sendTime", send_time)