From 47b30199407c947c09feeea8d51d43860d76b843 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 25 Feb 2016 17:45:51 +0100 Subject: [PATCH] Add MonitoringBackend::isIcinga2() This function is for the many places where we have to distinguish between Icinga 1.x and Icinga 2.x. refs #11100 --- .../Monitoring/Backend/MonitoringBackend.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php b/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php index fb2f80410..54caa726f 100644 --- a/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php +++ b/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php @@ -341,4 +341,22 @@ class MonitoringBackend implements Selectable, Queryable, ConnectionInterface { return $this->select()->from('programstatus', array('program_version'))->fetchOne(); } + + /** + * Get whether the backend is Icinga 2 + * + * @param string $programVersion + * + * @return bool + */ + public function isIcinga2($programVersion = null) + { + if ($programVersion === null) { + $programVersion = $this->select()->from('programstatus', array('program_version'))->fetchOne(); + } + return (bool) preg_match( + '/^[vr]2\.\d+\.\d+.*$/', + $programVersion + ); + } }