cvs: php-master-web /scripts mirror-summary

From: Date: Fri, 27 Dec 2002 17:04:15 +0000
Subject: cvs: php-master-web /scripts mirror-summary
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-14499@lists.php.net to get a copy of this message
goba Fri Dec 27 12:04:15 2002 EDT Modified files: /php-master-web/scripts mirror-summary Log: Apply common WS fixes, and add individual mailing of mirror maintainers in case a mirror is deactivated, so they get information about it...

Index: php-master-web/scripts/mirror-summary diff -u php-master-web/scripts/mirror-summary:1.4 php-master-web/scripts/mirror-summary:1.5 --- php-master-web/scripts/mirror-summary:1.4 Sat Jul 6 00:25:34 2002 +++ php-master-web/scripts/mirror-summary Fri Dec 27 12:04:15 2002 @@ -1,84 +1,121 @@ #!/usr/local/bin/php -q <?php -set_time_limit (0); -/* alert the php-mirrors team about dead mirrors. */ - -/* now prepare a mailer for php-mirrors */ - - $body = "Following is data gathered from the various mirrors. It is ordered by those\n" - . "that are suspected to be dead, mirrors which are alive but have errors, sites\n" - . "which need to be prompted to update their PHP version, and finally the rest,\n" - . "sorted by last update.\n" - . "Edit mirror listings here: http://master.php.net/manage/mirrors.php\n\n"; +/* + This script alerts the php-mirrors team about dead mirror, + as well as tries to mail notifications of deactivations + to the individual mirror maintainers (using the provided + contact details). +*/ - $body .= "No response was returned from these following hosts within the last three days:\n\n"; - -/* firstly, get some data */ +// This script will run for a long time +set_time_limit (0); -mysql_connect("localhost","nobody","") - or die("unable to connect to database"); +// Try to connect to the database and select php3 database +mysql_connect("localhost","nobody","") or die("unable to connect to database"); mysql_select_db("php3"); -$query = "SELECT maintainer,hostname,id,UNIX_TIMESTAMP(lastupdated) AS lastupdate,phpversion,(DATE_SUB(NOW(), INTERVAL 3 DAY) < lastchecked) AS active,(DATE_SUB(NOW(), INTERVAL 7 DAY) < lastupdated) AS current FROM mirrors WHERE mirrortype = 1 ORDER BY hostname"; +// Select all mirrors ordered by hostname +$query = "SELECT maintainer, hostname, id, UNIX_TIMESTAMP(lastupdated) AS lastupdate, " . + "phpversion, (DATE_SUB(NOW(), INTERVAL 3 DAY) < lastchecked) AS active, " . + "(DATE_SUB(NOW(), INTERVAL 7 DAY) < lastupdated) AS current " . + "FROM mirrors ORDER BY hostname"; -$result = mysql_query($query) - or die("unable to get from the database"); +// Execute SQL query +$result = mysql_query($query) or die("unable to get from the database"); +// Download data to the $hosts array, and count total number of hosts while ($host = mysql_fetch_assoc($result)) { - $hosts[] = $host; + $hosts[] = $host; } $total = count($hosts); - for($i=0; $i < $total; $i++) { - if (!$hosts[$i]['active']) { - $body .= sprintf("%s -- %s\n", $hosts[$i]['hostname'], $hosts[$i]['maintainer']); - - } - } - - - $body .= "\nThese mirrors have not been updated in at least 7 days:\n\n"; - for($i=0; $i < $total; $i++) { - if ($hosts[$i]['active'] && !$hosts[$i]['current']) { - $body .= sprintf("%s -- %s\n", $hosts[$i]['hostname'], $hosts[$i]['maintainer']); - - } - } - - - $body .= "\nAnd now for the rest of the mirrors:\n" - . "----------------------------------------------------------------------------------------\n" - . " Host \t\t PHP Version \t\t Last Updated\t\t Maintainer\n" - . "----------------------------------------------------------------------------------------\n"; +// This is the common text for the php-mirrors mail +$body = "Following is data gathered from the various mirrors. It is ordered by those\n" + . "that are suspected to be dead, mirrors which are alive but have errors, and\n" + . "finally the rest, sorted by last update time.\n" + . "Edit mirror listings here: http://master.php.net/manage/mirrors.php\n\n"; + +// List mirrors which seem to be down +$body .= "No response was returned from these following hosts within the last three days:\n\n"; +for ($i=0; $i < $total; $i++) { + if (!$hosts[$i]['active']) { + $body .= sprintf("%s -- %s\n", $hosts[$i]['hostname'], $hosts[$i]['maintainer']); + $inactives[$hosts[$i]['hostname']] = $hosts[$i]['maintainer']; + } +} + +// List all mirrors which seem to be outdated +$body .= "\nThese mirrors have not been updated in at least 7 days:\n\n"; +for ($i=0; $i < $total; $i++) { + if ($hosts[$i]['active'] && !$hosts[$i]['current']) { + $body .= sprintf("%s -- %s\n", $hosts[$i]['hostname'], $hosts[$i]['maintainer']); + $outdated[$hosts[$i]['hostname']] = $hosts[$i]['maintainer']; + } +} + +$body .= "\nAnd now for the rest of the mirrors:\n" + . "----------------------------------------------------------------------------------------\n" + . " Host \t\t PHP Version \t\t Last Updated\t\t Maintainer\n" + . "----------------------------------------------------------------------------------------\n"; -/* a note about the padding - given that email readers produce interesting results for spacing, +/* A note about the padding - given that email readers produce interesting results for spacing, i've gone for tabs here to help seperate the text columns. to make sure i don't over tab, i do a quick strlen check, and depending on how different it is from the string length i give as avg (first argument), will determine how many tabs i use, or alternatively a space. */ - function pad($deflen, $item) { - global $i, $hosts; - $str = strlen($hosts[$i][$item]); - if ($str >= $deflen*2) { - $sp =" "; - } - else if ($str <= $deflen){ - $sp ="\t\t"; - } else { - $sp = "\t"; - } - return $sp; - } - - for($i=0; $i < $total; $i++) { - if($hosts[$i]['active'] && $hosts[$i]['current']){ - $body .= sprintf(" %s%s%s%s%s\t\t%s\n", $hosts[$i]['hostname'], pad(11, "hostname"), $hosts[$i]['phpversion'], pad(5, "phpversion"), date("F j, Y, g:i a", $hosts[$i]['lastupdate']), $hosts[$i]['maintainer']); +// Padd an item, respecting a default length +function pad($deflen, $item) { + global $i, $hosts; + $str = strlen($hosts[$i][$item]); + if ($str >= $deflen*2) { + $sp =" "; + } + else if ($str <= $deflen){ + $sp ="\t\t"; + } else { + $sp = "\t"; } - } + return $sp; +} - $body . "---------------------------------------------------------------------------------------\n"; +for ($i=0; $i < $total; $i++) { + if ($hosts[$i]['active'] && $hosts[$i]['current']){ + $body .= sprintf(" %s%s%s%s%s\t\t%s\n", $hosts[$i]['hostname'], pad(11, "hostname"), $hosts[$i]['phpversion'], pad(5, "phpversion"), date("F j, Y, g:i a", $hosts[$i]['lastupdate']), $hosts[$i]['maintainer']); + } +} -/* please edit this when testing to send mail to yourself, not to the list every time */ +$body . "---------------------------------------------------------------------------------------\n"; +// Please edit this when testing to send mail to yourself, not to the list every time mail("php-mirrors@lists.php.net", "PHP Mirror Status Info.", $body, "From: php-mirrors@lists.php.net"); + +// Mail text for those mirror maintainers with inactive mirror sites +$inactives_text = "Hi!\n\nOur automatical mirror site check was unable to reach\n" + ."the PHP.net mirror site maintained by you for three days now,\n" + ."and therefore automatically disabled your listing as a PHP.net\n" + ."mirror site.\n\n" + ."Please correct the problem or reply to this mail with your\n" + ."questions, if you think that the problem is not on your side."; + +// This is just to test... +$inactives['goba'] = 'Goba <goba@php.net>'; + +// Send mail to all inactive mirror maintainers +foreach ($inactives as $hostname => $maintainer) { + mail($maintainer, "$hostname mirror site deactivated", $inactives_text, "From: php-mirrors@lists.php.net"); +} + +// Mail text for those mirror maintainers with outdated mirror sites +$outdated_text = "Hi!\n\nOur automatical mirror site check found out, that\n" + ."the PHP.net mirror site maintained by you was not updated in\n" + ."the last seven days, and therefore automatically disabled your\n" + ."listing as a PHP.net mirror site.\n\n" + ."Please correct the problem or reply to this mail with your\n" + ."questions, if you think that the problem is not on your side."; + +// Send mail to all outdated mirror maintainers +foreach ($outdated as $hostname => $maintainer) { + mail($maintainer, "$hostname mirror site deactivated", $outdated_text, "From: php-mirrors@lists.php.net"); +} + ?>
« previous php.mirrors (#14499) next »