diff --git a/front/plugins/__template/rename_me.py b/front/plugins/__template/rename_me.py index 49f2a760..c303d95d 100755 --- a/front/plugins/__template/rename_me.py +++ b/front/plugins/__template/rename_me.py @@ -15,7 +15,7 @@ from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from plugin_utils import get_plugins_configs from logger import mylog, Logger from const import pluginsPath, fullDbPath, logPath -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from messaging.in_app import write_notification import conf diff --git a/front/plugins/__test/test.py b/front/plugins/__test/test.py index e87bdfb4..21cfc1d0 100755 --- a/front/plugins/__test/test.py +++ b/front/plugins/__test/test.py @@ -23,7 +23,7 @@ from const import apiPath, confFileName, logPath from plugin_utils import getPluginObject from plugin_helper import Plugin_Objects from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value, bytes_to_string, sanitize_string, cleanDeviceName +from helper import get_setting_value, bytes_to_string, sanitize_string, cleanDeviceName from models.notification_instance import NotificationInstance from database import DB, get_device_stats diff --git a/front/plugins/_publisher_apprise/apprise.py b/front/plugins/_publisher_apprise/apprise.py index 967074ed..5f1c3c33 100755 --- a/front/plugins/_publisher_apprise/apprise.py +++ b/front/plugins/_publisher_apprise/apprise.py @@ -16,7 +16,7 @@ import conf from const import confFileName, logPath from plugin_helper import Plugin_Objects from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value +from helper import timeNowDB, get_setting_value from models.notification_instance import NotificationInstance from database import DB from pytz import timezone @@ -65,7 +65,7 @@ def main(): # Log result plugin_objects.add_object( primaryId = pluginName, - secondaryId = timeNowTZ(), + secondaryId = timeNowDB(), watched1 = notification["GUID"], watched2 = result, watched3 = 'null', diff --git a/front/plugins/_publisher_email/email_smtp.py b/front/plugins/_publisher_email/email_smtp.py index 682bf5ce..8d738844 100755 --- a/front/plugins/_publisher_email/email_smtp.py +++ b/front/plugins/_publisher_email/email_smtp.py @@ -25,7 +25,7 @@ import conf from const import confFileName, logPath from plugin_helper import Plugin_Objects from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value, hide_email +from helper import timeNowDB, get_setting_value, hide_email from models.notification_instance import NotificationInstance from database import DB from pytz import timezone @@ -86,7 +86,7 @@ def main(): # Log result plugin_objects.add_object( primaryId = pluginName, - secondaryId = timeNowTZ(), + secondaryId = timeNowDB(), watched1 = notification["GUID"], watched2 = result, watched3 = 'null', diff --git a/front/plugins/_publisher_mqtt/mqtt.py b/front/plugins/_publisher_mqtt/mqtt.py index fade6e18..03a441a3 100755 --- a/front/plugins/_publisher_mqtt/mqtt.py +++ b/front/plugins/_publisher_mqtt/mqtt.py @@ -23,7 +23,7 @@ from const import confFileName, logPath from plugin_utils import getPluginObject from plugin_helper import Plugin_Objects from logger import mylog, Logger -from helper import timeNowTZ, get_setting_value, bytes_to_string, \ +from helper import timeNowDB, get_setting_value, bytes_to_string, \ sanitize_string, normalize_string from database import DB, get_device_stats @@ -567,7 +567,7 @@ def prepTimeStamp(datetime_str): except ValueError: mylog('verbose', [f"[{pluginName}] Timestamp conversion failed of string '{datetime_str}'"]) # Use the current time if the input format is invalid - parsed_datetime = timeNowTZ() # Assuming this function returns the current time with timezone + parsed_datetime = timeNowDB() # Convert to the required format with 'T' between date and time and ensure the timezone is included return parsed_datetime.isoformat() # This will include the timezone offset diff --git a/front/plugins/_publisher_ntfy/ntfy.py b/front/plugins/_publisher_ntfy/ntfy.py index 4c3807b9..79df681f 100755 --- a/front/plugins/_publisher_ntfy/ntfy.py +++ b/front/plugins/_publisher_ntfy/ntfy.py @@ -19,7 +19,7 @@ import conf from const import confFileName, logPath from plugin_helper import Plugin_Objects, handleEmpty from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value +from helper import timeNowDB, get_setting_value from models.notification_instance import NotificationInstance from database import DB from pytz import timezone @@ -68,7 +68,7 @@ def main(): # Log result plugin_objects.add_object( primaryId = pluginName, - secondaryId = timeNowTZ(), + secondaryId = timeNowDB(), watched1 = notification["GUID"], watched2 = handleEmpty(response_text), watched3 = response_status_code, diff --git a/front/plugins/_publisher_pushover/pushover.py b/front/plugins/_publisher_pushover/pushover.py index 65357c91..8ebd1dee 100755 --- a/front/plugins/_publisher_pushover/pushover.py +++ b/front/plugins/_publisher_pushover/pushover.py @@ -11,7 +11,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Objects, handleEmpty # noqa: E402 from logger import mylog, Logger # noqa: E402 -from helper import timeNowTZ, get_setting_value, hide_string # noqa: E402 +from helper import timeNowDB, get_setting_value, hide_string # noqa: E402 from models.notification_instance import NotificationInstance # noqa: E402 from database import DB # noqa: E402 import conf @@ -63,7 +63,7 @@ def main(): # Log result plugin_objects.add_object( primaryId=pluginName, - secondaryId=timeNowTZ(), + secondaryId=timeNowDB(), watched1=notification["GUID"], watched2=handleEmpty(response_text), watched3=response_status_code, diff --git a/front/plugins/_publisher_pushsafer/pushsafer.py b/front/plugins/_publisher_pushsafer/pushsafer.py index 4a857e58..366f170a 100755 --- a/front/plugins/_publisher_pushsafer/pushsafer.py +++ b/front/plugins/_publisher_pushsafer/pushsafer.py @@ -19,7 +19,7 @@ import conf from const import confFileName, logPath from plugin_helper import Plugin_Objects, handleEmpty from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value, hide_string +from helper import timeNowDB, get_setting_value, hide_string from models.notification_instance import NotificationInstance from database import DB from pytz import timezone @@ -68,7 +68,7 @@ def main(): # Log result plugin_objects.add_object( primaryId = pluginName, - secondaryId = timeNowTZ(), + secondaryId = timeNowDB(), watched1 = notification["GUID"], watched2 = handleEmpty(response_text), watched3 = response_status_code, diff --git a/front/plugins/_publisher_telegram/tg.py b/front/plugins/_publisher_telegram/tg.py index a74842eb..c9f92d9d 100755 --- a/front/plugins/_publisher_telegram/tg.py +++ b/front/plugins/_publisher_telegram/tg.py @@ -16,7 +16,7 @@ import conf from const import confFileName, logPath from plugin_helper import Plugin_Objects from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value +from helper import timeNowDB, get_setting_value from models.notification_instance import NotificationInstance from database import DB from pytz import timezone @@ -65,7 +65,7 @@ def main(): # Log result plugin_objects.add_object( primaryId=pluginName, - secondaryId=timeNowTZ(), + secondaryId=timeNowDB(), watched1=notification["GUID"], watched2=result, watched3='null', diff --git a/front/plugins/_publisher_webhook/webhook.py b/front/plugins/_publisher_webhook/webhook.py index ec8a2407..f1eec9d7 100755 --- a/front/plugins/_publisher_webhook/webhook.py +++ b/front/plugins/_publisher_webhook/webhook.py @@ -22,7 +22,7 @@ import conf from const import logPath, confFileName from plugin_helper import Plugin_Objects, handleEmpty from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value, hide_string, write_file +from helper import timeNowDB, get_setting_value, hide_string, write_file from models.notification_instance import NotificationInstance from database import DB from pytz import timezone @@ -71,7 +71,7 @@ def main(): # Log result plugin_objects.add_object( primaryId = pluginName, - secondaryId = timeNowTZ(), + secondaryId = timeNowDB(), watched1 = notification["GUID"], watched2 = handleEmpty(response_stdout), watched3 = handleEmpty(response_stderr), diff --git a/front/plugins/arp_scan/script.py b/front/plugins/arp_scan/script.py index b3d4d426..01c868e1 100755 --- a/front/plugins/arp_scan/script.py +++ b/front/plugins/arp_scan/script.py @@ -16,7 +16,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from database import DB from plugin_helper import Plugin_Object, Plugin_Objects, handleEmpty from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from const import logPath, applicationPath import conf from pytz import timezone diff --git a/front/plugins/csv_backup/script.py b/front/plugins/csv_backup/script.py index 8ce00f89..c4c19951 100755 --- a/front/plugins/csv_backup/script.py +++ b/front/plugins/csv_backup/script.py @@ -16,7 +16,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from const import logPath, applicationPath, fullDbPath import conf from pytz import timezone diff --git a/front/plugins/db_cleanup/script.py b/front/plugins/db_cleanup/script.py index 55d56d8c..7d0fb012 100755 --- a/front/plugins/db_cleanup/script.py +++ b/front/plugins/db_cleanup/script.py @@ -16,7 +16,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from const import logPath, applicationPath, fullDbPath import conf from pytz import timezone diff --git a/front/plugins/ddns_update/script.py b/front/plugins/ddns_update/script.py index 9b787cb5..57a6da4c 100755 --- a/front/plugins/ddns_update/script.py +++ b/front/plugins/ddns_update/script.py @@ -19,7 +19,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value, check_IP_format +from helper import get_setting_value, check_IP_format from const import logPath, applicationPath, fullDbPath import conf from pytz import timezone diff --git a/front/plugins/dhcp_leases/script.py b/front/plugins/dhcp_leases/script.py index 491abebf..44a1b7c7 100755 --- a/front/plugins/dhcp_leases/script.py +++ b/front/plugins/dhcp_leases/script.py @@ -15,7 +15,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, handleEmpty, is_mac from logger import mylog, Logger from dhcp_leases import DhcpLeases -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value import conf from const import logPath from pytz import timezone diff --git a/front/plugins/dhcp_servers/script.py b/front/plugins/dhcp_servers/script.py index 6e449db2..6565072f 100755 --- a/front/plugins/dhcp_servers/script.py +++ b/front/plugins/dhcp_servers/script.py @@ -13,7 +13,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Objects, Plugin_Object from logger import mylog, Logger -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value import conf from pytz import timezone from const import logPath diff --git a/front/plugins/dig_scan/digscan.py b/front/plugins/dig_scan/digscan.py index 4ac67cf0..dd00c226 100755 --- a/front/plugins/dig_scan/digscan.py +++ b/front/plugins/dig_scan/digscan.py @@ -15,7 +15,7 @@ from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from plugin_utils import get_plugins_configs from logger import mylog, Logger from const import pluginsPath, fullDbPath, logPath -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from messaging.in_app import write_notification from database import DB from models.device_instance import DeviceInstance diff --git a/front/plugins/freebox/freebox.py b/front/plugins/freebox/freebox.py index 1ce9488a..da8a8884 100755 --- a/front/plugins/freebox/freebox.py +++ b/front/plugins/freebox/freebox.py @@ -24,7 +24,7 @@ from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from plugin_utils import get_plugins_configs from logger import mylog, Logger from const import pluginsPath, fullDbPath, logPath -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from messaging.in_app import write_notification import conf diff --git a/front/plugins/icmp_scan/icmp.py b/front/plugins/icmp_scan/icmp.py index 5577cb0e..467f3631 100755 --- a/front/plugins/icmp_scan/icmp.py +++ b/front/plugins/icmp_scan/icmp.py @@ -20,7 +20,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from const import logPath, applicationPath, fullDbPath from database import DB from models.device_instance import DeviceInstance diff --git a/front/plugins/internet_ip/script.py b/front/plugins/internet_ip/script.py index 574052c7..f56d2ed7 100755 --- a/front/plugins/internet_ip/script.py +++ b/front/plugins/internet_ip/script.py @@ -20,7 +20,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, check_IP_format, get_setting_value +from helper import timeNowDB, check_IP_format, get_setting_value from const import logPath, applicationPath, fullDbPath import conf from pytz import timezone @@ -80,7 +80,7 @@ def main(): mylog('verbose', [f'[{pluginName}] Curl Fallback (new_internet_IP|cmd_output): {new_internet_IP} | {cmd_output}']) # logging - append_line_to_file (logPath + '/IP_changes.log', '['+str(timeNowTZ()) +']\t'+ new_internet_IP +'\n') + append_line_to_file (logPath + '/IP_changes.log', '['+str(timeNowDB()) +']\t'+ new_internet_IP +'\n') plugin_objects = Plugin_Objects(RESULT_FILE) diff --git a/front/plugins/internet_speedtest/script.py b/front/plugins/internet_speedtest/script.py index 6e9063ed..ef4f5705 100755 --- a/front/plugins/internet_speedtest/script.py +++ b/front/plugins/internet_speedtest/script.py @@ -13,7 +13,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Objects from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value +from helper import timeNowDB, get_setting_value import conf from pytz import timezone from const import logPath @@ -40,7 +40,7 @@ def main(): speedtest_result = run_speedtest() plugin_objects.add_object( primaryId = 'Speedtest', - secondaryId = timeNowTZ(), + secondaryId = timeNowDB(), watched1 = speedtest_result['download_speed'], watched2 = speedtest_result['upload_speed'], watched3 = 'null', diff --git a/front/plugins/ipneigh/ipneigh.py b/front/plugins/ipneigh/ipneigh.py index dd0a7978..a556c213 100755 --- a/front/plugins/ipneigh/ipneigh.py +++ b/front/plugins/ipneigh/ipneigh.py @@ -18,7 +18,7 @@ from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64, handleEmp from plugin_utils import get_plugins_configs from logger import mylog, Logger from const import pluginsPath, fullDbPath, logPath -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from messaging.in_app import write_notification import conf diff --git a/front/plugins/luci_import/script.py b/front/plugins/luci_import/script.py index 5eaa578a..c4283a7d 100755 --- a/front/plugins/luci_import/script.py +++ b/front/plugins/luci_import/script.py @@ -9,7 +9,7 @@ pluginName = 'LUCIRPC' from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from const import logPath, applicationPath import conf from pytz import timezone diff --git a/front/plugins/maintenance/maintenance.py b/front/plugins/maintenance/maintenance.py index 2e28c6a5..5f13c79f 100755 --- a/front/plugins/maintenance/maintenance.py +++ b/front/plugins/maintenance/maintenance.py @@ -17,7 +17,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from const import logPath, applicationPath from messaging.in_app import remove_old import conf diff --git a/front/plugins/nbtscan_scan/nbtscan.py b/front/plugins/nbtscan_scan/nbtscan.py index 6a4e9fff..d555859d 100755 --- a/front/plugins/nbtscan_scan/nbtscan.py +++ b/front/plugins/nbtscan_scan/nbtscan.py @@ -15,7 +15,7 @@ from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from plugin_utils import get_plugins_configs from logger import mylog, Logger from const import pluginsPath, fullDbPath, logPath -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from messaging.in_app import write_notification from database import DB from models.device_instance import DeviceInstance diff --git a/front/plugins/nmap_dev_scan/nmap_dev.py b/front/plugins/nmap_dev_scan/nmap_dev.py index e9f25cd1..2c7f85ad 100755 --- a/front/plugins/nmap_dev_scan/nmap_dev.py +++ b/front/plugins/nmap_dev_scan/nmap_dev.py @@ -21,7 +21,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value, extract_between_strings, extract_ip_addresses, extract_mac_addresses +from helper import get_setting_value, extract_between_strings, extract_ip_addresses, extract_mac_addresses from const import logPath, applicationPath, fullDbPath from database import DB from models.device_instance import DeviceInstance diff --git a/front/plugins/nmap_scan/script.py b/front/plugins/nmap_scan/script.py index 1851b26c..180973bb 100755 --- a/front/plugins/nmap_scan/script.py +++ b/front/plugins/nmap_scan/script.py @@ -14,7 +14,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value +from helper import timeNowDB, get_setting_value from const import logPath, applicationPath import conf from pytz import timezone @@ -158,7 +158,7 @@ def performNmapScan(deviceIPs, deviceMACs, timeoutSec, args): elif 'PORT' in line and 'STATE' in line and 'SERVICE' in line: startCollecting = False # end reached elif startCollecting and len(line.split()) == 3: - newEntriesTmp.append(nmap_entry(ip, deviceMACs[devIndex], timeNowTZ(), line.split()[0], line.split()[1], line.split()[2])) + newEntriesTmp.append(nmap_entry(ip, deviceMACs[devIndex], timeNowDB(), line.split()[0], line.split()[1], line.split()[2])) newPortsPerDevice += 1 elif 'Nmap done' in line: duration = line.split('scanned in ')[1] diff --git a/front/plugins/nslookup_scan/nslookup.py b/front/plugins/nslookup_scan/nslookup.py index d0d1c4d4..05baa254 100755 --- a/front/plugins/nslookup_scan/nslookup.py +++ b/front/plugins/nslookup_scan/nslookup.py @@ -20,7 +20,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from const import logPath, applicationPath, fullDbPath from database import DB from models.device_instance import DeviceInstance diff --git a/front/plugins/omada_sdn_imp/omada_sdn.py b/front/plugins/omada_sdn_imp/omada_sdn.py index 1b714f32..ae2f482b 100755 --- a/front/plugins/omada_sdn_imp/omada_sdn.py +++ b/front/plugins/omada_sdn_imp/omada_sdn.py @@ -44,7 +44,7 @@ from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from plugin_utils import get_plugins_configs from logger import mylog, Logger from const import pluginsPath, fullDbPath, logPath -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from messaging.in_app import write_notification from pytz import timezone import conf diff --git a/front/plugins/plugin_helper.py b/front/plugins/plugin_helper.py index edd6a027..d95cb795 100755 --- a/front/plugins/plugin_helper.py +++ b/front/plugins/plugin_helper.py @@ -11,7 +11,7 @@ INSTALL_PATH = "/app" sys.path.append(f"{INSTALL_PATH}/front/plugins") sys.path.append(f'{INSTALL_PATH}/server') -from logger import mylog, Logger +from logger import mylog, Logger, timeNowDB from const import confFileName, default_tz #------------------------------------------------------------------------------- @@ -204,7 +204,7 @@ class Plugin_Object: self.pluginPref = "" self.primaryId = primaryId self.secondaryId = secondaryId - self.created = datetime.now().astimezone().isoformat() + self.created = timeNowDB() self.changed = "" self.watched1 = watched1 self.watched2 = watched2 diff --git a/front/plugins/snmp_discovery/script.py b/front/plugins/snmp_discovery/script.py index ad25d01d..11378168 100755 --- a/front/plugins/snmp_discovery/script.py +++ b/front/plugins/snmp_discovery/script.py @@ -13,7 +13,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64, handleEmpty, normalize_mac from logger import mylog, Logger -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from const import logPath, applicationPath import conf from pytz import timezone diff --git a/front/plugins/sync/sync.py b/front/plugins/sync/sync.py index f6b328ac..89695bec 100755 --- a/front/plugins/sync/sync.py +++ b/front/plugins/sync/sync.py @@ -18,7 +18,7 @@ from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from plugin_utils import get_plugins_configs, decode_and_rename_files from logger import mylog, Logger from const import pluginsPath, fullDbPath, logPath -from helper import timeNowTZ, get_setting_value +from helper import timeNowDB, get_setting_value from crypto_utils import encrypt_data from messaging.in_app import write_notification import conf @@ -149,7 +149,7 @@ def main(): message = f'[{pluginName}] Device data from node "{node_name}" written to {log_file_name}' mylog('verbose', [message]) if lggr.isAbove('verbose'): - write_notification(message, 'info', timeNowTZ()) + write_notification(message, 'info', timeNowDB()) # Process any received data for the Device DB table (ONLY JSON) @@ -255,7 +255,7 @@ def main(): message = f'[{pluginName}] Inserted "{len(new_devices)}" new devices' mylog('verbose', [message]) - write_notification(message, 'info', timeNowTZ()) + write_notification(message, 'info', timeNowDB()) # Commit and close the connection @@ -299,7 +299,7 @@ def send_data(api_token, file_content, encryption_key, file_path, node_name, pre if response.status_code == 200: message = f'[{pluginName}] Data for "{file_path}" sent successfully via {final_endpoint}' mylog('verbose', [message]) - write_notification(message, 'info', timeNowTZ()) + write_notification(message, 'info', timeNowDB()) return True except requests.RequestException as e: @@ -308,7 +308,7 @@ def send_data(api_token, file_content, encryption_key, file_path, node_name, pre # If all endpoints fail message = f'[{pluginName}] Failed to send data for "{file_path}" via all endpoints' mylog('verbose', [message]) - write_notification(message, 'alert', timeNowTZ()) + write_notification(message, 'alert', timeNowDB()) return False @@ -332,7 +332,7 @@ def get_data(api_token, node_url): except json.JSONDecodeError: message = f'[{pluginName}] Failed to parse JSON from {final_endpoint}' mylog('verbose', [message]) - write_notification(message, 'alert', timeNowTZ()) + write_notification(message, 'alert', timeNowDB()) return "" except requests.RequestException as e: mylog('verbose', [f'[{pluginName}] Error calling {final_endpoint}: {e}']) @@ -340,7 +340,7 @@ def get_data(api_token, node_url): # If all endpoints fail message = f'[{pluginName}] Failed to get data from "{node_url}" via all endpoints' mylog('verbose', [message]) - write_notification(message, 'alert', timeNowTZ()) + write_notification(message, 'alert', timeNowDB()) return "" diff --git a/front/plugins/unifi_api_import/unifi_api_import.py b/front/plugins/unifi_api_import/unifi_api_import.py index 6bdb52c8..8e8b9a94 100755 --- a/front/plugins/unifi_api_import/unifi_api_import.py +++ b/front/plugins/unifi_api_import/unifi_api_import.py @@ -16,7 +16,7 @@ from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64, decode_se from plugin_utils import get_plugins_configs from logger import mylog, Logger from const import pluginsPath, fullDbPath, logPath -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from messaging.in_app import write_notification import conf diff --git a/front/plugins/unifi_import/script.py b/front/plugins/unifi_import/script.py index c4dac026..95765829 100755 --- a/front/plugins/unifi_import/script.py +++ b/front/plugins/unifi_import/script.py @@ -21,7 +21,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, rmBadChars, is_typical_router_ip, is_mac from logger import mylog, Logger -from helper import timeNowTZ, get_setting_value, normalize_string +from helper import get_setting_value, normalize_string import conf from pytz import timezone from const import logPath diff --git a/front/plugins/vendor_update/script.py b/front/plugins/vendor_update/script.py index dbe6a055..4617ad5b 100755 --- a/front/plugins/vendor_update/script.py +++ b/front/plugins/vendor_update/script.py @@ -17,7 +17,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64, handleEmpty from logger import mylog, Logger, append_line_to_file -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from const import logPath, applicationPath, fullDbPath from scan.device_handling import query_MAC_vendor import conf diff --git a/front/plugins/wake_on_lan/wake_on_lan.py b/front/plugins/wake_on_lan/wake_on_lan.py index 775d2346..eaa0bdde 100755 --- a/front/plugins/wake_on_lan/wake_on_lan.py +++ b/front/plugins/wake_on_lan/wake_on_lan.py @@ -16,7 +16,7 @@ from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from plugin_utils import get_plugins_configs from logger import mylog, Logger from const import pluginsPath, fullDbPath, logPath -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value from messaging.in_app import write_notification from database import DB from models.device_instance import DeviceInstance diff --git a/front/plugins/website_monitor/script.py b/front/plugins/website_monitor/script.py index 0426444a..4acac72b 100755 --- a/front/plugins/website_monitor/script.py +++ b/front/plugins/website_monitor/script.py @@ -16,7 +16,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Objects from datetime import datetime from const import logPath -from helper import timeNowTZ, get_setting_value +from helper import get_setting_value import conf from pytz import timezone from logger import mylog, Logger diff --git a/server/api_server/api_server_start.py b/server/api_server/api_server_start.py index 974dd313..3a376791 100755 --- a/server/api_server/api_server_start.py +++ b/server/api_server/api_server_start.py @@ -9,7 +9,7 @@ INSTALL_PATH = "/app" sys.path.extend([f"{INSTALL_PATH}/server"]) from logger import mylog -from helper import get_setting_value, timeNowTZ +from helper import get_setting_value from db.db_helper import get_date_from_period from app_state import updateState diff --git a/server/api_server/device_endpoint.py b/server/api_server/device_endpoint.py index 7a331c5d..9c032f28 100755 --- a/server/api_server/device_endpoint.py +++ b/server/api_server/device_endpoint.py @@ -14,7 +14,7 @@ INSTALL_PATH="/app" sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from database import get_temp_db_connection -from helper import is_random_mac, format_date, get_setting_value, timeNowTZ +from helper import is_random_mac, format_date, get_setting_value, timeNowDB from db.db_helper import row_to_json, get_date_from_period # -------------------------- @@ -28,7 +28,7 @@ def get_device_data(mac): conn = get_temp_db_connection() cur = conn.cursor() - now = timeNowTZ().astimezone().isoformat() + now = timeNowDB() # Special case for new device if mac.lower() == "new": @@ -187,8 +187,8 @@ def set_device_data(mac, data): data.get("devSkipRepeated", 0), data.get("devIsNew", 0), data.get("devIsArchived", 0), - data.get("devLastConnection", timeNowTZ().astimezone().isoformat()), - data.get("devFirstConnection", timeNowTZ().astimezone().isoformat()), + data.get("devLastConnection", timeNowDB()), + data.get("devFirstConnection", timeNowDB()), data.get("devLastIP", ""), data.get("devGUID", ""), data.get("devCustomProps", ""), diff --git a/server/api_server/events_endpoint.py b/server/api_server/events_endpoint.py index 5b94940d..5d02fcda 100755 --- a/server/api_server/events_endpoint.py +++ b/server/api_server/events_endpoint.py @@ -14,7 +14,7 @@ INSTALL_PATH="/app" sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from database import get_temp_db_connection -from helper import is_random_mac, format_date, get_setting_value, format_date_iso, format_event_date, timeNowTZ, mylog, ensure_datetime +from helper import is_random_mac, format_date, get_setting_value, format_date_iso, format_event_date, mylog, ensure_datetime from db.db_helper import row_to_json, get_date_from_period diff --git a/server/api_server/sessions_endpoint.py b/server/api_server/sessions_endpoint.py index 7cde8cd7..811503be 100755 --- a/server/api_server/sessions_endpoint.py +++ b/server/api_server/sessions_endpoint.py @@ -16,7 +16,7 @@ INSTALL_PATH="/app" sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from database import get_temp_db_connection -from helper import is_random_mac, format_date, get_setting_value, format_date_iso, format_event_date, mylog, timeNowTZ, format_date_diff, format_ip_long, parse_datetime +from helper import is_random_mac, format_date, get_setting_value, format_date_iso, format_event_date, mylog, format_date_diff, format_ip_long, parse_datetime from db.db_helper import row_to_json, get_date_from_period diff --git a/server/api_server/sync_endpoint.py b/server/api_server/sync_endpoint.py index 66e8f0f1..59b8095e 100755 --- a/server/api_server/sync_endpoint.py +++ b/server/api_server/sync_endpoint.py @@ -2,7 +2,7 @@ import os import base64 from flask import jsonify, request from logger import mylog -from helper import get_setting_value, timeNowTZ +from helper import get_setting_value, timeNowDB from messaging.in_app import write_notification INSTALL_PATH = "/app" @@ -16,19 +16,19 @@ def handle_sync_get(): raw_data = f.read() except FileNotFoundError: msg = f"[Plugin: SYNC] Data file not found: {file_path}" - write_notification(msg, "alert", timeNowTZ()) + write_notification(msg, "alert", timeNowDB()) mylog("verbose", [msg]) return jsonify({"error": msg}), 500 response_data = base64.b64encode(raw_data).decode("utf-8") - write_notification("[Plugin: SYNC] Data sent", "info", timeNowTZ()) + write_notification("[Plugin: SYNC] Data sent", "info", timeNowDB()) return jsonify({ "node_name": get_setting_value("SYNC_node_name"), "status": 200, "message": "OK", "data_base64": response_data, - "timestamp": timeNowTZ() + "timestamp": timeNowDB() }), 200 @@ -61,11 +61,11 @@ def handle_sync_post(): f.write(data) except Exception as e: msg = f"[Plugin: SYNC] Failed to store data: {e}" - write_notification(msg, "alert", timeNowTZ()) + write_notification(msg, "alert", timeNowDB()) mylog("verbose", [msg]) return jsonify({"error": msg}), 500 msg = f"[Plugin: SYNC] Data received ({file_path_new})" - write_notification(msg, "info", timeNowTZ()) + write_notification(msg, "info", timeNowDB()) mylog("verbose", [msg]) return jsonify({"message": "Data received and stored successfully"}), 200 diff --git a/server/app_state.py b/server/app_state.py index 4a3dcad2..d4b33525 100755 --- a/server/app_state.py +++ b/server/app_state.py @@ -4,7 +4,7 @@ import json import conf from const import * from logger import mylog, logResult -from helper import timeNowTZ, timeNow, checkNewVersion +from helper import timeNowDB, timeNow, checkNewVersion # Register NetAlertX directories INSTALL_PATH="/app" @@ -59,7 +59,7 @@ class app_state_class: previousState = "" # Update self - self.lastUpdated = str(timeNowTZ().astimezone().isoformat()) + self.lastUpdated = str(timeNowDB()) if os.path.exists(stateFile): try: diff --git a/server/helper.py b/server/helper.py index f7787af1..61bec402 100755 --- a/server/helper.py +++ b/server/helper.py @@ -31,18 +31,11 @@ INSTALL_PATH="/app" #------------------------------------------------------------------------------- # DateTime #------------------------------------------------------------------------------- -# Get the current time in the current TimeZone def timeNowTZ(): if conf.tz: return datetime.datetime.now(conf.tz).replace(microsecond=0) else: return datetime.datetime.now().replace(microsecond=0) - # if isinstance(conf.TIMEZONE, str): - # tz = pytz.timezone(conf.TIMEZONE) - # else: - # tz = conf.TIMEZONE - - # return datetime.datetime.now(tz).replace(microsecond=0) def timeNow(): return datetime.datetime.now().replace(microsecond=0) @@ -53,6 +46,23 @@ def get_timezone_offset(): offset_formatted = "{:+03d}:{:02d}".format(int(offset_hours), int((offset_hours % 1) * 60)) return offset_formatted +def timeNowDB(local=True): + """ + Return the current time (local or UTC) as ISO 8601 for DB storage. + Safe for SQLite, PostgreSQL, etc. + + Example local: '2025-11-04 18:09:11' + Example UTC: '2025-11-04 07:09:11' + """ + if local: + try: + tz = ZoneInfo(conf.tz) if conf.tz else None + except Exception: + tz = None + return datetime.datetime.now(tz).strftime('%Y-%m-%d %H:%M:%S') + else: + return datetime.datetime.now(datetime.UTC).strftime('%Y-%m-%d %H:%M:%S') + #------------------------------------------------------------------------------- # Date and time methods @@ -79,7 +89,7 @@ def format_event_date(date_str: str, event_type: str) -> str: # ------------------------------------------------------------------------------------------- def ensure_datetime(dt: Union[str, datetime.datetime, None]) -> datetime.datetime: if dt is None: - return timeNowTZ() + return timeNowDB() if isinstance(dt, str): return datetime.datetime.fromisoformat(dt) return dt diff --git a/server/initialise.py b/server/initialise.py index e4031088..c16e71ba 100755 --- a/server/initialise.py +++ b/server/initialise.py @@ -12,7 +12,7 @@ import re # Register NetAlertX libraries import conf from const import fullConfPath, applicationPath, fullConfFolder, default_tz -from helper import getBuildTimeStamp, fixPermissions, collect_lang_strings, updateSubnets, isJsonObject, setting_value_to_python_type, timeNowTZ, get_setting_value, generate_random_string +from helper import getBuildTimeStamp, fixPermissions, collect_lang_strings, updateSubnets, isJsonObject, setting_value_to_python_type, timeNowDB, get_setting_value, generate_random_string from app_state import updateState from logger import mylog from api import update_api @@ -392,7 +392,7 @@ def importConfigs (pm, db, all_plugins): # ccd(key, default, config_dir, name, inputtype, options, group, events=None, desc="", setJsonMetadata=None, overrideTemplate=None, forceDefault=False) ccd('VERSION', buildTimestamp , c_d, '_KEEP_', '_KEEP_', '_KEEP_', '_KEEP_', None, "_KEEP_", None, None, True) - write_notification(f'[Upgrade] : App upgraded 🚀 Please clear the cache: