Chkdomains script



  • !/usr/bin/php -q

  • <?php
    /* Copyright 10/30/2006 freelock computing

    • chkdomains.php
    • basic site monitoring script
    • sends an email when status is different than previous running of the script

    • installation instructions
    • create a /var/www/conf directory to store this
    • /var/www/conf/satus contains the cache result
    • this must be writable by the user running the job
    • add a URL to the $site array for each site to check
    • set $mailto to appropriate email addresses, comma seporated
    • schedual the cron job (php command line package required php_cli)
    • The status file needs to be writiable by the script ( a user accont
    • that runs the script)
    • on your server that is to be checked, create a textfile called "FILENAME" with your success string, this must match exactly, newlines and whitespace matter.

    • Testing instructions
    • delete or change the contents of the domain_uptime.txt
    • run the script
    • check the contents of the new domain_uptime.txt file
    • check your email


    • files,
    • on each server, uptime.txt
    • on monitoring system
    /var/www/conf/chkdomains.php (this file)
    • /var/www/conf/status/domain_uptime.txt conists of 1's and 0's seporated by newlines, this is rewritten every run. 1's represent server being up, 0's represent server being down.
    • /


  • fully qualified URLS of http servers with a trailing slash

  • $site[] = "http://yoursite1.com/";
    $site[] = "http://yoursite2.org/";
    $site[] = "http://yoursite3.net/";

  • email address(es) seporated by commas

  • $mailto = "sys-admin@yourdomain.com,optionaladditional@email.com";

  • file to check from servers listed above

  • define('FILENAME', "uptime.txt");

  • file contents must match exactly

  • define('SUCCESS', "success");

  • file to store the status of the last run

  • define('STATUS_FILE', '/var/www/conf/status/domain_uptime.txt'); #

    $out = ;

    for ($i=0; $i
    {
    $filename = $site[$i] . FILENAME;

    if ($fp=@fopen($filename,'r')){
    $err = socket_get_status($fp);
    if ($err['timed_out']) {
    $txt = "$filename timed out\n";
    $status[$i]= 0;
    }
    else
    {
    $text = trim(fread($fp, 2048));

    $txt = $filename. ': ' . $text . '(' . ($text

    SUCCESS) . ")\n";
    $status[$i]=1;
    }
    fclose($fp);
    } else {

    $txt = "$filename not opened\n";
    $status[$i]=0;
    }

    $out .= $txt;
    }

    $changed = false;
    if ($oldstatus= @file(STATUS_FILE))
    {
    for ($i=0;$i
    {
    if ($status[$i]!=trim($oldstatus[$i]))
    {
    $changed = true;
    }
    }
    }
    else
    {
    $changed = true;
    }

    if ($changed)
    {
    $fp = fopen(STATUS_FILE, 'w');
    for ($i=0;$i
    {
    fwrite($fp, $status[$i] . "\n");
    }
    fclose($fp);
    mail( $mailto , 'Domain Uptime Report: Status Change', $out);
    }

    ?>

    Freelock Blog Posts

    Customer Feedback

    I had the privilege of working with John and Freelock in launching a new Little League website. The process was flawless and the end product was magnificent exceeding our expectations.

    John knows his stuff! He had a wonderful ability to bring the perfect solution to our community based organization. Being volunteer run, we needed some special considerations in the way our website works, John understood this and delivered solutions that were perfect for us.

    We now have a cool website that also has the ability to grow with us into the future.

    I highly recommend John Locke and Freelock Computing.

    Brian Boone
    Pacific Little League

    About Freelock

    We are located in the Fremont neighborhood of Seattle, WA. 3800 Woodland Park Ave. N. Seattle, WA 98103  USA [P] 206.577.0540 Contact Us | Site Map Get Updates ©1995-2011 Freelock Computing