From 439d4ebc3d9314785c2fec7c2603b9d3187aef80 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 15 Oct 2015 20:35:21 +0200 Subject: [PATCH] IcingaConfg: make use of new ShipConfigFiles hook --- .../Director/IcingaConfig/IcingaConfig.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/library/Director/IcingaConfig/IcingaConfig.php b/library/Director/IcingaConfig/IcingaConfig.php index 6d890b5d..577dbd34 100644 --- a/library/Director/IcingaConfig/IcingaConfig.php +++ b/library/Director/IcingaConfig/IcingaConfig.php @@ -3,9 +3,11 @@ namespace Icinga\Module\Director\IcingaConfig; use Icinga\Data\Db\DbConnection; +use Icinga\Exception\ProgrammingError; use Icinga\Module\Director\Util; use Icinga\Module\Director\Objects\IcingaCommand; use Icinga\Module\Director\Objects\IcingaHost; +use Icinga\Web\Hook; use Exception; class IcingaConfig @@ -90,6 +92,7 @@ class IcingaConfig protected function storeIfModified() { $this->generateFromDb(); + $this->collectExtraFiles(); $checksum = $this->calculateChecksum(); $exists = $this->db->fetchOne( $this->db->select()->from(self::$table, 'COUNT(*)')->where('checksum = ?', $this->dbBin($checksum)) @@ -327,6 +330,27 @@ continue; return $this->files[$filename]; } + protected function collectExtraFiles() + { + foreach (Hook::all('Director\\ShipConfigFiles') as $hook) { + foreach ($hook->fetchFiles() as $filename => $file) { + if (array_key_exists($filename, $this->files)) { + throw new ProgrammingError( + 'Cannot ship one file twice: %s', + $filename + ); + } + if ($file instanceof IcingaConfigFile) { + $this->files[$filename] = $file; + } else { + $this->configFile($filename, '')->setContent((string) $file); + } + } + } + + return $this; + } + public function getLastActivityHexChecksum() { return Util::binary2hex($this->getLastActivityChecksum());