Document rule system
This commit is contained in:
@@ -19,6 +19,7 @@ def process_rules(data):
|
||||
# up a NotificationRuleData object
|
||||
parsed_rule = rule.parse()
|
||||
matched = {}
|
||||
# Rule is invalid, this shouldn't happen
|
||||
if "index" not in parsed_rule:
|
||||
continue
|
||||
if "source" not in parsed_rule:
|
||||
@@ -30,8 +31,10 @@ def process_rules(data):
|
||||
# if not type(rule_source) == list:
|
||||
# rule_source = [rule_source]
|
||||
if index not in rule_index:
|
||||
# We don't care about this index, go to the next one
|
||||
continue
|
||||
if message["src"] not in rule_source:
|
||||
# We don't care about this source, go to the next one
|
||||
continue
|
||||
|
||||
matched["index"] = index
|
||||
@@ -43,8 +46,11 @@ def process_rules(data):
|
||||
# if not type(value) == list:
|
||||
# value = [value]
|
||||
if field == "src":
|
||||
# We already checked this
|
||||
continue
|
||||
if field == "tokens":
|
||||
# Check if tokens are in the rule
|
||||
# We only check if *at least one* token matches
|
||||
for token in value:
|
||||
if "tokens" in message:
|
||||
if token in message["tokens"]:
|
||||
@@ -55,8 +61,8 @@ def process_rules(data):
|
||||
# Continue to next field
|
||||
continue
|
||||
|
||||
# Allow partial matches for msg
|
||||
if field == "msg":
|
||||
# Allow partial matches for msg
|
||||
for msg in value:
|
||||
if "msg" in message:
|
||||
if msg.lower() in message["msg"].lower():
|
||||
@@ -67,8 +73,10 @@ def process_rules(data):
|
||||
# Continue to next field
|
||||
continue
|
||||
if field in message and message[field] in value:
|
||||
# Do exact matches for all other fields
|
||||
matched_field_number += 1
|
||||
matched[field] = message[field]
|
||||
# Subtract 2, 1 for source and 1 for index
|
||||
if matched_field_number == rule_field_length - 2:
|
||||
rule_notify(rule, index, message, matched)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from django.core.management.base import BaseCommand
|
||||
|
||||
from core.db.storage import db
|
||||
from core.lib.parsing import QueryError
|
||||
from core.lib.rules import NotificationRuleData
|
||||
from core.lib.rules import NotificationRuleData, RuleParseError
|
||||
from core.models import NotificationRule
|
||||
from core.util import logs
|
||||
|
||||
@@ -31,6 +31,8 @@ async def job(interval_seconds):
|
||||
# results = await db.schedule_query_results(rule.user, rule)
|
||||
except QueryError as e:
|
||||
log.error(f"Error running rule {rule}: {e}")
|
||||
except RuleParseError as e:
|
||||
log.error(f"Error parsing rule {rule}: {e}")
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
Reference in New Issue
Block a user