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
|
|
@ -8,7 +8,7 @@ import logging
|
|||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import close_old_connections
|
||||
from django.db import close_old_connections, transaction
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_noop as _
|
||||
|
|
@ -16,7 +16,7 @@ from libvirt import libvirtError
|
|||
|
||||
from computes.models import Compute
|
||||
from computes.utils import refresh_instance_database
|
||||
from operations import claims, jobs
|
||||
from operations import alerts, claims, jobs
|
||||
from operations.models import Operation
|
||||
from operations.utils import safe_text, said, say
|
||||
from vrtManager.util import ConnectionFailed
|
||||
|
|
@ -57,7 +57,8 @@ def run_schedules(now=None):
|
|||
continue
|
||||
in_maintenance = Compute.objects.filter(pk=vm.compute_id, maintenance_since__isnull=False).exists()
|
||||
if not open_:
|
||||
_record(policy, vm, day, BackupRun.SKIPPED, say(IN_MAINTENANCE if in_maintenance else NOT_STARTED))
|
||||
_record(policy, vm, day, BackupRun.SKIPPED, say(IN_MAINTENANCE if in_maintenance else NOT_STARTED),
|
||||
quiet=in_maintenance) # the operator put the host in maintenance
|
||||
elif not in_maintenance: # deferred while the window lasts
|
||||
due.setdefault(vm.compute_id, []).append((policy.pk, vm.pk, day, start))
|
||||
for compute_id in due.keys() | read.keys():
|
||||
|
|
@ -82,9 +83,15 @@ def occurrences(policy, now):
|
|||
yield day, start
|
||||
|
||||
|
||||
def _record(policy, vm, day, state, note=(), operation=None):
|
||||
BackupRun.objects.get_or_create(policy=policy, instance=vm, day=day,
|
||||
defaults={"state": state, "note": list(note), "operation": operation})
|
||||
def _record(policy, vm, day, state, note=(), operation=None, quiet=False):
|
||||
"""The run of the day; one not submitted is an alert unless quiet."""
|
||||
with transaction.atomic(): # the run and its alert together: a worker stopped between them loses neither
|
||||
_run, made = BackupRun.objects.get_or_create(policy=policy, instance=vm, day=day,
|
||||
defaults={"state": state, "note": list(note), "operation": operation})
|
||||
if made and state != BackupRun.SUBMITTED and not quiet:
|
||||
alerts.alert(say(_("Scheduled backup not taken: %(vm)s"), vm=vm.name),
|
||||
say(_("The schedule %(schedule)s did not back up %(vm)s on %(day)s: %(reason)s"),
|
||||
schedule=policy.name, vm=vm.name, day=day.isoformat(), reason=list(note)))
|
||||
|
||||
|
||||
def _active_superuser(user):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue