'================================================================================== ' ' VBScript Source File -- Created with SAPIEN Technologies PrimalSCRIPT(TM) ' ' NAME: Ping Response Latency Script ' VERSION: 1.0 ' ' AUTHOR: Pete Zerger & Neale Brown , AKOS Technology Services ' DATE : 10/2/2006 ' ' COMMENT: Script measures ping response time to ' ' PARAMETERS: ' Host - Name or IP address of target host. ' ResponseThreshold - Threshold (in milliseconds) above which the script ' generates an alert of WARNING severity. ' LogPerformanceData - 1 creates a performance object for charts & reporting ' 0 turns this feature off ' GenerateEvent - 1 generates an event (for testing) 0 turns this off. ' ' '================================================================================== 'declare constants 'map event types & numbers to friendly names 'Const MOM_SCRIPT_EVENT_ID = 5005 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 'map alert types & numbers to friendly names Const ALERT_SUCCESS = 10 Const ALERT_INFORMATION = 20 Const ALERT_WARNING = 30 Const ALERT_ERROR = 40 Const ALERT_CRITICAL_ERROR = 50 Const ALERT_SECURITY_BREACH = 60 Const ALERT_SERVICE_UNAVAILABLE = 70 Dim t, intResponse, PingResponse 'Get script parameter values sServer = ScriptContext.Parameters.Get("Host") nResponseThreshold = ScriptContext.Parameters.Get("ResponseThreshold") bLogPerformanceEvent = ScriptContext.Parameters.Get("LogPerformanceData") bGenerateEvent = ScriptContext.Parameters.Get("GenerateEvent") intResponse = -1 For t = 1 To 5 Set cPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery("SELECT * " & _ "FROM Win32_PingStatus WHERE Address = '" & sServer & "'") For Each oPingResult In cPingResults If oPingResult.StatusCode = 0 Then If intResponse = -1 Then intResponse = 0 intResponse = intResponse + oPingResult.ResponseTime End If Next Next If intResponse = -1 Then PingResponse = -1 Else PingResponse = cdbl(intResponse/5) End If 'Report Ping Response Time If bGenerateEvent = 1 Or bGenerateEvent = 3 Then If PingResponse = -1 Then CreateEvent 56001, EVENT_TYPE_ERROR, "Ping Response Time Average Script","Ping check failed for " & sServer & "." End If End If If bGenerateEvent = 2 Or bGenerateEvent = 3 Then If PingResponse = 0 Then CreateEvent 56002, EVENTLOG_INFORMATION_TYPE, "Ping Response Time Average Script","Successfully pinged " & sServer & " with avg response time less than 1 ms." Else CreateEvent 56002, EVENTLOG_INFORMATION_TYPE, "Ping Response Time Average Script","Successfully pinged " & sServer & " with avg response time of " & PingResponse & " ms." End If End If 'Log Performance Object If bLogPerformanceEvent Then CreatePerfData "Response Time Monitoring", "Ping Response Time Average", sServer, PingResponse End If 'Generate an alert if response threshold average (in milliseconds) is breached If cdbl(PingResponse) > cdbl(nResponseThreshold) Then CreateAlert ALERT_WARNING, "Ping Response Time Average", "Ping response threshold breached for host " & sServer & _ ". Response average of " & PingResponse & " ms is greater than response threshold of " & nResponseThreshold & " ms." End If '****************** 'Subs and Functions '****************** '****************************************************************************** ' Name: CreatePerfData ' ' Purpose: Creates a performance object to display response time in Performance View '****************************************************************************** Sub CreatePerfData(strObjectName,strCounterName,strInstanceName,numValue) Set objPerfData = ScriptContext.CreatePerfData objPerfData.ObjectName = strObjectName objPerfData.CounterName =strCounterName objPerfData.InstanceName = strInstanceName objPerfData.Value = numValue ScriptContext.Submit objPerfData End Sub '****************************************************************************** ' 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 '****************************************************************************** ' Name: CreateAlert ' ' Purpose: Raises an alert ' ' Parameters: ' iSeverity - The severity of the alert. ' strName - The name of the alert. ' strDescription - The alert description. '****************************************************************************** Function CreateAlert(iSeverity, strName, strDescription) Dim oAlert Set oAlert = ScriptContext.CreateAlert() oAlert.Name = strName 'oAlert.AlertSource = strSource oAlert.Description = strDescription oAlert.AlertLevel = iSeverity ScriptContext.Submit oAlert End Function