from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import datetime import json import smtplib import socket from base64 import b64encode import subprocess import requests from json2table import convert # pialert modules import conf from const import pialertPath, logPath from database import get_table_as_json from files import write_file from helper import generate_mac_links, isNewVersion, removeDuplicateNewLines, timeNow, hide_email, json_struc, updateState from logger import logResult, mylog, print_log from mqtt import mqtt_start #=============================================================================== # REPORTING #=============================================================================== # create a json for webhook and mqtt notifications to provide further integration options json_final = [] #------------------------------------------------------------------------------- class noti_struc: def __init__(self, json, text, html): self.json = json self.text = text self.html = html #------------------------------------------------------------------------------- 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 = get_table_as_json(db, 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('