From d45c753409ed5f2ee5f41b5b5dfc8f9e07f5d9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20He=C3=9F?= Date: Fri, 5 Apr 2019 15:21:25 +0200 Subject: [PATCH] =?UTF-8?q?Support=20temperatures=20(=C2=B0C,=20=C2=B0F)?= =?UTF-8?q?=20in=20perfdata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../library/Monitoring/Plugin/Perfdata.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php index db6f46f31..f077e9aae 100644 --- a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php +++ b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php @@ -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); }