' ********************************************************************* ' ' Name : LogToEventLog.vbs ' Author : 3Ds (UK) Limited ' Description : Example VBScript to log Sentry-go alert information ' to a local or remote Event log. ' ' Arguments : None. ' ' WIZARD:PARAMS=This script requires no parameters ' WIZARD:PARAMEXAMPLE= ' ' Returns : 0 - Success ' 1 - An error occurred and the information could not be ' logged. ' ' WIZARD:RESULTS=Return code ...||0 = OK|1 = An error prevented the script from running.||Script output also indicates "OK" for success, or "Error" with details of the faults found. ' ' Notes : Requires Windows Scripting Host (for VBScript). Should ' be called from Sentry-go as an Alert Engine file in ' order to expand the error-specific place-markers. ' ' Change the "TODOs" for your own requirements. ' ' WIZARD:REMOTE ' ' ********************************************************************* ' Enable in-line error handling On Error Resume Next ' ------ Local declarations ------ Dim WshShell ' Object reference for the shell Dim strMachine ' The name of the PC on which the Event log resides Dim strErrorMessage ' The text we wish to log Dim iEventType ' Event type we wish to log ' ------ Main Logic ------ ' TODO: Set the machine name (leave blank for the local machine) strMachine = "" ' TODO: Set up the error message we wish to log strErrorMessage = "Sentry-go monitored error logged on <$$TIMELOGGED>. Error: <$$ERROR> on Server: <$$SERVER>" ' TODO: Set the event type. This is numeric where ERROR = 1, WARNING = 2, INFORMATION = 4 iEventType = 1 ' Create a shell object Set WshShell = WScript.CreateObject("WScript.Shell") If Err.Number <> 0 Then ' Error WScript.Echo "Error. Unable to create the WScript.Shell object. " & Err.Description WScript.Quit(1) Else ' Write to the Event Log on the appropriate machine If Len(strMachine) > 0 Then WshShell.LogEvent iEventType, strErrorMessage, strMachine Else WshShell.LogEvent iEventType, strErrorMessage End If ' Check the result If Err.Number <> 0 Then ' Error Set WshShell = Nothing WScript.Echo "Error. Unable to log details to the Event Log. " & Err.Description WScript.Quit(1) End if End If ' ------ Cleanup ------ Set WshShell = Nothing WScript.Echo "OK. Details logged successfully" WScript.Quit (0) ' ------ End of Script ------