From 3ac869981a3d827c9a7a03427d082a81470246bb Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 22 Oct 2013 20:35:18 +0000 Subject: [PATCH] Small perfdata improvements --- .../library/Monitoring/Plugin/Perfdata.php | 16 ++++++++++++++++ .../library/Monitoring/Plugin/PerfdataSet.php | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php index b19a07621..c2f02187d 100644 --- a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php +++ b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php @@ -36,6 +36,22 @@ class Perfdata } } + public function hasMax() + { + return $this->max !== null && $this->max > 0; + } + + public function getPercentage() + { + if ($this->unit === self::PERCENT) { + return $this->val; + } + if ($this->hasMax()) { + return $this->val / $this->max * 100; + } + return false; + } + public function getValue() { return $this->val; diff --git a/modules/monitoring/library/Monitoring/Plugin/PerfdataSet.php b/modules/monitoring/library/Monitoring/Plugin/PerfdataSet.php index 690658734..7f6876f1a 100644 --- a/modules/monitoring/library/Monitoring/Plugin/PerfdataSet.php +++ b/modules/monitoring/library/Monitoring/Plugin/PerfdataSet.php @@ -30,7 +30,7 @@ class PerfdataSet public function getAll() { - return $this->perfdata; + return $this->perfdata === null ? array() : $this->perfdata; } protected function readLabel()