diff --git a/docker-compose.yml b/docker-compose.yml index 167cfa37..db933b65 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,10 +11,10 @@ services: network_mode: host # restart: unless-stopped volumes: - # - ${APP_DATA_LOCATION}/pialert_dev/config:/home/pi/pialert/config - - ${APP_DATA_LOCATION}/pialert/config:/home/pi/pialert/config - # - ${APP_DATA_LOCATION}/pialert_dev/db:/home/pi/pialert/db - - ${APP_DATA_LOCATION}/pialert/db:/home/pi/pialert/db + - ${APP_DATA_LOCATION}/pialert_dev/config:/home/pi/pialert/config + # - ${APP_DATA_LOCATION}/pialert/config:/home/pi/pialert/config + - ${APP_DATA_LOCATION}/pialert_dev/db:/home/pi/pialert/db + # - ${APP_DATA_LOCATION}/pialert/db:/home/pi/pialert/db # (optional) useful for debugging if you have issues setting up the container - ${LOGS_LOCATION}:/home/pi/pialert/front/log # --------------------------------------------------------------------------- diff --git a/front/js/pialert_common.js b/front/js/pialert_common.js index 4645a3d6..c9a6e490 100755 --- a/front/js/pialert_common.js +++ b/front/js/pialert_common.js @@ -349,6 +349,7 @@ function sanitize(data) // ----------------------------------------------------------------------------- function numberArrayFromString(data) { + console.log(data) data = JSON.parse(sanitize(data)); return data.replace(/\[|\]/g, '').split(',').map(Number); } @@ -516,6 +517,9 @@ function getNameByMacAddress(macAddress) { // A function used to make the IP address orderable function formatIPlong(ipAddress) { const parts = ipAddress.split('.'); + + console.log(ipAddress) + if (parts.length !== 4) { throw new Error('Invalid IP address format'); } diff --git a/front/plugins/csv_backup/script.py b/front/plugins/csv_backup/script.py index 45a501a3..3fbfc7e8 100755 --- a/front/plugins/csv_backup/script.py +++ b/front/plugins/csv_backup/script.py @@ -18,7 +18,7 @@ sys.path.append('/home/pi/pialert/pialert') from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from logger import mylog, append_line_to_file from helper import timeNowTZ -from const import logPath, pialertPath +from const import logPath, pialertPath, fullDbPath CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) @@ -43,7 +43,7 @@ def main(): mylog('verbose', ['[CSVBCKP] In script']) # Connect to the PiAlert SQLite database - conn = sqlite3.connect('/home/pi/pialert/db/pialert.db') + conn = sqlite3.connect(fullDbPath) cursor = conn.cursor() # Execute your SQL query diff --git a/front/plugins/db_cleanup/script.py b/front/plugins/db_cleanup/script.py index ada523e8..3f68d84e 100755 --- a/front/plugins/db_cleanup/script.py +++ b/front/plugins/db_cleanup/script.py @@ -18,7 +18,7 @@ sys.path.append('/home/pi/pialert/pialert') from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from logger import mylog, append_line_to_file from helper import timeNowTZ, get_setting_value -from const import logPath, pialertPath +from const import logPath, pialertPath, fullDbPath CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) @@ -44,7 +44,7 @@ def main(): # Execute cleanup/upkeep - cleanup_database('/home/pi/pialert/db/pialert.db', DAYS_TO_KEEP_EVENTS, PHOLUS_DAYS_DATA, HRS_TO_KEEP_NEWDEV, PLUGINS_KEEP_HIST) + cleanup_database(fullDbPath, DAYS_TO_KEEP_EVENTS, PHOLUS_DAYS_DATA, HRS_TO_KEEP_NEWDEV, PLUGINS_KEEP_HIST) mylog('verbose', ['[DBCLNP] Cleanup complete file ']) diff --git a/front/plugins/notification_processing/script.py b/front/plugins/notification_processing/script.py index 0af578ff..6d987ef2 100755 --- a/front/plugins/notification_processing/script.py +++ b/front/plugins/notification_processing/script.py @@ -16,21 +16,21 @@ sys.path.append('/home/pi/pialert/pialert') from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from logger import mylog, append_line_to_file from helper import timeNowTZ, get_setting_value -from const import logPath, pialertPath +from const import logPath, pialertPath, fullDbPath CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) LOG_FILE = os.path.join(CUR_PATH, 'script.log') RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') -pluginName= 'NTFPRCS' +pluginName = 'NTFPRCS' def main(): mylog('verbose', [f'[{pluginName}] In script']) # TODO - # process_notifications('/home/pi/pialert/db/pialert.db') + # process_notifications(fullDbPath) mylog('verbose', [f'[{pluginName}] Script finished']) @@ -40,9 +40,7 @@ def main(): # Cleanup / upkeep database #=============================================================================== def process_notifications (dbPath): - """ - Cleaning out old records from the tables that don't need to keep all data. - """ + # Connect to the PiAlert SQLite database conn = sqlite3.connect(dbPath) cursor = conn.cursor() diff --git a/front/plugins/pihole_scan/config.json b/front/plugins/pihole_scan/config.json index 6adb98f6..4425f49c 100755 --- a/front/plugins/pihole_scan/config.json +++ b/front/plugins/pihole_scan/config.json @@ -83,7 +83,7 @@ { "function": "CMD", "type": "text", - "default_value":"SELECT n.hwaddr AS Object_PrimaryID, {s-quote}null{s-quote} AS Object_SecondaryID, datetime() AS DateTime, na.ip AS Watched_Value1, n.lastQuery AS Watched_Value2, na.name AS Watched_Value3, n.macVendor AS Watched_Value4, {s-quote}null{s-quote} AS Extra, n.hwaddr AS ForeignKey FROM EXTERNAL_PIHOLE.Network AS n LEFT JOIN EXTERNAL_PIHOLE.Network_Addresses AS na ON na.network_id = n.id WHERE n.hwaddr NOT LIKE {s-quote}ip-%{s-quote} AND n.hwaddr <> {s-quote}00:00:00:00:00:00{s-quote} AND na.ip <> null;", + "default_value":"SELECT n.hwaddr AS Object_PrimaryID, {s-quote}null{s-quote} AS Object_SecondaryID, datetime() AS DateTime, na.ip AS Watched_Value1, n.lastQuery AS Watched_Value2, na.name AS Watched_Value3, n.macVendor AS Watched_Value4, {s-quote}null{s-quote} AS Extra, n.hwaddr AS ForeignKey FROM EXTERNAL_PIHOLE.Network AS n LEFT JOIN EXTERNAL_PIHOLE.Network_Addresses AS na ON na.network_id = n.id WHERE n.hwaddr NOT LIKE {s-quote}ip-%{s-quote} AND n.hwaddr is not {s-quote}00:00:00:00:00:00{s-quote} AND na.ip is not null", "options": [], "localized": ["name", "description"], "name" : [{ diff --git a/front/plugins/vendor_update/script.py b/front/plugins/vendor_update/script.py index 29e654cf..09e696ab 100755 --- a/front/plugins/vendor_update/script.py +++ b/front/plugins/vendor_update/script.py @@ -19,7 +19,7 @@ sys.path.append('/home/pi/pialert/pialert') from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64, handleEmpty from logger import mylog, append_line_to_file from helper import timeNowTZ -from const import logPath, pialertPath +from const import logPath, pialertPath, fullDbPath from device import query_MAC_vendor @@ -37,7 +37,7 @@ def main(): # Resolve missing vendors plugin_objects = Plugin_Objects(RESULT_FILE) - plugin_objects = update_vendors('/home/pi/pialert/db/pialert.db', plugin_objects) + plugin_objects = update_vendors(fullDbPath, plugin_objects) plugin_objects.write_result_file() diff --git a/pialert/plugin.py b/pialert/plugin.py index dbfa41f2..526209aa 100755 --- a/pialert/plugin.py +++ b/pialert/plugin.py @@ -327,6 +327,8 @@ def execute_plugin(db, plugin, pluginsState = plugins_state() ): try: sql.execute ("ATTACH DATABASE '"+ fullSqlitePath +"' AS EXTERNAL_"+plugin["unique_prefix"]) arr = db.get_sql_array (q) + sql.execute ("DETACH DATABASE EXTERNAL_"+plugin["unique_prefix"]) + except sqlite3.Error as e: mylog('none',[f'[Plugins] ⚠ ERROR: DB_PATH setting ({fullSqlitePath}) for plugin {plugin["unique_prefix"]}. Did you mount it correctly?']) mylog('none',[f'[Plugins] ⚠ ERROR: ATTACH DATABASE failed with SQL ERROR: ', e]) diff --git a/pialert/reporting.py b/pialert/reporting.py index d4d0f15b..6e4afbdc 100755 --- a/pialert/reporting.py +++ b/pialert/reporting.py @@ -59,7 +59,7 @@ def get_notifications (db): mylog('verbose', ['[Notification] included sections: ', conf.INCLUDED_SECTIONS ]) - if 'new_devices' in conf.INCLUDED_SECTIONS : + if 'new_devices' in conf.INCLUDED_SECTIONS: # Compose New Devices Section sqlQuery = """SELECT eve_MAC as MAC, eve_DateTime as Datetime, dev_LastIP as IP, eve_EventType as "Event Type", dev_Name as "Device name", dev_Comments as Comments FROM Events_Devices WHERE eve_PendingAlertEmail = 1 @@ -75,8 +75,9 @@ def get_notifications (db): } json_new_devices = json_obj.json["data"] - if 'down_devices' in conf.INCLUDED_SECTIONS : - # Compose Devices Down Section + if 'down_devices' in conf.INCLUDED_SECTIONS: + # Compose Devices Down Section + # - select only Down Alerts with pending email of devices that didn't reconnect within the specified time window sqlQuery = f""" SELECT * FROM Events AS down_events @@ -102,7 +103,7 @@ def get_notifications (db): } json_down_devices = json_obj.json["data"] - if 'events' in conf.INCLUDED_SECTIONS : + if 'events' in conf.INCLUDED_SECTIONS: # Compose Events Section sqlQuery = """SELECT eve_MAC as MAC, eve_DateTime as Datetime, dev_LastIP as IP, eve_EventType as "Event Type", dev_Name as "Device name", dev_Comments as Comments FROM Events_Devices WHERE eve_PendingAlertEmail = 1 @@ -142,7 +143,7 @@ def get_notifications (db): "events_meta": json_events_meta, "plugins": json_plugins, "plugins_meta": json_plugins_meta, - } + } return final_json