mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
docs + #1042
This commit is contained in:
@@ -50,23 +50,24 @@ class WorkflowManager:
|
||||
def process_event(self, event):
|
||||
"""Process the events. Check if events match a workflow trigger"""
|
||||
|
||||
guid = event["GUID"]
|
||||
mylog('verbose', [f"[WF] Processing event with GUID {guid}"])
|
||||
evGuid = event["GUID"]
|
||||
|
||||
mylog('verbose', [f"[WF] Processing event with GUID {evGuid}"])
|
||||
|
||||
# Check if the trigger conditions match
|
||||
for workflow in self.workflows:
|
||||
|
||||
# Ensure workflow is enabled before proceeding
|
||||
if workflow.get("enabled", "No").lower() == "yes":
|
||||
|
||||
mylog('debug', [f"[WF] Checking if '{event["GUID"]}' triggers the workflow '{workflow["name"]}'"])
|
||||
wfName = workflow["name"]
|
||||
mylog('debug', [f"[WF] Checking if '{evGuid}' triggers the workflow '{wfName}'"])
|
||||
|
||||
# construct trigger object which also evaluates if the current event triggers it
|
||||
trigger = Trigger(workflow["trigger"], event, self.db)
|
||||
|
||||
if trigger.triggered:
|
||||
|
||||
mylog('verbose', [f"[WF] Event with GUID '{event["GUID"]}' triggered the workflow '{workflow["name"]}'"])
|
||||
mylog('verbose', [f"[WF] Event with GUID '{evGuid}' triggered the workflow '{wfName}'"])
|
||||
|
||||
self.execute_workflow(workflow, trigger)
|
||||
|
||||
@@ -83,6 +84,8 @@ class WorkflowManager:
|
||||
def execute_workflow(self, workflow, trigger):
|
||||
"""Execute the actions in the given workflow if conditions are met."""
|
||||
|
||||
wfName = workflow["name"]
|
||||
|
||||
# Ensure conditions exist
|
||||
if not isinstance(workflow.get("conditions"), list):
|
||||
m = f"[WF] workflow['conditions'] must be a list"
|
||||
@@ -96,7 +99,7 @@ class WorkflowManager:
|
||||
|
||||
if evaluator.evaluate(trigger): # If any group evaluates to True
|
||||
|
||||
mylog('none', [f"[WF] Workflow {workflow["name"]} will be executed - conditions were evaluated as TRUE"])
|
||||
mylog('none', [f"[WF] Workflow {wfName} will be executed - conditions were evaluated as TRUE"])
|
||||
mylog('debug', [f"[WF] Workflow condition_group: {condition_group}"])
|
||||
|
||||
self.execute_actions(workflow["actions"], trigger)
|
||||
|
||||
Reference in New Issue
Block a user