Allow disabling ingesting
This commit is contained in:
parent
0e12b0d185
commit
27fea06198
|
@ -88,6 +88,7 @@ class NotificationRuleForm(RestrictedFormMixin, ModelForm):
|
|||
"url",
|
||||
"service",
|
||||
"policy",
|
||||
"ingest",
|
||||
"enabled",
|
||||
)
|
||||
help_texts = {
|
||||
|
@ -102,6 +103,7 @@ class NotificationRuleForm(RestrictedFormMixin, ModelForm):
|
|||
"window": "Time window to search: 1d, 1h, 1m, 1s, etc.",
|
||||
"amount": "Amount of matches to be returned for scheduled queries. Cannot be used with on-demand queries.",
|
||||
"policy": "When to trigger this policy.",
|
||||
"ingest": "Whether to ingest matches",
|
||||
}
|
||||
|
||||
def clean(self):
|
||||
|
|
|
@ -357,7 +357,8 @@ class NotificationRuleData(object):
|
|||
:param matches: the matches to store
|
||||
"""
|
||||
# new_matches = self.reform_matches(index, matches, meta, mode)
|
||||
await self.db.async_store_matches(matches)
|
||||
if self.object.ingest:
|
||||
await self.db.async_store_matches(matches)
|
||||
|
||||
def ingest_matches_sync(self, index, matches, meta, mode):
|
||||
"""
|
||||
|
@ -366,7 +367,8 @@ class NotificationRuleData(object):
|
|||
:param matches: the matches to store
|
||||
"""
|
||||
# new_matches = self.reform_matches(index, matches, meta, mode)
|
||||
self.db.store_matches(matches)
|
||||
if self.object.ingest:
|
||||
self.db.store_matches(matches)
|
||||
|
||||
async def rule_matched(self, index, message, meta, mode):
|
||||
"""
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
# Generated by Django 4.1.6 on 2023-02-13 21:03
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0027_alter_notificationrule_policy_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='notificationrule',
|
||||
old_name='send_empty',
|
||||
new_name='ingest',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='notificationrule',
|
||||
name='interval',
|
||||
field=models.IntegerField(choices=[(0, 'On demand'), (5, 'Every 5 seconds'), (60, 'Every minute'), (900, 'Every 15 minutes'), (1800, 'Every 30 minutes'), (3600, 'Every hour'), (14400, 'Every 4 hours'), (86400, 'Every day')], default=60),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='notificationrule',
|
||||
name='service',
|
||||
field=models.CharField(choices=[('ntfy', 'NTFY'), ('webhook', 'Custom webhook'), ('none', 'Disabled')], default='webhook', max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='notificationrule',
|
||||
name='window',
|
||||
field=models.CharField(blank=True, default='30d', max_length=255, null=True),
|
||||
),
|
||||
]
|
|
@ -194,14 +194,16 @@ class NotificationRule(models.Model):
|
|||
priority = models.IntegerField(choices=PRIORITY_CHOICES, default=1)
|
||||
topic = models.CharField(max_length=2048, null=True, blank=True)
|
||||
url = models.CharField(max_length=1024, null=True, blank=True)
|
||||
interval = models.IntegerField(choices=INTERVAL_CHOICES, default=0)
|
||||
window = models.CharField(max_length=255, null=True, blank=True)
|
||||
interval = models.IntegerField(choices=INTERVAL_CHOICES, default=60)
|
||||
window = models.CharField(max_length=255, default="30d", null=True, blank=True)
|
||||
amount = models.PositiveIntegerField(default=1, null=True, blank=True)
|
||||
enabled = models.BooleanField(default=True)
|
||||
data = models.TextField()
|
||||
match = models.JSONField(null=True, blank=True)
|
||||
service = models.CharField(choices=SERVICE_CHOICES, max_length=255, default="ntfy")
|
||||
send_empty = models.BooleanField(default=False)
|
||||
service = models.CharField(
|
||||
choices=SERVICE_CHOICES, max_length=255, default="webhook"
|
||||
)
|
||||
ingest = models.BooleanField(default=False)
|
||||
policy = models.CharField(choices=POLICY_CHOICES, max_length=255, default="default")
|
||||
|
||||
def __str__(self):
|
||||
|
@ -238,8 +240,6 @@ class NotificationRule(models.Model):
|
|||
user_settings["url"] = self.url
|
||||
if self.service is not None:
|
||||
user_settings["service"] = self.service
|
||||
if self.send_empty is not None:
|
||||
user_settings["send_empty"] = self.send_empty
|
||||
|
||||
if check:
|
||||
if user_settings["service"] == "ntfy" and user_settings["topic"] is None:
|
||||
|
|
Loading…
Reference in New Issue