From 6e24cfd538f31f9093818081a12ed2a3964762a5 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 29 May 2015 17:26:56 +0200 Subject: [PATCH] Implement ::worseThan() refs #8205 --- .../library/Monitoring/Plugin/Perfdata.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php index ef91f7f93..c1af78114 100644 --- a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php +++ b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php @@ -480,4 +480,34 @@ class Perfdata return Service::STATE_OK; } + + /** + * Return whether the state indicated by this perfdata is worse than + * the state indicated by the other perfdata + * CRITICAL > UNKNOWN > WARNING > OK + * + * @param Perfdata $rhs the other perfdata + * + * @return bool + */ + public function worseThan(Perfdata $rhs) + { + if (($state = $this->getState()) === ($rhsState = $rhs->getState())) { + return $this->getPercentage() > $rhs->getPercentage(); + } + + if ($state === Service::STATE_CRITICAL) { + return true; + } + + if ($state === Service::STATE_UNKNOWN) { + return $rhsState !== Service::STATE_CRITICAL; + } + + if ($state === Service::STATE_WARNING) { + return $rhsState === Service::STATE_OK; + } + + return false; + } }