Perfdata::format(): handle ThresholdRanges

refs #8194
This commit is contained in:
Alexander A. Klimov 2016-04-29 11:34:59 +02:00 committed by Johannes Meyer
parent 392231dc81
commit 259bafea35
1 changed files with 11 additions and 16 deletions

View File

@ -416,6 +416,15 @@ class Perfdata
*/ */
protected function format($value) 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()) { if ($this->isPercentage()) {
return (string)$value . '%'; return (string)$value . '%';
} }
@ -447,20 +456,6 @@ class Perfdata
public function toArray() 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( return array(
'label' => $this->getLabel(), 'label' => $this->getLabel(),
'value' => $this->format($this->getvalue()), 'value' => $this->format($this->getvalue()),
@ -470,8 +465,8 @@ class Perfdata
'max' => isset($this->maxValue) && !$this->isPercentage() 'max' => isset($this->maxValue) && !$this->isPercentage()
? $this->format($this->maxValue) ? $this->format($this->maxValue)
: '', : '',
'warn' => $warn, 'warn' => $this->format($this->warningThreshold),
'crit' => $crit 'crit' => $this->format($this->criticalThreshold)
); );
} }