'========================================================================== ' NAME: SMTP Port Check ' ' AUTHOR: Neale Brown, AKOS Technology Services ' DATE : 10/2/2006 ' ' COMMENT: This script uses the FREE Toolsack Baseline COM objects from ' http://www.arcticlabs.com/ ' This script uses the Socket function from this library to ' open a TCP connection to port 25 of the specified server. ' If provided, the script is capable of running one command and ' using using search string comparision to verify the command ' worked. ' ' PARAMETERS: Host - A single host NetBIOS, FQDN and IP okay ' Command - Send a command to the SMTP service on the server. ' If this command is left blank, then a simple port ' will run instead. ' SearchString - A search string will be used when a command ' is sent to the STMP server, otherwise this ' is ignored. ' LogSuccessEvent - 1 - log successful events ' 0 - logs failure events '========================================================================== On Error Resume Next 'Declare variables Dim strServer, strCommand, strResults, strSearchString Dim intPortFailure, intTimeout, intPortCheck, intPort, intLogSuccessEvent 'declare constants 'map event types & numbers to friendly names Const EVENT_TYPE_SUCCESS = 0 Const EVENT_TYPE_ERROR = 1 Const EVENT_TYPE_WARNING = 2 Const EVENTLOG_TYPE_INFORMATION = 4 Const EVENTLOG_AUDIT_SUCCESS = 8 Const EVENTLOG_AUDIT_FAILURE = 16 'Get script parameter values from MOM strServer = ScriptContext.Parameters.Get("Host") strCommand = ScriptContext.Parameters.Get("Command") strSearchString = ScriptContext.Parameters.Get("SearchString") intLogSuccessEvent = ScriptContext.Parameters.Get("LogSuccessEvent") strPort = "25" intPortFailure = 0 If strCommand <> "" Then intCommandCount = "1" End If 'Initializing the Toolsack baseline COM objects for use Set SMTPSocket = CreateObject("Toolsack.Socket") Set sleeper = CreateObject("Toolsack.Sleeper") 'Connect to the specified server and port SMTPSocket.Connect strServer, strPort '******************************************************************************* 'This gigantic If conidion checks to see what kind of error the 'SMTPSocket.Connect returns when it attempts to connect to the server. '******************************************************************************* If Err.Number = 0 Then sleeper.sleep .5 If SMTPSocket.IsLineAvailable Then If intCommandCount = 1 Then SMTPSocket.Write strCommand & VbCrLf For i = 0 to intCommandCount strResults = SMTPSocket.Readline Next intPortFailure = 0 Else SMTPSocket.Write strCommand & VbCrLf strResults = SMTPSocket.Readline intPortFailure = 0 End If Else intPortFailure = 1 End If If intPortFailure Then CreateEvent 56102, EVENT_TYPE_ERROR, "Synthetic SMTP Check", "Server or Port unavailable at " & strServer & "." ElseIf intPortFailure = 0 And intCommandCount = 1 Then If InStr(strResults, strSearchString) <> 0 And intLogSuccessEvent = 1 Then CreateEvent 56101, EVENT_TYPE_INFORMATION, "Synthetic SMTP Check", "Specified String Successfully found." Else strSearchFailureMessage = "Synthetic SMTP Check - Could not find specified search string at " & strServer & VBCr & _ "Server Returned: " & strResults & vbcr& "Search String: " & strSearchString CreateEvent 56102, EVENT_TYPE_ERROR, "", strSearchFailureMessage End If Else If intLogSuccessEvent = 1 Then CreateEvent 56101, EVENT_TYPE_INFORMATION, "Synthetic SMTP Check", "Successfully contacted port 25 on " & strServer End If End If Else If Err.Number = "-2147352567" Then CreateEvent 56102, EVENT_TYPE_ERROR, "Synthetic SMTP Check", "Server or Port unavailable at " & strServer & "." ElseIf Err.Number = "424" Then CreateEvent 56103, EVENT_TYPE_WARNING, "Synthetic SMTP Check", "Toolsack Baseline COM+ object not registered on Agent Server." Else CreateEvent 56103, EVENT_TYPE_WARNING, "Synthetic SMTP Check", "Unknown Script Failure." End If End If '****************************************************************************** ' Name: CreateEvent ' ' Purpose: Logs an event '****************************************************************************** Sub CreateEvent(intEventNumber,intEventType,strEventSource,strEventMessage) Set objEvent = ScriptContext.CreateEvent() objEvent.EventNumber = intEventNumber objEvent.EventType = intEventType objEvent.EventSource = strEventSource objEvent.Message = strEventMessage ScriptContext.Submit objEvent End Sub