Just adding a note that there are very capable and customizable packages like Nagios (formerly NetSaint), mon and Big Brother available freely to monitor just about everything you can think of in a network. I recommend you pick one of those instead of trying to roll your own - not only for reasons of robustness but also synergy. Any future improvements to them will benefit you automatically, and your own improvements to them will benefit many others as well.