IcingaConfg: make use of new ShipConfigFiles hook

This commit is contained in:
Thomas Gelf 2015-10-15 20:35:21 +02:00
parent 81c6920b93
commit 439d4ebc3d
1 changed files with 24 additions and 0 deletions

View File

@ -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());