from datetime import datetime import demistomock as demisto from CommonServerPython import * def create_html_table(headers, certList, listType): tableBody = "" tableBody += "\t\t

\n\t\t\t\n\t\t\t\tCertificates expiring between 91 and 180 days' + " from today\n\t\t\t\n\t\t

\n" ) elif listType == "good": tableBody += ( ' style="color: #339966;">\n\t\t\t\tCertificates expiring more than 180 days from today' + "\n\t\t\t\n\t\t

\n" ) # Setup table tableBody += '\t\t\n\t\t\t' # Setup table row headers tableBody += '\n\t\t\t\t' tableBody += '' if listType != "expired": tableBody += '\n' else: tableBody += '\n' # Parse table rows from certList for cert in certList: tableBody += '\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t" + "\n\t\t\t\t\n" ) tableBody += "\t\t\t\n\t\t
Site/Domain/IPExpiration DateDays to Expiration
Days Expired
' + cert["Domain"] tableBody += '' + cert["ExpirationDate"] tableBody += ( '' + str(cert["TimeToExpiration"]) + " days
\n" return tableBody def main(): try: emailHTMLBody = "" headers = ("Site", "Expiration Date", "Days to Expiration") good = demisto.get(demisto.context(), "SSLReport.Good") warning = demisto.get(demisto.context(), "SSLReport.Warning") expiring = demisto.get(demisto.context(), "SSLReport.Expiring") expired = demisto.get(demisto.context(), "SSLReport.Expired") # Setup email header emailHTMLBody += ( "\n\t\n\t\t\n\t\n\t\t

\n" + "\t\t\tSSL Certificate Report for " + datetime.today().strftime("%Y/%m/%d") + "\n\t\t

\n" ) # Setup tables if expired: emailHTMLBody += create_html_table(headers, expired, "expired") if expiring: emailHTMLBody += create_html_table(headers, expiring, "expiring") if warning: emailHTMLBody += create_html_table(headers, warning, "warning") if good: emailHTMLBody += create_html_table(headers, good, "good") emailHTMLBody += "\t\n" demisto.setContext("SSLReport.HTML", emailHTMLBody) except Exception as ex: return_error(f"An Error occured: {ex}", error=ex) if __name__ in ("__main__", "__builtin__", "builtins"): main()