From 259bafea3565b47066acbd099db5b501cc12d05d Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 29 Apr 2016 11:34:59 +0200 Subject: [PATCH] Perfdata::format(): handle ThresholdRanges refs #8194 --- .../library/Monitoring/Plugin/Perfdata.php | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php index 10fcbb277..db6f46f31 100644 --- a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php +++ b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php @@ -416,6 +416,15 @@ class Perfdata */ protected function format($value) { + if ($value instanceof ThresholdRange) { + if ($value->getMin()) { + return (string) $value; + } + + $max = $value->getMax(); + return $max === null ? '' : $this->format($max); + } + if ($this->isPercentage()) { return (string)$value . '%'; } @@ -447,20 +456,6 @@ class Perfdata public function toArray() { - if ($this->warningThreshold->getMin() === null) { - $max = $this->warningThreshold->getMax(); - $warn = $max === null ? '∞' : $this->format($max); - } else { - $warn = (string) $this->warningThreshold; - } - - if ($this->criticalThreshold->getMin() === null) { - $max = $this->criticalThreshold->getMax(); - $crit = $max === null ? '∞' : $this->format($max); - } else { - $crit = (string) $this->criticalThreshold; - } - return array( 'label' => $this->getLabel(), 'value' => $this->format($this->getvalue()), @@ -470,8 +465,8 @@ class Perfdata 'max' => isset($this->maxValue) && !$this->isPercentage() ? $this->format($this->maxValue) : '', - 'warn' => $warn, - 'crit' => $crit + 'warn' => $this->format($this->warningThreshold), + 'crit' => $this->format($this->criticalThreshold) ); }