I was asked recently to post an article on how we do web page monitoring. For a number of reasons we do not really use the built-in “Web Application” monitoring template. One of the reasons is that we are not really happy with the selection of the watcher nodes. We needed a way to monitor every web server in our farms without managing the watcher nodes manually all the time. We create host entries on our web servers pointing to themselves. So every time you browse to www.code4ward.net on one of the web servers you do not go through the load balancer. Since the host entry for www.code4ward.net points to the web server itself, you will browse to the web hosted on the server you are currently connected to.
So I created a small script which is basically doing web monitoring the way we wanted it to be. In this blog post I will talk about the implementation we started to use back in MOM 2005 and still use it (slightly modified) in our SCOM 2007 environments. We have recently migrated all those scripts to PowerShell and did our own class definitions using the authoring console. For now, I will focus on the much simpler implementation using VBScript and OpsConsole without any work in the Authoring Console. Download the vbscript from the following link:
Before you begin you should create a group containing all your computers you want to monitor with a web page. Or you can of course also use the script like the Web Application template to monitor a web page through a load balancer or whatever using watcher nodes. In any case, create a computer group with your web servers/watcher nodes.
In your Operations Manager console switch to the “Authoring Space”, expand “Management Pack Objects”, right-click on the “Monitors” node, select Create a Monitor –> Unit Monitor
Now select “Scripting / Generic / Timed Script Two State Monitor”
Select a destination management pack.
Attention: The group I talked about earlier needs to be in the same management pack with the script monitor we now create. Or the group is in a sealed management pack, then you can select a different destination management pack.
Provide a name for your monitor and select a target like “Windows Server”.
Notice that we uncheck the checkbox “Monitor is enabled”. We will later create an override to enable the monitor for all the web servers/watcher nodes we created the group earlier.
Configure a schedule. In general we schedule all our monitors (or rule) to run every 5 minutes (of course there are exceptions).
I strongly suggest to provide a meaningful script file name on this page, as it will help you to find it on the agent when you have to trouble shoot something.
Let’s setup the timeout to 5 minutes.
Open the script attached to this blog post and copy everything from the code4ward.Sample.WebContentCheck.vbs into the script text field.
The script is very generic and needs 3 parameters to run successfully.
As you can see from the script body,
Parameter 1: is the URL of the web page you want to monitor
Parameter 2: is the expected text in the content
Parameter 3: is the timeout in seconds (-1 means no timeout)
Before we click on next, click on the Parameters button to specify your parameters.
To be on the safe side, I always put the parameters in double-quotes. The parameters line reads:
”http://www.code4ward.net” “code4ward” “30”
The configuration means, download the web page from www.code4ward.net every 5 minutes (the scheduled we configured earlier), look for the string “code4ward” (without the quotes) in the content, abort request after 30 seconds if there’s no answer from the web server.
If “code4ward” is in the content and the web page was returned within 30 seconds, the monitor is healthy.
If “code4ward” is not in the content or the web page took longer than 30 seconds, the monitor is unhealthy.
Now we need to hook up the property bag status messages from the script with the health monitor’s unhealthy state:
Property[@Name=’Status’] Equals Error
Now we need to hook up the property bag status messages from the script with the health monitor’s healthy state:
Property[@Name=’Status’] Equals OK
Here you can decide, if you want the health state to be warning or critical.
The last page of the wizard let’s you configure the alert properties for this monitor. In order to get all the nice output from the monitor in the alert description, you need to copy “$Data/Context/Property[@Name=’Message’]$” (without the quotes”) into the alert description field.
Now click on “Create” and your monitor is ready to use.
All you need to do now, is to create an enable-override on the monitor for the group we created before.
As you can see, the monitor itself is pretty simple and has not all the features you know from the Web Application template. But sometimes less is more and this script monitor is used to monitor hundreds of sites without any problems.
CEO of code4ward GmbH and Windows lead developer at http://www.royalapps.com where most of the time is spent on Royal TS, a multi platform, multi protocol remote management solution, for Windows, macOS and mobile supporting RDP, VNC, SSH, Telnet, and many more.
Long time Microsoft MVP supporting communities on- and offline as well as speaking at user groups and conferences about DevOps and other software development topics.