To check if url is working and send a status report through mail

We have some upgraded going on some of our web severs.
Till that time we need check many urls manually daily.

I want to write a vb script to check urls if it is up or not and send us status report through mail.

urls address start with https:// and we need to use F5 Token and disable proxy setting to connect those server.

we don't have power shell access as well.

could somebody please help me to write a vbscript or bat script to automate these stuff.
sandeep KumarAsked:
Who is Participating?
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.

An Average Forum Participant Just For FunHardware Tester and DebuggerCommented:
This script will both ping a website and check it for content to verify that it is online. If the website if offline, it will send a email notification. This script writes to a log file every time it runs so that you can check to make sure it is working as expected. Combine this script with a scheduled task to actively monitor the website.

'*********************************************************
' Purpose: Tests to make sure a website is online.
' Created By: An Average Forum Participant Just For Fun
' Notes: This script will scan a website and send an alert
' email out when there is either no ping or no content.
' It also keeps a log of each scan.
'
' I recommend setting up a scheduled task to run this
' script regularly.
'*********************************************************
Option Explicit
'Configure the script here
Dim strLogFile, strEmailHost, strFromEmail, strToEmail, strSubjectMsg, strWebsite
strLogFile = "\\PATHTOSERVER\log.txt"
strEmailHost = "YOUREMAILSERVER"
strFromEmail = "SOMEONE@SOMEWHERE.COM"
strToEmail = "YOU@YOURMAIL.COM"
strSubjectMsg = "Website Alert" 
strWebsite = "WWW.MONITORTHISSITE.COM"

'Tests the website for both ping and content
Dim strAlert, strWebStatus
If PingSite ( strWebsite ) Then
	Dim strWebContent
	strWebContent = GetDataFromURL("http://" & strWebsite, "GET", "")
	If len(strWebContent) > 100 Then
		SendToLog( "Up" )
	Else
		SendToLog( "Down" )
		strAlert = "No Content"
		strWebStatus = "Down"
	End IF
Else
	SendToLog ( "Down" )
	strAlert = "No Ping"
	strWebStatus = "Down"
End If

If strWebStatus = "Down" Then
	SendEmail
End If


'Creates a record in the log
Function SendToLog ( strStatus )
Dim dtmTimeStamp, objFSO, objLogFile
dtmTimeStamp = now()
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile(strLogFile, 8, TRUE)
objLogFile.Write "Time: " & dtmTimeStamp & " Status: " & strStatus & vbCrLf
End Function

'Gets web content
Function GetDataFromURL ( strURL, strMethod, strPostData )
Dim lngTimeout, strUserAgentString, intSslErrorIgnoreFlags, blnEnableRedirects
Dim blnEnableHttpsToHttpRedirects, strHostOverride, strLogin, strPassword
Dim strResponseText, objWinHttp
  lngTimeout = 59000
  strUserAgentString = "http_requester/0.1"
  intSslErrorIgnoreFlags = 13056 ' 13056: ignore all err, 0: accept no err
  blnEnableRedirects = True
  blnEnableHttpsToHttpRedirects = True
  strHostOverride = ""
  strLogin = ""
  strPassword = ""
  Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
  objWinHttp.SetTimeouts lngTimeout, lngTimeout, lngTimeout, lngTimeout
  objWinHttp.Open strMethod, strURL
  If strMethod = "POST" Then
    objWinHttp.setRequestHeader "Content-type", _
      "application/x-www-form-urlencoded"
  End If
  If strHostOverride <> "" Then
    objWinHttp.SetRequestHeader "Host", strHostOverride
  End If
  objWinHttp.Option(0) = strUserAgentString
  objWinHttp.Option(4) = intSslErrorIgnoreFlags
  objWinHttp.Option(6) = blnEnableRedirects
  objWinHttp.Option(12) = blnEnableHttpsToHttpRedirects
  If (strLogin <> "") And (strPassword <> "") Then
    objWinHttp.SetCredentials strLogin, strPassword, 0
  End If    
  On Error Resume Next
  objWinHttp.Send(strPostData)
  If Err.Number = 0 Then
    If objWinHttp.Status = "200" Then
      GetDataFromURL = objWinHttp.ResponseText
    Else
      GetDataFromURL = "HTTP " & objWinHttp.Status & " " & _
        objWinHttp.StatusText
    End If
  Else
    GetDataFromURL = "Error " & Err.Number & " " & Err.Source & " " & _
      Err.Description
  End If
  On Error GoTo 0
  Set objWinHttp = Nothing
 End Function
 
'Pings websites and returns a status
Function PingSite( myWebsite )
    Dim intStatus, objHTTP
    Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
    objHTTP.Open "GET", "http://" & myWebsite & "/", False
    objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"
    On Error Resume Next
    objHTTP.Send
    intStatus = objHTTP.Status
    On Error Goto 0

    If intStatus = 200 Then
        PingSite = True
    Else
        PingSite = False
    End If

    Set objHTTP = Nothing
End Function

'Sends email alerts
Function SendEmail
	Dim strCDOSchema, strCDOConfig, strCDOMessage
    strCDOSchema = "http://schemas.microsoft.com/cdo/configuration/"  
    Set strCDOConfig = CreateObject("CDO.Configuration") 
 
    With strCDOConfig.Fields 
        .Item(strCDOSchema & "sendusing") = 2 ' cdoSendUsingPort 
        .Item(strCDOSchema & "smtpserver") = strEmailHost
        .update 
    End With 
	
    Set strCDOMessage = CreateObject("CDO.Message") 
 
    With strCDOMessage 
        Set .Configuration = strCDOConfig 
		.From = strFromEmail
        .To = strToEmail 
        .Subject = strSubjectMsg
		.TextBody = strWebsite & " is down!" & vbCrLf & "Alert Type: " & strAlert
        .Send 
    End With 
	
    Set strCDOMessage = Nothing 
    Set strCDOConfig = Nothing 
End Function

Open in new window

0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Can you explain why and how you "need to use F5 Token and disable proxy setting" exactly?
0
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NTCommented:
I am weak in vbscript.
Performed the same cygwin installing using
64 bit
http://www.cygwin.com/setup-x86_64.exe --no-admin
or
32 bit
http://www.cygwin.com/setup-x86.exe --no-admin

Enable following options during installation:
wget
Updated and tested code at windows:
#!/bin/bash
HTTPS_USERNAME="murugesandins"
HTTPS_PASSWD="RELATEDPASSWORD"
OUTPUT_FILE="output.html"
URL=https://www.experts-exchange.com/questions/29098173/To-check-if-url-is-working-and-send-a-status-report-through-mail.html
URL_SOURCE_BASE=$(echo $URL | /bin/sed "s/https:\/\///;s/\/.*//;")
OS=$(/bin/uname -s | /bin/sed "s/\-[0-9].*//;")
if [ "CYGWIN_NT" = "$OS" ]
then
	PING="/cygdrive/c/Windows/System32/ping"
	PING_OPTION=" -n 1"
else
	PING="/usr/bin/ping"
	PING_OPTION=" -c 1"
fi
WGET="/usr/bin/wget"
EXCEPTION=0
for RequiredFiles in $PING \
$WGET
do
	if [ ! -f "$RequiredFiles" ]
	then
		echo /bin/ls -ld "$RequiredFiles"
		/bin/ls -ld "$RequiredFiles"
		EXCEPTION=1
	fi
done
if [ -f "$OUTPUT_FILE" ]
then
	echo "$OUTPUT_FILE file is present"
	while [ 1 ]
	do
		echo "Do you wish to re download?[Yes/No]:"
		read YES_NO
		echo "$YES_NO" | /bin/grep -w -i "No" >/dev/null 2>&1
		if [ 0 -eq $? ]
		then
			EXCEPTION=1
			break
		fi
		echo "$YES_NO" | /bin/grep -w -i "Yes" >/dev/null 2>&1
		if [ 0 -eq $? ]
		then
			break
		fi
	done
fi
if [ 0 -eq $EXCEPTION ]
then
	echo $PING $PING_OPTION "$URL_SOURCE_BASE"
	$PING $PING_OPTION "$URL_SOURCE_BASE" >/dev/null
	if [ 0 -eq $? ]
	then
		echo "$PING $URL_SOURCE_BASE PASS"
		echo $WGET $URL \
		--no-check-certificate -O "$OUTPUT_FILE" \
		--user "$HTTPS_USERNAME" \
		--password "$HTTPS_PASSWD"
		$WGET $URL \
		--no-check-certificate -O "$OUTPUT_FILE" \
		--user "$HTTPS_USERNAME" \
		--password "$HTTPS_PASSWD"
	else
		echo "$PING $URL_SOURCE_BASE FAIL"
	fi
fi

Open in new window

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
VB Script

From novice to tech pro — start learning today.