breakup plugins.py
This commit is contained in:
@@ -125,7 +125,7 @@ def main ():
|
|||||||
conf.plugins_once_run = True
|
conf.plugins_once_run = True
|
||||||
|
|
||||||
# check if there is a front end initiated event which needs to be executed
|
# 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 endpoints
|
||||||
update_api(db)
|
update_api(db)
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ def importConfigs (db):
|
|||||||
# General
|
# General
|
||||||
conf.LOG_LEVEL = ccd('LOG_LEVEL', 'verbose' , c_d, 'Log verboseness', 'text.select', "['none', 'minimal', 'verbose', 'debug']", '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.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_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.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')
|
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')
|
||||||
|
|||||||
@@ -533,7 +533,7 @@ def process_plugin_events(db, plugin, pluginsState, plugEventsArr):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Rollback the transaction in case of an error
|
# Rollback the transaction in case of an error
|
||||||
conn.rollback()
|
conn.rollback()
|
||||||
mylog('none', ['[Plugins] SQL transaction error: ', e])
|
mylog('none', ['[Plugins] Error: ', e])
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
# Perform database table mapping if enabled for the plugin
|
# Perform database table mapping if enabled for the plugin
|
||||||
|
|||||||
0
pialert/plugin_utils.py
Normal file → Executable file
0
pialert/plugin_utils.py
Normal file → Executable file
@@ -98,9 +98,11 @@ def construct_notifications(db, sqlQuery, tableTitle, skipText = False, supplied
|
|||||||
for header in headers:
|
for header in headers:
|
||||||
html = format_table(html, header, thProps)
|
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):
|
def send_notifications (db):
|
||||||
@@ -241,7 +243,7 @@ def send_notifications (db):
|
|||||||
json_ports = conf.changedPorts_json_struc.json["data"]
|
json_ports = conf.changedPorts_json_struc.json["data"]
|
||||||
|
|
||||||
notiStruc = construct_notifications(db, "", "Ports", True, conf.changedPorts_json_struc)
|
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)
|
mail_html = mail_html.replace ('<PORTS_TABLE>', notiStruc.html)
|
||||||
|
|
||||||
portsTxt = ""
|
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 = db.sql # TO-DO
|
||||||
sql.execute(""" select * from Parameters where par_ID = "Front_Event" """)
|
sql.execute(""" select * from Parameters where par_ID = "Front_Event" """)
|
||||||
rows = sql.fetchall()
|
rows = sql.fetchall()
|
||||||
@@ -501,7 +503,7 @@ def check_and_run_event(db):
|
|||||||
if event == 'test':
|
if event == 'test':
|
||||||
handle_test(param)
|
handle_test(param)
|
||||||
if event == 'run':
|
if event == 'run':
|
||||||
handle_run(param, db)
|
pluginsState = handle_run(param, db, pluginsState)
|
||||||
|
|
||||||
# clear event execution flag
|
# clear event execution flag
|
||||||
sql.execute ("UPDATE Parameters SET par_Value='finished' WHERE par_ID='Front_Event'")
|
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
|
# commit to DB
|
||||||
db.commitDB()
|
db.commitDB()
|
||||||
|
|
||||||
|
return pluginsState
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
def handle_run(runType, db):
|
def handle_run(runType, db, pluginsState):
|
||||||
|
|
||||||
mylog('minimal', ['[', timeNowTZ(), '] START Run: ', runType])
|
mylog('minimal', ['[', timeNowTZ(), '] START Run: ', runType])
|
||||||
|
|
||||||
# run the plugin to run
|
# run the plugin to run
|
||||||
for plugin in conf.plugins:
|
for plugin in conf.plugins:
|
||||||
if plugin["unique_prefix"] == runType:
|
if plugin["unique_prefix"] == runType:
|
||||||
execute_plugin(db, plugin)
|
pluginsState = execute_plugin(db, plugin, pluginsState)
|
||||||
|
|
||||||
mylog('minimal', ['[', timeNowTZ(), '] END Run: ', runType])
|
mylog('minimal', ['[', timeNowTZ(), '] END Run: ', runType])
|
||||||
|
return pluginsState
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user