Module: check_mk
Branch: master
Commit: 6d301a5e13aa74e7c8d722c3d0fdc48cf7f549a3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6d301a5e13aa74…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Wed Dec 2 12:46:34 2015 +0100
#2804 FIX Avoid redeclaration errors in graphs when using pnp basket
The pnp basket might include the same template files multiple times.
This caused redeclaration exceptions in a number of check templates, e.g. default,
mem-linux.
---
.werks/2804 | 10 ++++++
ChangeLog | 1 +
pnp-templates/check_mk-hp_blade_psu.php | 25 +++++++-------
pnp-templates/check_mk-mem.linux.php | 54 ++++++++++++++++---------------
pnp-templates/default.php | 15 +++++----
5 files changed, 59 insertions(+), 46 deletions(-)
diff --git a/.werks/2804 b/.werks/2804
new file mode 100644
index 0000000..23f4370
--- /dev/null
+++ b/.werks/2804
@@ -0,0 +1,10 @@
+Title: Avoid redeclaration errors in graphs when using pnp basket
+Level: 1
+Component: multisite
+Compatible: compat
+Version: 1.2.7i4
+Date: 1449056407
+Class: fix
+
+The pnp basket might include the same template files multiple times.
+This caused redeclaration exceptions in a number of check templates, e.g. default,
mem-linux.
diff --git a/ChangeLog b/ChangeLog
index 9e291de..c31f389 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -144,6 +144,7 @@
* 2846 FIX: View refresh could reset checkboxes on views where "always show
checkboxes" is enabled
* 2778 FIX: Fixed correct scaling of sidebar on newer versions of Chrome browser
* 2781 FIX: Fix role handling of "Custom Links" snapin in case of adapted
roles...
+ * 2804 FIX: Avoid redeclaration errors in graphs when using pnp basket...
WATO:
* 2442 WATO remove host: improved cleanup of obsolete host files...
diff --git a/pnp-templates/check_mk-hp_blade_psu.php
b/pnp-templates/check_mk-hp_blade_psu.php
index e6b4ab3..1fb978d 100644
--- a/pnp-templates/check_mk-hp_blade_psu.php
+++ b/pnp-templates/check_mk-hp_blade_psu.php
@@ -30,23 +30,20 @@
# Author: Lars Michelsen <lm(a)mathias-kettner.de>
#
-function getAllPsuFiles($path) {
- $files = array();
- if($h = opendir($path)) {
- while(($file = readdir($h)) !== false) {
- if(preg_match('/^PSU_[0-9]+_output\.rrd$/', $file, $aRet))
- $files[] = $aRet[0];
- }
- natcasesort($files);
- closedir($h);
- }
- return $files;
-}
-
$colors = array("008CFF", "6FBEFF", "2F7EBF",
"00589F");
$path = dirname($RRDFILE[1]);
-$files = getAllPsuFiles($path);
+
+# get all psu files
+$files = array();
+if($h = opendir($path)) {
+ while(($file = readdir($h)) !== false) {
+ if(preg_match('/^PSU_[0-9]+_output\.rrd$/', $file, $aRet))
+ $files[] = $aRet[0];
+ }
+ natcasesort($files);
+ closedir($h);
+}
$opt[0] = "-l 0 --vertical-label \"Watt\" --title \"HP Blade
Enclosure - PSU Power Usage\" ";
$def[0] = '';
diff --git a/pnp-templates/check_mk-mem.linux.php b/pnp-templates/check_mk-mem.linux.php
index a633cbe..ddb1177 100644
--- a/pnp-templates/check_mk-mem.linux.php
+++ b/pnp-templates/check_mk-mem.linux.php
@@ -33,37 +33,39 @@ foreach ($NAME as $i => $n) {
$mem_defines[$n] = "DEF:$n=$RRDFILE[$i]:$DS[$i]:MAX ";
}
-function mem_area($varname, $color, $title, $stacked)
-{
- return mem_curve("AREA", $varname, $color, $title, $stacked);
-}
-
-function mem_line($varname, $color, $title, $stacked)
-{
- return mem_curve("LINE1", $varname, $color, $title, $stacked);
-}
+# avoid redeclaration errors if this file is include multiple times (e.g. by basket)
+if (!function_exists('mem_area')) {
+ function mem_area($varname, $color, $title, $stacked)
+ {
+ return mem_curve("AREA", $varname, $color, $title, $stacked);
+ }
-function mem_curve($how, $varname, $color, $title, $stacked)
-{
- global $mem_defines;
- $tit = sprintf("%-30s", $title);
- if (isset($mem_defines[$varname])) {
- $x = $mem_defines[$varname] .
"$how:$varname#$color:\"$tit\"";
- if ($stacked)
- $x .= ":STACK";
- $x .= " ";
- $x .= "CDEF:${varname}_gb=$varname,1073741824,/ ";
- $x .= "GPRINT:${varname}_gb:LAST:\"%6.1lf GB last\" ";
- $x .= "GPRINT:${varname}_gb:AVERAGE:\"%6.1lf GB avg\" ";
- $x .= "GPRINT:${varname}_gb:MAX:\"%6.1lf GB max\\n\" ";
- return $x;
+ function mem_line($varname, $color, $title, $stacked)
+ {
+ return mem_curve("LINE1", $varname, $color, $title, $stacked);
}
- else {
- return "";
+
+ function mem_curve($how, $varname, $color, $title, $stacked)
+ {
+ global $mem_defines;
+ $tit = sprintf("%-30s", $title);
+ if (isset($mem_defines[$varname])) {
+ $x = $mem_defines[$varname] .
"$how:$varname#$color:\"$tit\"";
+ if ($stacked)
+ $x .= ":STACK";
+ $x .= " ";
+ $x .= "CDEF:${varname}_gb=$varname,1073741824,/ ";
+ $x .= "GPRINT:${varname}_gb:LAST:\"%6.1lf GB last\" ";
+ $x .= "GPRINT:${varname}_gb:AVERAGE:\"%6.1lf GB avg\" ";
+ $x .= "GPRINT:${varname}_gb:MAX:\"%6.1lf GB max\\n\" ";
+ return $x;
+ }
+ else {
+ return "";
+ }
}
}
-
# 1. Overview
$opt[] = $defopt . "--title \"RAM + Swap overview\"";
$def[] = ""
diff --git a/pnp-templates/default.php b/pnp-templates/default.php
index 2e0609b..9151127 100644
--- a/pnp-templates/default.php
+++ b/pnp-templates/default.php
@@ -2,12 +2,15 @@
# Fetch dynamic PNP template from Check_MK's new metrics system
-function get_apache_port() {
- $path = getenv("OMD_ROOT") . "/etc/omd/site.conf";
- foreach (file($path) as $line) {
- if (strpos($line, "CONFIG_APACHE_TCP_PORT") === 0) {
- list($key, $val) = explode("=", $line);
- return trim($val, "'\n\r");
+# avoid redeclaration errors if this file is include multiple times (e.g. by basket)
+if (!function_exists('get_apache_port')) {
+ function get_apache_port() {
+ $path = getenv("OMD_ROOT") . "/etc/omd/site.conf";
+ foreach (file($path) as $line) {
+ if (strpos($line, "CONFIG_APACHE_TCP_PORT") === 0) {
+ list($key, $val) = explode("=", $line);
+ return trim($val, "'\n\r");
+ }
}
}
}