From a0accaf710e6e3c1fd27d665bb1e109ff00bab37 Mon Sep 17 00:00:00 2001 From: Dirk Heilig Date: Tue, 14 Feb 2023 11:01:44 +0100 Subject: [PATCH] add per-host aggregated block --- Readme.md | 7 +++++++ htdocs/index.php | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Readme.md b/Readme.md index 4a0c750..60e8e05 100644 --- a/Readme.md +++ b/Readme.md @@ -34,6 +34,7 @@ Just point kumar to your webservice. The Output looks something like this: ``` +BACKUP|HOST|PATH|STATUS BACKUP|host1|/opt/mailcow|OK BACKUP|host1|/var/lib/docker/volumes|OK BACKUP|host2|/opt/docker|OK @@ -45,6 +46,12 @@ BACKUP|host4|/var/lib/docker/volumes|OK BACKUP|host5|/opt/docker|TOO_OLD BACKUP|host5|/var/lib/docker/volumes|TOO_OLD +BACKUP|HOST|STATUS +BACKUP|host1|OK +BACKUP|host2|OK +BACKUP|host3|TOO_OLD +BACKUP|host4|OK +BACKUP|host5|TOO_OLD ``` output is always sorted by host and path. so you might check a whole block of hosts at once. diff --git a/htdocs/index.php b/htdocs/index.php index 3bb5dec..cf14b04 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -57,6 +57,7 @@ header("Content-Type: text/plain"); $maxAge = isset($_GET["maxage"]) ? intval($_GET["maxage"]) : 28; $maxAge = $maxAge * 60 * 60; $backups = json_decode(file_get_contents("/var/www/data/backups.json"), true); +echo "BACKUP|HOST|PATH|STATUS\n"; foreach ($backups as $backupName => $backupTime) { echo "BACKUP|$backupName|"; if ($backupTime + $maxAge < time()) { @@ -66,3 +67,25 @@ foreach ($backups as $backupName => $backupTime) { } echo "\n"; } + +$byHost = []; +foreach ($backups as $backupName => $backupTime) { + $backupName = explode("|", $backupName); + $host = $backupName[0]; + $path = $backupName[1]; + if (!isset($byHost[$host])) { + $byHost[$host] = PHP_INT_MAX; + } + $byHost[$host] = min($backupTime, $byHost[$host]); +} + +echo "\nBACKUP|HOST|STATUS\n"; +foreach ($byHost as $host => $latest) { + echo "BACKUP|$host|"; + if ($latest + $maxAge < time()) { + echo "TOO_OLD"; + } else { + echo "OK"; + } + echo "\n"; +}