I am currently trying to create a script that allows me to check multiple web url’s in order to see if they are online and active. My company has multiple servers with different environments active (Production, Staging, Development etc.) I need a script that can check all the environments URL’s and tell me whether or not they are online each and every morning so I can be ahead of the game in addressing any servers or websites being down.
My issue however is I can’t solely base the logic strictly on an HTTP code to deem the site online or not, some of our websites may be online from an HTTP standpoint but have components or webparts of the site that is down displaying an error message on the page.
I am having trouble coming up with a script that can not only check the HTTP status as well as scan the page and parse out any error messages and then write to host based on both pieces of logic whether or not the site is “Online” or “Down”
Here is what I have so far, you will notice it does not include anything regarding parse for key words as I don’t know how to implement…
#Lower Environments Checklist Automated Script
Write-Host Report generated at (Get-date)
write-host(“Lower Environments Status Check”);
$msg = “”
$array = get-content C:\LowerEnvChecklist\appurls.txt
$log = “C:\LowerEnvChecklist\lowerenvironmentslog.txt”
write-host(“Checking appurls.txt…One moment please.”);
("`n--------------------------------------------------------------------------- ") | out-file $log -Append
Get-Date | Out-File $log -Append
(“`nChecking Links”) | out-file $log -Append
(“`n”) | out-file $log -Append
for ($i=0; $i -lt $array.length; $i++) {
$HTTP_Status = -1
$HTTP_Request = [System.Net.WebRequest]::Create($array[$i])
$HTTP_Request.Timeout =60000
$HTTP_Response = $HTTP_Request.GetResponse()
$HTTP_Status = [int]$HTTP_Response.StatusCode
If ($HTTP_Status -eq 200) {
$msg = $array[$i] + " is ONLINE!"
}
Else {
$msg = $array[$i] + " may be DOWN, please check!"
}
$HTTP_Response.Close()
$msg | Out-File $log -Append -width 120
write-host $msg
}
(“`n”) | out-file $log -Append
(“`nLower Environments Checklist Completed”) | out-file $log -Append
write-host(“Lower Environments Checklist Completed”);
appurls.txt just contains the internal URLs I need checked FYI.
Any help would be much appreciated! Thanks.