'========================================================================== ' ' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.0 ' ' NAME: Multi-Host Ping Script for MOM ' ' AUTHOR: Pete Zerger & Neale Brown , AKOS Technology Services ' DATE : 10/4/2006 ' ' COMMENT: Accepts a comma-separated list of hosts and performs a ping check ' ' PARAMETERS: Hosts - Comma-separated list of hosts, NetBIOS, FQDN and IP okay ' LogSuccessEvent - Boolean value 1=LogEventOnSuccess 0=LogOnFailOnly '========================================================================== '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_INFORMATION_TYPE = 4 Const EVENTLOG_AUDIT_SUCCESS = 8 Const EVENTLOG_AUDIT_FAILURE = 16 Dim sHosts, sServer, bLogSuccessEvent 'Script Parameters sHosts = Split(ScriptContext.Parameters.Get("Hosts"), ",") bLogSuccessEvent = CBool(ScriptContext.Parameters.Get("LogSuccessEvent")) 'Call the PingHost function for each host in the list above For Each sServer In sHosts On Error Resume Next PingHost(sServer) Next '******************************************************************************* 'Routine that pings the specified address 'Raises an event if ping fails '******************************************************************************* Sub PingHost(sHost) Set cPingResults = _ GetObject("winmgmts://./root/cimv2").ExecQuery("SELECT * " & _ "FROM Win32_PingStatus WHERE Address = '" & sHost & "'") For Each oPingResult In cPingResults If oPingResult.StatusCode = 0 Then If bLogSuccessEvent then CreateEvent 51002,EVENT_TYPE_INFORMATION,"Multi-host Ping Script","Successfully pinged " & sHost & "." Else CreateEvent 51001,EVENT_TYPE_ERROR,"Multi-host Ping Script","Ping check failed for " & sHost & "." End If Next End Sub '****************************************************************************** ' Name: CreateEvent ' ' Purpose: Logs an event '****************************************************************************** Sub CreateEvent(iEventNumber,iEventType,sEventSource,sEventMessage) Set oEvent = ScriptContext.CreateEvent() oEvent.EventNumber = iEventNumber oEvent.EventType = iEventType oEvent.EventSource = sEventSource oEvent.Message = sEventMessage ScriptContext.Submit oEvent End Sub