FDMEE Email Alert with Check Report Attached

Hello Experts,

On request from my peers across the world, I wish to share this below solution to get email alerts for Check Reports directly sent to your email as “PDF File” instead of a blank pdf .

I am sure most of you are aware of this process, just in case do keep this handy.

If you have any query, or suggestions drop me a comment to hfm.trainer@gmail.com

#=========================================================================================
# FDMEE Email Alert with PDF Attached for Check Error
# Purpose: To notify user(s) if there is a failure of Check Rule to Any Location in
# FDMEE with respective PDF file attached to email for quick action. 
#
#Author: Satyanadh Kolluri (www.satyanadh.in)
#          Oracle Knowledge Documents
#
#Change Tracker:
#Ticket# Date Change Description
#======= ========== ==============================================================
#
#
#
#
#=========================================================================================

#Global Import
import com.hyperion.aif.scripting.API as API
import smtplib
import os
from email.MIMEMultipart import MIMEMultipart
#Important to read PDF Files MIMEApplication
from email.MIME.Application import MIMEApplication
from email.MIMEText import MIMEText

#FDMEE Convert to Variable
sTargetAppName = fdmContext["TARGETAPPNAME"]
fdmProcessID = fdmContext["LOADID"]
sRuleName = fdmContext["RULENAME"]
sLocName = fdmContext["LOCNAME"]
sPeriod = fdmContext["PERIODNAME"]
sSource = fdmContext["SOURCENAME"]

#FDMEE Process ID Details
ProcessID = fdmAPI.getBatchJobDetails(fdmProcessID)
status = fdmAPI.getProcessStates(fdmProcessID)
expStatus = str(status["EXPSTATUS"])
chkStatus = str(status["CHKSTATUS"])
statusmsg = fdmAPI.getCustomMessage(fdmProcessID)

#Email Output Preparation
global sBatchDetails, sBatchDetails1, sBatchDetails2, sBatchDetails3, sBatchDetails4, sBatchDetails5, sBatchDetails6, sBatchDetails7,  sBatchDetails8, sBatchDetails9, sBatchDetails10
if str(status["EXPSTATUS"]) == "1" and str(status["CHKSTATUS"]) == "0":
    try:
        sBatchDetails = "============================================================= \n"
        sBatchDetails1 = "Location Name : %s \n" % sLocName
        sBatchDetails2 = "Period : %s \n" % sPeriod
        sBatchDetails3 = "Process ID : %s \n" % fdmProcessID
        sBatchDetails4 = "Rule Executed : %s \n" % sRuleName
        sBatchDetails5 = "Data Source %s \n" % sSource
        sBatchDetails6 = "\n"
        sBatchDetails7 = "Status : Check Failed.\n"
        sBatchDetails8 = "\n"
        sBatchDetails9 = "%s \n" % mResults
        sBatchDetails10 = "============================================================= \n"

        #Send Email
        #Subject
        mail_subject = "DEV - FDMEE Check Failed for %s" % (sLocName)

        #Sender [Enter your Sender Email Address]
        mail_sender = "Hyperion_FDMEE@satyanadh.in"

        #To List  [Enter your To List under section mail_to, CC List under mail_cc, if by Application Specific modify Application name else remove elif string]
        if str(sTargetAppName) == "HFMMGMT":
            mail_to = ['hyperion@satyanadh.in']
            mail_cc = ['XXX@YYY.com', 'XXXGroup@yyy.com']
        elif str(sTargetAppName) == "HFMLGL":
            mail_to = ['hyperion@satyanadh.in']
            mail_cc = ['XXX@YYY.com', 'XXXGroup@yyy.com']

        #Body
        mail_txt = "Hi, \n DEV - FDMEE Load Status: %s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n \n Regards, \n Hyperion Administrator" %(sBatchDetails, sBatchDetails1, sBatchDetails2, sBatchDetails3, sBatchDetails4, sBatchDetails5, sBatchDetails6, sBatchDetails7, sBatchDetails8, sBatchDetails9, sBatchDetails10)
        mail_html = """\
        <html>
        <head></head>
        <body>
        <pr>Hi,<br>
        Please find below the status for Data Load from DEV Instance <br>
        %s <br>
        %s <br>
        %s <br>
        %s <br>
        %s <br>
        %s <br>
        %s <br>
        %s <br>
        %s <br>
        %s <br>
        %s <br>
        <br>
        Regards,<br>
        Hyperion Admin <br>
        <br>
        <br>
        Note: This is an Auto Generated Email, please do not reply to this email id.
        </p>
        </body>
        </html>
        """ % (sBatchDetails, sBatchDetails1, sBatchDetails2, sBatchDetails3, sBatchDetails4, sBatchDetails5, sBatchDetails6, sBatchDetails7, sBatchDetails8, sBatchDetails9, sBatchDetails10)

        #Mail Consolidate
        #MIMEMultipart changed from alternative to mixed, this helps in displaying the email output in iPhone / Android in readable format
        mail = MIMEMultipart('mixed')
        mail['Subject'] = mail_subject
        mail['FROM']=mail_sender
        mail['To']=", ".join(mail_to)
        mail_p2=MIMEText(mail_html, 'html', 'utf-8')
        #mail.attach(mail_p1)
        mail.attach(mail_p2)
    
        #Attachment
        os.chdir("D:\Oracle\Middleware\user_projects\HFM1\FDMEE\outbox\reports")
        LogFile = "%s.pdf" % (fdmProcessID)
        fLog = open(LogFile, "rb")
        #Ensures PDF File is not coming as Blank
        part = MIMEApplication(fLog.read(), 'pdf')
        fLog.close()
        part.add_header('Content-Disposition', 'attachment; filename="%s"' % LogFile)
        mail.attach(part)

        #Connection to SMTP
        #Enter SMTP Server Details, In case your server do require authentication modify authentication parameter below and uncomment
        s = smtplib.SMTP("mail.satyanadh.in:25")
        s.sendmail(mail_sender, mail_to+mail_cc, mail.as_string())
        s.quit()

    except e:
        print str(e)



Output of the Email Snapshot:

0Shares

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *