From e7bc0a136b4f302b145adefef8aa4d57456244ec Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 28 Feb 2022 09:46:48 +0100 Subject: [PATCH] Perfdata: Render unknown UOMs as-is --- modules/monitoring/library/Monitoring/Plugin/Perfdata.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php index 34a63c787..bafb49f49 100644 --- a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php +++ b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php @@ -307,8 +307,8 @@ class Perfdata $parts = explode(';', $this->perfdataValue); $matches = array(); - if (preg_match('@^(-?\d+(\.\d+)?)([a-zA-Z%°]{1,2})$@u', $parts[0], $matches)) { - $this->unit = strtolower($matches[3]); + if (preg_match('@^(-?(?:\d+)?(?:\.\d+)?)([a-zA-Z%°]{1,3})$@u', $parts[0], $matches)) { + $this->unit = strtolower($matches[2]); $this->value = self::convert($matches[1], $this->unit); } else { $this->value = self::convert($parts[0]); @@ -458,7 +458,7 @@ class Perfdata if ($this->isTemperature()) { return (string)$value . strtoupper($this->unit); } - return number_format($value, 2); + return number_format($value, 2) . ($this->unit !== null ? ' ' . $this->unit : ''); } /**