Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/argus/dev/management/commands/check_ended_maintenance.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import logging
from datetime import timedelta
import sys

from django.conf import settings
from django.core.management.base import BaseCommand
from django.utils import timezone

from argus.plannedmaintenance.models import PlannedMaintenanceTask


LOG = logging.getLogger(__name__)


class Command(BaseCommand):
help = "Find all planned maintenance tasks that have ended recently and remove the incidents connection"

Expand All @@ -19,8 +25,16 @@ def add_arguments(self, parser):
)

def handle(self, *args, **options):
if not getattr(settings, "ENABLE_CRON_JOBS", False):
sys.exit()
end_time = timezone.now() - timedelta(minutes=options.get("minutes"))
ended_pm_tasks = PlannedMaintenanceTask.objects.ended_after_time(end_time)
if count := ended_pm_tasks.count():
LOG.info("Cleaning up after %s ended planned maintenance tasks", count)
else:
LOG.info("No planned maintenance tasks to clean up after")

for pm_task in ended_pm_tasks:
pm_task.incidents.clear()
else:
LOG.info("Finished cleaning up after ended planned maintenance tasks")
14 changes: 14 additions & 0 deletions src/argus/dev/management/commands/check_started_maintenance.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import logging
from datetime import timedelta
import sys

from django.conf import settings
from django.core.management.base import BaseCommand
from django.utils import timezone

from argus.plannedmaintenance.models import PlannedMaintenanceTask


LOG = logging.getLogger(__name__)


class Command(BaseCommand):
help = "Find all planned maintenance tasks that have started recently and connect them with incidents that are hit by them"

Expand All @@ -19,8 +25,16 @@ def add_arguments(self, parser):
)

def handle(self, *args, **options):
if not getattr(settings, "ENABLE_CRON_JOBS", False):
sys.exit()
start_time = timezone.now() - timedelta(minutes=options.get("minutes"))
started_pm_tasks = PlannedMaintenanceTask.objects.started_after_time(start_time)
if count := started_pm_tasks.count():
LOG.info("Linking up %i just started planned maintenance tasks to incidents", count)
else:
LOG.info("No planned maintenance tasks to link up")

for pm_task in started_pm_tasks:
pm_task.connect_covered_incidents()
else:
LOG.info("Finished linking up incidents to started planned maintenance tasks")
2 changes: 2 additions & 0 deletions src/argus/site/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,5 @@
update_settings(globals(), EXTRA_APPS)

BANNER_MESSAGE = get_str_env("ARGUS_BANNER_MESSAGE", default=None)

ENABLE_CRON_JOBS = get_bool_env("ARGUS_ENABLE_CRON_JOBS", default=False)
Loading