nagios-dash
This commit is contained in:
parent
367a5a676b
commit
c55bee87fd
|
@ -246,6 +246,7 @@ RUN pip install speedtest-cli
|
|||
COPY overlay/opt/nagios/libexec/* ${NAGIOS_HOME}/libexec/
|
||||
COPY overlay/opt/nagios/share/stylesheets/* ${NAGIOS_HOME}/share/stylesheets/
|
||||
COPY overlay/opt/nagios/share/index.php ${NAGIOS_HOME}/share/
|
||||
COPY overlay/opt/nagios/share/dashboard ${NAGIOS_HOME}/share/
|
||||
#COPY overlay/usr ${NAGIOS_HOME}/usr
|
||||
|
||||
RUN cd /opt/nagios/etc/objects && \
|
||||
|
|
|
@ -12,7 +12,7 @@ services:
|
|||
build:
|
||||
dockerfile: Dockerfile
|
||||
container_name: nagios
|
||||
image: docker-registry1.in.thelinuxpro.net:5000/tlp/nagios:241230.0.11
|
||||
image: docker-registry1.in.thelinuxpro.net:5000/tlp/nagios:241230.0.12
|
||||
networks:
|
||||
infra_dev_net:
|
||||
ipv4_address: 10.99.23.36
|
||||
|
|
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
$refreshvalue = 10; //value in seconds to refresh page
|
||||
$pagetitle = "Operations Nagios Dashboard";
|
||||
?>
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title><? echo($pagetitle); ?></title>
|
||||
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js">
|
||||
</script>
|
||||
<style type="text/css">
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
line-height: 1.3em;
|
||||
overflow-x: hidden;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
td {
|
||||
padding: .1em 1em;
|
||||
}
|
||||
|
||||
h1 {
|
||||
display: inline-block;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.head {
|
||||
background: lightGray;
|
||||
color: black;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.head th {
|
||||
border-right: 1px solid #888;
|
||||
padding: .2em 10px;
|
||||
}
|
||||
|
||||
.critical {
|
||||
background: #b40000;
|
||||
color: white;
|
||||
font-size: 1.4em;
|
||||
line-height: 1.2em;
|
||||
}
|
||||
|
||||
.critical td {
|
||||
border-bottom: 2px solid #7f0000;
|
||||
border-right: 2px solid #7f0000;
|
||||
padding: .1em 10px;
|
||||
}
|
||||
|
||||
.warning {
|
||||
background: yellow;
|
||||
color: black;
|
||||
font-size: 1em;
|
||||
}
|
||||
.warning td{
|
||||
border-bottom: 1px solid #bdbf00;
|
||||
border-right: 1px solid #bdbf00;
|
||||
}
|
||||
.statusinfo {
|
||||
font-size: 14px !important;
|
||||
}
|
||||
#nagios_placeholder {
|
||||
}
|
||||
#loading {
|
||||
background: transparent url(throbber.gif) no-repeat center center;
|
||||
width: 214px;
|
||||
height: 13px;
|
||||
display: inline-block;
|
||||
}
|
||||
#refreshing {
|
||||
color: gray;
|
||||
display: inline-block;
|
||||
font-family: monospace;
|
||||
}
|
||||
#refreshing_countdown {
|
||||
display: inline-block;
|
||||
width: 15px;
|
||||
text-align: center;
|
||||
}
|
||||
#refreshing, #loading, h1 {
|
||||
line-height: 50px;
|
||||
font-size: 1em;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
|
||||
var placeHolder,
|
||||
refreshValue = <?php print $refreshvalue; ?>;
|
||||
|
||||
$().ready(function(){
|
||||
placeHolder = $("#nagios_placeholder");
|
||||
updateNagiosData(placeHolder);
|
||||
window.setInterval(updateCountDown, 1000);
|
||||
});
|
||||
|
||||
function updateNagiosData(block){
|
||||
$("#loading").fadeIn(200);
|
||||
block.load("nagios_get.php", function(response){
|
||||
$(this).empty();
|
||||
$(this).html(response);
|
||||
$("#loading").fadeOut(200);
|
||||
});
|
||||
}
|
||||
|
||||
function updateCountDown(){
|
||||
var countdown = $("#refreshing_countdown");
|
||||
var remaining = parseInt(countdown.text());
|
||||
if(remaining == 0){
|
||||
updateNagiosData(placeHolder);
|
||||
countdown.text(refreshValue);
|
||||
}
|
||||
else {
|
||||
countdown.text(remaining - 1);
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
<div id="nagios_placeholder"></div>
|
||||
<p id="refreshing">Refresh in <span id="refreshing_countdown"><?php print $refreshvalue; ?></span> seconds</p>
|
||||
<div id="loading"></div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,300 @@
|
|||
<?php
|
||||
$file = fopen("/var/cache/nagios3/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
|
||||
$colhost = true; //true/false to show host column in table
|
||||
$colstatusinfo = true; //true/false to show status info/plugin info column in table
|
||||
$colservice = true; //true/false to show service type column column in table
|
||||
|
||||
$pagetitle = "Operations Nagios Dashboard";
|
||||
|
||||
$thedate = date('Y-m-d H:i:s');
|
||||
$showthedate = false;
|
||||
?>
|
||||
<?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>");
|
||||
}
|
||||
if (($collastcheck == false) and ($colhost == true) and ($colstatusinfo == true) and ($colservice == false)) {
|
||||
echo("<table width=90% border=0 class=boldtable align=center>");
|
||||
}
|
||||
if (($collastcheck == false) and ($colhost == false) and ($colstatusinfo == true) and ($colservice == false)) {
|
||||
echo("<table width=90% border=0 class=boldtable align=center>");
|
||||
}
|
||||
if (($collastcheck == false) and ($colhost == true) and ($colstatusinfo == false) and ($colservice == false)) {
|
||||
echo("<table width=90% border=0 class=boldtable align=center>");
|
||||
}
|
||||
if (($collastcheck == true) and ($colhost == true) and ($colstatusinfo == true) and ($colservice == true)) {
|
||||
echo("<table width=90% border=0 class=boldtable align=center>");
|
||||
}
|
||||
?>
|
||||
<tr class="head">
|
||||
<?php
|
||||
if ($collastcheck == true) {
|
||||
echo("<th width=210>Last Checked</th>");
|
||||
}
|
||||
if ($colhost == true) {
|
||||
echo("<th width=140>Host</th>");
|
||||
}
|
||||
if ($colstatusinfo == true) {
|
||||
echo("<th width=290>Status Info</th>");
|
||||
}
|
||||
if ($colservice == true) {
|
||||
echo("<th width=150>Service</td>");
|
||||
}
|
||||
?>
|
||||
</tr>
|
||||
<?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, ','));
|
||||
$dashline = substr($dashline, strpos($dashline, ',') + 1, strlen($dashline));
|
||||
switch ($dashstatus) {
|
||||
case 0:
|
||||
$dashstatus = "UP";
|
||||
$trclass = "up";
|
||||
break;
|
||||
case 1:
|
||||
$dashstatus = "WARNING";
|
||||
$trclass = "warning";
|
||||
break;
|
||||
case 2:
|
||||
$dashstatus = "CRITICAL";
|
||||
$trclass = "critical";
|
||||
break;
|
||||
case 3:
|
||||
$dashstatus = "DISABLED";
|
||||
$trclass = "disabled";
|
||||
break;
|
||||
}
|
||||
$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
|
||||
if ($collastcheck == true) {
|
||||
echo("<td>".date("Y-m-d H:i:s", $dashdate)."</td>");
|
||||
}
|
||||
if ($colhost == true) {
|
||||
echo("<td>".$dashhost."</td>");
|
||||
}
|
||||
if ($colstatusinfo == true) {
|
||||
echo("<td class=\"statusinfo\">".$dashplugin."</td>");
|
||||
}
|
||||
if ($colservice == true) {
|
||||
if ($dashservice == "") {
|
||||
echo("<td>HOST PING</td>");
|
||||
} else {
|
||||
echo("<td>".$dashservice."</td>");
|
||||
}
|
||||
}
|
||||
endif; ?>
|
||||
</tr>
|
||||
<?php
|
||||
} //end display function
|
||||
|
||||
//arrays for different fields in nagios status.dat
|
||||
$hostarray = array();
|
||||
$servicearray = array();
|
||||
$statearray = array();
|
||||
$pluginarray = array();
|
||||
$checkarray = array();
|
||||
$ackarray = array();
|
||||
$disarray = array();
|
||||
|
||||
//arrays for status of hosts/services
|
||||
$finaluparray = array();
|
||||
$finalwarnarray = array();
|
||||
$finalcritarray = array();
|
||||
$finaldisarray = array();
|
||||
|
||||
//field to check in nagios status.dat
|
||||
$hostname = 'host_name=';
|
||||
$servicedes = 'service_description=';
|
||||
$currstate = 'current_state=';
|
||||
$pluginout = 'plugin_output=';
|
||||
$lastcheck = 'last_check=';
|
||||
$ackcheck = 'been_acknowledged=';
|
||||
$discheck = 'active_checks_enabled=';
|
||||
|
||||
//counters for loops
|
||||
$hostcount = 0;
|
||||
$servicecount = 0;
|
||||
$currcount = 0;
|
||||
$plugcount = 0;
|
||||
$lastcount = 0;
|
||||
$discount = 0;
|
||||
$disttlcount = 0;
|
||||
$ackcount = 0;
|
||||
$ttlcount = 0;
|
||||
$check = 0;
|
||||
$okcount = 0;
|
||||
$warncount = 0;
|
||||
$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);
|
||||
$currpos = strpos($line, $currstate);
|
||||
$plugpos = strpos($line, $pluginout);
|
||||
$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++;
|
||||
$pluginarray[$plugcount] = substr($line, strpos($line, '=') + 1, strlen($line));
|
||||
$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++;
|
||||
$ackarray[$ackcount] = substr($line, strpos($line, '=') + 1, strlen($line));
|
||||
$check = 1;
|
||||
}
|
||||
|
||||
$check = 0;
|
||||
|
||||
if ($dispos !== false) {
|
||||
$discount++;
|
||||
$disarray[$discount] = substr($line, strpos($line, '=') + 1, strlen($line));
|
||||
$check = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($check == 1) { //if for final array building
|
||||
$ttlcount++;
|
||||
|
||||
if ($disarray[$ttlcount] == 1) { //if for active checks being enabled (1)
|
||||
|
||||
if ($statearray[$ttlcount] == 0) { //if for state being up/ok (0 for acknowledgements, you dont acknowledge an up service/host)
|
||||
$okcount++;
|
||||
$finaluparray[$okcount] = $statearray[$ttlcount].",0,".$checkarray[$ttlcount].",".$hostarray[$ttlcount].",".$pluginarray[$ttlcount].",".$servicearray[$servicecount];
|
||||
}
|
||||
|
||||
if ($statearray[$ttlcount] == 1) { //if for state being warning
|
||||
$warncount++;
|
||||
if ($ackarray[$ttlcount] == "") {
|
||||
$ackarray[$ttlcount] = 0;
|
||||
}
|
||||
|
||||
$finalwarnarray[$warncount] = $statearray[$ttlcount].",".$ackarray[$ttlcount].",".$checkarray[$ttlcount].",".$hostarray[$ttlcount].",".$pluginarray[$ttlcount].",".$servicearray[$servicecount];
|
||||
}
|
||||
|
||||
if ($statearray[$ttlcount] == 2) { //if for state being critical
|
||||
$critcount++;
|
||||
|
||||
if ($ackarray[$ttlcount] == "") {
|
||||
$ackarray[$ttlcount] = "0";
|
||||
}
|
||||
|
||||
$finalcritarray[$critcount] = $statearray[$ttlcount].",".$ackarray[$ttlcount].",".$checkarray[$ttlcount].",".$hostarray[$ttlcount].",".$pluginarray[$ttlcount].",".$servicearray[$servicecount];
|
||||
}
|
||||
} //end if for active checks being enabled
|
||||
|
||||
//if active checks are 0 then checking is disabled (0), the 3 represents the disabled state
|
||||
if ($disarray[$ttlcount] == 0) {
|
||||
$disttlcount++;
|
||||
$finaldisarray[$disttlcount] = "3,0,".$checkarray[$ttlcount].",".$hostarray[$ttlcount].",".$pluginarray[$ttlcount].",".$servicearray[$servicecount];
|
||||
}
|
||||
|
||||
} //end if for final array building
|
||||
}//end while loop through nagios status.dat
|
||||
|
||||
fclose($file);
|
||||
|
||||
//loops sending arrays and column details to display function
|
||||
//loops run in order > critical, warnings, up, disabled
|
||||
|
||||
for ($l = 1; $l <= $critcount; $l++) {
|
||||
dashdisplay($finalcritarray[$l], $collastcheck, $colhost, $colstatusinfo, $colservice);
|
||||
}
|
||||
|
||||
for ($m = 1; $m <= $warncount; $m++) {
|
||||
dashdisplay($finalwarnarray[$m], $collastcheck, $colhost, $colstatusinfo, $colservice);
|
||||
}
|
||||
|
||||
#for ($n = 1; $n <= $okcount; $n++) {
|
||||
# dashdisplay($finaluparray[$n],$collastcheck,$colhost,$colstatusinfo,$colservice);
|
||||
#}
|
||||
|
||||
#for ($o = 1; $o <= $disttlcount; $o++) {
|
||||
# dashdisplay($finaldisarray[$o],$collastcheck,$colhost,$colstatusinfo,$colservice);
|
||||
#}
|
||||
?>
|
||||
</table>
|
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
Loading…
Reference in New Issue