Merge pull request #3735 from dasJ/feature/perf-temperatures
Support temperatures (°C, °F) in perfdata
This commit is contained in:
commit
269f432d58
|
@ -146,6 +146,16 @@ class Perfdata
|
||||||
return in_array($this->unit, array('s', 'ms', 'us'));
|
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
|
* Return whether this performance data's value is in percentage
|
||||||
*
|
*
|
||||||
|
@ -287,7 +297,7 @@ class Perfdata
|
||||||
$parts = explode(';', $this->perfdataValue);
|
$parts = explode(';', $this->perfdataValue);
|
||||||
|
|
||||||
$matches = array();
|
$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->unit = strtolower($matches[3]);
|
||||||
$this->value = self::convert($matches[1], $this->unit);
|
$this->value = self::convert($matches[1], $this->unit);
|
||||||
} else {
|
} else {
|
||||||
|
@ -434,6 +444,9 @@ class Perfdata
|
||||||
if ($this->isSeconds()) {
|
if ($this->isSeconds()) {
|
||||||
return Format::seconds($value);
|
return Format::seconds($value);
|
||||||
}
|
}
|
||||||
|
if ($this->isTemperature()) {
|
||||||
|
return (string)$value . strtoupper($this->unit);
|
||||||
|
}
|
||||||
return number_format($value, 2);
|
return number_format($value, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue