import datetime import json import socket import subprocess import requests from json2table import convert # pialert modules import conf from const import pialertPath, logPath, apiPath from helper import noti_struc, generate_mac_links, removeDuplicateNewLines, timeNow, hide_email, updateState, get_file_content, write_file from logger import logResult, mylog, print_log from publishers.email import (check_config as email_check_config, send as send_email ) from publishers.ntfy import (check_config as ntfy_check_config, send as send_ntfy ) from publishers.apprise import (check_config as apprise_check_config, send as send_apprise) from publishers.webhook import (check_config as webhook_check_config, send as send_webhook) from publishers.pushsafer import (check_config as pushsafer_check_config, send as send_pushsafer) from publishers.mqtt import (check_config as mqtt_check_config, mqtt_start ) #=============================================================================== # REPORTING #=============================================================================== # create a json for webhook and mqtt notifications to provide further integration options json_final = [] #------------------------------------------------------------------------------- def construct_notifications(db, 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' " build_direction = "TOP_TO_BOTTOM" text_line = '{}\t{}\n' if suppliedJsonStruct is None: json_struc = db.get_table_as_json(sqlQuery) else: json_struc = suppliedJsonStruct jsn = json_struc.json html = "" text = "" if len(jsn["data"]) > 0: text = tableTitle + "\n---------\n" html = convert(jsn, build_direction=build_direction, table_attributes=table_attributes) html = format_table(html, "data", headerProps, tableTitle).replace('