Write a ping response to the event viewer

We have some server monitoring software that can alert us if a particular event is logged in event viewer. We would like to run a script or batch file every 15 mintes to run a ping command to a remote site connected via vpn. Based on the response form the remote site i would like to be able to log an event into event viewer to alert us if the remote site has been disconnected. So for example if the remote site is down and i get a request timed out error message on the ping command i would like this to log an event to event viewer which in turn i can look out for with our serve rmonitoring software which will alert us accordingly.
LVL 6
shaynegAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dusan_BajicCommented:
I used Keep Connected for similar purpose:
http://www.greyware.com/software/keepconnected/

It is not a batch file, but it can do what you need (and much more).

Brad HoweDevOps ManagerCommented:
Here you go.

Save as a VBS and run through Job scheduler.

Cheers,
Hades666
'Ping_event_logging.vbs

Dim strHost
strHost =  "10.0.1.3"

Ping(strHost)

Function Ping(strHost)
    dim objPing, objRetStatus, objcode
    set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
      ("select * from Win32_PingStatus where address = '" & strHost & "'")

    for each objRetStatus in objPing
        if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
           Select Case objRetStatus.StatusCode
		Case 0 PingStatus = "Success"
		Case 11001 PingStatus = "Status code 11001 - Buffer Too Small"
	        Case 11002 PingStatus = "Status code 11002 - Destination Net Unreachable"
            	Case 11003 PingStatus = "Status code 11003 - Destination Host Unreachable"
              	Case 11004 PingStatus = "Status code 11004 - Destination Protocol Unreachable"
	        Case 11005 PingStatus = "Status code 11005 - Destination Port Unreachable"
            	Case 11006 PingStatus = "Status code 11006 - No Resources"
            	Case 11007 PingStatus = "Status code 11007 - Bad Option"
            	Case 11008 PingStatus = "Status code 11008 - Hardware Error"
            	Case 11009 PingStatus = "Status code 11009 - Packet Too Big"
            	Case 11010 PingStatus = "Status code 11010 - Request Timed Out"
            	Case 11011 PingStatus = "Status code 11011 - Bad Request"
            	Case 11012 PingStatus = "Status code 11012 - Bad Route"
            	Case 11013 PingStatus = "Status code 11013 - TimeToLive Expired Transit"
            	Case 11014 PingStatus = "Status code 11014 - TimeToLive Expired Reassembly"
            	Case 11015 PingStatus = "Status code 11015 - Parameter Problem"
            	Case 11016 PingStatus = "Status code 11016 - Source Quench"
            	Case 11017 PingStatus = "Status code 11017 - Option Too Big"
            	Case 11018 PingStatus = "Status code 11018 - Bad Destination"
            	Case 11032 PingStatus = "Status code 11032 - Negotiating IPSEC"
           	Case 11050 PingStatus = "Status code 11050 - General Failure"
            	Case Else PingStatus = "Status code " & objPing.StatusCode &  " - Unable to determine cause of failure."
          End Select

            objcode = Now() & " - Host " & strHost & " could not be contacted - "  & PingStatus 
	    EventLogger (objcode)
        end if
    next
End Function 

Function EventLogger (sText)
' Constants for type of event log entry
	const EVENTLOG_SUCCESS = 0
	const EVENTLOG_ERROR = 1
	const EVENTLOG_WARNING = 2
	const EVENTLOG_INFORMATION = 4
	const EVENTLOG_AUDIT_SUCCESS = 8
	const EVENTLOG_AUDIT_FAILURE = 16

set objShell = CreateObject("WScript.Shell")
objShell.LogEvent EVENTLOG_INFORMATION, sText
End Function

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shaynegAuthor Commented:
Solution worked great thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.