It is not uncommon that we need to perform health monitoring on SharePoint Sites to ensure that we have stable and healthy SharePoint Farms and to ensure maximum possible availability of all the sites.
In this article we will discuss a simple yet powerful automation technique using PowerShell that will try ping the Site and if gets failed it will send the email notifications to the designated SharePoint Admins for the Site.
With this background let’s start with the demo…
In this demo we have two SharePoint Sites in Question as follows-
- First site is SharePoint On-Premise Site (Central Administration Site) with URL http://sp-2016-dev:2016
- The other site is SharePoint Online Site with URL http://spodevelopment.sharepoint.com
The On-Premise site is up and running while SharePoint Online Site is down and unavailable due to some technical reasons
In order to automate this monitoring process I have written a simple function in PowerShell as explained below-
Step 1: Create an Object of System.Net.WebClient Class. This object will provide us the methods to deal with Site Pages
Step 2: Make use of DownloadString Method of this class to download the html of the respective Site Page
Step 3: Check for Possible Error Messages that SharePoint Page would generally contains in case of Site is not accessible by making use of Wild Card Search using Contains Method
Step 4 & 5: We are sending emails to the SharePoint Admins Informing that a specific site is down, so that they can take appropriate actions accordingly.
Step 6: This is the initiation function that is having an array of SharePoint Site URLs that requires monitoring.
Step 7: This function will call for Step 1 to Step 5 for each SharePoint Site URL in a periodic manner and keep on circulating the notifications in case of health issues with SharePoint Sites.
Once this automation script executes we can see the following email notification for SharePoint Online Site which is currenly down:
And there will be no emails for SharePoint On-Premise Site since it is healthy and active as shown below:
That is all for this demo.
Hope you find it helpful.