FDMEE Email Alert with Attachment

Hello Experts,

I recently received a request to enable the FDMEE Alert on failure of Data Loads from one of my customer, referred to quite number of Oracle Knowledge Base articles and Support community results for a script that would suffice the need of hour quickly. On interesting note, I could not find such script which is readily available; thus worked on the below script which worked for me and hope this helps you too.

Benefits with this script:Any application Data Load failed will trigger email alert with respective Log file attached for quick reference of the failure reason.

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

#Import Parameters
import com.hyperion.aif.scripting.API as API
import java.sql.DriverManager.getConnection
import smtplib
import string
import os
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from email.Utils import COMMASPACE, formatdate
from email import Encoders
import java.math.BigDecimal as BigDecimal
from datetime import datetime

#Global Variables [Not required to change]
sTargetAppName = fdmContext["TARGETAPPNAME"]
fdmProcessID = fdmContext["LOADID"]
sRuleName = fdmContext["RULENAME"]
sLocName = fdmContext["LOCNAME"]
sPeriod = fdmContext["PERIODNAME"]
sSource = fdmContext["SOURCENAME"]

ProcessID = fdmAPI.getBatchJobDetails(fdmProcessID)
status = fdmAPI.getProcessStates(fdmProcessID)
expStatus = str(status["EXPSTATUS"])
valStatus = str(status["VALSTATUS"])
impStatus = str(status["IMPSTATUS"])

#Status Controls (0 = Failed / Not Started, 1 = Completed)
if str(status["IMPSTATUS"]) == "0":
 try:
 #Customize your needs OR wording of your choice
 sBatchDetails = "============================================================= \n"
 sBatchDetails1 = "Location Name : %s \n" %sLocName
 sBatchDetails2 = "\n"
 sBatchDetails3 = "Period : %s \n" %sPeriod
 sBatchDetails4 = "\n"
 sBatchDetails5 = "Process ID : %s \n" %fdmProcessID
 sBatchDetails6 = "\n"
 sBatchDetails7 = "Rule Executed : %s \n" %sRuleName
 sBatchDetails8 = "\n"
 sBatchDetails9 = "Status : Validation Failed \n" 
 sBatchDetails10 = "\n"
 sBatchDetails11 = "Data Source : %s \n" %sSource
 sBatchDetails12 = "============================================================= \n"
 except e:
 print "Next Step"
elif str(status["VALSTATUS"]) == "0":
 try:
 #Customize your needs OR wording of your choice
 sBatchDetails = "============================================================= \n"
 sBatchDetails1 = "Location Name : %s \n" %sLocName
 sBatchDetails2 = "\n"
 sBatchDetails3 = "Period : %s \n" %sPeriod
 sBatchDetails4 = "\n"
 sBatchDetails5 = "Process ID : %s \n" %fdmProcessID
 sBatchDetails6 = "\n"
 sBatchDetails7 = "Rule Executed : %s \n" %sRuleName
 sBatchDetails8 = "\n"
 sBatchDetails9 = "Status : Validation Failed \n" 
 sBatchDetails10 = "\n"
 sBatchDetails11 = "Data Source : %s \n" %sSource
 sBatchDetails12 = "============================================================= \n"
 except e:
 print "Next Step"

elif str(status["EXPSTATUS"]) == "0":
 try:
 #Customize your needs OR wording of your choice
 sBatchDetails = "============================================================= \n"
 sBatchDetails1 = "Location Name : %s \n" %sLocName
 sBatchDetails2 = "\n"
 sBatchDetails3 = "Period : %s \n" %sPeriod
 sBatchDetails4 = "\n"
 sBatchDetails5 = "Process ID : %s \n" %fdmProcessID
 sBatchDetails6 = "\n"
 sBatchDetails7 = "Rule Executed : %s \n" %sRuleName
 sBatchDetails8 = "\n"
 sBatchDetails9 = "Status : Validation Failed \n" 
 sBatchDetails10 = "\n"
 sBatchDetails11 = "Data Source : %s \n" %sSource
 sBatchDetails12 = "============================================================= \n" 
 except e:
 print "Next Step"

#Email Section
#Subject
#Customize your needs OR wording of your choice
mail_subject = "DEVELOPMENT - FDMEE Load 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]
mail_to = ['hyperion@satyanadh.in','me@satyanadh.in']
mail_cc = ['XXX@YYY.com', 'XXXGroup@yyy.com']


#Body
#Customize your needs OR wording of your choice
mail_txt = "Hi, \n DEVELOPMENT - 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%s\n%s\n \n Regards, \n Hyperion Administrator" %(sBatchDetails, sBatchDetails1,sBatchDetails2,sBatchDetails3,sBatchDetails4,sBatchDetails5,sBatchDetails6,sBatchDetails7,sBatchDetails8,sBatchDetails9,sBatchDetails10,sBatchDetails11,sBatchDetails12)
mail_html = """\
<html>
<head></head>
<body>
<pr>Hi,<br>
Please find below the status for Data Load from DEVELOPMENT Instance <br>
%s <br>
%s <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,sBatchDetails11,sBatchDetails12)

#Mail Consolidate
mail = MIMEMultipart('alternative')
mail['Subject'] = mail_subject
mail['FROM']=mail_sender
mail['To']=", ".join(mail_to)
mail_p1=MIMEText(mail_txt, 'text')
mail_p2=MIMEText(mail_html, 'html')
mail.attach(mail_p1)
mail.attach(mail_p2)

#Attachment
#Change the Directory of your environment location
os.chdir("D:\Oracle\Middleware\user_projects\FDMEE\outbox\logs")
LogFile = "%s_%s.log" %(sTargetAppName, fdmProcessID)
fLog = file(LogFile)
part = MIMEText(fLog.read())
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 = smtplib.login("user", "password")
s.sendmail(mail_sender, mail_to, mail.as_string())
s.quit()
0Shares
Read more