Monday, 10 November 2014

Tell me when there are errors in my log files

This should help a lot of people.  This is a simple vbs script that you can schedule every 15 minutes (or when you want), which will tell you if your specified errors have been logged in a JD Edwards log file.  Note that this script is completely generic and you do not need to use it for JD Edwards.

Schedule it every 15 minutes and you are away.  If you schedule longer or shorter, change the scriptSleepTime variable in the header.

dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell 'instance of the wshSHell object
set objShell = CreateObject("WScript.Shell")
FromEmailAddress="jde@myriad-it.com"
Const strSmartHost = "smtp"
Company="Myriad IT"
RecipientNames = ARRAY("smoir@myriad-it.com",someone@thing.com)
ScriptSleepTimeMinutes=15


strSearchForArray = ARRAY("ORA-03114","ORA-03113","GetRecipientPreferences")
Set oFSO = CreateObject("Scripting.FileSystemObject")
JDELogFolder = "D:\JDEdwards\E910\log"

Set objFolder = objFSO.GetFolder(JDELogFolder)

Set jdeLogFiles = objFolder.Files
For Each objFile in jdeLogFiles
'Wscript.Echo objFile.Name
strFile = JDELogFolder & "\" & objFile.Name
set objFile = objFSO.getFile(strFile)
if objFile.size > 0 then
for each SearchString in strSearchForArray
If InStr(oFSO.OpenTextFile(strFile).ReadAll, SearchString ) > 0 Then
'Email Details
if objFile.size < 2000000 then
If DateDiff("n", objFile.DateLastModified, Now) < ScriptSleepTimeMinutes Then
'File has been modified in past 10 minutes.
i=sendMail("URGENT: " & SearchString & " Found in log file - see attached", "See attachment", strFile)
End If
else
i=sendMail("URGENT: " & SearchString & " Found in log file - too big to attach", "NO attachment", "")
end if
END If
next
END If
Next
wscript.echo "Script complete"


'#####################################################################
'FUNCTION:sendMail
'#####################################################################
function sendMail(subjectText, emailBody, attachment)
on error resume next
Dim iMsg
Dim iConf
Dim Flds
Const cdoSendUsingPort = 2

for each name in RecipientNames
'Create the message object
Set iMsg = CreateObject("CDO.Message")
'Create the configuration object
Set iConf = iMsg.Configuration
'Set the fields of the configuration object to send using SMTP via port 25.
With iConf.Fields
.item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSmartHost
.Update
End With

'Set the message to,from,subject,body properties.
if strlen(attachment) > 1 then
With iMsg
.AddAttachment attachment
.To = name
.From = FromEmailAddress
.Subject = subjectText & " " & now()
.TextBody = chr(1) & " " & emailBody
.Send
End With
else
With iMsg
.To = name
.From = FromEmailAddress
.Subject = subjectText & " " & now()
.TextBody = emailBody
.Send
End With
end if
set iMsg = Nothing
next

end function

No comments:

Extending JDE to generative AI