Perfdata: Render unknown UOMs as-is

This commit is contained in:
Johannes Meyer 2022-02-28 09:46:48 +01:00
parent 5b8bbf0d32
commit e7bc0a136b
1 changed files with 3 additions and 3 deletions

View File

@ -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 : '');
}
/**