From 3d1f096f80f4547415d06a24b58339694cf5e626 Mon Sep 17 00:00:00 2001 From: "Infineon\\StieberD" Date: Tue, 18 Mar 2025 14:34:03 -0700 Subject: [PATCH] added additional logging to try and capture the root cause of email service critical mona alerts --- LSL2/STPROC/EMAIL_SERVICES.txt | 24 ++++++++++++++++-------- LSL2/STPROC/OBJ_NOTES.txt | 16 +++++++++------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/LSL2/STPROC/EMAIL_SERVICES.txt b/LSL2/STPROC/EMAIL_SERVICES.txt index e980f12..f31c033 100644 --- a/LSL2/STPROC/EMAIL_SERVICES.txt +++ b/LSL2/STPROC/EMAIL_SERVICES.txt @@ -41,32 +41,40 @@ Return Response or "" Service SendEmail(FromAddress, ToAddress, Subject, Body) - If ( (FromAddress NE '') and (ToAddress NE '') ) then - ErrorMessage = '' + ErrorMessage = '' + If ( (FromAddress NE '') and (ToAddress NE '') ) then + ErrorCode = '' EmailServer = Environment_Services('GetIfxEmailServer') DotNetHandle = StartDotNet("","4.0") DotNetDir = CheckDotNet('4.0'):'\' MailDll = DotNetDir:'System.dll' Set_Property.Net(DotNetHandle, "AssemblyName", MailDll) - If Not(Get_Status(ErrorMessage)) then + If Not(Get_Status(ErrorCode)) then Params = FromAddress:@FM:ToAddress:@FM:Subject:@FM:Body ParamTypes = 'System.String':@FM:'System.String':@FM:'System.String':@FM:'System.String' objEmailMessage = Create_Class.Net(DotNetHandle, "System.Net.Mail.MailMessage", 0, Params, ParamTypes) - If Not(Get_Status(ErrorMessage)) then + If Not(Get_Status(ErrorCode)) then objEmailClient = Create_Class.Net(DotNetHandle, "System.Net.Mail.SmtpClient", 0, EmailServer, 'System.String') - If Not(Get_Status(ErrorMessage)) then + If Not(Get_Status(ErrorCode)) then rv = Send_Message.Net(objEmailClient, 'Send', objEmailMessage, 'RevDotNet', 0) - If Get_Status(ErrorMessage) then Null + If Get_Status(ErrorCode) then ErrorMessage = 'Error in ':Service:' service. Get_Status response: ':ErrorCode Free_Class.Net(objEmailClient) + end else + ErrorMessage = 'Error in ':Service:' service. Get_Status response: ':ErrorCode end Free_Class.Net(objEmailMessage) + end else + ErrorMessage = 'Error in ':Service:' service. Get_Status response: ':ErrorCode end + end else + ErrorMessage = 'Error in ':Service:' service. Get_Status response: ':ErrorCode end end else ErrorMessage = 'Error in ':Service:' service. Null FromAddress or ToAddress passed into service.' end - Response = (ErrorMessage EQ '') + If ErrorMessage NE '' then Error_Services('Add', ErrorMessage) - + Response = (ErrorMessage EQ '') + End Service diff --git a/LSL2/STPROC/OBJ_NOTES.txt b/LSL2/STPROC/OBJ_NOTES.txt index 3fa7393..d6cb424 100644 --- a/LSL2/STPROC/OBJ_NOTES.txt +++ b/LSL2/STPROC/OBJ_NOTES.txt @@ -35,7 +35,7 @@ LoggingDTM = LogDate : ' ' : LogTime ; // Logging DTM LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\EmailService' LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' EmailService.csv' -Headers = 'Logging DTM' : @FM : 'Error' +Headers = 'Logging DTM' : @FM : 'LogData' objLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ',', Headers, '', False$, False$) ErrTitle = 'Error in Stored Procedure "obj_Notes"' @@ -358,16 +358,15 @@ ForwardEMail: hSysLists = Database_Services('GetTableHandle', 'SYSLISTS') ServiceKeyID = 'Obj_Notes*ForwardEMail' Lock hSysLists, ServiceKeyID then - rv = Set_Status(0) + rv = Set_Status(0) RList('SELECT EMAIL_BOX BY NOTE_KEY', 5, '', '', '') - Done = 0 + Done = False$ LOOP - ReadNext eMailBoxKey else Done = 1 + ReadNext eMailBoxKey else Done = True$ UNTIL Done mbParms = 'EMAIL_BOX':@RM:eMailBoxKey eMailBoxRec = obj_Tables('ReadRec',mbParms) If @File_Error EQ '' then - eMailAddr = eMailBoxRec eMailText = eMailBoxRec eMailHeader = eMailBoxRec @@ -377,11 +376,15 @@ ForwardEMail: IF OISentFrom = 'OI_ERROR' THEN SendTo := XLATE('SEC_GROUPS', 'OI_ADMIN', 'USER', 'X') Success = Email_Services('SendEmail', SentFrom, SendTo, eMailHeader, eMailText) If Success then + LogData = '' + LogData<1> = LoggingDtm + LogData<2> = 'Successfully sent email From: ':SentFrom:' To: ':SendTo:' Header: ':eMailHeader:' Body: ':eMailText + Logging_Services('AppendLog', objLog, LogData, @RM, @FM) Mona_Services('SendBufferedStatus', 'OPENINSIGHT_MES_OP_FE', 'Email-Service', 'ok') end else LogData = '' LogData<1> = LoggingDtm - LogData<2> = Error_Services('GetMessage') + LogData<2> = 'Failed to send email From: ':SentFrom:' To: ':SendTo:' Header: ':eMailHeader:' Body: ':eMailText:' Error message: ':Error_Services('GetMessage') Logging_Services('AppendLog', objLog, LogData, @RM, @FM) Mona_Services('SendBufferedStatus', 'OPENINSIGHT_MES_OP_FE', 'Email-Service', 'critical') end @@ -643,4 +646,3 @@ BulkCreate: RETURN -