Email Alert system for Win 2003 Server Crashes

Hello,

Im after a way that I can recieve a email if certain servers in the domain crash. I thought their might be a program that simply ping's the servers periodically and emails you if the ping fails but I cant seem to find anything yet. Even an email alert when certain services stop running would be useful.

Does anyone know of a way to do this ?

Thanks
ACIARAsked:
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.

mass2612Commented:
Hi,

If you are interested in a simple vbs script to ping servers and email if they are down.

I run this using a scheduled task that run a cmd file every 20 minutes.

The input file is called servers.txt and contains the list of server hostnames or IP addresses you wish to ping.You need to updated the smtpserver.company.com line and the to, from support@company.com lines.

CMD file
cscript.exe pingservers.vbs


Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject("WScript.Shell")
'Here you can set how many pings you want to send, and how long to wait for the response
pingNumber = 4
'note this is in milliseconds
timeOut = 10000
InputFile = "servers.txt"
Set objFile = objFSO.OpenTextFile(InputFile,1,FALSE)
Do Until objFile.AtEndOfStream
     strServer = objFile.ReadLine
     'Give the ability to comment out servers
     If Left(strServer,1) = "'" Then
          strSrvNameLen = Len(strServer)
          WScript.Echo "Skipping server " & Right(strServer,(strSrvNameLen - 1))
     Else
     WScript.Echo "Pinging " & strServer & "..."
     Set objPing = objShell.Exec ("ping " & strServer & " -n " & pingNumber &" -w " & timeOut)
     strPingOut = objPing.StdOut.ReadAll
     If (Split(strPingOut," ")(0)) = "Unknown" Then
          WScript.Echo strPingOut
          Else
          arrPingWholeReturn = Split(strPingOut,"Received")
          arrPingData = arrPingWholeReturn(1)
          arrPingResult = Split(arrPingData," ")
          If arrPingResult(2) = "0," Then
               'Box or network is dead - better tell someone
               WScript.Echo strServer & " - Ping timed out. Machine may be down."
               'Grab a reference to the email object
               Set objMessage = CreateObject("CDO.Message") 
               'Send an email with the results... self explanatory!
               objMessage.Subject = strServer & " - Ping timed out"
               objMessage.Sender = "support@company.com"
               objMessage.From = "support@company.com"
               objMessage.To = "support@company.com"
               objMessage.TextBody = strPingOut
               objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
               'SMTP Server
               objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtpserver.company.com"
               'SMTP Port
               objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
               objMessage.Configuration.Fields.Update
               objMessage.Send
               Else
               'Don't really need to do anything... maybe write a log file?
               WScript.Echo strServer & " ping response OK"
          End If
          End If
     End If
Loop
'Cleanup vars
Set objShell = Nothing
Set objMessage = Nothing

Open in new window

0

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
ACIARAuthor Commented:
Hello Mass2612,

A couple of questions if I was to use this approach. Im not so familiar with VB scripts so I need to clarify a few questions

* You have 3 different file names mentioned: server.txt || cscript.exe || pingservers.vbs - I think I name the text you provided above and name that pingservers.vbs. With the server.txt file I assume I have to put in the IP address's or Server hostnames - but in what format ??? And lastly what is the cscript.exe file for?

0
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

mass2612Commented:
You need to modify the code for the SMTP address info on lines 31, 32, 33 and 34 in the code above.

Aside from that its very simple. Create a directory to store the files i.e. C:\Script\Ping_Script.

Save the code above as a vbs file i.e. pingservers.vbs in C:\Script\Ping_Script.

Create a txt files called servers.txt in C:\Script\Ping_Script. The contents of servers.txt should just include either the hostnames or IP addresses of the servers/Ip's you wish to monitor (hostnames are best): -
Server1
Server2
Server3
etc

Create a batch file or cmd file called pingservers.cmd in C:\Scripts\Ping_Script with the following command: -
cscript.exe pingservers.vbs

Setup a scheduled task to run C:\Scripts\Ping_Script\pingservers.cmd every so many minutes. We do this every 20 minutes so if a box goes down we get an email.

cscript.exe is the Windows executable for vbs scripts cscript runs in a command line mode wscript.exe runs in a Windows/GUI mode.
0
ACIARAuthor Commented:
Did you mean line 38 not line 34 ?
0
ACIARAuthor Commented:
Opps - "Did you mean line 38 not line 31"

I cant see what im meant to change on 31 ?
0
mass2612Commented:
Forgot about line 38. You need to change that as well. You also need to change the email addresses: -
support@company.com
0
ACIARAuthor Commented:
Hello Mass2612 and tgtran,

I found a server monitoring program that meet my requirements however you have both helped me head in the right direction so ill award points between the 2 of you.

Thanks for the help and thanks Mass2612 for the effort on your part, I think I can also use your method aswell if I ever need to.
0
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
Windows Server 2003

From novice to tech pro — start learning today.