From e260cdb427d62a7f8e21c7fcb321b59320bffe72 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Fri, 22 Nov 2019 10:10:29 +0100 Subject: improve monitoring reporting about offline / corrupted mirror --- check.php | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/check.php b/check.php index 10cb5cfd..7e07ccca 100755 --- a/check.php +++ b/check.php @@ -1,5 +1,9 @@ #!/usr/bin/env php Les RPM de Remi - Mirror check - + @@ -31,12 +35,12 @@ if ($cli) { 'Enterprise Linux 8', 'enterprise/7' => 'Enterprise Linux 7', 'enterprise/6' => 'Enterprise Linux 6', - 'enterprise/5' => 'Enterprise Linux 5', - 'fedora/22' => 'Fedora 22', - 'fedora/21' => 'Fedora 21', - 'fedora/20' => 'Fedora 20', + 'fedora/31' => 'Fedora 31', + 'fedora/30' => 'Fedora 30', + 'fedora/29' => 'Fedora 29', ); $subs = array( 'remi', @@ -120,16 +124,25 @@ $deprecated = array( 'http://mirror.pw/remi/', ); function getRepoTime($uri) { - $xml = @simplexml_load_file($uri.'/repodata/repomd.xml'); - if ($xml && $xml->revision) { + $ctx = stream_context_create([ + 'http' => [ + 'timeout' => 1.5, + ] + ]); + $txt = @file_get_contents($uri . '/repodata/repomd.xml', false, $ctx); + if (!$txt) { + return ERR_OFFLINE; + } + $xml = @simplexml_load_string($txt); + if ($xml && $xml->revision>100000) { return intval($xml->revision); } - return 0; + return ERR_CONTENT; } if (isset($_GET['mirror']) && isset($repos[$_GET['mirror']])) { $path = $_GET['mirror']; } else { - $path = 'enterprise/7'; + $path = 'enterprise/8'; } if (isset($_GET['repo']) && in_array($_GET['repo'], $subs)) { $repo = $_GET['repo']; @@ -170,7 +183,11 @@ if ($ref) { } else { // Child $pids = array(); $loc = getRepoTime($mirror.$full); - if ($ref == $loc) { + if ($loc == ERR_OFFLINE) { + printf("%50.50s : ** Unreachable **\n", $mirror); + } else if ($loc == ERR_CONTENT) { + printf("%50.50s : ** Corrupted **\n", $mirror); + } else if ($ref == $loc) { printf("%50.50s : Ok\n", $mirror); } else if ($loc) { printf("%50.50s : %s\n", $mirror, date('r', $loc)); @@ -183,9 +200,13 @@ if ($ref) { } flush(); $host = parse_url($mirror, PHP_URL_HOST); - printf("
  • %s ", $mirror, $host); + //printf("
  • %s ", $mirror, $host); $loc = getRepoTime($mirror.$full); - if ($ref == $loc) { + if ($loc == ERR_OFFLINE) { + printf("
  • %s Unreachable
  • \n", $mirror, $mirror); + } else if ($loc == ERR_CONTENT) { + printf("
  • %s Corrupted
  • \n", $mirror, $mirror); + } else if ($ref == $loc) { printf("
  • %s Ok
  • \n", $mirror, $mirror); } else if ($loc) { printf("
  • %s %s
  • \n", $mirror, $mirror, date('r', $loc)); -- cgit