|
@ -18,28 +18,38 @@ class Command(BaseCommand): |
|
|
|
|
|
|
|
|
def handle(self, *args, **options): |
|
|
def handle(self, *args, **options): |
|
|
|
|
|
|
|
|
|
|
|
ticks = 0 |
|
|
while True: |
|
|
while True: |
|
|
# Gone down? |
|
|
# Gone down? |
|
|
query = Check.objects |
|
|
query = Check.objects |
|
|
query = query.filter(alert_after__lt=timezone.now()) |
|
|
query = query.filter(alert_after__lt=timezone.now()) |
|
|
|
|
|
query = query.filter(user__isnull=False) |
|
|
query = query.filter(status="up") |
|
|
query = query.filter(status="up") |
|
|
for check in query: |
|
|
for check in query: |
|
|
check.status = "down" |
|
|
check.status = "down" |
|
|
check.save() |
|
|
|
|
|
|
|
|
|
|
|
_log("\nSending email about going down for %s\n" % check.code) |
|
|
_log("\nSending email about going down for %s\n" % check.code) |
|
|
send_status_notification(check) |
|
|
send_status_notification(check) |
|
|
|
|
|
ticks = 0 |
|
|
|
|
|
|
|
|
|
|
|
# Save status after the notification is sent |
|
|
|
|
|
check.save() |
|
|
|
|
|
|
|
|
# Gone up? |
|
|
# Gone up? |
|
|
query = Check.objects |
|
|
query = Check.objects |
|
|
query = query.filter(alert_after__gt=timezone.now()) |
|
|
query = query.filter(alert_after__gt=timezone.now()) |
|
|
|
|
|
query = query.filter(user__isnull=False) |
|
|
query = query.filter(status="down") |
|
|
query = query.filter(status="down") |
|
|
for check in query: |
|
|
for check in query: |
|
|
check.status = "up" |
|
|
check.status = "up" |
|
|
check.save() |
|
|
|
|
|
|
|
|
|
|
|
_log("\nSending email about going up for %s\n" % check.code) |
|
|
_log("\nSending email about going up for %s\n" % check.code) |
|
|
send_status_notification(check) |
|
|
send_status_notification(check) |
|
|
|
|
|
ticks = 0 |
|
|
|
|
|
|
|
|
|
|
|
# Save status after the notification is sent |
|
|
|
|
|
check.save() |
|
|
|
|
|
|
|
|
time.sleep(1) |
|
|
time.sleep(1) |
|
|
_log(".") |
|
|
|
|
|
|
|
|
ticks = (ticks + 1) % 80 |
|
|
|
|
|
_log("." + ("\n" if ticks == 0 else "")) |