We monitor the Joomla sites of our enterprise clients – and we do not do so with the help of a paying 3rd party tool – we do so with a little tool that we developed ourselves. The tool is nothing fancy, but it works really well!
Today, we are sharing full details about this small tool, including the source code!
So, what is this tool?
This tool is a simple Linux shell script that checks if the website works by grabbing the content (using wget), and seeing if the length of the content is above a certain (fixed) amount of bytes. If it’s not able to grab the content, or if the size is not above the threshold, then it emails us telling us that the website is down.
Will it know that a website is hacked?
In short, the answer is no, it won’t know if the website is hacked. This is because a hacked website, in general, does not result in smaller pages (in fact, in many cases, a hacked website will result in larger pages). Having a tool that discovers if a website is hacked is more complex (but still feasible).
Can I have the source code of this tool?
But certainly! You only needed to ask (well, not even)! Here’s how to do it:
- Create, in the Linux shell (and as root), a file called sitebeat.sh (place it under the /home/scripts/ folder – if that folder doesn’t exist, then create it), make it executable by root by issuing the following commands:
chown root sitebeat.sh
chmod 700 sitebeat.shIt is important that the above file is created on a server other than the server hosting your site(s) – because if the server hosting your site(s) goes down, then your script will still work (and will send you notification in this case).
-
Add the following code to the sitebeat.sh file:
strMessage="" intMinimumSize=50000 siteSize="`wget -qO - https://www.yourjoomlawebsite.com/ | wc -c`" if [[ "$siteSize" -lt "$intMinimumSize" ]]; then isError="1" strMessage="https://www.yourjoomlawebsite.com/ Not Responding\n" fi siteSize="`wget -qO - https://www.yoursecondjoomlawebsite.com/ | wc -c`" if [[ "$siteSize" -lt "$intMinimumSize" ]]; then isError="1" strMessage="$strMessage""https://www.yoursecondjoomlawebsite.com/ Not Responding\n" fi if [[ "$isError" == "1" ]]; then echo -e $strMessage echo -e $strMessage | mail -s "Warning - At Least One Website Is Faulty" youremail@yourjoomlawebsite.com else echo -e "Heartbeat is normal" fi
Some explanation here:
- The intMinimumSize value is the minimum size, in bytes, of your homepage. If you expect the minimum size to be bigger or smaller then you should increase/decrease the intMinimumSize.
-
You should change the https://www.yourjoomlawebsite.com/ and https://www.yoursecondjoomlawebsite.com/ links to your actual Joomla websites – you should also change youremail@yourjoomlawebsite.com to your work email.
-
You can remove the blue lines if you only have one website. If you have more than 2 websites, then you can clone the blue lines and just change the URL in each cloned block of code. You may need to adjust the intMinimumSize (or hardcode it for each website) when you are checking multiple websites.
-
In the crontab, add the following line:
*/10 * * * * /home/scripts/sitebeat.sh #check the heartbeat of the website every 10 minutes
The above code runs the sitebeat.sh script every 10 minutes, you can increase or decrease the frequency by just changing the */10 code – for example, if you want the script to run every 5 minutes, then you can just replace */10 to */5.
-
Ensure that on the destination server (e.g. the server hosting your websites), you have the IP of the sitebeat server whitelisted. This may not be necessary, but it is a good idea.
-
That’s it!
We hope you find this post informative and useful. If you need help with the implementation, then all you need is to contact us. Our fees are super cheap, our work is super professional, and we deliver very quickly!