Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I create a simple program or script that will notify me when one of our servers is down?

Posted on 2008-06-13
7
Medium Priority
?
737 Views
Last Modified: 2011-06-09
We have about a dozen Windows servers in our office, some of which are virtual. Some of the less-essential servers go down on occasion and I don't know about it untl after a problem has arisen. For example, we have a fax server that will go down sometimes and I won't know until customers call and say they can't fax something to us.

I thought about running a batch file or script that would ping each server on the hour and let me know if the ping fails. Then I realized we have one server where being powered on isn't enough -- it must be logged in, so a startup program can launch (for some reason it won't start as a system service).

What can I do to monitor my servers in an old-school way that involves some simple scripting? I'd be willing to use an open-source program to handle it if one exists, but this isn't something I want to throw hundreds of dollars at (with a commercial program) when I know can do it for free either on my own or with a program someone else has already written for this purpse. I am decent with batch files and I've done some beginner stuff with C++ and VB scripting. What's the best way to attack this problem?
0
Comment
Question by:wdabbs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 28

Expert Comment

by:FishMonger
ID: 21780328
Nagios is what our company uses, and it's open source.

http://www.nagios.org/
0
 
LVL 18

Expert Comment

by:BSonPosh
ID: 21781206
I would recommend Powershell. You could use a very simple script to connect to each server and let you know the Current Uptime and check specific services.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 800 total points
ID: 21783410
Hi, here's a VBS script that will monitor servers in a text file called "computers.txt", pinging them every two minutes.

We could modify the script to check for the existence of the Explorer.exe process, which would tell us whether someone was currently logged in or not....

Regards,

Rob.
strFile = "computers.txt"
strLogFile = "LogFile.txt"
 
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "about:blank"
objIE.ToolBar = False
objIE.AddressBar = False
objIE.Top = 0
objIE.left = 0
objIE.Width = 800
objIE.Height = 600
objIE.Visible = True
objIE.menubar = False
objIE.StatusBar = False
objIE.Document.Body.Title = "Ping Status"
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
While IsObject(objIE) = True
	On Error Resume Next
	objIE.Document.Body.InnerHTML = "<br><table><tr><td width='40' bgcolor='green'></td><td> Successful ping</td><td width='40' bgcolor='orange'></td><td> Successful ping but failed connectivity</td><td width='40' bgcolor='red'></td><td> Failed ping</td></table><br>"
	If Err.Number <> 0 Then WScript.Quit
	On Error GoTo 0
	Set objFile = objFSO.OpenTextFile(strFile, intForReading, False)
	While Not objFile.AtEndOfStream
		strComputer = objFile.ReadLine
		If Ping(strComputer) = True Then
			strColor = "green"
			On Error Resume Next
			Set objWMIService = GetObject("winmgmts:" _
				& "{impersonationLevel=impersonate}!\\" & StrComputer & "\root\cimv2")
			If Err.Number <> 0 Then strColor = "orange"
			Err.Clear
			On Error GoTo 0
		Else
			strColor = "red"
		End If
		On Error Resume Next
		objIE.Document.Body.InnerHTML = objIE.Document.Body.InnerHTML & "<table><tr><td width='200'>" & strComputer & "</td><td width='40' bgcolor='" & strColor & "'></td></tr></table>" & VbCrLf
		If strColor = "green" Then
			strLog = Now & ": " & strComputer & " - GREEN - pinged successfully."
		ElseIf strColor = "orange" Then
			strLog = Now & ": " & strComputer & " - ORANGE - pinged successfully, but connectivity failed."
		ElseIf strColor = "red" Then
			strLog = Now & ": " & strComputer & " - RED - ping failed."
		End If
		WriteToLog strLog
		If Err.Number <> 0 Then WScript.Quit
		On Error GoTo 0
	Wend
	objFile.Close
	Set objFile = Nothing
	On Error Resume Next
	strFullPage = objIE.Document.Body.InnerHTML
	If Err.Number <> 0 Then WScript.Quit
	On Error GoTo 0
	For intSeconds = 120 To 0 Step - 1
		On Error Resume Next
		objIE.Document.Body.InnerHTML = strFullPage & "<br><br>Refreshing in " & intSeconds & " seconds..."
		If Err.Number <> 0 Then WScript.Quit
		On Error GoTo 0
		WScript.Sleep 1000
	Next
Wend
Set objFSO = Nothing
MsgBox "Done"
 
Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 4 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function
 
Sub WriteToLog(strText)
	Set objLogFile = objFSO.OpenTextFile(strLogFile, 8, True)
	objLogFile.WriteLine strText
	objLogFile.Close
	Set objLogFile = Nothing
End Sub

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:wdabbs
ID: 21793345
@RobSampson:

Thanks for the script, I like it. How can I use it to notify me by email? Do I need a separate routine to monitor that log file and look for errors?
0
 
LVL 15

Assisted Solution

by:sr75
sr75 earned 400 total points
ID: 21803279
I had a script that would ping an array of servers, log it, and send an email if the server is non-responsive.  I cannot find it at the moment (I left my thumb drive at home).   However, I use this code to send me the emails.  You should be able to add that to RobSampson's script.
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.Sender = "sender@domain.com"
objMessage.To = "recipient@domain.com"
objMessage.TextBody = "This is some sample message text."
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.domain.com"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
objMessage.Send

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 21818094
Thanks for the grade.  Sorry for not replying...I've been busy....I hope you've managed to piece together the emailng code...

Regards,

Rob.
0
 
LVL 11

Expert Comment

by:bsharath
ID: 21823298
wdabbs
Did you get this to work togeather?
If yes can you post the final post please... So we can use them....
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question