mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-07 02:31:27 -07:00
BE: link to server in reports #1267
Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
@@ -20,11 +20,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td height=200 valign=top style="padding: 10px">
|
<td height=200 valign=top style="padding: 10px">
|
||||||
<NEW_DEVICES_TABLE>
|
NEW_DEVICES_TABLE
|
||||||
<DOWN_DEVICES_TABLE>
|
DOWN_DEVICES_TABLE
|
||||||
<DOWN_RECONNECTED_TABLE>
|
DOWN_RECONNECTED_TABLE
|
||||||
<EVENTS_TABLE>
|
EVENTS_TABLE
|
||||||
<PLUGINS_TABLE>
|
PLUGINS_TABLE
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -34,11 +34,11 @@
|
|||||||
<table width=100% bgcolor=#3c8dbc cellpadding=5px cellspacing=0 style="font-size: 10px; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px;">
|
<table width=100% bgcolor=#3c8dbc cellpadding=5px cellspacing=0 style="font-size: 10px; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px;">
|
||||||
<tr>
|
<tr>
|
||||||
<td width=50% style="text-align:center;color: white;" bgcolor="#3c8dbc">
|
<td width=50% style="text-align:center;color: white;" bgcolor="#3c8dbc">
|
||||||
<NEW_VERSION>
|
NEW_VERSION
|
||||||
| Sent: <REPORT_DATE>
|
| Sent: REPORT_DATE
|
||||||
| Server: <SERVER_NAME>
|
| Server: <a href="REPORT_DASHBOARD_URL" target="_blank" style="color:#ffffff;">SERVER_NAME</a>
|
||||||
| Built: <BUILD_DATE>
|
| Built: BUILD_DATE
|
||||||
| Version: <BUILD_VERSION>
|
| Version: BUILD_VERSION
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
<NEW_DEVICES_TABLE>
|
NEW_DEVICES_TABLE
|
||||||
<DOWN_DEVICES_TABLE>
|
DOWN_DEVICES_TABLE
|
||||||
<DOWN_RECONNECTED_TABLE>
|
DOWN_RECONNECTED_TABLE
|
||||||
<EVENTS_TABLE>
|
EVENTS_TABLE
|
||||||
<PLUGINS_TABLE>
|
PLUGINS_TABLE
|
||||||
|
|
||||||
Report Date: <REPORT_DATE>
|
Report Date: REPORT_DATE
|
||||||
Server: <SERVER_NAME>
|
Server: SERVER_NAME
|
||||||
<NEW_VERSION>
|
Link: REPORT_DASHBOARD_URL
|
||||||
|
NEW_VERSION
|
||||||
@@ -14,6 +14,7 @@ from helper import (
|
|||||||
removeDuplicateNewLines,
|
removeDuplicateNewLines,
|
||||||
write_file,
|
write_file,
|
||||||
get_setting_value,
|
get_setting_value,
|
||||||
|
getBuildTimeStampAndVersion,
|
||||||
)
|
)
|
||||||
from messaging.in_app import write_notification
|
from messaging.in_app import write_notification
|
||||||
from utils.datetime_utils import timeNowDB, get_timezone_offset
|
from utils.datetime_utils import timeNowDB, get_timezone_offset
|
||||||
@@ -25,6 +26,7 @@ from utils.datetime_utils import timeNowDB, get_timezone_offset
|
|||||||
class NotificationInstance:
|
class NotificationInstance:
|
||||||
def __init__(self, db):
|
def __init__(self, db):
|
||||||
self.db = db
|
self.db = db
|
||||||
|
self.serverUrl = get_setting_value("REPORT_DASHBOARD_URL")
|
||||||
|
|
||||||
# Create Notifications table if missing
|
# Create Notifications table if missing
|
||||||
self.db.sql.execute("""CREATE TABLE IF NOT EXISTS "Notifications" (
|
self.db.sql.execute("""CREATE TABLE IF NOT EXISTS "Notifications" (
|
||||||
@@ -108,83 +110,71 @@ class NotificationInstance:
|
|||||||
if conf.newVersionAvailable:
|
if conf.newVersionAvailable:
|
||||||
newVersionText = "🚀A new version is available."
|
newVersionText = "🚀A new version is available."
|
||||||
|
|
||||||
mail_text = mail_text.replace("<NEW_VERSION>", newVersionText)
|
mail_text = mail_text.replace("NEW_VERSION", newVersionText)
|
||||||
mail_html = mail_html.replace("<NEW_VERSION>", newVersionText)
|
mail_html = mail_html.replace("NEW_VERSION", newVersionText)
|
||||||
|
|
||||||
# Report "REPORT_DATE" in Header & footer
|
# Report "REPORT_DATE" in Header & footer
|
||||||
timeFormated = timeNowDB()
|
timeFormated = timeNowDB()
|
||||||
mail_text = mail_text.replace('<REPORT_DATE>', timeFormated)
|
mail_text = mail_text.replace("REPORT_DATE", timeFormated)
|
||||||
mail_html = mail_html.replace('<REPORT_DATE>', timeFormated)
|
mail_html = mail_html.replace("REPORT_DATE", timeFormated)
|
||||||
|
|
||||||
# Report "SERVER_NAME" in Header & footer
|
# Report "SERVER_NAME" in Header & footer
|
||||||
mail_text = mail_text.replace("<SERVER_NAME>", socket.gethostname())
|
mail_text = mail_text.replace("SERVER_NAME", socket.gethostname())
|
||||||
mail_html = mail_html.replace("<SERVER_NAME>", socket.gethostname())
|
mail_html = mail_html.replace("SERVER_NAME", socket.gethostname())
|
||||||
|
|
||||||
# Report "VERSION" in Header & footer
|
# Report "VERSION" in Header & footer
|
||||||
try:
|
buildTimestamp, newBuildVersion = getBuildTimeStampAndVersion()
|
||||||
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"
|
|
||||||
|
|
||||||
mail_text = mail_text.replace("<BUILD_VERSION>", VERSIONFILE)
|
mail_text = mail_text.replace("BUILD_VERSION", newBuildVersion)
|
||||||
mail_html = mail_html.replace("<BUILD_VERSION>", VERSIONFILE)
|
mail_html = mail_html.replace("BUILD_VERSION", newBuildVersion)
|
||||||
|
|
||||||
# Report "BUILD" in Header & footer
|
# Report "BUILD" in Header & footer
|
||||||
try:
|
mail_text = mail_text.replace("BUILD_DATE", str(buildTimestamp))
|
||||||
BUILDFILE = subprocess.check_output(
|
mail_html = mail_html.replace("BUILD_DATE", str(buildTimestamp))
|
||||||
["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>", BUILDFILE)
|
# Report "REPORT_DASHBOARD_URL" in footer
|
||||||
mail_html = mail_html.replace("<BUILD_DATE>", BUILDFILE)
|
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
|
# Start generating the TEXT & HTML notification messages
|
||||||
# new_devices
|
# new_devices
|
||||||
# ---
|
# ---
|
||||||
html, text = construct_notifications(self.JSON, "new_devices")
|
html, text = construct_notifications(self.JSON, "new_devices")
|
||||||
|
|
||||||
mail_text = mail_text.replace("<NEW_DEVICES_TABLE>", text + "\n")
|
mail_text = mail_text.replace("NEW_DEVICES_TABLE", text + "\n")
|
||||||
mail_html = mail_html.replace("<NEW_DEVICES_TABLE>", html)
|
mail_html = mail_html.replace("NEW_DEVICES_TABLE", html)
|
||||||
mylog("verbose", ["[Notification] New Devices sections done."])
|
mylog("verbose", ["[Notification] New Devices sections done."])
|
||||||
|
|
||||||
# down_devices
|
# down_devices
|
||||||
# ---
|
# ---
|
||||||
html, text = construct_notifications(self.JSON, "down_devices")
|
html, text = construct_notifications(self.JSON, "down_devices")
|
||||||
|
|
||||||
mail_text = mail_text.replace("<DOWN_DEVICES_TABLE>", text + "\n")
|
mail_text = mail_text.replace("DOWN_DEVICES_TABLE", text + "\n")
|
||||||
mail_html = mail_html.replace("<DOWN_DEVICES_TABLE>", html)
|
mail_html = mail_html.replace("DOWN_DEVICES_TABLE", html)
|
||||||
mylog("verbose", ["[Notification] Down Devices sections done."])
|
mylog("verbose", ["[Notification] Down Devices sections done."])
|
||||||
|
|
||||||
# down_reconnected
|
# down_reconnected
|
||||||
# ---
|
# ---
|
||||||
html, text = construct_notifications(self.JSON, "down_reconnected")
|
html, text = construct_notifications(self.JSON, "down_reconnected")
|
||||||
|
|
||||||
mail_text = mail_text.replace("<DOWN_RECONNECTED_TABLE>", text + "\n")
|
mail_text = mail_text.replace("DOWN_RECONNECTED_TABLE", text + "\n")
|
||||||
mail_html = mail_html.replace("<DOWN_RECONNECTED_TABLE>", html)
|
mail_html = mail_html.replace("DOWN_RECONNECTED_TABLE", html)
|
||||||
mylog("verbose", ["[Notification] Reconnected Down Devices sections done."])
|
mylog("verbose", ["[Notification] Reconnected Down Devices sections done."])
|
||||||
|
|
||||||
# events
|
# events
|
||||||
# ---
|
# ---
|
||||||
html, text = construct_notifications(self.JSON, "events")
|
html, text = construct_notifications(self.JSON, "events")
|
||||||
|
|
||||||
mail_text = mail_text.replace("<EVENTS_TABLE>", text + "\n")
|
mail_text = mail_text.replace("EVENTS_TABLE", text + "\n")
|
||||||
mail_html = mail_html.replace("<EVENTS_TABLE>", html)
|
mail_html = mail_html.replace("EVENTS_TABLE", html)
|
||||||
mylog("verbose", ["[Notification] Events sections done."])
|
mylog("verbose", ["[Notification] Events sections done."])
|
||||||
|
|
||||||
# plugins
|
# plugins
|
||||||
# ---
|
# ---
|
||||||
html, text = construct_notifications(self.JSON, "plugins")
|
html, text = construct_notifications(self.JSON, "plugins")
|
||||||
|
|
||||||
mail_text = mail_text.replace("<PLUGINS_TABLE>", text + "\n")
|
mail_text = mail_text.replace("PLUGINS_TABLE", text + "\n")
|
||||||
mail_html = mail_html.replace("<PLUGINS_TABLE>", html)
|
mail_html = mail_html.replace("PLUGINS_TABLE", html)
|
||||||
|
|
||||||
mylog("verbose", ["[Notification] Plugins sections done."])
|
mylog("verbose", ["[Notification] Plugins sections done."])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user