web.config Connection String Monitoring with PRTG Network Monitor

5 Dec

I use PRTG Network monitor to check all our websites, and I generally just check the homepage for certain words to make sure it’s loaded ok. I also have checks on the SQL Server to make sure the service is still running etc, but this wasn’t exactly fail proof. For example, the site could be working and the database running, but if a connection string was incorrect, this might not affect the home page but could impact anyone using the site.

The solution was a monitoring page that checked all the connections strings in the web.config file for each site. PRTG could then check this page and monitor it for keywords. In my case it checks that it must contain the word ‘complete’, so the page has loaded fully, and must not contain the word ‘failed’, one or more of the connection strings has an error.

I setup a virtual directory within all the sites (/monitoring/) and they all then pointed to the .aspx page that i put in a single location. This meant it was easier to update down the line. Because it was a virtual directory, it picked up the web.config of the site that was calling it.

Thanks to PizzaBoy for the initial code:

<%@ Import Namespace="System" %>
<%@ Page Language="c#" Theme="" %>






    
    Dore Database Monitoring
    


Dore Database Monitoring

<% CheckConnectionStrings(); %>


I did some basic styling, so errors were in red etc and so it was nice to view on my phone.

body
{
background-color:#d4d4d4;
}

h1
{
color:#ff7300;
text-align:center;
font-size:200%;
}

h2
{
color:#000;.
font-size:150%;
}

h3
{
text-align:center;
color:#000;
font-size:100%;
}

li.passed{
 color:#339900;
}

li.failed{
 color:#ff0000;
}

#monitoring{
	background-color:#fff;
	-moz-border-radius: 15px 15px 15px 15px;
	-web-kit-border-radius: 15px 15px 15px 15px;
	-khtml-border-radius: 15px 15px 15px 15px;
	border-radius: 15px 15px 15px 15px;
	padding: 20px;
	margin: auto;
	width:600px;
	border:2px solid #ff7300;
}

The virtual directory also had its own web.config to override ASP.net authorization rules for the sites and also lock access down to the IP address of my monitoring server.



    
        
            
        
    


Thats it really. Within PRTG I set it to monitor all the pages and check for the specific keywords. If anything fails, I’ll know about it.

And because it automatically checks all the connection strings in the web.config, it’s future proof too, bingo.