server monitor VB script.
deicist
Manchester, UK
So, I was bored at work today and decided to write a little script that pings all our servers regularly and alerts me if one of them doesn't respond. It seems to work fine, just thought I'd post it here in case anyone wants something similar.
first you need sleep.exe from Here, this is used to delay the loop in the batch file so you're not constantly pinging the servers. now create a folder (I use c:\srvping) and put sleep.exe in there.
Now onto the visual basic script.... heres the main script, called pingtest.vbs:
in addition we have a batch file (called pingit.bat)
obviously you replace srv11 to srv17 with your server names. the '600' after the sleep is how long to wait between pings, 600 is 10 minutes.
So, put all those files in the same folder, add a wave file (warning.wav) which plays whenever a server is down and run the batch file. It sits happily on your task bar (just minimize it) and if any of your servers stop responding to pings you'll get a warning sound (I use robbie the robot saying "warning, warning") and a pop up on your screen telling you which server it is. if you don't minimize it you get a nice read out of what servers have been pinged and when the last ping was done.
first you need sleep.exe from Here, this is used to delay the loop in the batch file so you're not constantly pinging the servers. now create a folder (I use c:\srvping) and put sleep.exe in there.
Now onto the visual basic script.... heres the main script, called pingtest.vbs:
Option Explicit
Dim ws : Set ws = CreateObject("WScript.Shell")
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim ThisLine, IP
Dim up : up = "DOWN"
dim server
dim objshell
set objShell = wscript.CreateObject("wscript.shell")
With fso.GetFile("c:\srvping\ping.txt").OpenAsTextStream
Do While NOT .AtEndOfStream
ThisLine = .ReadLine
If InStr(ThisLine, "Pinging") <> 0 Then server = Mid(ThisLine, 8, InStr(ThisLine, ".")-8)
If InStr(ThisLine, "Reply") <> 0 Then up = "UP"
Loop
.Close
End With
if up = "DOWN" then
ws.run "c:\srvping\Warning.wav", 0, true
objshell.popup(Server & " is " & up)
end if
fso.GetFile("c:\srvping\ping.txt").Delete
Set fso = Nothing
Set ws = Nothing
in addition we have a batch file (called pingit.bat)
@echo off
:start
cls
echo =====Pinging servers=====
time /t
echo Pinging SRV01
ping srv01 -n 1 > c:\srvping\ping.txt
pingtest
echo Pinging SRV02
ping srv02 -n 1 > c:\srvping\ping.txt
pingtest
echo Pinging SRV03
ping srv03 -n 1 > c:\srvping\ping.txt
pingtest
echo Pinging SRV04
ping srv04 -n 1 > c:\srvping\ping.txt
pingtest
echo Pinging SRV11
ping srv11 -n 1 > c:\srvping\ping.txt
pingtest
echo Pinging SRV12
ping srv12 -n 1 > c:\srvping\ping.txt
pingtest
echo Pinging SRV13
ping srv13 -n 1 > c:\srvping\ping.txt
pingtest
echo Pinging SRV14
ping srv14 -n 1 > c:\srvping\ping.txt
pingtest
echo Pinging SRV15
ping srv15 -n 1 > c:\srvping\ping.txt
pingtest
echo Pinging SRV16
ping srv16 -n 1 > c:\srvping\ping.txt
pingtest
echo Pinging SRV17
ping srv17 -n 1 > c:\srvping\ping.txt
pingtest
echo ==Server pings completed==
echo ==========================
sleep 600
goto start
obviously you replace srv11 to srv17 with your server names. the '600' after the sleep is how long to wait between pings, 600 is 10 minutes.
So, put all those files in the same folder, add a wave file (warning.wav) which plays whenever a server is down and run the batch file. It sits happily on your task bar (just minimize it) and if any of your servers stop responding to pings you'll get a warning sound (I use robbie the robot saying "warning, warning") and a pop up on your screen telling you which server it is. if you don't minimize it you get a nice read out of what servers have been pinged and when the last ping was done.
0