nagios-dash

This commit is contained in:
Kameron Kenny 2024-12-30 16:40:33 -05:00
parent c55bee87fd
commit dee322af88
2 changed files with 29 additions and 29 deletions

View File

@ -12,7 +12,7 @@ services:
build:
dockerfile: Dockerfile
container_name: nagios
image: docker-registry1.in.thelinuxpro.net:5000/tlp/nagios:241230.0.12
image: docker-registry1.in.thelinuxpro.net:5000/tlp/nagios:241230.0.13
networks:
infra_dev_net:
ipv4_address: 10.99.23.36

View File

@ -1,5 +1,5 @@
<?php
$file = fopen("/var/cache/nagios3/status.dat", "r") or exit("Unable to open file!"); //path to nagios file
<?php
$file = fopen("/opt/nagios/var/status.dat", "r") or exit("Unable to open file!"); //path to nagios file
$refreshvalue = 10; //value in seconds to refresh page
$collastcheck = true; //true/false to show last checked date column in table
@ -12,7 +12,7 @@ $pagetitle = "Operations Nagios Dashboard";
$thedate = date('Y-m-d H:i:s');
$showthedate = false;
?>
<?php
<?php
//i may have missed some column displays here so add them in if you need them
if (($collastcheck == true) and ($colhost == true) and ($colstatusinfo == true) and ($colservice == false)) {
echo("<table width=90% border=0 class=boldtable align=center>");
@ -31,7 +31,7 @@ if (($collastcheck == true) and ($colhost == true) and ($colstatusinfo == true)
}
?>
<tr class="head">
<?php
<?php
if ($collastcheck == true) {
echo("<th width=210>Last Checked</th>");
}
@ -46,7 +46,7 @@ if (($collastcheck == true) and ($colhost == true) and ($colstatusinfo == true)
}
?>
</tr>
<?php
<?php
function dashdisplay($dashline, $collastcheck, $colhost, $colstatusinfo, $colservice) { //function to display array data into table with colors/font etc
$dashstatus = substr($dashline, 0, strpos($dashline, ','));
@ -71,26 +71,26 @@ function dashdisplay($dashline, $collastcheck, $colhost, $colstatusinfo, $colser
}
$dashack = substr($dashline, 0, strpos($dashline, ','));
$dashline = substr($dashline, strpos($dashline, ',') + 1, strlen($dashline));
if ($dashack == "") { //if somehow the acknowledgement state is blank, set it to 0 (acknowledged)
$dashack = 0;
}
$dashdate = substr($dashline, 0, strpos($dashline, ',') - 1);
$dashline = substr($dashline, strpos($dashline, ',') + 1, strlen($dashline));
$dashhost = substr($dashline, 0, strpos($dashline, ',') - 1);
$dashline = substr($dashline, strpos($dashline, ',') + 1, strlen($dashline));
$dashplugin = substr($dashline, 0, strrpos($dashline, ',') - 1);
$dashline = substr($dashline, strrpos($dashline, ',') + 1, strlen($dashline));
$dashservice = $dashline;
?>
<?php if($dashack == 0): ?>
<tr class="<?php print $trclass ?>">
<?php
<?php
if ($collastcheck == true) {
echo("<td>".date("Y-m-d H:i:s", $dashdate)."</td>");
}
@ -109,7 +109,7 @@ function dashdisplay($dashline, $collastcheck, $colhost, $colstatusinfo, $colser
}
endif; ?>
</tr>
<?php
<?php
} //end display function
//arrays for different fields in nagios status.dat
@ -153,7 +153,7 @@ $critcount = 0;
while (!feof($file)) { //begin while through nagios status.dat
$line = fgets($file);
//strpos to check for field line by line
$hostpos = strpos($line, $hostname);
$servicepos = strpos($line, $servicedes);
@ -162,31 +162,31 @@ while (!feof($file)) { //begin while through nagios status.dat
$lastpos = strpos($line, $lastcheck);
$dispos = strpos($line, $discheck);
$ackpos = strpos($line, $ackcheck);
if ($hostpos !== false) {
$hostcount++;
$hostarray[$hostcount] = substr($line, strpos($line, '=') + 1, strlen($line));
$check = 1;
}
$check = 0;
if ($servicepos !== false) {
$servicecount++;
$servicearray[$servicecount] = substr($line, strpos($line, '=') + 1, strlen($line));
$check = 1;
}
$check = 0;
if ($currpos !== false) {
$currcount++;
$statearray[$currcount] = substr($line, strpos($line, '=') + 1, strlen($line));
$check = 1;
}
$check = 0;
if ($plugpos !== false) {
if (strpos($line, "long_plugin_output=") === false) {
$plugcount++;
@ -194,33 +194,33 @@ while (!feof($file)) { //begin while through nagios status.dat
$check = 1;
}
}
$check = 0;
if ($lastpos !== false) {
$lastcount++;
$checkarray[$lastcount] = substr($line, strpos($line, '=') + 1, strlen($line));
$check = 1;
}
$check = 0;
if ($servicearray[$servicecount] != "") { //if the host has a service being checked
if ($dispos !== false) {
$discount++;
$disarray[$discount] = substr($line, strpos($line, '=') + 1, strlen($line));
$check = 1;
}
$check = 0;
if ($ackpos !== false) {
$ackcount++;
$ackarray[$ackcount] = substr($line, strpos($line, '=') + 1, strlen($line));
$check = 1;
}
}
if ($servicearray[$servicecount] == "") { //if the host has no service being checked
if ($ackpos !== false) {
$ackcount++;