Preserve threshold ranges in ThresholdRange, not in Perfdata
refs #8194
This commit is contained in:
parent
881267d829
commit
b706792c9b
|
@ -72,20 +72,6 @@ class Perfdata
|
|||
*/
|
||||
protected $criticalThreshold;
|
||||
|
||||
/**
|
||||
* The WARNING threshold as got from the plugin
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rawWarningThreshold;
|
||||
|
||||
/**
|
||||
* The CRITICAL threshold as got from the plugin
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rawCriticalThreshold;
|
||||
|
||||
/**
|
||||
* Create a new Perfdata object based on the given performance data label and value
|
||||
*
|
||||
|
@ -321,27 +307,23 @@ class Perfdata
|
|||
}
|
||||
/* @noinspection PhpMissingBreakStatementInspection */
|
||||
case 3:
|
||||
$this->rawCriticalThreshold = trim($parts[2]);
|
||||
$this->criticalThreshold = self::convert(
|
||||
ThresholdRange::fromString($this->rawCriticalThreshold),
|
||||
ThresholdRange::fromString(trim($parts[2])),
|
||||
$this->unit
|
||||
);
|
||||
// Fallthrough
|
||||
case 2:
|
||||
$this->rawWarningThreshold = trim($parts[1]);
|
||||
$this->warningThreshold = self::convert(
|
||||
ThresholdRange::fromString($this->rawWarningThreshold),
|
||||
ThresholdRange::fromString(trim($parts[1])),
|
||||
$this->unit
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->warningThreshold === null) {
|
||||
$this->warningThreshold = new ThresholdRange();
|
||||
$this->rawWarningThreshold = '';
|
||||
}
|
||||
if ($this->criticalThreshold === null) {
|
||||
$this->criticalThreshold = new ThresholdRange();
|
||||
$this->rawCriticalThreshold = '';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -469,14 +451,14 @@ class Perfdata
|
|||
$max = $this->warningThreshold->getMax();
|
||||
$warn = $max === null ? '∞' : $this->format($max);
|
||||
} else {
|
||||
$warn = $this->rawWarningThreshold;
|
||||
$warn = (string) $this->warningThreshold;
|
||||
}
|
||||
|
||||
if ($this->criticalThreshold->getMin() === null) {
|
||||
$max = $this->criticalThreshold->getMax();
|
||||
$crit = $max === null ? '∞' : $this->format($max);
|
||||
} else {
|
||||
$crit = $this->rawCriticalThreshold;
|
||||
$crit = (string) $this->criticalThreshold;
|
||||
}
|
||||
|
||||
return array(
|
||||
|
|
|
@ -29,6 +29,13 @@ class ThresholdRange
|
|||
*/
|
||||
protected $inverted = false;
|
||||
|
||||
/**
|
||||
* The unmodified range as passed to fromString()
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $raw;
|
||||
|
||||
/**
|
||||
* Create a new instance based on a threshold range conforming to <https://nagios-plugins.org/doc/guidelines.html>
|
||||
*
|
||||
|
@ -39,6 +46,7 @@ class ThresholdRange
|
|||
public static function fromString($rawRange = '')
|
||||
{
|
||||
$range = new static();
|
||||
$range->raw = $rawRange;
|
||||
|
||||
if ($rawRange === '') {
|
||||
return $range;
|
||||
|
@ -166,13 +174,6 @@ class ThresholdRange
|
|||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if ($this->min === null) {
|
||||
$res = '~:';
|
||||
} else {
|
||||
$res = $this->min === 0.0 ? '' : $this->min . ':';
|
||||
}
|
||||
$res .= $this->max === null ? '' : $this->max;
|
||||
|
||||
return ($this->inverted ? '@' : '') . (empty($res) ? '0:' : $res);
|
||||
return (string) $this->raw;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue