From b659a0f06dcbfdea7676daf6b523a122b69328e9 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Tue, 11 Nov 2025 23:09:28 +1100 Subject: [PATCH] BE: link to server in reports #1267 Signed-off-by: jokob-sk --- front/report_templates/report_template.html | 20 +++---- front/report_templates/report_template.txt | 17 +++--- server/models/notification_instance.py | 62 +++++++++------------ 3 files changed, 45 insertions(+), 54 deletions(-) diff --git a/front/report_templates/report_template.html b/front/report_templates/report_template.html index 7be350b5..2ee21506 100755 --- a/front/report_templates/report_template.html +++ b/front/report_templates/report_template.html @@ -20,11 +20,11 @@ - - - - - + NEW_DEVICES_TABLE + DOWN_DEVICES_TABLE + DOWN_RECONNECTED_TABLE + EVENTS_TABLE + PLUGINS_TABLE @@ -34,11 +34,11 @@
- - | Sent: - | Server: - | Built: - | Version: + NEW_VERSION + | Sent: REPORT_DATE + | Server: SERVER_NAME + | Built: BUILD_DATE + | Version: BUILD_VERSION
diff --git a/front/report_templates/report_template.txt b/front/report_templates/report_template.txt index 8be4447b..c0fabe6f 100755 --- a/front/report_templates/report_template.txt +++ b/front/report_templates/report_template.txt @@ -1,9 +1,10 @@ - - - - - +NEW_DEVICES_TABLE +DOWN_DEVICES_TABLE +DOWN_RECONNECTED_TABLE +EVENTS_TABLE +PLUGINS_TABLE -Report Date: -Server: - \ No newline at end of file +Report Date: REPORT_DATE +Server: SERVER_NAME +Link: REPORT_DASHBOARD_URL +NEW_VERSION \ No newline at end of file diff --git a/server/models/notification_instance.py b/server/models/notification_instance.py index 09c78efd..c4367c67 100755 --- a/server/models/notification_instance.py +++ b/server/models/notification_instance.py @@ -14,6 +14,7 @@ from helper import ( removeDuplicateNewLines, write_file, get_setting_value, + getBuildTimeStampAndVersion, ) from messaging.in_app import write_notification from utils.datetime_utils import timeNowDB, get_timezone_offset @@ -25,6 +26,7 @@ from utils.datetime_utils import timeNowDB, get_timezone_offset class NotificationInstance: def __init__(self, db): self.db = db + self.serverUrl = get_setting_value("REPORT_DASHBOARD_URL") # Create Notifications table if missing self.db.sql.execute("""CREATE TABLE IF NOT EXISTS "Notifications" ( @@ -108,83 +110,71 @@ class NotificationInstance: if conf.newVersionAvailable: newVersionText = "🚀A new version is available." - mail_text = mail_text.replace("", newVersionText) - mail_html = mail_html.replace("", newVersionText) + mail_text = mail_text.replace("NEW_VERSION", newVersionText) + mail_html = mail_html.replace("NEW_VERSION", newVersionText) # Report "REPORT_DATE" in Header & footer timeFormated = timeNowDB() - mail_text = mail_text.replace('', timeFormated) - mail_html = mail_html.replace('', timeFormated) + mail_text = mail_text.replace("REPORT_DATE", timeFormated) + mail_html = mail_html.replace("REPORT_DATE", timeFormated) # Report "SERVER_NAME" in Header & footer - mail_text = mail_text.replace("", socket.gethostname()) - mail_html = mail_html.replace("", socket.gethostname()) + mail_text = mail_text.replace("SERVER_NAME", socket.gethostname()) + mail_html = mail_html.replace("SERVER_NAME", socket.gethostname()) # Report "VERSION" in Header & footer - try: - VERSIONFILE = subprocess.check_output( - ["php", applicationPath + "/front/php/templates/version.php"], - timeout=5, - ).decode("utf-8") - except Exception as e: - mylog("debug", [f"[Notification] Unable to read version.php: {e}"]) - VERSIONFILE = "unknown" + buildTimestamp, newBuildVersion = getBuildTimeStampAndVersion() - mail_text = mail_text.replace("", VERSIONFILE) - mail_html = mail_html.replace("", VERSIONFILE) + mail_text = mail_text.replace("BUILD_VERSION", newBuildVersion) + mail_html = mail_html.replace("BUILD_VERSION", newBuildVersion) # Report "BUILD" in Header & footer - try: - BUILDFILE = subprocess.check_output( - ["php", applicationPath + "/front/php/templates/build.php"], - timeout=5, - ).decode("utf-8") - except Exception as e: - mylog("debug", [f"[Notification] Unable to read build.php: {e}"]) - BUILDFILE = "unknown" + mail_text = mail_text.replace("BUILD_DATE", str(buildTimestamp)) + mail_html = mail_html.replace("BUILD_DATE", str(buildTimestamp)) - mail_text = mail_text.replace("", BUILDFILE) - mail_html = mail_html.replace("", BUILDFILE) + # Report "REPORT_DASHBOARD_URL" in footer + mail_text = mail_text.replace("REPORT_DASHBOARD_URL", self.serverUrl) + mail_html = mail_html.replace("REPORT_DASHBOARD_URL", self.serverUrl) # Start generating the TEXT & HTML notification messages # new_devices # --- html, text = construct_notifications(self.JSON, "new_devices") - mail_text = mail_text.replace("", text + "\n") - mail_html = mail_html.replace("", html) + mail_text = mail_text.replace("NEW_DEVICES_TABLE", text + "\n") + mail_html = mail_html.replace("NEW_DEVICES_TABLE", html) mylog("verbose", ["[Notification] New Devices sections done."]) # down_devices # --- html, text = construct_notifications(self.JSON, "down_devices") - mail_text = mail_text.replace("", text + "\n") - mail_html = mail_html.replace("", html) + mail_text = mail_text.replace("DOWN_DEVICES_TABLE", text + "\n") + mail_html = mail_html.replace("DOWN_DEVICES_TABLE", html) mylog("verbose", ["[Notification] Down Devices sections done."]) # down_reconnected # --- html, text = construct_notifications(self.JSON, "down_reconnected") - mail_text = mail_text.replace("", text + "\n") - mail_html = mail_html.replace("", html) + mail_text = mail_text.replace("DOWN_RECONNECTED_TABLE", text + "\n") + mail_html = mail_html.replace("DOWN_RECONNECTED_TABLE", html) mylog("verbose", ["[Notification] Reconnected Down Devices sections done."]) # events # --- html, text = construct_notifications(self.JSON, "events") - mail_text = mail_text.replace("", text + "\n") - mail_html = mail_html.replace("", html) + mail_text = mail_text.replace("EVENTS_TABLE", text + "\n") + mail_html = mail_html.replace("EVENTS_TABLE", html) mylog("verbose", ["[Notification] Events sections done."]) # plugins # --- html, text = construct_notifications(self.JSON, "plugins") - mail_text = mail_text.replace("", text + "\n") - mail_html = mail_html.replace("", html) + mail_text = mail_text.replace("PLUGINS_TABLE", text + "\n") + mail_html = mail_html.replace("PLUGINS_TABLE", html) mylog("verbose", ["[Notification] Plugins sections done."])