Monitoring site errors using Server Density and Python
I recently stumbled upon the site Server Density while upgrading all my servers and signed up for the service. It as a great pretty interface, a customizable dashboard, and pretty extensive alert capabilities. They also have a free trial so I suggest signing up. The one thing I did not like was the inability to scan for a specific string on the website to confirm if the website is still operational, like with host-tracker.com.
The good news is Server Density allows you to create python plugins to run at the update interval on any/all of your servers. This gives you free reign over your reports. Using this tutorial, I will explain how to manually create and install this and any other plugin. Or you can just download or install it from the below links.
GitHub - https://github.com/arzynik/sd-webcheck
Server Density Plugin - http://plugins.serverdensity.com/webcheck
Create your plugin
First, log into your SD account and go to Plugins. Then add a new plugin and name it WebCheck.
Add your plugin to your server
Next you will need to ssh into your server and create the directory
mkdir /usr/bin/sd-agent/plugins/
In that directory, create a new file called WebCheck.py. This will be the main and only file for the plugin. Grab the code from https://github.com/arzynik/sd-webcheck/blob/master/WebCheck.py and paste it into the file.
Configure your plugin
If this is your first plugin, you will need to add your plugin directory to your plugin config file. Open up /etc/sd-agent/config.cfg and replace the plugin_directory line with
plugin_directory: /usr/bin/sd-agent/plugins
WebCheck allows you to check the status of as many sites as you want. In order to check they you will need to enter a new config entry for each site, using the below fields:
- name - The name and key you want to use on the SD interface. Remember that all \".\" will be replaced with \"_\" due to api limitations.
- url -
- find - The regex or string to search for. I typically just use an html tag but you can search for anything.
- result - The result is the regex quantifier. Lets say you want to search from </html>, you would keep this True. Or lets say you want to search for Parse Error, you would then make this False.
Here is an example config entry
[WebCheck 1] name: devin.la url: http://devin.la/ find: