mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
wf work
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import sys
|
||||
import sqlite3
|
||||
|
||||
# Register NetAlertX directories
|
||||
INSTALL_PATH="/app"
|
||||
@@ -7,6 +8,8 @@ sys.path.extend([f"{INSTALL_PATH}/server"])
|
||||
import conf
|
||||
from logger import mylog, Logger
|
||||
from helper import get_setting_value, timeNowTZ
|
||||
from models.device_instance import DeviceInstance
|
||||
from models.plugin_object_instance import PluginObjectInstance
|
||||
|
||||
# Make sure log level is initialized correctly
|
||||
Logger(get_setting_value('LOG_LEVEL'))
|
||||
@@ -27,22 +30,76 @@ class Action:
|
||||
class UpdateFieldAction(Action):
|
||||
"""Action to update a specific field of an object."""
|
||||
|
||||
def __init__(self, field, value, trigger):
|
||||
def __init__(self, db, field, value, trigger):
|
||||
super().__init__(trigger) # Call the base class constructor
|
||||
self.field = field
|
||||
self.value = value
|
||||
self.db = db
|
||||
|
||||
def execute(self):
|
||||
mylog('verbose', [f"Updating field '{self.field}' to '{self.value}' for event object {self.trigger.object_type}"])
|
||||
mylog('verbose', f"[WF] Updating field '{self.field}' to '{self.value}' for event object {self.trigger.object_type}")
|
||||
|
||||
obj = self.trigger.object
|
||||
|
||||
# convert to dict for easeir handling
|
||||
if isinstance(obj, sqlite3.Row):
|
||||
obj = dict(obj) # Convert Row object to a standard dictionary
|
||||
|
||||
processed = False
|
||||
|
||||
# currently unused
|
||||
if isinstance(obj, dict) and "ObjectGUID" in obj:
|
||||
plugin_instance = PluginObjectInstance(self.trigger.db)
|
||||
mylog('debug', f"[WF] Updating Object '{obj}' ")
|
||||
plugin_instance = PluginObjectInstance(self.db)
|
||||
plugin_instance.updateField(obj["ObjectGUID"], self.field, self.value)
|
||||
processed = True
|
||||
|
||||
elif isinstance(obj, dict) and "devGUID" in obj:
|
||||
device_instance = DeviceInstance(self.trigger.db)
|
||||
mylog('debug', f"[WF] Updating Device '{obj}' ")
|
||||
device_instance = DeviceInstance(self.db)
|
||||
device_instance.updateField(obj["devGUID"], self.field, self.value)
|
||||
processed = True
|
||||
|
||||
if not processed:
|
||||
mylog('none', f"[WF] Could not process action for object: {obj}")
|
||||
|
||||
return obj
|
||||
|
||||
|
||||
class DeleteObjectAction(Action):
|
||||
"""Action to delete an object."""
|
||||
|
||||
def __init__(self, db, trigger):
|
||||
super().__init__(trigger) # Call the base class constructor
|
||||
self.db = db
|
||||
|
||||
def execute(self):
|
||||
mylog('verbose', f"[WF] Deleting event object {self.trigger.object_type}")
|
||||
|
||||
obj = self.trigger.object
|
||||
|
||||
# convert to dict for easeir handling
|
||||
if isinstance(obj, sqlite3.Row):
|
||||
obj = dict(obj) # Convert Row object to a standard dictionary
|
||||
|
||||
processed = False
|
||||
|
||||
# currently unused
|
||||
if isinstance(obj, dict) and "ObjectGUID" in obj:
|
||||
mylog('debug', f"[WF] Updating Object '{obj}' ")
|
||||
plugin_instance = PluginObjectInstance(self.db)
|
||||
plugin_instance.delete(obj["ObjectGUID"])
|
||||
processed = True
|
||||
|
||||
elif isinstance(obj, dict) and "devGUID" in obj:
|
||||
mylog('debug', f"[WF] Updating Device '{obj}' ")
|
||||
device_instance = DeviceInstance(self.db)
|
||||
device_instance.delete(obj["devGUID"])
|
||||
processed = True
|
||||
|
||||
if not processed:
|
||||
mylog('none', f"[WF] Could not process action for object: {obj}")
|
||||
|
||||
return obj
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user