• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 590
  • Last Modified:

Email Alert system for Win 2003 Server Crashes


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 ?

  • 4
  • 3
2 Solutions

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))
     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
          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 
               'Don't really need to do anything... maybe write a log file?
               WScript.Echo strServer & " ping response OK"
          End If
          End If
     End If
'Cleanup vars
Set objShell = Nothing
Set objMessage = Nothing

Open in new window

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?

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

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): -

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.
ACIARAuthor Commented:
Did you mean line 38 not line 34 ?
ACIARAuthor Commented:
Opps - "Did you mean line 38 not line 31"

I cant see what im meant to change on 31 ?
Forgot about line 38. You need to change that as well. You also need to change the email addresses: -
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now