I wrote this script primarily because we were having connectivity issues and servers becoming unavailable. As the comments imply I have integrated this with MOM, as to alert the administrators of these outages. If you do not have a monitoring system in place, you could work a simple mail program into it.
CODE
'' 'Place this script in any directory. ' 'Execute script and receive MOM alerts.' 'Writes to files in same directory. ' 'Logs an Information event if ' 'connectivity fails for 3 consecutive ' 'minutes (measure of 6). ' '2 echo's each minute. ' 'Running total parameters: ' 'Line up = 0 ' '50% packet loss = 1 ' '100% packet loss = 2 ' 'Logs an event when running total ' '= 6. ' 'Author: Jonathan Almquist ' 'monsterjta at tek-tips ' '''
Option Explicit
Dim WshShell Dim Fso Dim CurDir Dim TodaysLog Dim LogName Dim TempLogName Dim CreateLog Dim TodayDate Dim TomorrowDate Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8
Set WshShell = CreateObject ("wscript.Shell") Set Fso = CreateObject ("scripting.filesystemobject")
TodayDate = Date TomorrowDate = Date + 1 CurDir = CreateObject ("WScript.Shell").CurrentDirectory & "\" TempLogName = CurDir & "TempLog.txt"
'' 'Definitions and ip address array' '' Dim AddressList Dim ipAddress
AddressList = Array ("<ip_address or A_Record")
' 'Create the logfiles' ' Call CreateLogFile
'' 'Ping each ip address and write to logfile' '' Do While TodayDate = Date For Each ipAddress In AddressList Call KeepAlive Next WScript.Sleep (30000) For Each ipAddress In AddressList Call AnalyzeLogs Next WScript.Sleep (30000) ' 'New day' ' If TodayDate <> Date Then TodayDate = Date TomorrowDate = Date + 1 Call CreateLogFile End If Loop
' 'FUNCTIONS' ' Function CreateLogFile
For Each ipAddress In AddressList LogName = CurDir & Replace (TodayDate, "/", "-", 1) & "_" LogName = LogName & ipAddress & ".txt"
Set CreateLog = Fso.CreateTextFile (LogName, True) CreateLog.Close Next
End Function
Function KeepAlive
Dim Ping Dim Command Dim CreateTempLog Dim ReadTempLog Dim TempLine Dim CurTime Dim WriteLog
Set ReadTempLog = Fso.OpenTextFile (TempLogName, ForReading)
Do Until ReadTempLog.AtEndOfStream TempLine = ReadTempLog.ReadLine TempLine = Trim (TempLine) ' 'Build string for logfile' ' If InStr (TempLine, "Packets:") Then If InStr (TempLine, "(0% loss)") Then WriteLog.WriteLine _ (CurTime & " ::: Line Up! ::: code 0") If InStr (TempLine, "(50% loss)") Then WriteLog.WriteLine _ (CurTime & " ::: Warning! ::: 50% Packet Loss during this keepalive interval! ::: code 1") If InStr (TempLine, "(100% loss)") Then WriteLog.WriteLine _ (CurTime & " ::: Critical! ::: 100% Packet Loss during this keepalive interval! ::: code 2") End If Loop