Added php files for nagios monitoring
This commit is contained in:
31
check_content.php
Normal file
31
check_content.php
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/php
|
||||
<?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);
|
||||
}
|
||||
|
||||
$problems = [];
|
||||
|
||||
foreach ($data as $site) {
|
||||
if ($site['wordcheck_ok'] != 1) {
|
||||
$problems[] = $site['domain'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($problems)) {
|
||||
echo "CRITICAL - Content problems on: " . implode(', ', $problems) . "\n";
|
||||
exit(2);
|
||||
}
|
||||
|
||||
echo "OK - All content checks passed\n";
|
||||
exit(0);
|
||||
49
check_expiry.php
Normal file
49
check_expiry.php
Normal 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);
|
||||
33
check_ssl.php
Normal file
33
check_ssl.php
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/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);
|
||||
}
|
||||
|
||||
$problems = [];
|
||||
|
||||
foreach ($data as $site) {
|
||||
if ($site['sslcheck_ok'] != 1) {
|
||||
$problems[] = $site['domain'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($problems)) {
|
||||
echo "CRITICAL - SSL problems on: " . implode(', ', $problems) . "\n";
|
||||
exit(2);
|
||||
}
|
||||
|
||||
echo "OK - All SSL certificates valid\n";
|
||||
exit(0);
|
||||
@@ -20,68 +20,27 @@ use function PHPSTORM_META\type;
|
||||
}
|
||||
}
|
||||
|
||||
function status_class_bg($ssl, $word, $expiry, $retcol=null, $showday="null"){
|
||||
|
||||
// CSS CLASS
|
||||
$red = "alert_red";
|
||||
$orange = "alert_orange";
|
||||
$yellow = "alert_yellow";
|
||||
$green = "alert_green";
|
||||
|
||||
// CSS COLOR
|
||||
$col_red = "#ff4747";
|
||||
$col_orange = "#ff830f";
|
||||
$col_yellow = "#ffd70f";
|
||||
$col_green = "#42c500";
|
||||
$style="style='font-weight:bold; color:";
|
||||
function get_status_class($ssl, $word, $expiry){
|
||||
|
||||
if ($ssl != 1 || $word != 1) {
|
||||
return "alert_red";
|
||||
}
|
||||
|
||||
$days = ssl_days_left($expiry);
|
||||
|
||||
if ($showday == "on"){
|
||||
return $days;
|
||||
}
|
||||
|
||||
if ($ssl != 1 || $word != 1) {
|
||||
echo $red;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($days !== null) {
|
||||
|
||||
if ($days <= SSL_CRITICAL_DAYS) {
|
||||
|
||||
if ($retcol){ // CRITICAL
|
||||
echo $style . $col_orange . ";'";
|
||||
}else{
|
||||
echo $orange;
|
||||
return;
|
||||
}
|
||||
}elseif ($days <= SSL_WARNING_DAYS) {
|
||||
|
||||
if ($retcol){
|
||||
echo $style . $col_yellow . ";'";
|
||||
|
||||
}else{
|
||||
echo $yellow;
|
||||
return;
|
||||
if ($days < 0) {
|
||||
return "alert_red";
|
||||
}
|
||||
elseif ($days <= SSL_CRITICAL_DAYS) {
|
||||
return "alert_orange";
|
||||
}
|
||||
elseif ($days <= SSL_WARNING_DAYS) {
|
||||
return "alert_yellow";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($retcol){
|
||||
echo $style . $col_green . ";'";
|
||||
return ;
|
||||
}else{
|
||||
echo $green;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return "alert_green";
|
||||
}
|
||||
|
||||
|
||||
@@ -100,17 +59,27 @@ function status_class_bg($ssl, $word, $expiry, $retcol=null, $showday="null"){
|
||||
// Ordina: problemi prima
|
||||
usort($webcheck_json, function($a, $b) {
|
||||
|
||||
// 1️⃣ Problemi contenuto o SSL
|
||||
$a_problem = ($a['sslcheck_ok'] != 1 || $a['wordcheck_ok'] != 1);
|
||||
$b_problem = ($b['sslcheck_ok'] != 1 || $b['wordcheck_ok'] != 1);
|
||||
|
||||
// Se A ha problema e B no → A prima
|
||||
if ($a_problem && !$b_problem) return -1;
|
||||
|
||||
// Se B ha problema e A no → B prima
|
||||
if (!$a_problem && $b_problem) return 1;
|
||||
|
||||
// Se entrambi uguali → mantieni ordine
|
||||
return 0;
|
||||
// 2️⃣ Giorni alla scadenza
|
||||
$a_days = ssl_days_left($a['ssl-expiry']);
|
||||
$b_days = ssl_days_left($b['ssl-expiry']);
|
||||
|
||||
// Se uno non ha data → mettilo in fondo
|
||||
if ($a_days === null && $b_days !== null) return 1;
|
||||
if ($b_days === null && $a_days !== null) return -1;
|
||||
|
||||
// 3️⃣ SSL già scaduti prima
|
||||
if ($a_days < 0 && $b_days >= 0) return -1;
|
||||
if ($b_days < 0 && $a_days >= 0) return 1;
|
||||
|
||||
// 4️⃣ Ordina per giorni crescenti (meno giorni prima)
|
||||
return $a_days <=> $b_days;
|
||||
});
|
||||
|
||||
foreach($webcheck_json as $check_element){
|
||||
@@ -126,7 +95,11 @@ function status_class_bg($ssl, $word, $expiry, $retcol=null, $showday="null"){
|
||||
$ssl_expiry=$check_element['ssl-expiry'];
|
||||
$ssl_company=$check_element['ssl-company'];
|
||||
$http_error=$check_element['content_http_code'];
|
||||
$expirying_days=status_class_bg($sslcheck_ok, $checkword_ok, $ssl_expiry, false, 'on');
|
||||
$content_error=$check_element['content_error'];
|
||||
$ssl_error=$check_element['ssl_error'];
|
||||
$expirying_days = ssl_days_left($ssl_expiry);
|
||||
$expiry_col = get_expiry_style($expirying_days);
|
||||
$status_class = get_status_class($sslcheck_ok, $checkword_ok, $ssl_expiry);
|
||||
$col_red = "#ff4747";
|
||||
$col_orange = "#ff830f";
|
||||
$col_yellow = "#ffd70f";
|
||||
@@ -147,7 +120,7 @@ function status_class_bg($ssl, $word, $expiry, $retcol=null, $showday="null"){
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="alert-container <?php status_class_bg($sslcheck_ok, $checkword_ok, $ssl_expiry)?>">
|
||||
<div class="alert-container <?= $status_class ?>">
|
||||
<div class="alert-info">
|
||||
<div><b>HOST: </b><span><?= $host ?></span></div>
|
||||
<div><b>DOMAIN: </b><span><?= $domain ?></span></div>
|
||||
@@ -155,13 +128,22 @@ function status_class_bg($ssl, $word, $expiry, $retcol=null, $showday="null"){
|
||||
<div <?php word_col_status($sslcheck_ok) ?>><b>SSL: </b><span><?= checktoword($sslcheck_ok) ?></span></div>
|
||||
</div>
|
||||
<div class="alert-details">
|
||||
<?php
|
||||
if (!$content_error || !$ssl_error){
|
||||
?>
|
||||
<div><b>WORD TO CHECK: </b> <span><?= $wordtocheck ?></span></div>
|
||||
<div><b>SSL RELEASED: </b> <span><?= $ssl_released ?></span></div>
|
||||
<div><b>SSL EXPIRY: </b> <span <?= $expiry_col ?>><?= $ssl_expiry ?></span></div>
|
||||
<div><b>SSL DAYS LEFT: </b> <span <?= $expiry_col ?>><?= $expirying_days ?></span></div>
|
||||
<div><b>SSL DAYS LEFT: </b> <span <?= $expiry_col ?>><?= $expirying_days ?></span></span></div>
|
||||
<div><b>SSL COMPANY: </b> <span> <?= $ssl_company ?></span></div>
|
||||
<div><b>PATH: </b> <span><?= $path ?></span></div>
|
||||
<div><b>ERROR CODE: </b> <span><?= $http_error ?></span></div>
|
||||
<?php }else{?>
|
||||
<div style="color:red;"><b>ERROR CODE: </b> <span><?= $http_error ?></span></div>
|
||||
<div style="color:red;"><b>CONTENT ERROR: </b> <span><?= $content_error ?></span></div>
|
||||
<div style="color:red;"><b>SSL ERROR: </b> <span><?= $ssl_error ?></span></div>
|
||||
|
||||
<?php }?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -236,5 +218,27 @@ function status_class_bg($ssl, $word, $expiry, $retcol=null, $showday="null"){
|
||||
return $days;
|
||||
}
|
||||
|
||||
function get_expiry_style($days){
|
||||
|
||||
$col_red = "#ff4747";
|
||||
$col_orange = "#ff830f";
|
||||
$col_yellow = "#ffd70f";
|
||||
$col_green = "#42c500";
|
||||
|
||||
if ($days === null) return "";
|
||||
|
||||
if ($days < 0) {
|
||||
return "style='font-weight:bold;color:$col_red;'";
|
||||
}
|
||||
elseif ($days <= SSL_CRITICAL_DAYS) {
|
||||
return "style='font-weight:bold;color:$col_orange;'";
|
||||
}
|
||||
elseif ($days <= SSL_WARNING_DAYS) {
|
||||
return "style='font-weight:bold;color:$col_yellow;'";
|
||||
}
|
||||
|
||||
return "style='font-weight:bold;color:$col_green;'";
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,73 @@
|
||||
[
|
||||
{
|
||||
"host": "hostname",
|
||||
"domain": "domain",
|
||||
"path": "/path(leave empty if is the webroot)",
|
||||
"wordtocheck": "word to check",
|
||||
"wordcheck_ok": 0,
|
||||
"sslcheck_ok": 0,
|
||||
"ssl-released": null,
|
||||
"ssl-expiry": null,
|
||||
"ssl-company": null,
|
||||
"content_http_code": 0,
|
||||
"content_error": "URL rejected: Malformed input to a URL function",
|
||||
"ssl_error": "stream_socket_client failed: php_network_getaddresses: getaddrinfo for domain failed: Name or service not known (0)"
|
||||
},
|
||||
|
||||
{
|
||||
"host": "hostname",
|
||||
"domain": "domain",
|
||||
"path": "/path(leave empty if is the webroot)",
|
||||
"wordtocheck": "word to check",
|
||||
"wordcheck_ok": 1,
|
||||
"sslcheck_ok": 1,
|
||||
"ssl-released": "24/12/2025",
|
||||
"ssl-expiry": "24/02/2026",
|
||||
"ssl-company": null,
|
||||
"content_http_code": 200,
|
||||
"content_error": null,
|
||||
"ssl_error": null
|
||||
},
|
||||
{
|
||||
"host": "hostname",
|
||||
"domain": "testdomain",
|
||||
"path": "/path(leave empty if is the webroot)",
|
||||
"wordtocheck": "word to check",
|
||||
"wordcheck_ok": 1,
|
||||
"sslcheck_ok": 1,
|
||||
"ssl-released": "24/12/2025",
|
||||
"ssl-expiry": "16/02/2026",
|
||||
"ssl-company": null,
|
||||
"content_http_code": 200,
|
||||
"content_error": null,
|
||||
"ssl_error": null
|
||||
},
|
||||
{
|
||||
"host": "sld-app-a",
|
||||
"domain": "sld-server.org",
|
||||
"path": "",
|
||||
"wordtocheck": "proxmox",
|
||||
"wordcheck_ok": 1,
|
||||
"sslcheck_ok": 1,
|
||||
"ssl-released": "24/12/2025",
|
||||
"ssl-expiry": "24/03/2026",
|
||||
"ssl-company": "Cloudflare TLS Issuing ECC CA 3",
|
||||
"content_http_code": 200,
|
||||
"content_error": null,
|
||||
"ssl_error": null
|
||||
},
|
||||
{
|
||||
"host": "hostname",
|
||||
"domain": "domain",
|
||||
"path": "/path(leave empty if is the webroot)",
|
||||
"wordtocheck": "word to check",
|
||||
"wordcheck_ok": 1,
|
||||
"sslcheck_ok": 1,
|
||||
"ssl-released": "24/12/2025",
|
||||
"ssl-expiry": "22/02/2026",
|
||||
"ssl-company": null,
|
||||
"content_http_code": 200,
|
||||
"content_error": null,
|
||||
"ssl_error": null
|
||||
}
|
||||
]
|
||||
@@ -7,5 +7,14 @@
|
||||
"basic_auth":false,
|
||||
"basic_auth_name":"basic_auth_name",
|
||||
"basic_auth_password":"basic_auth_pass"
|
||||
},
|
||||
{
|
||||
"host":"sld-app-a",
|
||||
"domain":"sld-server.org",
|
||||
"path":"",
|
||||
"word-to-check":"proxmox",
|
||||
"basic_auth":false,
|
||||
"basic_auth_name":"basic_auth_name",
|
||||
"basic_auth_password":"basic_auth_pass"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user