From ad8a2e04f609708d8561aa4371fe7ab2186f8048 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 14 Nov 2018 08:12:58 +0100 Subject: [PATCH] CoreApi: allow to fetch the Icinga Core version --- library/Director/Core/CoreApi.php | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/library/Director/Core/CoreApi.php b/library/Director/Core/CoreApi.php index bba3aef5..3926febf 100644 --- a/library/Director/Core/CoreApi.php +++ b/library/Director/Core/CoreApi.php @@ -31,6 +31,43 @@ class CoreApi implements DeploymentApiInterface return $this; } + /** + * @return string|null + */ + public function getVersion() + { + return $this->parseVersion($this->getRawVersion()); + } + + /** + * @return string|null + */ + public function getRawVersion() + { + try { + return $this->client->get('')->getRaw('version'); + } catch (Exception $exception) { + return null; + } + } + + /** + * @param $version + * @return string|null + */ + protected function parseVersion($version) + { + if ($version === null) { + return null; + } + + if (preg_match('/^v?(\d\.\d+\.\d+)/', $version, $match)) { + return $match[1]; + } else { + return null; + } + } + public function getObjects($pluralType, $attrs = array(), $ignorePackage = null) { $params = (object) [];