From 31fa794440fcd349cdbca148730c268292e5bd4b Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 20 May 2014 20:36:39 +0000 Subject: [PATCH] monitoring/ido: implement IDO version support We want to make use of new IDO features without breaking compatibility. This is a quickfix as otherwise we would currently break everything below 1.10. Code contains a few TODOs as this needs improvement. --- .../Monitoring/Backend/Ido/Query/IdoQuery.php | 39 +++++++++++++++++++ .../Backend/Ido/Query/StatusQuery.php | 4 ++ .../Monitoring/DataView/ServiceStatus.php | 2 +- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php index e682c33bf..471856775 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php @@ -35,6 +35,8 @@ use Icinga\Application\Benchmark; use Icinga\Exception\ProgrammingError; use Icinga\Filter\Query\Tree; use Icinga\Module\Monitoring\Filter\UrlViewFilter; +use Icinga\Application\Icinga; +use Icinga\Web\Session; /** * Base class for Ido Queries @@ -184,6 +186,18 @@ abstract class IdoQuery extends Query */ protected $allowCustomVars = false; + /** + * Current IDO version. This is bullshit and needs to be moved somewhere + * else. As someone decided that we need no Backend-specific connection + * class unfortunately there is no better place right now. And as of the + * 'check_source' patch we need a quick fix immediately. So here you go. + * + * TODO: Fix this. + * + * @var string + */ + protected static $idoVersion; + /** * Return true when the column is an aggregate column * @@ -580,4 +594,29 @@ abstract class IdoQuery extends Query $query = new $class($this->ds, $columns); return $query; } + + // TODO: Move this away, see note related to $idoVersion var + protected function getIdoVersion() + { + if (self::$idoVersion === null) { + $session = null; + if (Icinga::app()->isWeb()) { + // TODO: Once we have version per connection we should choose a + // namespace based on resource name + $session = Session::getSession()->getNamespace('monitoring/ido'); + if (isset($session->version)) { + self::$idoVersion = $session->version; + return self::$idoVersion; + } + } + self::$idoVersion = $this->db->fetchOne( + $this->db->select()->from($this->prefix . 'dbversion', 'version') + ); + if ($session !== null) { + $session->version = self::$idoVersion; + $session->write(); // <- WHY? I don't want to care about this! + } + } + return self::$idoVersion; + } } diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php index fd582e096..d1c6a251a 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php @@ -305,6 +305,10 @@ class StatusQuery extends IdoQuery protected function joinBaseTables() { + if (version_compare($this->getIdoVersion(), '1.10.0', '<')) { + $this->columnMap['hoststatus']['host_check_source'] = '(NULL)'; + $this->columnMap['servicestatus']['service_check_source'] = '(NULL)'; + } $this->baseQuery = $this->db->select()->from( array('ho' => $this->prefix . 'objects'), array() diff --git a/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php b/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php index 5e34fb5aa..839c7da55 100644 --- a/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php +++ b/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php @@ -103,7 +103,7 @@ class ServiceStatus extends DataView 'service_hard_state', 'service_problem', 'service_perfdata', - 'service_check_source', + 'service_check_source', 'service_active_checks_enabled', 'service_active_checks_enabled_changed', 'service_passive_checks_enabled',