diff --git a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php index a6eaddabd..6af3cde17 100644 --- a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php +++ b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php @@ -190,6 +190,9 @@ class Perfdata if ($this->maxValue !== null) { $minValue = $this->minValue !== null ? $this->minValue : 0; + if ($this->maxValue - $minValue === 0.0) { + return null; + } if ($this->value > $minValue) { return (($this->value - $minValue) / ($this->maxValue - $minValue)) * 100; @@ -267,9 +270,13 @@ class Perfdata switch (count($parts)) { case 5: - $this->maxValue = self::convert($parts[4], $this->unit); + if ($parts[4] !== '') { + $this->maxValue = self::convert($parts[4], $this->unit); + } case 4: - $this->minValue = self::convert($parts[3], $this->unit); + if ($parts[3] !== '') { + $this->minValue = self::convert($parts[3], $this->unit); + } case 3: // TODO(#6123): Tresholds have the same UOM and need to be converted as well! $this->criticalThreshold = trim($parts[2]) ? trim($parts[2]) : null; diff --git a/modules/monitoring/test/php/library/Monitoring/Plugin/PerfdataTest.php b/modules/monitoring/test/php/library/Monitoring/Plugin/PerfdataTest.php index 2d8a98b73..9cc132eb2 100644 --- a/modules/monitoring/test/php/library/Monitoring/Plugin/PerfdataTest.php +++ b/modules/monitoring/test/php/library/Monitoring/Plugin/PerfdataTest.php @@ -347,6 +347,14 @@ class PerfdataTest extends BaseTestCase Perfdata::fromString('test=25;;;50;100')->getPercentage(), 'Perfdata objects do return a percentage though their value is lower than it\'s allowed minimum' ); + $this->assertNull( + Perfdata::fromString('test=25;;;0;')->getPercentage(), + 'Perfdata objects do not ignore empty max values when returning percentages' + ); + $this->assertNull( + Perfdata::fromString('test=25;;;0;0')->getPercentage(), + 'Perfdata objects do not ignore impossible min/max combinations when returning percentages' + ); } /**