From 081d0f340083538816cf52826df2111a91eaa3ad Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Fri, 27 Sep 2024 10:02:24 +1000 Subject: [PATCH] Sync --- README.md | 2 +- front/plugins/sync/sync.py | 17 +++++++++++++++-- server/plugin.py | 4 +++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 213eb045..e94ef266 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![GitHub Committed](https://img.shields.io/github/last-commit/jokob-sk/NetAlertX?color=40ba12&label=Committed&logo=GitHub&logoColor=fff&style=for-the-badge)](https://github.com/jokob-sk/NetAlertX) +[![GitHub Committed](https://img.shields.io/github/last-commit/jokob-sk/NetAlertX?color=40ba12&label=Pushed&logo=GitHub&logoColor=fff&style=for-the-badge)](https://github.com/jokob-sk/NetAlertX) [![Docker Size](https://img.shields.io/docker/image-size/jokobsk/netalertx?label=Size&logo=Docker&color=0aa8d2&logoColor=fff&style=for-the-badge)](https://hub.docker.com/r/jokobsk/netalertx) [![Docker Pulls](https://img.shields.io/docker/pulls/jokobsk/netalertx?label=Pulls&logo=docker&color=0aa8d2&logoColor=fff&style=for-the-badge)](https://hub.docker.com/r/jokobsk/netalertx) [![GitHub Release](https://img.shields.io/github/v/release/jokob-sk/NetAlertX?color=0aa8d2&logoColor=fff&logo=GitHub&style=for-the-badge)](https://github.com/jokob-sk/NetAlertX/releases) diff --git a/front/plugins/sync/sync.py b/front/plugins/sync/sync.py index 9e39cfd7..177d6885 100755 --- a/front/plugins/sync/sync.py +++ b/front/plugins/sync/sync.py @@ -151,10 +151,10 @@ def main(): write_notification(message, 'info', timeNowTZ()) - # Process any received data for the Device DB table + # Process any received data for the Device DB table (ONLY JSON) # Create the file path - # Decode files, rename them, and get the list of files + # Get all "last_result" files from the sync folder, decode, rename them, and get the list of files files_to_process = decode_and_rename_files(file_dir, file_prefix) if len(files_to_process) > 0: @@ -192,6 +192,16 @@ def main(): device['dev_SyncHubNodeName'] = tmp_SyncHubNodeName unique_mac_addresses.add(device['dev_MAC']) device_data.append(device) + + # Rename the file to "processed_" + current name + new_file_name = f"processed_{file_name}" + new_file_path = os.path.join(file_dir, new_file_name) + + # Overwrite if the new file already exists + if os.path.exists(new_file_path): + os.remove(new_file_path) + + os.rename(file_path, new_file_path) if len(device_data) > 0: # Retrieve existing dev_MAC values from the Devices table @@ -243,6 +253,9 @@ def main(): mylog('verbose', [message]) write_notification(message, 'info', timeNowTZ()) + + + # Commit and close the connection conn.commit() diff --git a/server/plugin.py b/server/plugin.py index 4b03a600..7ed51b1c 100755 --- a/server/plugin.py +++ b/server/plugin.py @@ -226,12 +226,14 @@ def execute_plugin(db, all_plugins, plugin, pluginsState = plugins_state() ): file_dir = os.path.join(pluginsPath, plugin["code_name"]) file_prefix = 'last_result' - # Decode files, rename them, and get the list of files + # Decode files, rename them, and get the list of files, this will return all files starting with the prefix, even if they are not encoded files_to_process = decode_and_rename_files(file_dir, file_prefix) for filename in files_to_process: full_path = os.path.join(file_dir, filename) + + mylog('debug', [f'[Plugins] Processing file "{full_path}"']) # Open the decrypted file and process its contents with open(full_path, 'r') as f: