old_console/correlation/services/rules.py
2024-11-02 14:12:45 +03:00

19 lines
604 B
Python

from django.forms import model_to_dict
def to_correlator_data(rule):
return {
"name": rule.name,
"depth": str(int(rule.depth.total_seconds())) + "s",
"id": str(rule.pk),
"predicat": rule.rule_json,
"actions": rule.actions_json,
"multi": rule.multi
}
def check_if_only_status_changed(rule):
initial_data = getattr(rule, '_initial', {})
new_data = model_to_dict(rule, fields=[field.name for field in rule._meta.fields])
diffs = [k for k, v in initial_data.items() if v != new_data[k]]
return len(diffs) == 1 and 'status' in diffs