' ********************************************************************* ' ' Name : AlertToANetworkFile.vbs ' Author : 3Ds (UK) Limited ' Description : Example VBScript to record record Sentry-go alert ' information to a text file on a shared drive using ' the UNC naming convention. ' ' 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 completing successfully.||If an error occurs, a message will be output giving details of the fault encountered. ' ' 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. ' ' ********************************************************************* ' Enable in-line error handling On Error Resume Next ' ------ Local declarations ------ Dim objFSO ' File System Object Dim iFile ' File Number Dim strFileName ' The file to write Dim strTextToSend ' Text to write Const ForAppending = 8 ' VB Constant for appending ' ------ Main Logic ------ ' TODO: Set the filename using the UNC format \\Server\Share strFileName = "\\MyServer\MyShareName\Logs\Sentry-go.txt" ' Create the FSO and open the file Set objFSO = CreateObject("Scripting.FileSystemObject") If Err.Number <> 0 Then ' Error WScript.Echo "Unable to create the file system object. " & Err.Description WScript.Quit(1) End If Set iFile = objFSO.OpenTextFile(strFileName, ForAppending, True) If Err.Number <> 0 Then ' Error WScript.Echo "Could not open the file for writing. " & Err.Description Set objFSO = Nothing WScript.Quit(1) End If ' TODO: Build our error using Sentry-go's place-markers strTextToSend = "Sentry-go monitored error logged on <$$TIMELOGGED>. Error: <$$ERROR> on Server: <$$SERVER>" & vbCrLf & vbCrLf ' Write out the line & close the file iFile.Write (strTextToSend) If Err.Number <> 0 Then ' Error WScript.Echo "Could not write to the file. " & Err.Description iFile.Close 3 WScript.Quit(1) End If iFile.Close ' ------ Cleanup ------ Set objFSO = Nothing WScript.Quit(0) ' ------ End of Script ------