Permalink
Browse files

std_html_bar Gadget: Added new parameters "perfdata" and "border"

  • Loading branch information...
LarsMichelsen committed Jun 28, 2017
1 parent c212d79 commit 028829cc9bb68fa233cf5c00f2d65c574e343823
Showing with 27 additions and 11 deletions.
  1. +4 −0 ChangeLog
  2. +23 −11 share/userfiles/gadgets/std_html_bar.php
View
@@ -1,4 +1,8 @@
1.9.3
Frontend:
* std_html_bar Gadget: Added new optional parameters "perfdata" to specify
the perfdata index to show and "border" to enable/disable the border of the
bar using the values 0/1
1.9.2
Core:
@@ -75,18 +75,30 @@
$min = 0;
$max = -1;
$default = 0;
// Set default parameters values
$border = 1; // Border
$perfdata = 0; // Perfdata
// Get parameters from gadget_opts
if (isset($_GET['opts']) && ($_GET['opts'] != '')){
preg_match_all('/(\w+)=(\d+)/', $_GET['opts'], $matches, PREG_SET_ORDER);
for ($i = 0; $i < count($matches); $i++) {
if ($matches[$i][1] == 'border') { $border = $matches[$i][2]; }
if ($matches[$i][1] == 'perfdata') { $perfdata = $matches[$i][2]; }
}
}
/* Now read the parameters */
// This gadget is simple and dirty, it only recognizes the first dataset of
// performance data
// Read dataset of performance data from parameters
$value = $aPerfdata[0]['value'];
$uom = $aPerfdata[0]['uom'];
$warn = $aPerfdata[0]['warning'];
$crit = $aPerfdata[0]['critical'];
$min = $aPerfdata[0]['min'];
$max = $aPerfdata[0]['max'];
$value = $aPerfdata[$perfdata]['value'];
$uom = $aPerfdata[$perfdata]['uom'];
$warn = $aPerfdata[$perfdata]['warning'];
$crit = $aPerfdata[$perfdata]['critical'];
$min = $aPerfdata[$perfdata]['min'];
$max = $aPerfdata[$perfdata]['max'];
//================
// Normalize / Fix value and max
@@ -98,7 +110,7 @@
if($max != '' && $value < $min) {
$value = $min;
} elseif($max != '' && $max != -1 && $value > $max) {
$value = $max;
$value = $max;
}
}
@@ -107,11 +119,11 @@
if(intval($crit) == 0 || $crit != '')
$max = $crit + 1;
else
$max = $warn + 1;
$max = $warn + 1;
$width = (int) $value * 100 / $max;
echo "<div style='position:absolute;left:0;width:100px;height:30px;text-align:center;line-height:30px;'>".$value.$uom."</div>";
echo "<table style='width:100px;border:1px solid #000;height:30px;'><tr><td style='text-align:center;background-color:#dfdfdf;width:".$width."px'></td><td></td></tr></table>";
echo "<table style='width:100px;border:".$border."px solid #000;height:30px;'><tr><td style='text-align:center;background-color:#dfdfdf;width:".$width."px'></td><td></td></tr></table>";
exit(0);
?>

0 comments on commit 028829c

Please sign in to comment.