Help with modifying a PHP domain monitoring script.

Discussion in 'PHP' started by JSellnau_TSCC, Dec 28, 2005.

  1. #1
    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.
     

    Attached Files:

    JSellnau_TSCC, Dec 28, 2005 IP
  2. Nathan Malone

    Nathan Malone Well-Known Member

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #2
    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):
     
    Nathan Malone, Dec 28, 2005 IP
  3. Nathan Malone

    Nathan Malone Well-Known Member

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #3
    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.
     
    Nathan Malone, Dec 28, 2005 IP
    JSellnau_TSCC likes this.
  4. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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?
     
    JSellnau_TSCC, Dec 28, 2005 IP
  5. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The code you gave me worked well. Thank you. Any ideas for the other questions I asked?
     
    JSellnau_TSCC, Dec 28, 2005 IP
  6. Juls

    Juls Well-Known Member

    Messages:
    1,867
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    170
    #6
    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.

    :)
     
    Juls, Dec 28, 2005 IP
  7. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I have it setup as a cron allready. :)
     
    JSellnau_TSCC, Dec 28, 2005 IP
  8. Nathan Malone

    Nathan Malone Well-Known Member

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #8
    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.
     
    Nathan Malone, Dec 28, 2005 IP
  9. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    The server supports mySQL, PHP, and PERL.
     
    JSellnau_TSCC, Dec 28, 2005 IP
  10. Nathan Malone

    Nathan Malone Well-Known Member

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #10
    Okay, I'll try to write something tomorrow morning...
     
    Nathan Malone, Dec 28, 2005 IP
    jimrthy likes this.