BefValidate
if fdmContext["LOCNAME"] == "HFM_TB_DATA_J_D" or "HFM_CASH_CUR" or "HFM_BS_DATA_A_M" or "HFM_TB_DATA_A_M":
query = "UPDATE tdataseg SET ICPX = '[ICP None]' WHERE (ICP IS NULL or ICP=' ' or ICP = '') and loadid = ?"
params = [ fdmContext["LOADID"] ]
print fdmAPI.executeDML(query, params, False)
fdmAPI.commitTransaction()
AftValidate
#********************************************************************************
strStep = "VALIDATE"
strFlag = "a"
strBanner = " ***** "
strPart = "after "
strEnv = "EXA_EXA"
strApp = "XHFM"
strEmailDelimiter = ","
strUserID = ""
strPW = ""
UpperPasslimit = 1.5
LowerPassLimit = -1.5
ACCOUNTLIST = "'1120201K','1120301K','1120302K','1240401K','2123701K','2140101K','2210501K','4100101K','4100103K','4100106K','4100107K','4100108K','4100109K','4100110K','4110101K','4110102K','4110103K','4110104K','4110105K','5211701K','5211703K','5220401K','5220406K'"
EntityList = "'CL999','HQ110','HQ110_USD','US999'"
#********************************************************************************
import os
import shutil
import time
#********************************************************************************
#----------------------------------------------Email Send ---------------------------------------------------------------------------------------
def SendEmail (strServer, strUserID, strPW, strSender, strReceivers, strSubject, strBody, strAttachment1, strAttachment2, strAttachment3, strAttachment4):
import smtplib
#import email.mime.application
from email.mime.application import MIMEApplication
from email.MIMEMultipart import MIMEMultipart
from email.mime.text import MIMEText
strMessage = ""
strMessage = strMessage + strServer + "\n"
strMessage = strMessage + strSender + "\n"
strMessage = strMessage + strReceivers + "\n"
strMessage = strMessage + strUserID + "\n"
strMessage = strMessage + strPW + "\n"
strMessage = strMessage + strSubject + "\n"
strMessage = strMessage + strBody + "\n"
strMessage = strMessage + strAttachment1 + "\n"
strMessage = strMessage + strAttachment2 + "\n"
EmailMessage = MIMEMultipart()
EmailMessage['Subject'] = strSubject
EmailMessage['From'] = strSender
EmailMessage['To'] = strReceivers
part = MIMEText(strBody, 'plain')
EmailMessage.attach(part)
if strAttachment1 != "":
try:
strFilename1 = strAttachment1.split('/')[-1]
strAttach1 = "attachment; filename=" + strFilename1
part = MIMEApplication(open(strAttachment1,"rb").read())
part.add_header('Content-Disposition', strAttach1)
EmailMessage.attach(part)
except Exception, e:
strMessage = strMessage + "Email Attachment1 Error: " + str(e) + "\n"
if strAttachment2 != "":
try:
strFilename2 = strAttachment2.split('/')[-1]
strAttach2 = "attachment; filename=" + strFilename2
part = MIMEApplication(open(strAttachment2,"rb").read())
part.add_header('Content-Disposition', strAttach2)
EmailMessage.attach(part)
except Exception, e:
strMessage = strMessage + "Email Attachment2 Error: " + str(e) + "\n"
if strAttachment3 != "":
try:
strFilename3 = strAttachment3.split('/')[-1]
strAttach3 = "attachment; filename=" + strFilename3
part = MIMEApplication(open(strAttachment3,"rb").read())
part.add_header('Content-Disposition', strAttach3)
EmailMessage.attach(part)
except Exception, e:
strMessage = strMessage + "Email Attachment3 Error: " + str(e) + "\n"
if strAttachment4 != "":
try:
strFilename4 = strAttachment4.split('/')[-1]
strAttach4 = "attachment; filename=" + strFilename4
part = MIMEApplication(open(strAttachment4,"rb").read())
part.add_header('Content-Disposition', strAttach4)
EmailMessage.attach(part)
except Exception, e:
strMessage = strMessage + "Email Attachment4 Error: " + str(e) + "\n"
try:
smtpServer = smtplib.SMTP (strServer, 25)
strMessage = strMessage + "OK "
except Exception, e:
strMessage = strMessage + "Email (smtplib.SMTP) Error: " + str(e) + "\n"
try:
smtpServer.set_debuglevel(1)
smtpServer.ehlo()
smtpServer.starttls()
strMessage = strMessage + "OK "
except Exception, e:
strMessage = strMessage + "Email (smtpServer.ehlo, smtpServer.starttls) Error: " + str(e) + "\n"
try:
smtpServer.login(strUserID, strPW)
except Exception, e:
strMessage = strMessage + "Email (smtpServer.login) Error: " + str(e) + "\n"
try:
smtpServer.sendmail(strSender, strReceivers.split(","), EmailMessage.as_string())
strMessage = "Successfully sent Email"
smtpServer.quit()
strMessage = strMessage + "OK "
except Exception, e:
strMessage = strMessage + "Email (smtpServer.sendmail) Error: " + str(e) + "\n"
return strMessage
#---------------------------------------------Email End ----------------------------------------------------------------------------------------
#********************************************************************************
def writeToFile(strPath, strFile, strBuf, strFlag):
strFilePath = strPath + strFile
objFile = open(strFilePath, strFlag)
objFile.write(strBuf + "\n")
objFile.close()
return "ok"
#********************************************************************************
def getLocOption (strOptionNumber, Loc_rs, Rule_rs):
strOption = ""
try:
strTemp = str(Loc_rs.next())
strLocOption = str(Loc_rs.getString ("partIntgConfig" + strOptionNumber))
strTemp = str(Rule_rs.next())
strRuleOption = str(Rule_rs.getString ("RULE_ATTR" + strOptionNumber))
except Exception, e:
strOption + "ERROR " + str(e) + "\n"
strOption = strLocOption
if strRuleOption != "None": strOption = strRuleOption
return strOption
#********************************************************************************
def getLocOptionList (Loc_rs, Rule_rs):
strOptions = ""
try:
strTemp = str(Loc_rs.next())
strLocOption1 = str(Loc_rs.getString ("partIntgConfig1"))
strLocOption2 = str(Loc_rs.getString ("partIntgConfig2"))
strLocOption3 = str(Loc_rs.getString ("partIntgConfig3"))
strLocOption4 = str(Loc_rs.getString ("partIntgConfig4"))
strTemp = str(Rule_rs.next())
strRuleOption1 = str(Rule_rs.getString ("RULE_ATTR1"))
strRuleOption2 = str(Rule_rs.getString ("RULE_ATTR2"))
strRuleOption3 = str(Rule_rs.getString ("RULE_ATTR3"))
strRuleOption4 = str(Rule_rs.getString ("RULE_ATTR4"))
if strRuleOption1 != "None": strLocOption1 = strRuleOption1
if strRuleOption2 != "None": strLocOption2 = strRuleOption2
if strRuleOption3 != "None": strLocOption3 = strRuleOption3
if strRuleOption4 != "None": strLocOption4 = strRuleOption4
strOptions = strLocOption1 + "," + strLocOption2 + "," + strLocOption3 + "," + strLocOption4
except Exception, e:
strOptions = "\nERROR " + str(e) + "\n"
return strOptions
#********************************************************************************
def setOptionFlag (strOptionList, strSearchString):
strOptionList = "," + strOptionList + ","
strSearchString = "," + strSearchString + ","
if strOptionList.find (strSearchString) >= 0:
bExists = True
else:
bExists = False
return bExists
def GetEmailAddresses (strOptionList, strSearchString):
strOptionList = "," + strOptionList + ","
returnStr = ""
Count = 0
for strInBuf in strOptionList.split(","):
if strInBuf.find (strSearchString) >= 0:
if Count ==0:
returnStr = strInBuf
Count = Count +1
else:
returnStr = returnStr +"," + strInBuf
else:
bExists = False
return returnStr
#********************************************************************************
def GetPOV_Filename (strLoc, strCat, strPer, strExt, strDelimiter):
return strLoc + strDelimiter + strCat + strDelimiter + strPer + "." + strExt
#********************************************************************************
def AppendToFile(strSourceFilePath, strTargetFilePath, strReplace, strDelimiter, strFlag):
try:
objFile1 = open(strSourceFilePath)
objFile2 = open(strTargetFilePath, strFlag)
strList = objFile1.readlines()
for strInBuf in strList:
strOutBuf = strInBuf
if strReplace != "" :
strArray = strInBuf.split (strDelimiter)
strArray [len(strArray)-1] = strReplace + "\n"
strOutBuf = strDelimiter.join(strArray)
bWrite = True
if len(strArray) == 1:bWrite = False
if bWrite == True:objFile2.write(strOutBuf)
objFile1.close()
objFile2.close()
strMessage = "OK"
except Exception, e:
strMessage = "Error: " + str(e)
return strMessage
#********************************************************************************
strMessage = ""
strLoc = fdmContext ["LOCNAME"]
strCat = fdmContext["CATNAME"]
strPer = fdmContext["PERIODNAME"]
strLogPath = fdmContext["OUTBOXDIR"] + "/status/"
strLogFile = strLoc + "_" + strCat + "_" + strPer + ".log"
strTime = time.strftime ('%Y-%m-%d %H:%M:%S', time.localtime())
strBuf = strBanner + strStep + " " + strPart + " " + strTime + strBanner + ""
strLogFile = strLoc + "_" + strCat + "_" + strPer + ".log"
rc = writeToFile(strLogPath, strLogFile, strBuf, strFlag)
#------------------------------------------------------------------------------------------------------------------------
try:
strLoadID = str(fdmContext ["LOADID"])
strLoc = fdmContext ["LOCNAME"]
strCat = fdmContext["CATNAME"]
strPer = fdmContext["PERIODNAME"]
strRule = fdmContext["RULENAME"]
strAppName = fdmContext["TARGETAPPNAME"]
#strFilename = strAppName + "_" + strLoadID + ".dat"
states = fdmAPI.getProcessStates(fdmContext["LOADID"])
strStatus = str(states["PROCESSSTATUS"])
strLogPath = fdmContext["OUTBOXDIR"] + "/status/"
strLogFile = strLoc + "_" + strCat + "_" + strPer + ".log"
strLogFilePath = strLogPath + strLogFile
except Exception, e:
rc = writeToFile(strLogPath, strLogFile, "ERROR " + str(e) + "\n", strFlag)
#------------------------------------------------------------------------------------------------------------------------
strBuf = "********************************************************************************\n"
rc = writeToFile(strLogPath, strLogFile, strBuf, strFlag)
strBuf = strStep + " - " + strLoc + " " + strCat + " " + strPer
strFlag = "a"
rc = writeToFile(strLogPath, strLogFile, strBuf, strFlag)
rc = writeToFile(strLogPath, strLogFile, "LOADID=" + strLoadID, strFlag)
rc = writeToFile(strLogPath, strLogFile, "LOC=" + strLoc, strFlag)
rc = writeToFile(strLogPath, strLogFile, "CAT=" + strCat, strFlag)
rc = writeToFile(strLogPath, strLogFile, "PER=" + strPer, strFlag)
rc = writeToFile(strLogPath, strLogFile, "APPNAME=" + strAppName, strFlag)
#rc = writeToFile(strLogPath, strLogFile, "FILENAME=" + strFilename, strFlag)
rc = writeToFile(strLogPath, strLogFile, "STATUS=" + strStatus + "\n", strFlag)
#------------------------------------------------------------------------------------------------------------------------
try:
strOptionList = getLocOptionList (fdmAPI.getLocationDetails (fdmContext["LOCKEY"]), fdmAPI.getRuleDetails (fdmContext["RULEID"]))
rc = writeToFile(strLogPath, strLogFile, "OPTIONS=" + strOptionList, strFlag)
except Exception, e:
rc = writeToFile(strLogPath, strLogFile, "ERROR " + str(e) + "\n", strFlag)
strKeyword = "EMAIL"
bEmail = setOptionFlag (strOptionList, strKeyword)
rc = writeToFile(strLogPath, strLogFile, strKeyword + "=" + str(bEmail), strFlag)
strKeyword = "DEBUG"
bDebug = setOptionFlag (strOptionList, strKeyword)
rc = writeToFile(strLogPath, strLogFile, strKeyword + "=" + str(bDebug), strFlag)
rc = writeToFile(strLogPath, strLogFile, "", strFlag)
#------------------------------------------------------------------------------------------------------------------------
UstrLoadID = str(fdmContext ["LOADID"])
UstrProcessID = str(fdmContext ["PROCESSID"])
UstrLoc = fdmContext ["LOCNAME"]
UstrLocKey = fdmContext ["LOCKEY"]
UstrCat = fdmContext["CATNAME"]
UstrCatKey = fdmContext["CATKEY"]
UstrPer = fdmContext["PERIODNAME"]
UstrPeriodKey = fdmContext["PERIODKEY"]
UstrRule = fdmContext["RULEID"]
UstrAppName = fdmContext["TARGETAPPNAME"]
UstroutboxPath = fdmContext["OUTBOXDIR"]+"/Xhfm/"
#-----------------------------------------------------------------EMail Parameter-------------------------------------------
UstrSMTPServer = "X.X.COM"
UiSMTPPort = 25
UstrSender = "[email protected]"
UstrHFMPOV = fdmContext["LOCNAME"] + "-" + fdmContext["CATNAME"] + "-" + fdmContext["PERIODNAME"]+ "- RULE NAME " + fdmContext["RULENAME"] + " "
UstrUserID = ""
UstrPW = ""
UstrSubject = strEnv + " Validation Failure for POV " + UstrHFMPOV + time.asctime()
UstrBody = "HFM Validation is failed due to the following errors: "+'\n'
UstrAttachment1 = ""
UstrAttachment2 = ""
UstrAttachment3 = ""
UstrAttachment4 = ""
#---------------------------------------------------------------------------------------------------------------------------
strLogFile = strLoc + "_" + strCat + "_" + strPer + ".log"
strLogPath = fdmContext["OUTBOXDIR"] + "/status/"
strFlag = "a"
strBuf = str(UstrLocKey) + str(UstrCatKey)+str(UstrPeriodKey)
rc = writeToFile(strLogPath, strLogFile, strBuf, strFlag)
ustrDateParam = "to_date('" + str(UstrPeriodKey) + "', 'YYYY-MM-DD') "
SuspenseCount = 0
ErrStatus = 0
strSqlLE = "Select Entity AS SRC_LE,sum(Amount)as DataSum from TdataSeg where ENTITY NOT IN (" + str(EntityList) + ") AND ACCOUNTX NOT IN (" + str(ACCOUNTLIST) + ") AND UD6X NOT IN ('IGNORE') AND PARTITIONKEY = " + str(UstrLocKey) + " AND CATKEY = " + str(UstrCatKey) + " AND PERIODKEY = " + ustrDateParam + " AND RULE_ID = " + str(UstrRule) + " And LOADID = " + UstrLoadID + " Group By Entity having (sum(Amount) > " + str(UpperPasslimit) + " or sum(Amount) <" + str(LowerPassLimit) + ")"
#strSuspenseSql = "Select * from ( " + strSqlAS + strSqlFUS + strSqlLES + ") Order By DimName"
#rsfile = strSuspenseSql
strLogFile = strLoc + "_" + strCat + "_" + strPer + ".log"
strLogPath = fdmContext["OUTBOXDIR"] + "/status/"
strFlag = "a"
rsLE = fdmAPI.executeQuery(strSqlLE, [])
strFilePath = UstroutboxPath + "Validation.log"
objFile = open(strFilePath, "w")
if UstrLoc == "HFM_TB_DATA_J_D" :
strUstrReceivers = GetEmailAddresses (strOptionList, "@")
if len(strUstrReceivers) <=0:
UstrReceivers = "[email protected]","[email protected]"
else:
UstrReceivers = strUstrReceivers
if (rsLE.next()):
objFile.write('\n')
UstrBody = UstrBody + '\n'
Heading = "1. Entity Not balanced : "+"\n"
objFile.write(Heading + '\n')
UstrBody = UstrBody + Heading + '\n'
Condition = True
while (Condition):
if (float(rsLE.getString("DataSum")) > LowerPassLimit or float(rsLE.getString("DataSum")) < UpperPasslimit ):
FileContent = " " + rsLE.getString("SRC_LE") +" : TB Diff = " + rsLE.getString("DataSum")
objFile.write(FileContent + '\n')
UstrBody = UstrBody + FileContent + '\n'
Condition = rsLE.next()
#objFile.close()
ustrReason = "TB check Failure"
strQueryValFail = "update tlogprocess set PROCESSSTATUS = 12,BLNVALDIRTY = 1,processval = 0, processvalnote = ?, processexp = 0, processentload = 0 where PARTITIONKEY = " + str(UstrLocKey) + " AND CATKEY = " + str(UstrCatKey) + " AND PERIODKEY = " + ustrDateParam + " AND RULE_ID = " + str(UstrRule)
Params = ["Tb Check Failure"]
fdmAPI.executeDML(strQueryValFail, Params, False)
fdmAPI.commitTransaction()
ErrStatus = 1
if UstrLoc == "HFM_FA_MOT":
ustrDateParam = " '" + str(UstrPeriodKey) + "'"
strQueryValFail = "update TDATASEG set AMOUNTX= (-1 * AMOUNT) where UD1 IN ('ACCUM_DEPR_RET','ACCUM_DEPR_TRF') AND PARTITIONKEY = " + str(UstrLocKey) + " AND CATKEY = " + str(UstrCatKey)
strQueryValFail = strQueryValFail + " AND RULE_ID = " + str(UstrRule) + " AND LOADID = " + str(UstrLoadID)
Params = []
fdmAPI.executeDML(strQueryValFail, Params, False)
fdmAPI.commitTransaction()
fdmAPI.closeConnection()
if ErrStatus == 1:
rc = SendEmail (UstrSMTPServer, UstrUserID, UstrPW, UstrSender, UstrReceivers, UstrSubject, UstrBody, UstrAttachment1, UstrAttachment2, UstrAttachment3, UstrAttachment4)
if ErrStatus == 1:
fdmAPI.showCustomFile(UstroutboxPath + "Validation.log")
else:
fdmAPI.showCustomMessage("Validation successful")
objFile.close()
AftLoad
strStep = "LOAD"
strFlag = "a"
strBanner = " ***** "
strPart = "After "
strEnv = "PRD_EXA"
strTargetApp = "XHFM"
strSubject = ""
strEmailToAddresses = ""
strEmailDelimiter = ","
strIntegrityMsg = ""
strUserID = ""
strPW = ""
EmailResult = "OK"
#********************************************************************************
import os
import shutil
import time
import smtplib
#********************************************************************************
#----------------------------------------------Email Send ---------------------------------------------------------------------------------------
def F_SEND_EMAIL(strServer, strUserID, strPW, strSender, strReceivers, strSubject, strBody, strAttachment1, strAttachment2, strAttachment3, strAttachment4):
#import smtplib
#import email.mime.application
#from email.mime.application import MIMEApplication
#from email.mime.Multipart import MIMEMultipart
#from email.mime.text import MIMEText
#Above lines are commented and Below lines are added for email triggers
import smtplib, os, sys
from email.mime.multipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.mime.text import MIMEText
from email.MIMEImage import MIMEImage
from email import Encoders
from HTMLParser import HTMLParser
strMessage = ""
strMessage = strMessage + strServer + "\n"
strMessage = strMessage + strSender + "\n"
strMessage = strMessage + strReceivers + "\n"
strMessage = strMessage + strUserID + "\n"
strMessage = strMessage + strPW + "\n"
strMessage = strMessage + strSubject + "\n"
strMessage = strMessage + strBody + "\n"
strMessage = strMessage + strAttachment1 + "\n"
strMessage = strMessage + strAttachment2 + "\n"
EmailMessage = MIMEMultipart()
EmailMessage['Subject'] = strSubject
EmailMessage['From'] = strSender
EmailMessage['To'] = strReceivers
part = MIMEText(strBody, 'plain')
EmailMessage.attach(part)
if strAttachment1 != "":
try:
strFilename1 = strAttachment1.split('/')[-1]
strAttach1 = "attachment; filename=" + strFilename1
part = MIMEApplication(open(strAttachment1,"rb").read())
part.add_header('Content-Disposition', strAttach1)
EmailMessage.attach(part)
except Exception, e:
strMessage = strMessage + "Email Attachment1 Error: " + str(e) + "\n"
if strAttachment2 != "":
try:
strFilename2 = strAttachment2.split('/')[-1]
strAttach2 = "attachment; filename=" + strFilename2
part = MIMEApplication(open(strAttachment2,"rb").read())
part.add_header('Content-Disposition', strAttach2)
EmailMessage.attach(part)
except Exception, e:
strMessage = strMessage + "Email Attachment2 Error: " + str(e) + "\n"
if strAttachment3 != "":
try:
strFilename3 = strAttachment3.split('/')[-1]
strAttach3 = "attachment; filename=" + strFilename3
part = MIMEApplication(open(strAttachment3,"rb").read())
part.add_header('Content-Disposition', strAttach3)
EmailMessage.attach(part)
except Exception, e:
strMessage = strMessage + "Email Attachment3 Error: " + str(e) + "\n"
if strAttachment4 != "":
try:
strFilename4 = strAttachment4.split('/')[-1]
strAttach4 = "attachment; filename=" + strFilename4
part = MIMEApplication(open(strAttachment4,"rb").read())
part.add_header('Content-Disposition', strAttach4)
EmailMessage.attach(part)
except Exception, e:
strMessage = strMessage + "Email Attachment4 Error: " + str(e) + "\n"
try:
smtpServer = smtplib.SMTP ("APACSMTP.X.COM", 25)
strMessage = strMessage + "SMTP SERVER OK "
except Exception, e:
strMessage = strMessage + "Email (smtplib.SMTP) Error: " + str(e) + "\n"
try:
smtpServer.set_debuglevel(1)
smtpServer.ehlo()
smtpServer.starttls()
strMessage = strMessage + "OK "
except Exception, e:
strMessage = strMessage + "Email (smtpServer.ehlo, smtpServer.starttls) Error: " + str(e) + "\n"
try:
smtpServer.login(strUserID, strPW)
except Exception, e:
strMessage = strMessage + "Email (smtpServer.login) Error: " + str(e) + "\n"
try:
smtpServer.sendmail(strSender, strReceivers.split(","), EmailMessage.as_string())
strMessage = "Successfully sent Email"
smtpServer.quit()
strMessage = strMessage + "OK "
except Exception, e:
strMessage = strMessage + "Email (smtpServer.sendmail) Error: " + str(e) + "\n"
return strMessage
#---------------------------------------------Email End ----------------------------------------------------------------------------------------
#********************************************************************************
def writeToFile(strPath, strFile, strBuf, strFlag):
strFilePath = strPath + strFile
objFile = open(strFilePath, strFlag)
objFile.write(strBuf + "\n")
objFile.close()
return "ok"
#********************************************************************************
def getLocOption (strOptionNumber, Loc_rs, Rule_rs):
strOption = ""
try:
strTemp = str(Loc_rs.next())
strLocOption = str(Loc_rs.getString ("partIntgConfig" + strOptionNumber))
strTemp = str(Rule_rs.next())
strRuleOption = str(Rule_rs.getString ("RULE_ATTR" + strOptionNumber))
except Exception, e:
strRuleOption = "ERROR " + str(e) + "\n"
strOption = strLocOption
if strRuleOption != "None": strOption = strRuleOption
return strOption
#********************************************************************************
def getLocOptionList (Loc_rs, Rule_rs):
strOptions = ""
try:
strTemp = str(Loc_rs.next())
strLocOption1 = str(Loc_rs.getString ("partIntgConfig1"))
strLocOption2 = str(Loc_rs.getString ("partIntgConfig2"))
strLocOption3 = str(Loc_rs.getString ("partIntgConfig3"))
strLocOption4 = str(Loc_rs.getString ("partIntgConfig4"))
strTemp = str(Rule_rs.next())
strRuleOption1 = str(Rule_rs.getString ("RULE_ATTR1"))
strRuleOption2 = str(Rule_rs.getString ("RULE_ATTR2"))
strRuleOption3 = str(Rule_rs.getString ("RULE_ATTR3"))
strRuleOption4 = str(Rule_rs.getString ("RULE_ATTR4"))
if strRuleOption1 != "None": strLocOption1 = strRuleOption1
if strRuleOption2 != "None": strLocOption2 = strRuleOption2
if strRuleOption3 != "None": strLocOption3 = strRuleOption3
if strRuleOption4 != "None": strLocOption4 = strRuleOption4
strOptions = strLocOption1 + "," + strLocOption2 + "," + strLocOption3 + "," + strLocOption4
except Exception, e:
strOptions = "\nERROR " + str(e) + "\n"
return strOptions
#********************************************************************************
def setOptionFlag (strOptionList, strSearchString):
strOptionList = "," + strOptionList + ","
strSearchString = "," + strSearchString + ","
if strOptionList.find (strSearchString) >= 0:
bExists = True
else:
bExists = False
return bExists
def GetEmailAddresses (strOptionList, strSearchString):
strOptionList = "," + strOptionList + ","
returnStr = ""
Count = 0
for strInBuf in strOptionList.split(","):
if strInBuf.find (strSearchString) >= 0:
if Count ==0:
returnStr = strInBuf
Count = Count +1
else:
returnStr = returnStr +"," + strInBuf
else:
bExists = False
return returnStr
#********************************************************************************
def GetPOV_Filename (strLoc, strCat, strPer, strExt, strDelimiter):
return strLoc + strDelimiter + strCat + strDelimiter + strPer + "." + strExt
#********************************************************************************
def AppendToFile(strSourceFilePath, strTargetFilePath, strReplace, strDelimiter, strFlag):
try:
objFile1 = open(strSourceFilePath)
objFile2 = open(strTargetFilePath, strFlag)
strList = objFile1.readlines()
for strInBuf in strList:
strOutBuf = strInBuf
if strReplace != "" :
strArray = strInBuf.split (strDelimiter)
strArray [len(strArray)-1] = strReplace + "\n"
strOutBuf = strDelimiter.join(strArray)
bWrite = True
if len(strArray) == 1:bWrite = False
if bWrite == True:objFile2.write(strOutBuf)
objFile1.close()
objFile2.close()
strMessage = "OK"
except Exception, e:
strMessage = "Error: " + str(e)
return strMessage
#********************************************************************************
strMessage = ""
strLoc = fdmContext ["LOCNAME"]
strCat = fdmContext["CATNAME"]
strPer = fdmContext["PERIODNAME"]
strLogPath = fdmContext["OUTBOXDIR"] + "/status/"
strLogFile = strLoc + "_" + strCat + "_" + strPer + ".log"
strTime = time.strftime ('%Y-%m-%d %H:%M:%S', time.localtime())
strBuf = strBanner + strStep + " " + strPart + " " + strTime + strBanner + ""
strLogFile = strLoc + "_" + strCat + "_" + strPer + ".log"
rc = writeToFile(strLogPath, strLogFile, "", "w")
#------------------------------------------------------------------------------------------------------------------------
try:
strLoadID = str(fdmContext ["LOADID"])
strLoc = fdmContext ["LOCNAME"]
strCat = fdmContext["CATNAME"]
strPer = fdmContext["PERIODNAME"]
strRule = fdmContext["RULENAME"]
strAppName = fdmContext["TARGETAPPNAME"]
strFilename = strAppName + "_" + strLoadID + ".dat"
states = fdmAPI.getProcessStates(fdmContext["LOADID"])
strStatus = str(states["PROCESSSTATUS"])
strLogPath = fdmContext["OUTBOXDIR"] + "/status/"
strLogFile = strLoc + "_" + strCat + "_" + strPer + ".log"
strLogFilePath = strLogPath + strLogFile
except Exception, e:
rc = writeToFile(strLogPath, strLogFile, "ERROR " + str(e) + "\n", strFlag)
#------------------------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------------------------
try:
strOptionList = getLocOptionList (fdmAPI.getLocationDetails (fdmContext["LOCKEY"]), fdmAPI.getRuleDetails (fdmContext["RULEID"]))
#rc = writeToFile(strLogPath, strLogFile, "OPTIONS=" + strOptionList, strFlag)
except Exception, e:
rc = writeToFile(strLogPath, strLogFile, "ERROR " + str(e) + "\n", strFlag)
#------------------------------------------------------------------------------------------------------------------------
UstrLoadID = str(fdmContext ["LOADID"])
UstrProcessID = str(fdmContext ["PROCESSID"])
UstrLoc = fdmContext ["LOCNAME"]
UstrLocKey = fdmContext ["LOCKEY"]
UstrCat = fdmContext["CATNAME"]
UstrCatKey = fdmContext["CATKEY"]
UstrPer = fdmContext["PERIODNAME"]
UstrPeriodKey = fdmContext["PERIODKEY"]
UstrRule = fdmContext["RULEID"]
UstrAppName = fdmContext["TARGETAPPNAME"]
UstroutboxPath = fdmContext["OUTBOXDIR"]+"/XHFM/"
#-----------------------------------------------------------------EMail Parameter-------------------------------------------
UstrSMTPServer = "X.X.COM"
UiSMTPPort = 25
UstrReceivers = "[email protected]","[email protected]","[email protected]","[email protected]","[email protected]"
UstrSender = "[email protected]"
UstrHFMPOV = fdmContext["LOCNAME"] + "-" + fdmContext["CATNAME"] + "-" + fdmContext["PERIODNAME"]+ "- RULE NAME " + fdmContext["RULENAME"] + " "
UstrUserID = ""
UstrPW = ""
UstrSubject = strEnv + " Validation Failure for POV " + UstrHFMPOV + time.asctime()
UstrBody = "HFM Validation is failed due to the following errors: "+'\n'
UstrAttachment1 = ""
UstrAttachment2 = ""
UstrAttachment3 = ""
UstrAttachment4 = ""
#---------------------------------------------------------------------------------------------------------------------------
strLogFile = strLoc + "_" + strCat + "_" + strPer + ".log"
strLogPath = fdmContext["OUTBOXDIR"] + "/status/"
strFlag = "a"
strBuf = str(UstrLocKey) + str(UstrCatKey)+str(UstrPeriodKey)
#rc = writeToFile(strLogPath, strLogFile, strBuf, strFlag)
ustrDateParam = "to_date('" + str(UstrPeriodKey) + "', 'YYYY-MM-DD') "
SuspenseCount = 0
ErrStatus = 0
strLogFile = strLoc + "_" + strCat + "_" + strPer + ".log"
strLogPath = fdmContext["OUTBOXDIR"] + "/status/"
strFlag = "a"
if UstrLoc == "HFM_TB_DATA_J_D":
strUstrReceivers = GetEmailAddresses (strOptionList, "@")
if len(strUstrReceivers) <=0:
UstrReceivers = "[email protected]"
else:
UstrReceivers = strUstrReceivers
strBuf = " ==> EMAIL WILL BE PROCESSED FOR THIS LOCATION and Location status is " + "\n" + strStatus
rc = writeToFile(strLogPath, strLogFile, strBuf, strFlag)
strPOV = strLoc + " " + strCat + " " + strPer
if strStatus == "31":
strSubject = strEnv + "FDMEE Successful Load - App: " + strTargetApp + " Loc: " + strLoc + " Pd: " + strPer
strBody = "A successful load from FDMEE was processed" + "\n" + "\n"
strBody = strBody + "Target Application: " + strTargetApp + "\n"
strBody = strBody + "FDMEE Location: " + strLoc + "\n"
strBody = strBody + "POV Period: " + strPer + "\n"
strBody = strBody + "POV Scenario: " + strCat + "\n" + "\n"
strBody = strBody + "Time Stamp: " + time.strftime ('%Y-%m-%d %H:%M:%S', time.localtime()) + "\n"
else:
strSubject = strEnv + "FDMEE Load ERROR - App: " + strTargetApp + " Loc: " + strLoc + " Pd: " + strPer
strBody = "An UNSUCCESSFUL load from FDMEE was processed !" + "\n" + "\n"
strBody = strBody + "Target Application: " + strTargetApp + "\n"
strBody = strBody + "FDMEE Location: " + strLoc + "\n"
strBody = strBody + "POV Period: " + strPer + "\n"
strBody = strBody + "POV Scenario: " + strCat + "\n" + "\n"
strBody = strBody + "Time Stamp: " + time.strftime ('%Y-%m-%d %H:%M:%S', time.localtime()) + "\n"
#rc = writeToFile(strPath, strFile, strSMTPServer, strFlag)
#smtpServer = smtplib.SMTP("X.X.COM", 25)
if strIntegrityMsg != "":
strBody = strBody + "\n"
strBody = strBody + strIntegrityMsg
strSubject = "ISSUE NOTIFICATION: " + strSubject
strBuf = " ==> Email Recipients: " + UstrReceivers
rc = writeToFile(strLogPath, strLogFile, strBuf, strFlag)
strBuf = " ==> Email Body: " + strBody
rc = writeToFile(strLogPath, strLogFile, strBuf, strFlag)
strAttachment1 = ""
strAttachment2 = ""
strAttachment3 = ""
strAttachment4 = ""
strAttachment1FilePath = ""
strAttachment2FilePath = ""
strAttachment3FilePath = ""
strAttachment4FilePath = ""
if os.path.exists(strAttachment1FilePath):
strAttachment1 = strAttachment1FilePath
if os.path.exists(strAttachment2FilePath):
strAttachment2 = strAttachment2FilePath
if os.path.exists(strAttachment3FilePath):
strAttachment3 = strAttachment3FilePath
if os.path.exists(strAttachment4FilePath):
strAttachment4 = strAttachment4FilePath
#UstrReceivers = "[email protected]"
if UstrSender != "":
rc = F_SEND_EMAIL(UstrSMTPServer, UstrUserID, UstrPW, UstrSender, UstrReceivers, strSubject, strBody, strAttachment1, strAttachment2, strAttachment3, strAttachment4)
if EmailResult == "OK":
strBuf = " ==> Email was successfully sent" + rc
rc = writeToFile(strLogPath, strLogFile, strBuf, strFlag)
else:
strBuf = " ==> An ERROR occurred sending the Email" + "\n" + rc
rc = writeToFile(strLogPath, strLogFile, strBuf, strFlag)
else:
strBuf = " ==> NO EMAIL WAS SENT - NO RECIPIENTS ARE DEFINED FOR THE LOCATION"
rc = writeToFile(strLogPath, strLogFile, strBuf, strFlag)
fdmAPI.showCustomFile(strLogPath + strLogFile)