mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
feat(alerts): mail and webhook alerts, and /healthz for a monitor
A failed backup, a scheduled backup not taken, backups the daily check finds missing and a job that ends uncertain could only be seen on the pages. They are now queued as alerts in the transaction of the change they tell of (never stopping it) and sent by the worker's periodic pass to the Settings page's alert e-mail addresses (the server's SMTP settings) and alert webhook (a JSON POST), each tried again for ten passes on its own. A skip for a host in maintenance is no alert. Setting values take 255 characters. /healthz answers 200 while the database answers and the job worker runs, 503 otherwise, without a login.
This commit is contained in:
parent
2cf7dbe577
commit
dcd7e32df7
21 changed files with 695 additions and 74 deletions
|
|
@ -1,11 +1,14 @@
|
|||
from urllib.parse import urlencode
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_not_required
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.core.paginator import Paginator
|
||||
from django.http import Http404
|
||||
from django.db import Error as DatabaseError
|
||||
from django.http import Http404, JsonResponse
|
||||
from django.shortcuts import redirect, render
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.decorators.cache import never_cache
|
||||
from django.views.decorators.http import require_POST
|
||||
from vrtManager.util import OperationError
|
||||
|
||||
|
|
@ -84,3 +87,16 @@ def resolve(request, pk):
|
|||
except OperationError as err:
|
||||
messages.error(request, words(said(err)))
|
||||
return redirect("operations:job", pk=op.pk)
|
||||
|
||||
|
||||
@login_not_required
|
||||
@never_cache
|
||||
def healthz(request):
|
||||
"""For a monitor, without a login: 200 while the database answers and the job worker runs, 503 otherwise."""
|
||||
try:
|
||||
seen = last_seen()
|
||||
except DatabaseError:
|
||||
return JsonResponse({"database": False, "worker": False}, status=503)
|
||||
running = not worker_gone(seen)
|
||||
return JsonResponse({"database": True, "worker": running, "worker_seen": seen and seen.isoformat()},
|
||||
status=200 if running else 503)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue