Added php files for nagios monitoring

This commit is contained in:
2026-02-12 22:44:33 +00:00
parent ecaf54e2fb
commit 573421700d
6 changed files with 263 additions and 64 deletions

49
check_expiry.php Normal file
View File

@@ -0,0 +1,49 @@
#!/usr/bin/php
<?php
require_once __DIR__ . '/config/init.php';
$jsonFile = __DIR__ . '/web_check.json';
if (!file_exists($jsonFile)) {
echo "CRITICAL - JSON file not found\n";
exit(2);
}
$data = json_decode(file_get_contents($jsonFile), true);
if (!$data) {
echo "CRITICAL - Invalid JSON\n";
exit(2);
}
$critical = [];
$warning = [];
foreach ($data as $site) {
$days = ssl_days_left($site['ssl-expiry']);
if ($days === null) continue;
if ($days <= SSL_CRITICAL_DAYS) {
$critical[] = $site['domain'] . " ($days days)";
}
elseif ($days <= SSL_WARNING_DAYS) {
$warning[] = $site['domain'] . " ($days days)";
}
}
if (!empty($critical)) {
echo "CRITICAL - SSL expiring soon: " . implode(', ', $critical) . "\n";
exit(2);
}
if (!empty($warning)) {
echo "WARNING - SSL expiring: " . implode(', ', $warning) . "\n";
exit(1);
}
echo "OK - No SSL expiring soon\n";
exit(0);