add per-host aggregated block

master
Dirk Heilig 2023-02-14 11:01:44 +01:00
parent c54d49022a
commit a0accaf710
2 changed files with 30 additions and 0 deletions

View File

@ -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.

View File

@ -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";
}