From f70a3a420786c10cf78822bb8e4bb53b50b1ccd9 Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Tue, 31 Jan 2023 23:55:15 +1100 Subject: [PATCH] Rework of notification templates 0.5 --- back/pialert.py | 19 ++++++++++++------- back/report_template.txt | 3 +++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/back/pialert.py b/back/pialert.py index 77d8083a..6931e3db 100755 --- a/back/pialert.py +++ b/back/pialert.py @@ -2242,12 +2242,16 @@ def send_notifications (): mail_text = mail_text.replace ('', notiStruc.text + '\n') mail_html = mail_html.replace ('', notiStruc.html) - if 'ports' in INCLUDED_SECTIONS and changedPorts_json_struc is not None: - json_ports = changedPorts_json_struc.json["data"] + if 'ports' in INCLUDED_SECTIONS: + # collect "ports" for the webhook json + if changedPorts_json_struc is not None: + json_ports = changedPorts_json_struc.json["data"] - notiStruc = construct_notifications("", "Events", True, changedPorts_json_struc) + notiStruc = construct_notifications("", "Ports", True, changedPorts_json_struc) mail_html = mail_html.replace ('', notiStruc.html) + # mail_text = mail_text.replace ('', notiStruc.text + '\n') + mail_text = mail_text.replace ('', "Ports changed! Check PiAlert for details!" + '\n') json_final = { "internet": json_internet, @@ -2330,6 +2334,9 @@ def send_notifications (): #------------------------------------------------------------------------------- def construct_notifications(sqlQuery, tableTitle, skipText = False, suppliedJsonStruct = None): + if suppliedJsonStruct is None and sqlQuery == "": + return noti_struc("", "", "") + table_attributes = {"style" : "border-collapse: collapse; font-size: 12px; color:#70707", "width" : "100%", "cellspacing" : 0, "cellpadding" : "3px", "bordercolor" : "#C0C0C0", "border":"1"} headerProps = "width='120px' style='color:blue; font-size: 16px;' bgcolor='#909090' " thProps = "width='120px' style='color:#F0F0F0' bgcolor='#909090' " @@ -2337,10 +2344,10 @@ def construct_notifications(sqlQuery, tableTitle, skipText = False, suppliedJson build_direction = "TOP_TO_BOTTOM" text_line = '{}\t{}\n' - if sqlQuery != "": + if suppliedJsonStruct is None: json_struc = get_table_as_json(sqlQuery) else: - json_struc = suppliedJson + json_struc = suppliedJsonStruct json = json_struc.json html = "" @@ -3426,8 +3433,6 @@ class serviceSchedule: return result - # print("Hello my name is " + self.scheduleObject) - #=============================================================================== # BEGIN #=============================================================================== diff --git a/back/report_template.txt b/back/report_template.txt index 9d161ec0..91f94052 100755 --- a/back/report_template.txt +++ b/back/report_template.txt @@ -13,3 +13,6 @@ Events Internet ---------------------- +Ports +---------------------- +