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

View File

@@ -20,68 +20,27 @@ use function PHPSTORM_META\type;
}
}
function status_class_bg($ssl, $word, $expiry, $retcol=null, $showday="null"){
function get_status_class($ssl, $word, $expiry){
// 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:";
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;
if ($days < 0) {
return "alert_red";
}
}elseif ($days <= SSL_WARNING_DAYS) {
if ($retcol){
echo $style . $col_yellow . ";'";
}else{
echo $yellow;
return;
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) {
$a_problem = ($a['sslcheck_ok'] != 1 || $a['wordcheck_ok'] != 1);
$b_problem = ($b['sslcheck_ok'] != 1 || $b['wordcheck_ok'] != 1);
// 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;
if ($a_problem && !$b_problem) return -1;
if (!$a_problem && $b_problem) return 1;
// Se B ha problema e A no → B prima
if (!$a_problem && $b_problem) return 1;
// 2⃣ Giorni alla scadenza
$a_days = ssl_days_left($a['ssl-expiry']);
$b_days = ssl_days_left($b['ssl-expiry']);
// Se entrambi uguali → mantieni ordine
return 0;
// 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 EXPIRY: </b> <span <?= $expiry_col ?>><?= $ssl_expiry ?></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;'";
}
?>