Merge pull request #3735 from dasJ/feature/perf-temperatures

Support temperatures (°C, °F) in perfdata
This commit is contained in:
Johannes Meyer 2019-04-16 08:07:38 +02:00 committed by GitHub
commit 269f432d58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 1 deletions

View File

@ -146,6 +146,16 @@ class Perfdata
return in_array($this->unit, array('s', 'ms', 'us'));
}
/**
* Return whether this performance data's value is a temperature
*
* @return bool True in case it's temperature, otherwise False
*/
public function isTemperature()
{
return in_array($this->unit, array('°c', '°f'));
}
/**
* Return whether this performance data's value is in percentage
*
@ -287,7 +297,7 @@ class Perfdata
$parts = explode(';', $this->perfdataValue);
$matches = array();
if (preg_match('@^(-?\d+(\.\d+)?)([a-zA-Z%]{1,2})$@', $parts[0], $matches)) {
if (preg_match('@^(-?\d+(\.\d+)?)([a-zA-Z%°]{1,2})$@u', $parts[0], $matches)) {
$this->unit = strtolower($matches[3]);
$this->value = self::convert($matches[1], $this->unit);
} else {
@ -434,6 +444,9 @@ class Perfdata
if ($this->isSeconds()) {
return Format::seconds($value);
}
if ($this->isTemperature()) {
return (string)$value . strtoupper($this->unit);
}
return number_format($value, 2);
}