breakup plugins.py

This commit is contained in:
Jokob-sk
2023-08-23 09:32:46 +10:00
parent 908789230b
commit 2239aa6c25
5 changed files with 14 additions and 9 deletions

View File

@@ -125,7 +125,7 @@ def main ():
conf.plugins_once_run = True
# check if there is a front end initiated event which needs to be executed
check_and_run_event(db)
pluginsState = check_and_run_event(db, pluginsState)
# Update API endpoints
update_api(db)

View File

@@ -85,7 +85,7 @@ def importConfigs (db):
# General
conf.LOG_LEVEL = ccd('LOG_LEVEL', 'verbose' , c_d, 'Log verboseness', 'text.select', "['none', 'minimal', 'verbose', 'debug']", 'General')
conf.TIMEZONE = ccd('TIMEZONE', 'Europe/Berlin' , c_d, 'Time zone', 'text', '', 'General')
conf.PLUGINS_KEEP_HIST = ccd('PLUGINS_KEEP_HIST', 1000 , c_d, 'Keep history entries', 'integer', '', 'General')
conf.PLUGINS_KEEP_HIST = ccd('PLUGINS_KEEP_HIST', 250 , c_d, 'Keep history entries', 'integer', '', 'General')
conf.PIALERT_WEB_PROTECTION = ccd('PIALERT_WEB_PROTECTION', False , c_d, 'Enable logon', 'boolean', '', 'General')
conf.PIALERT_WEB_PASSWORD = ccd('PIALERT_WEB_PASSWORD', '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92' , c_d, 'Logon password', 'readonly', '', 'General')
conf.INCLUDED_SECTIONS = ccd('INCLUDED_SECTIONS', ['internet', 'new_devices', 'down_devices', 'events', 'ports'] , c_d, 'Notify on', 'text.multiselect', "['internet', 'new_devices', 'down_devices', 'events', 'ports', 'plugins']", 'General')

View File

@@ -533,7 +533,7 @@ def process_plugin_events(db, plugin, pluginsState, plugEventsArr):
except Exception as e:
# Rollback the transaction in case of an error
conn.rollback()
mylog('none', ['[Plugins] SQL transaction error: ', e])
mylog('none', ['[Plugins] Error: ', e])
raise e
# Perform database table mapping if enabled for the plugin

0
pialert/plugin_utils.py Normal file → Executable file
View File

View File

@@ -98,9 +98,11 @@ def construct_notifications(db, sqlQuery, tableTitle, skipText = False, supplied
for header in headers:
html = format_table(html, header, thProps)
return noti_struc(jsn, text, html)
notiStruc = noti_struc(jsn, text, html)
mylog('debug', ['[Notification] Ports: notiStruc:', json.dumps(notiStruc.__dict__, indent=4) ])
return notiStruc
def send_notifications (db):
@@ -241,7 +243,7 @@ def send_notifications (db):
json_ports = conf.changedPorts_json_struc.json["data"]
notiStruc = construct_notifications(db, "", "Ports", True, conf.changedPorts_json_struc)
mylog('verbose', ['[Notification] Ports: notiStruc:', notiStruc ])
mail_html = mail_html.replace ('<PORTS_TABLE>', notiStruc.html)
portsTxt = ""
@@ -483,7 +485,7 @@ def skip_repeated_notifications (db):
#===============================================================================
#-------------------------------------------------------------------------------
def check_and_run_event(db):
def check_and_run_event(db, pluginsState):
sql = db.sql # TO-DO
sql.execute(""" select * from Parameters where par_ID = "Front_Event" """)
rows = sql.fetchall()
@@ -501,7 +503,7 @@ def check_and_run_event(db):
if event == 'test':
handle_test(param)
if event == 'run':
handle_run(param, db)
pluginsState = handle_run(param, db, pluginsState)
# clear event execution flag
sql.execute ("UPDATE Parameters SET par_Value='finished' WHERE par_ID='Front_Event'")
@@ -509,17 +511,20 @@ def check_and_run_event(db):
# commit to DB
db.commitDB()
return pluginsState
#-------------------------------------------------------------------------------
def handle_run(runType, db):
def handle_run(runType, db, pluginsState):
mylog('minimal', ['[', timeNowTZ(), '] START Run: ', runType])
# run the plugin to run
for plugin in conf.plugins:
if plugin["unique_prefix"] == runType:
execute_plugin(db, plugin)
pluginsState = execute_plugin(db, plugin, pluginsState)
mylog('minimal', ['[', timeNowTZ(), '] END Run: ', runType])
return pluginsState