Forum Discussion
AlexanderM
14 years agoStaff
Hi Andrei,
You can find a suitable script in the Get current Log Items How To article.
The modified version that does exactly what you need is below. Posting the message to the log is replaced by sending an e-mail message.
Sub Test()
Call SendMail(<ToAddress>, <MailServerNameOrIP>, <FromName>, <FromAddress>, <Subject>, GetLogItems())
End Sub
Function GetLogItems()
Dim tempFolder, xDoc, result
tempFolder = aqEnvironment.GetEnvironmentVariable("temp") & "\" & GetTickCount() & "\"
If 0 <> aqFileSystem.CreateFolder(tempFolder) Then
Log.Error("The " & tempFolder & " temp folder was not created")
GetLogItems = ""
Exit Function
End If
If Not Log.SaveResultsAs(tempFolder, lsHTML) Then
Log.Error("Log was not exported to the " & tempFolder & " temp folder")
GetLogItems = ""
Exit Function
End If
Set xDoc = Sys.OleObject("MSXML2.DOMDocument.4.0")
xDoc.load(tempFolder & "root.xml")
result = LogDataToText(xDoc.childNodes.item(1), 0, " ")
Call aqFileSystem.DeleteFolder(tempFolder, True)
GetLogItems = result
End Function
Function LogDataToText(logData, indentIndex, indentSymbol)
Dim i, result
If "LogData" <> logData.nodeName Then
LogDataToText = ""
Exit Function
End If
result = ""
For i = 0 To indentIndex - 1
result = result & indentSymbol
Next
result = result & "Name: " & logData.getAttribute("name") & ", status: " & GetTextOfStatus(logData.getAttribute("status")) & vbCrLf
For i = 0 To logData.childNodes.length - 1
result = result & LogDataToText(logData.childNodes.item(i), indentIndex + 1, indentSymbol)
Next
LogDataToText = result
End Function
Function GetTextOfStatus(statusIndex)
Select Case statusIndex
Case "0" GetTextOfStatus = "OK"
Case "1" GetTextOfStatus = "WARNING"
Case "2" GetTextOfStatus = "FAILED"
Case Else GetTextOfStatus = "UNDEFINED"
End Select
End Function