[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Help Help In Creating VBScript that will notify me when an Internal Web Pages goes Down

Posted on 2008-06-21
7
Medium Priority
?
295 Views
Last Modified: 2011-10-19
Hi All, we are 100% Microsoft Windows organization. We have a custom application that has a custom web interface that has a tendency to go down about twice a week. (this is a seperate issue) Anyway I was wonder if it is possible to create a VBScript to notify me and my boss when this web page is down and to send a net send message to our workstations as well. For example is the web address in question is http:\\intranet1 get a page cannot be displayed I need this script to automatic send an email to myseld & my boss along with a net send message? Is this possible? Please note I'm not a script writing person
0
Comment
Question by:compdigit44
  • 3
  • 3
7 Comments
 
LVL 29

Expert Comment

by:Badotz
ID: 21837712
If the web interface goes down, how can it tell you it went down? It *is* down.

You want something to monitor the web interface outside of the web interface? A service could do this, but a vbscript? I am not so sure...
0
 
LVL 20

Author Comment

by:compdigit44
ID: 21837724
If the web page is down when users try to access it they usually get something like page cannot be displayed
0
 
LVL 29

Expert Comment

by:Badotz
ID: 21837728
>>...they usually get something like page cannot be displayed

And your question is...?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 20

Author Comment

by:compdigit44
ID: 21837868
I need a script to notify me when this happens so I can address the issue before anyone know the web page is down.
0
 
LVL 29

Expert Comment

by:Badotz
ID: 21838048
See my comment in http:#a21837712
0
 
LVL 20

Author Comment

by:compdigit44
ID: 21838998
I'm trying to find a way to notify myself when the web service goes down before anyone knows about it
0
 
LVL 15

Accepted Solution

by:
sr75 earned 2000 total points
ID: 21839338
Your in luck.  I just wrote a script that does just that.  It does just a bit more then notify you if the website is up or down.  It notifies you if there was a change to the webpage as well.  Just in case your site was defaced.  I added the XMD5.dll that the script uses and another script that will generate the MD5 hash of the particular website you are testing.   Then you just need to add the script and run it as a scheduled task.  Delete the ".txt" from the filename.
'########################################################################################
'#											#
'#	Name:		Check_Website.vbs						#
'#	Version:	1.0.0								#
'#	Created:	June 6th, 2008							#
'#	Modified:	n/a								#
'#	Author:		Martin Roeske							#
'#											#
'#	Description:	This script will Chek the content of the listed website against #
'#			its known good MD5 hash. If the check fails, it will attempt to #
'#			restart the website in IIS, log the failure, and send an email. #
'#			Email notifications will only be sent every 30 mintes.		#
'#											#			
'#	Software:	XMD5.dll  (from XStandard and scanned by www.virustotal.com)	#
'#			MS IIS   (needs to be running and configured on the system)	#
'#			GetWebHash.vbs  (script to obtain the MD5 hash of a website)	#
'#											#
'#	Notes:		This script uses the MSXML2.XMLHTTP.3.0 library to retrieve the	#
'#			html document via an http get request.  It then uses the 	#
'#			XMD5.dll to retrieve the MD5 hash digital signiture of the html #
'#			source code. 							#
'#											#
'#				Sub Function		Description			#
'#			---------------------------------------------------------------	#
'#			func_CheckWebContent()	This function makes use of the 		#
'#						MSXML2.XMLHTTP.3.0 object and the 	#
'#						XMD5.dll to retrieve the source code of #
'#						the page via an http GET request, and 	#
'#						then converts this to an MD5 Hash. The  #
'#						Hash is compared to a provided known 	#
'#						good Hash for the same source code.  It #
'#						then provides a boolean to the main 	#
'#						function for either PASS or FAIL.	#
'#											#
'#			func_RestartWebsite()	This function will attempt to restart 	#
'#						the website server only if it is 	#
'#						currently running.  If the serverstate 	#
'#						is is stopped, it will not make an 	#
'#						attempt to restart due to the fact that #
'#						it may be administratively down.	#
'#											#
'#			func_SiteState()	This function convert the numeric code 	#
'#						of the websites ServerState property to #
'#						a string.				#
'#											#
'#			func_Cookie()		This function will create a "cookie" 	#
'#						if the ping connectivity test fails. It #
'#						will also check the cookie so that a 	#
'#						notification is sent every 30 minutes.	#
'#											#
'#			func_Log()		This function will write the product	#
'#						information to a network share. It will #
'#						also rotate out any data that is older 	#
'#						than 90 days.				#
'#											#
'#			func_TimeStamp()	This function will generate a timestamp	#
'#						in this format:  YYYYMMDD HH:MM:SS AM	#
'#											#
'#			func_Notify()		This function will send an notification	#
'#						via email stating that the server has	#
'#						failed its test.			#
'#											#
'########################################################################################
'---------------------------------------------------------------------------
'
'				Main Function
'
'---------------------------------------------------------------------------
'On Error Resume Next
 
DIM strServer
DIM strWebServer
DIM WebServer
DIM FSO
DIM WebService
DIM WebSite
DIM strMD5
DIM strName
DIM boolSite
DIM strMSG
DIM boolRestart
DIM strCookFldr
DIM strCookie
 
strWebServer = "IIS Web Server"
WebSite = "Website URL"
strMD5 = "MD5 hash of the site"
strServer = "localhost"
 
set FSO = CreateObject("Scripting.FileSystemObject")
set WebService = GetObject("IIS://" & strServer & "/W3SVC")
 
For Each WebServer in WebService
        If WebServer.Class = "IIsWebServer" then 
                strName = lcase(WebServer.ServerComment)
		If lcase(strName) = lcase(strWebServer) then
               	        If InStr(left(WebSite, 10), "://") = FALSE then
                       	        WebSite = "http://" & WebSite
                       	End If
                        boolSite = func_CheckWebContent(WebSite,strMD5)
			If boolSite = FALSE then
				strMSG = func_TimeStamp() & vbtab & strName & vbtab & WebSite & vbtab
				strMSG = strMSG1 & "Website failed to pass the MD5 consistency check."  
				boolRestart = func_RestartSite(WebServer)
                              
                        	If boolRestart = TRUE then
       	                              	strMSG = strMSG & " Site successfully restarted." & vbcrlf
               	               	Else
                       	               	strMSG = strMSG & " Site restart was unsuccessful." & vbcrlf
                       	       	End If
 
                       	Else
				strCookFldr = "C:\ScriptLogs\Cookie\"
				strCookie = strCookFldr & strName & ".Cookie"
			
				If FSO.FileExists(strCookie) then
					FSO.DeleteFile(strCookie)
 
					strMSG = func_TimeStamp() & vbtab & strName & vbtab & WebSite & vbtab
					strMSG = strMSG & "Website has returned to normal" & vbcrlf
				End If
 
               		End If
			If strMSG <> "" then 
				func_Log strMSG,strName
                      	End If
			strMSG = "" 
		End If
        End If
Next
 
set strServer = Nothing
set FSO = Nothing
set WebService = Nothing
set WebSite = Nothing
set strWebSite = Nothing
set strWebServer = Nothing
set WebServer = Nothing
set strMD5 = Nothing
set strName = Nothing
set boolSite = Nothing
set strMSG = Nothing
set boolRestart = Nothing
set strCookFldr = Nothing
set strCookie = Nothing
 
wscript.quit
 
 
'---------------------------------------------------------------------------
'
'				Sub Functions
'
'---------------------------------------------------------------------------
Function func_CheckWebContent(URL, strTest)
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	'
	'  This function uses the MSXML2.XMLHTTP.3.0 object and the
	'  XMD5.dll to retrieve the source code of the page via an
	'  http GET request, and then converts this to an MD5 Hash.
	'  The Hash is compared to a provided known good Hash for
	'  the same source code.  It then provides a boolean to 
	'  the main function for either PASS or FAIL.
	'
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
	DIM XML
	DIM MD5
	DIM strHTML
	DIM strHASH
 
	Set XML = CreateObject("MSXML2.XMLHTTP.3.0")
	Set MD5 = CreateObject( "XStandard.MD5" )
 
        XML.Open "GET", URL, False
        XML.setRequestHeader "User-Agent","MyBrowser"  
        XML.send   
 
        If err.number <> 0 then 
                strHTML = "Url not found" 
        else 
                strHTML = XML.responseText 
        End If
 
        strHash = MD5.GetCheckSumFromString(strHTML)
 
        If strHash = strTest then
                func_CheckWebContent = TRUE
        Else
                func_CheckWebContent = FALSE
        End If
 
	set MD5 = Nothing
	set XML = Nothing
	set strHTML = Nothing
	set strHash = Nothing
 
End Function 'func_CheckWebContent()
 
 
Function func_RestartSite(WebServer)
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	'
	'  This function will attempt to restart the website server
	'  only if it is currently running.  If the serverstate is
	'  is stopped, it will not make an attempt to restart due
	'  to the fact that it may be administratively down.
	'
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
        func_RestartSite = FALSE
       	If WebServer.serverstate = 2 then 
		WebServer.Stop
                wscript.sleep 3000
		WebServer.start
		func_RestartSite = TRUE
	End If
	
End function 'func_RestartSite()
 
 
        
Function func_SiteState(strState)
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	'
	'  This function convert the numeric code of the websites
	'  ServerState property to a string.
	'
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
	SELECT CASE strState
	CASE 1
		func_SiteState = "Starting Website"
	CASE 2
		func_SiteState = "Website Started"
	CASE 3
		func_SiteState = "Stopping Website"
	CASE 4
		func_SiteState = "Website Stopped"
	CASE 5
		func_SiteState = "Pausing Website"
	CASE 6
		func_SiteState = "Website Paused"
	CASE 7
		func_SiteState = "Continuing Website"
	CASE ELSE
		func_SiteState = "Unknown state"
	END SELECT
 
End Function 'func_SiteState()
 
Function func_Cookie(CServer, test)
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	'
	'  This function will create a "cookie" should the MD5 
	'  check fail for the website.  It will also check the 
	'  cookie so that a notification is sent every 30 minutes.
	' 
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
	DIM strCFold,strCook,blCookie
	DIM rFile,rLine,rDate,cFile,nTime
 
	strCFold = "C:\ScriptLogs\Cookie\"
	strCook = strCFold & CServer & ".Cookie"
 
	If FSO.FileExists(strCook) then
		Set rFile = FSO.OpenTextFile(strCook)
	
		Do Until rFile.AtEndOfStream
			rLine = rFile.ReadLine
			If rLine <> "" then
				rDate = CDate(split(rLine, vbtab)(0))
				nTime = Now()
				If DateDiff("N", rDate, nTime) < 30 then
					blCookie = FALSE
				Else
					blCookie = TRUE
				End If
			End If
		Loop
	Else
		blCookie = TRUE
	End If
 
	If blCookie = TRUE then
                If FSO.FolderExists(strCFold) = false then
                        FSO.CreateFolder(strCFold)
                End If
 
		set cFile = FSO.OpenTextFile(strCook, 2, True)
		cFile.Write func_TimeStamp() & vbtab & CServer
		cFile.close
		func_Cookie = TRUE
	Else
		func_Cookie = FALSE
	End If		
 
	set strCFold = Nothing
	set strCook = Nothing
	set blCookie = Nothing
	set rFile = Nothing
	set rLine = Nothing
	set rDate = Nothing
	set cFile = Nothing
	set nTime = Nothing
		
End Function 'func_Cookie()
 
 
Function func_Log(strLMSG,LServer)
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	'
	'  This function will Log the failed pings to a file on 
	'  the network.  It will also check to ensure the data is
	'  not duplicated in the log.
	'
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
	DIM strFold,strFile,blTest,wFile
	DIM rFile,rLine,rLog,rDate,nTime
 
	strFold = "C:\ScriptLogs\"
	strFile = strFold & LServer & ".Log"
	Timestamp = func_TimeStamp()
 
        If FSO.FolderExists(strFold) = false then
                FSO.CreateFolder(strFold)
        End If
 
	If FSO.FileExists(strFile) then
		Set rFile = FSO.OpenTextFile(strFile)
 
		Do Until rFile.AtEndOfStream
			rLine = rFile.ReadLine
			If rLine <> "" then
				rDate = CDate(split(rLine, vbtab)(0))
				nTime = Now()
				If DateDiff("D", rDate, nTime) < 90 then
					rLog = rLog & rLine & vbcrlf
				End If
			End If
		Loop
		rFile.close
	End If 
 
	If inStr(lcase(strLMSG), "normal") = FALSE then
		blTest = func_Cookie(LServer,rLog)
		strSub = " website failure"
	Else
		blTest = TRUE
		strSub = " website OK"
	End If
 
	set wFile = FSO.OpenTextFile(strFile, 2, True)
	wFile.write strLMSG 
 
	If blTest = TRUE then
		wFile.Write TimeStamp & vbTab & Server & vbTab & "**** Email Sent ****" & vbcrlf 
		func_Notify LServer,strLMSG,strSub
	End If
 
 
	wFile.Write rLog
	wFile.Close 
 
	set strFold = Nothing
	set strFile = Nothing
	set blTest = Nothing
	set wFile = Nothing
	set rFile = Nothing
	set rLine = Nothing
	set rLog = Nothing
	set rDate = Nothing
	set nTime = Nothing
 
End Function 'func_Log()
 
 
Function func_TimeStamp()
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	'
	'  This function will generate a timestamp in this format:
	'
	'		 YYYYMMDD HH:MM:SS AM/PM
	'
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
	DIM strYear
	DIM strMonth
	DIM strDay
	DIM strTime
	DIM strStamp
 
	strYear = Year(Now)
	strMonth = Month(Now)
	strDay = Day(Now)
	strTime = Time()
	If len(strMonth) < 2 then
		strMonth = "0" & strMonth
	End If
	If len(strDay) < 2 then
		strDay = "0" & strDay
	End If
	
	strStamp = strYear & "-" & strMonth & "-" & strDay & " " & strTime
 
	if len(strStamp) <> 22 then
		Do Until len(strStamp) > 21
			strStamp = strStamp & " "
		Loop
	end If
		
	func_TimeStamp = strStamp
 
	set strYear = Nothing
	set strMonth = Nothing
	set strDay = Nothing
	set strTime = Nothing
	set strStamp = Nothing
 
End Function 'func_TimeStamp()
 
 
Function func_Notify(Server,strEMSG, strESub)	
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	'
	'  This function will send an email notification stating 
	'  that Server has failed it's ping test.
	'
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
	DIM strSendName
	DIM strRecip
	DIM strSubject
	DIM strSrv
	DIM strSend
	DIM strServer
	DIM strPort
	DIM Msg
 
	strSendName = "webmaster@domain.com"		            'Sender's Email
	strSrv = "servername or ip"               		    'SMTP Server
	strSubject = "ALERT!!!  " & ucase(Server) & strESub         'Email Subject
	strRecip = "recipient@domain.com"		            'Recipient's Email
 
	strSend = "http://schemas.microsoft.com/cdo/configuration/sendusing"
	strServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
	strPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
	
	Set Msg = CreateObject("CDO.Message")
	Msg.Configuration.Fields.Item(strSend) = 2
	Msg.Configuration.Fields.Item(strServer) = strSrv
	Msg.Configuration.Fields.Item(strPort) = 25
	Msg.Configuration.Fields.Update
 
	Msg.Subject = strSubject
	Msg.From = strSendName
	Msg.To = strRecip
	Msg.TextBody = strEMsg
	Msg.Send
 
	set strName = Nothing
	set strRecip = Nothing
	set strSubject = Nothing
	set strSrv = Nothing
	set strSend = Nothing
	set strServer = Nothing
	set strPort = Nothing
	set Msg = Nothing
 
End Function 'func_Notify()

Open in new window

GetWebHash.vbs.txt
XMD5.dll.txt
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

867 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