I was wondering if anyone would be able to help me by making some "simple" modifications to a PHP script I have found for monitoring domians. The script that I have (attached) checks to see if it can connect (port 80) to a list of domians and if it can not connect it sends an email to a list of addresses. The problem is that there are about 15-20 domains in the list and it sends multiple emails if multiple domains are not responding. What I would like it to be able to do is check all the domains and compile a list (array) of the ones it can not connect to and then send only 1 email with the list. (example: if 5 domains do not respond then it sends 5 emails....i want it to send 1 email to each address listed with the list of 5 domains). Feel free to ask any questions necessary. Thank you for your time.
Try this code: <?php // DOMAIN MONITORING LIST $sites = array(); //benchmark domains $sites[] = 'google.com'; //TSCC domains $sites[] = 'tsccgraphix.com'; $sites[] = 'tri-stateconsulting.com'; $sites[] = 'tri-stateconsulting.net'; $sites[] = 'tri-stateconsulting.org'; $sites[] = 'adserver.tri-stateconsulting.com'; //Corenas domains $sites[] = 'ckgartworks.com'; $sites[] = 'thingstohelp.com'; $sites[] = 'yourheadergraphics.com'; //Pauls domains $sites[] = 'privaterights.com'; $sites[] = 'espired.com'; $sites[] = 'lockvault.com'; $sites[] = 'privaterightssuccess.com'; $sites[] = 'dognatural.com'; $sites[] = 'PageBrand.com'; // END DOMAIN LIST foreach($sites as $site) { $sock = fsockopen($site, 80, $errno, $errstr, 5); if (!$sock) { $domain_array[] = $site; } else { echo''; } } if ($domain_array) { // The e-mail address you want the report of a unresponsive server sent to. Example: 4251234567@tmomail.net. // You can send the report to multiple addresses: 4251234567@tmomail.net,7035551234@messaging.nextel.com. $to= "jsellnau_tscc@hotmail.com,6084989489@vmobl.com,webmaster@tri-stateconsulting.net,espired@gmail.com,kleinmeulman@gmail.com"; //This code sends out the e-mail $message = 'The following sites are returning errors: '.implode(' ',$domain_array); $subject = 'Site Status Error'; mail($to, $subject, $message); } ?> Code (markup):
It just occured to me... Should all of the domains be sent to all of the emails, or do you have separate emails monitoring specific domains? The code above (assuming it works) sends all of the non-responsive domains to all of the email addresses. Let me know if you want it set up differently.
I want the list to be sent to all of the email addresses listed in the script. (at this point in time). However you just gave me an idea... How hard would it be set it up so that different domains could be monitored by different email addresses. What about a web-interface for adding domains, emails, and associtating specific domain(s) with certain emails?
nice work nathan joel for your other questions you might have to learn php yourself to add a control panel to it. also dont forget to set it up with cron to automatically check the sites/servers for your on a regular basis.
While it is possible to get a script that would associate different url's with different email addresses, I don't have time to do write one right now. If I have some time tomorrow morning, I'll try to write a script that will do that. Does your server support MySQL? While it's possible to do it with flat files, it would be easier with a database.