Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-20 10:15:20

0001 # Seed the pings alarm entry (docs/PINGS.md): the one alarm configuration
0002 # behind every ping, carried by the engine's `pings` detect module.
0003 # Recipients are the ping subscribers, edited on the alarm dashboard.
0004 import time
0005 
0006 from django.db import migrations
0007 
0008 
0009 def seed(apps, schema_editor):
0010     EntryContext = apps.get_model('monitor_app', 'EntryContext')
0011     Entry = apps.get_model('monitor_app', 'Entry')
0012     ctx, _ = EntryContext.objects.get_or_create(
0013         name='swf-alarms', defaults={'title': 'swf-alarms'})
0014     if Entry.objects.filter(context=ctx, kind='alarm',
0015                             data__entry_id='alarm_pings').exists():
0016         return
0017     now = time.time()
0018     Entry.objects.create(
0019         title='Pings', kind='alarm', context=ctx, status='active',
0020         content=('A ping is a dated obligation: an action to take on a '
0021                  'subject by a due date. This alarm raises each open ping '
0022                  'once its due date is within its lead time, repeats it '
0023                  'weekly, and raises it as an alarm once the due date has '
0024                  'passed. Mark the ping fulfilled on the alarm dashboard '
0025                  'when the obligation is met; its event clears on the '
0026                  'next tick.'),
0027         data={
0028             'entry_id': 'alarm_pings',
0029             # Email off: an alarm emails only once an operator turns it on
0030             # (docs/alarms.md). Detection runs regardless.
0031             'enabled': False,
0032             'severity': 'ping',
0033             'recipients': '@prodops',
0034             'renotification_window_hours': 168,
0035             'params': {'default_lead_days': 7},
0036         },
0037         timestamp_created=now, timestamp_modified=now)
0038 
0039 
0040 def unseed(apps, schema_editor):
0041     Entry = apps.get_model('monitor_app', 'Entry')
0042     Entry.objects.filter(context_id='swf-alarms', kind='alarm',
0043                          data__entry_id='alarm_pings').delete()
0044 
0045 
0046 class Migration(migrations.Migration):
0047 
0048     dependencies = [
0049         ('monitor_app', '0011_seed_bind_mount_rule'),
0050     ]
0051 
0052     operations = [
0053         migrations.RunPython(seed, unseed),
0054     ]