This is *G o o g l e*'s cache of http://www.momanswers.com/Downloads/ICMPPing.txt as retrieved on 28 Oct 2006 23:58:47 GMT. *G o o g l e*'s cache is the snapshot that we took of the page as we crawled the web. The page may have changed since that time. Click here for the current page without highlighting. This cached page may reference images which are no longer available. Click here for the cached text only. To link to or bookmark this page, use the following url: |http://www.google.com/search?q=cache:u1fKe4vhrWAJ:www.momanswers.com/Downloads/ICMPPing.txt+ICMPPing.txt&hl=en&gl=uk&ct=clnk&cd=3&client=firefox-a| /Google is neither affiliated with the authors of this page nor responsible for its content./ These terms only appear in links pointing to this page: *icmpping txt * ------------------------------------------------------------------------ '********************************************************************************* ' ' Script Name - ICMPPing ' ' Version - 2.2.2 (17-aug-2004) ' ' Purpose - Pings a list of hosts and raise events ' ' Events - 1000 = Host is alive (information) ' 1001 = Host is NOT alive (warning) ' 1002 = Host has recovered (information) ' ' Parameters - IncludeComputers = List of computers that should be allowed to run the script. ' Leave blank to allow all. Seperate multiple values by ";". ' ExcludeComputers = List of computers that should NOT be allowed to run the script. ' Exclude overrule Include. Seperate multiple values by ";". ' Hosts = List of IP addresses or hostnames to PING seperated by ";". ' (Fx. "host1;host2;host3") ' HostDescription = Description of the host. This info is included in the event and is ' useful if the host PING'ed is an IP-address and not a hostname. ' DomainSuffix = If not left blank DomainSuffix will be appended to all seperate ' hostnames (and IP-addresses) in the list. ' RetryAttempts = Maximum number of times the script will attempt to retrieve the status. ' Defaults to 3 if left blank. ' RetryInterval = Interval in seconds between each retry attempt. ' Defaults to 5 seconds if left blank. ' EventFrequency = Number of minutes that must pass between two "Host Not Alive" events on ' the same host before creating a new event. Essentially the timestamp of ' the checkfile is checked if it exists and if the specified number of minutes ' haven't passed since the last time the timestamp was updated no event is ' logged. This is useful if a host is PING'ed every 2 minutes, but you only want ' an event every 15 minutes as long as it is unreachable (requires that the EPR ' doesn't consolidate the events from the script). Defaults to 15 if left blank. ' SuppressEvents = List of events to suppress. Seperate multiple values by ";". ' (Fx. "1000;1002") ' WorkingFolder = Path to folder where "PING-.NotAlive" ' check files are saved. Must end with a backslash "\". ' PingSeverity = Severity of the PING. This parameter is logged in the event as ' Event_Parameter1 so it can be checked in a rule to differentiate ' the reponse to different PING's (fx. internal vs. external servers). ' If PingSeverity is set to fx. "low" this is the text to check the ' Event_Parameter1 of the event for in the event processing rule. ' If left blank Event_Parameter1 will not be included with the event. ' ' Notes - If you want to ignore an agent without diabling the rule, this is possible by creating an ' Ignore-file in the format "PING-.Ignore" in the folder specified in WorkingFolder ' (fx. "PING-myserver.mydomain.com.Ignore"). ' ' Author - Nicolaj Rasmussen ' '********************************************************************************* Option Explicit ' --- Define Constants --- ' Event types Const Event_Type_Success = 0 Const Event_Type_Error = 1 Const Event_Type_Warning = 2 Const Event_Type_Info = 4 Const Event_Type_Audit_Success = 8 Const Event_Type_Audit_Failure = 16 ' Event property-IDs Const Event_Host_Alive = 0 Const Event_Host_Not_Alive = 1 Const Event_Host_Recovered = 2 ' Default values Const Default_Retry_Interval = 5 Const Default_Retry_Attempts = 3 Const Default_Ping_Data = "ICMPPINGICMPPINGICMPPINGICMPPING" ' 32 bytes Const Default_LogFile_Prefex = "PING-" Const Default_CheckFile_Ext = ".NotAlive" Const Default_IgnoreFile_Ext = ".Ignore" Const Default_Event_Not_Alive_Age = 15 Const Host_Not_Specified = "HOST_NOT_SPECIFIED" Const CheckFileContents = "Host unreachable!" ' --- Define variables --- ' Integers Dim intEventID, intEventType Dim intRetryAttempts, intRetryInterval, intCurrentAttempt Dim intCurrentHostStatus, intEventFrequency Dim intMinutesSinceLastEvent ' Strings Dim strHosts, strHost, strSuppressAliveMsg, strDomainSuffix Dim strWorkingFolder, strEventMsg Dim strIncludeComputers, strIncludeComputerName, strExcludeComputers, strExcludeComputerName Dim strPingSeverity, strPingData Dim strLocalComputerName Dim strSuppressEvents, strSuppressEvent Dim strHostDescription Dim strFileLastModified Dim strLogFilePrefex, strIgnoreFilename, strIgnoreFileExt, strCheckFilename, strCheckFileExt ' Arrays Dim arrHosts, arrIncludeComputers, arrExcludeComputers, arrEventInfo(2), arrSuppressEvents ' Objects Dim objUtil, objINet, objParams, objFSO ' Textstreams Dim txtLogFile ' Long integers Dim lngRoundTripMs ' Booleans Dim bolPingSuccess, bolExcludeComputer, bolExecuteOnComputer, bolSuppressEvents, bolSubmitEvent InitVars CreateObjects GetParameters ParseParameters SetEventProperties CheckIfExecute ' Start main routine if script is allowed to run on the local agent computer If bolExecuteOnComputer = True Then ' Do it for every host in the list For Each strHost In arrHosts ' Append domain suffix to host If strDomainSuffix <> "" Then strHost = strHost & strDomainSuffix ' Reset variables ResetVariables ' Only continue if there doesn't exist an ignorefile for the host If Not objFSO.FileExists(strIgnoreFilename) Then ' Start loop Do While intCurrentAttempt <= intRetryAttempts ' Increment attempt intCurrentAttempt = intCurrentAttempt + 1 ' Ping the host If objINet.Ping(strHost, strPingData, lngRoundTripMs) Then ' If ping successfully then exit loop bolPingSuccess = True Exit Do End If objUtil.Sleep intRetryInterval ' Loop until specified number of retry attempts is reached Loop Select Case bolPingSuccess ' Case: Host is reachable Case True ' If the checkfile already exists it means that the host was unreachable during ' the last run and that it has recovered since then If objFSO.FileExists(strCheckFilename) Then intCurrentHostStatus = Event_Host_Recovered ' Delete checkfile objFSO.DeleteFile(strCheckFilename) Else ' Set event properties intCurrentHostStatus = Event_Host_Alive End If ' Case: Host is unreachable Case False intCurrentHostStatus = Event_Host_Not_Alive ' Check if the checkfile exists (unreachable during the last run) If objFSO.FileExists(strCheckFilename) Then ' Get LastModified date of the checkfile strFileLastModified = GetFileModifiedDate(strCheckFilename) ' Calculate the minutes that have passed since the checkfile was last modified intMinutesSinceLastEvent = DateDiff("n", strFileLastModified, Now()) ' CHeck if the number of minutes passed since the last update exceeds or equals the EventFrequency parameter If intMinutesSinceLastEvent >= intEventFrequency Then ' Update timestamp of NotAlive-checkfile CreateOrUpdateCheckFile strCheckFilename Else bolSubmitEvent = False End If Else ' Create NotAlive-checkfile CreateOrUpdateCheckFile strCheckFilename End If End Select ' Build event-message strEventMsg = "The host '" & strHost & "'" & strHostDescription ' Get event properties from array intEventID = arrEventInfo(intCurrentHostStatus)(0) strEventMsg = strEventMsg & arrEventInfo(intCurrentHostStatus)(1) intEventType = arrEventInfo(intCurrentHostStatus)(2) ' Add trailer to event message strEventMsg = strEventMsg & vbCRLF & "(PING executed from '" & strLocalComputerName & "')" ' Check if the event should be suppressed If Not CheckSuppressEvent(intEventID) Then ' Create and submit event if bolSubmitEvent is set to true If bolSubmitEvent Then CreateSubmitEvent strEventMsg, intEventID, intEventType, strPingSeverity End If End If Next End If DeleteObjects ' -------------------- Functions and subs -------------------- ' Function : WriteLogFile(strFilename, strTxt) ' Parameters : strFilename = path+filename to log (directory MUST exist) ' strTxt = text to write to logfile ' Description : Write a line of text to a logfile Function WriteLogFile(strFilename, strTxt) ' Declare constants Const ForReading = 1, ForWriting = 2, ForAppending = 8 ' Declase variables Dim objFSO, txtLogFile, intFileMode ' Create FSO object Set objFSO = CreateObject("Scripting.FileSystemObject") ' If logfile exists then open for appending else open for writing (thus create the file) If objFSO.FileExists(strFilename) Then intFileMode = ForAppending Else intFileMode = ForWriting End If ' Open logfile Set txtLogFile = objFSO.OpenTextFile(strFilename, intFileMode, True) ' Write txt to logfile txtLogFile.WriteLine strTxt ' Close logfile, save contents txtLogFile.Close Set objFSO = Nothing End Function ' Sub : CreateOrUpdateCheckFile(strCheckFilename) ' Parameters : strCheckFilename ' Description : Create NotAlive-checkfile if is doesn't exist and update timestamp if it does Sub CreateOrUpdateCheckFile(strCheckFilename) Set txtLogFile = objFSO.CreateTextFile(strCheckFilename, True) txtLogFile.WriteLine(CheckFileContents) txtLogFile.Close End Sub ' Function : GetFileModifiedDate(strFileSpec) ' Parameters : strFileSpec = Complete path to file ' Description : Returns a string with the Modified Date-stamp of a file. ' Returns -1 if the file doesn't exist Function GetFileModifiedDate(strFileSpec) Dim objFSO, objFile Set objFSO = CreateObject("Scripting.FileSystemObject") ' Only bind to file if it exists If objFSO.FileExists(strFileSpec) Then Set objFile = objFSO.GetFile(strFileSpec) GetFileModifiedDate = objFile.DateLastModified Else GetFileModifiedDate = -1 End If End Function ' Function : CheckSuppressEvent(intEventID) ' Parameters : intEventID = The eventID that should be checked for suppression ' Description : Check if a eventID should be suppressed (specified in the parameters) Function CheckSuppressEvent(intEventID) If bolSuppressEvents = True Then For Each strSuppressEvent In arrSuppressEvents If CInt(strSuppressEvent) = CInt(intEventID) Then CheckSuppressEvent = True End If Next Else CheckSuppressEvent = False End If End Function ' Function : GetLocalComputerName() ' Parameters : None ' Description : Gets the name of the local computer Function GetLocalComputerName() Dim objNetwork Set objNetwork = CreateObject("WScript.Network") GetLocalComputerName = objNetwork.ComputerName Set objNetwork = Nothing End Function ' Sub : CreateObjects ' Parameters : None ' Description : Creates objects used by the script Sub CreateObjects Set objUtil = CreateObject("OpScrUtil.Utility") Set objINet = CreateObject("OpScrUtil.INet") Set objFSO = CreateObject("Scripting.FileSystemObject") End Sub ' Sub : DeleteObjects ' Parameters : None ' Description : Deletes objects used by the script Sub DeleteObjects Set objUtil = Nothing Set objINet = Nothing Set objFSO = Nothing End Sub ' Sub : GetParameters ' Parameters : None ' Description : Retrieves the parameters used in the script Sub GetParameters ' Create parameter object Set objParams = ScriptContext.Parameters strIncludeComputers = LCase(objParams.Get("IncludeComputers")) ' Always lowercase strExcludeComputers = LCase(objParams.Get("ExcludeComputers")) ' Always lowercase strHosts = objParams.Get("Hosts") strDomainSuffix = objParams.Get("DomainSuffix") intRetryInterval = objParams.Get("RetryInterval") intRetryAttempts = objParams.Get("RetryAttempts") strPingSeverity = objParams.Get("PingSeverity") strWorkingFolder = objParams.Get("WorkingFolder") strSuppressEvents = objParams.Get("SuppressEvents") strHostDescription = objParams.Get("HostDescription") intEventFrequency = objParams.Get("EventFrequency") ' Delete parameter object Set objParams = Nothing End Sub ' Sub : ParseParameters ' Parameters : None ' Description : Parses the parameters used in the script Sub ParseParameters ' Add trailing backslash to strWorkingFolder if it is missing If Right(strWorkingFolder,1) <> "\" Then strWorkingFolder = strWorkingFolder & "\" ' Add leading dot (.) to strDomainSuffix if it is missing If strDomainSuffix <> "" Then If Left(strDomainSuffix,1) <> "." Then strDomainSuffix = "." & strDomainSuffix ' Default to value of constant Host_Not_Specified if nothing is specified in the parameters (Hosts) If strHosts = "" Then strHosts = Host_Not_Specified ' Split hosts into array arrHosts = Split(strHosts, ";") ' Make sure intRetryInterval is integer If IsNumeric(intRetryInterval) Then intRetryInterval = CInt(intRetryInterval) Else ' Set to default value if nothing is specified in the parameters (RetryInterval) intRetryInterval = Default_Retry_Interval End If ' Make sure intRetryAttempts is integer If IsNumeric(intRetryAttempts) Then intRetryAttempts = CInt(intRetryAttempts) Else ' Set to default value if nothing is specified in the parameters or value is invalid intRetryAttempts = Default_Retry_Attempts End If ' Set strIncludeComputer to local computername if it is not specified in the parameters If strIncludeComputers = "" Then strIncludeComputers = GetLocalComputerName() ' Split names into array if multiple computernames are specified. arrIncludeComputers = Split(strIncludeComputers, ";", -1, 1) If strSuppressEvents <> "" Then bolSuppressEvents = True arrSuppressEvents = Split(strSuppressEvents, ";", -1, 1) End If ' If any computernames are specified in the parameters to be excluded split names into array If strExcludeComputers <> "" Then bolExcludeComputer = True arrExcludeComputers = Split(strExcludeComputers, ";", -1, 1) End If ' If HostDescription contains data, include this in the eventmessage in a paranthesis If strHostDescription <> "" Then strHostDescription = " (" & strHostDescription & ") " If IsNumeric(intEventFrequency) Then intEventFrequency = CInt(intEventFrequency) Else intEventFrequency = Default_Event_Not_Alive_Age End If End Sub ' Sub : InitVars ' Parameters : None ' Description : Inits the variables used in the script Sub InitVars bolExcludeComputer = False bolExecuteOnComputer = False bolSuppressEvents = False bolSubmitEvent = True ' Set PING data to default strPingData = Default_Ping_Data ' Set Checkfile variables to default strLogFilePrefex = Default_LogFile_Prefex strCheckFileExt = Default_CheckFile_Ext strIgnoreFileExt = Default_IgnoreFile_Ext End Sub ' Sub : ResetVariables ' Parameters : None ' Description : Reset the variables used in the script Sub ResetVariables intCurrentAttempt = 0 bolPingSuccess = False bolSubmitEvent = True strEventMsg = "The host '" & strHost & "' " ' Set name of checkfile strCheckFilename = strWorkingFolder & strLogFilePrefex & strHost & strCheckFileExt ' Set name of ignorefile strIgnoreFilename = strWorkingFolder & strLogFilePrefex & strHost & strIgnoreFileExt End Sub ' Sub : CreateSubmitEvent ' Parameters : None ' Description : Create and submit an event Sub CreateSubmitEvent(varEventMsg, varEventID, varEventType, varEventParam1) Dim objNewEvent Set objNewEvent = ScriptContext.CreateEvent objNewEvent.Message = varEventMsg objNewEvent.EventNumber = varEventID objNewEvent.EventType = varEventType ' If varEventParam1 contains anything then include the text as Event_Parameter1 If varEventParam1 <> "" Then objNewEvent.SetEventParameter(varEventParam1) ScriptContext.Submit(objNewEvent) Set objNewEvent = Nothing End Sub ' Sub : CheckIfExecute ' Parameters : None ' Description : Check if the local computername matches one of those specified in ' the parameters. This prevents the script from running on other agent ' computers if otherwise is specified in the parameters. Sub CheckIfExecute ' Get local computername strLocalComputerName = LCase(GetLocalComputerName()) ' Check is the local computername is specified in the parameter IncludeComputer For Each strIncludeComputerName In arrIncludeComputers If LCase(strIncludeComputerName) = strLocalComputerName Then bolExecuteOnComputer = True Next ' Check if the local computername is specified in the parameter ExcludeComputer If bolExcludeComputer = True Then For Each strExcludeComputerName In arrExcludeComputers If LCase(strExcludeComputerName) = strLocalComputerName Then bolExecuteOnComputer = False Next End If End Sub ' Sub : SetEventProperties ' Parameters : None ' Description : Sets the properties of the events returned Sub SetEventProperties arrEventInfo(0) = Array(1000, " is alive!", Event_Type_Info) arrEventInfo(1) = Array(1001, " is NOT alive!", Event_Type_Warning) arrEventInfo(2) = Array(1002, " has RECOVERED!", Event_Type_Info) End Sub ' -------------------- END SCRIPT --------------------1