Support temperatures (°C, °F) in perfdata
This commit is contained in:
parent
fc99865241
commit
d45c753409
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue