Add interval and window fields to NotificationRule

This commit is contained in:
Mark Veidemanis 2023-01-14 14:36:46 +00:00
parent 158fffed99
commit fbe5607899
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
3 changed files with 45 additions and 3 deletions

View File

@ -8,10 +8,9 @@ from core.lib.rules import NotificationRuleData
from .models import NotificationRule, NotificationSettings, User from .models import NotificationRule, NotificationSettings, User
# from django.forms import ModelForm # flake8: noqa: E501
# Create your forms here.
class RestrictedFormMixin: class RestrictedFormMixin:
""" """
This mixin is used to restrict the queryset of a form to the current user. This mixin is used to restrict the queryset of a form to the current user.
@ -89,16 +88,20 @@ class NotificationRuleForm(RestrictedFormMixin, ModelForm):
fields = ( fields = (
"name", "name",
"data", "data",
"interval",
"window",
"priority", "priority",
"topic", "topic",
"enabled", "enabled",
) )
help_texts = { help_texts = {
"name": "The name of the rule.", "name": "The name of the rule.",
"priority": "The priority of the rule.", "priority": "The notification priority of the rule.",
"topic": "The topic to send notifications to. Leave blank for default.", "topic": "The topic to send notifications to. Leave blank for default.",
"enabled": "Whether the rule is enabled.", "enabled": "Whether the rule is enabled.",
"data": "The notification rule definition.", "data": "The notification rule definition.",
"interval": "How often to run the search. On demand only evaluates messages as they are received.",
"window": "Time window to search: 1d, 1h, 1m, 1s, etc.",
} }
def clean(self): def clean(self):

View File

@ -0,0 +1,23 @@
# Generated by Django 4.1.3 on 2023-01-14 14:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0015_notificationrule_topic'),
]
operations = [
migrations.AddField(
model_name='notificationrule',
name='interval',
field=models.CharField(choices=[('ondemand', 'On demand'), ('minute', 'Every minute'), ('15m', 'Every 15 minutes'), ('30m', 'Every 30 minutes'), ('hour', 'Every hour'), ('4h', 'Every 4 hours'), ('day', 'Every day'), ('week', 'Every week'), ('month', 'Every month')], default='ondemand', max_length=255),
),
migrations.AddField(
model_name='notificationrule',
name='window',
field=models.CharField(blank=True, max_length=255, null=True),
),
]

View File

@ -23,6 +23,18 @@ PRIORITY_CHOICES = (
(5, "max"), (5, "max"),
) )
INTERVAL_CHOICES = (
("ondemand", "On demand"),
("minute", "Every minute"),
("15m", "Every 15 minutes"),
("30m", "Every 30 minutes"),
("hour", "Every hour"),
("4h", "Every 4 hours"),
("day", "Every day"),
("week", "Every week"),
("month", "Every month"),
)
class Plan(models.Model): class Plan(models.Model):
name = models.CharField(max_length=255, unique=True) name = models.CharField(max_length=255, unique=True)
@ -147,6 +159,10 @@ class NotificationRule(models.Model):
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
priority = models.IntegerField(choices=PRIORITY_CHOICES, default=1) priority = models.IntegerField(choices=PRIORITY_CHOICES, default=1)
topic = models.CharField(max_length=255, null=True, blank=True) topic = models.CharField(max_length=255, null=True, blank=True)
interval = models.CharField(
choices=INTERVAL_CHOICES, max_length=255, default="ondemand"
)
window = models.CharField(max_length=255, null=True, blank=True)
enabled = models.BooleanField(default=True) enabled = models.BooleanField(default=True)
data = models.TextField() data = models.TextField()