IcingaConfig: add a couple of config files

This commit is contained in:
Thomas Gelf 2015-06-11 22:48:41 +02:00
parent e4e31268c2
commit a250d4730b
6 changed files with 119 additions and 0 deletions

View File

@ -0,0 +1,8 @@
<?php
namespace Icinga\Module\Director\IcingaConfig;
class IcingaCommandsConfigFile extends IcingaConfigFile
{
protected $content = "library \"methods\"\n\n";
}

View File

@ -0,0 +1,56 @@
<?php
namespace Icinga\Module\Director\IcingaConfig;
use Icinga\Data\Db\DbConnection;
use Icinga\Module\Director\Objects\IcingaCommand;
use Icinga\Module\Director\Objects\IcingaHost;
class IcingaConfig
{
protected $files = array();
protected function __construct()
{
}
public function getFiles()
{
return $this->files;
}
public static function fromDb(DbConnection $db)
{
$config = new static;
return $config->loadFromDb($db);
}
protected function loadFromDb(DbConnection $db)
{
$this->db = $db;
$this
->createFileFromDb('zone')
->createFileFromDb('command')
->createFileFromDb('host')
->createFileFromDb('service')
;
return $this;
}
protected function createFileFromDb($type)
{
$class = 'Icinga\\Module\\Director\\Objects\\Icinga' . ucfirst($type);
$objects = $class::loadAll($this->db);
if (! empty($objects)) {
$class = 'Icinga\\Module\\Director\\IcingaConfig\\Icinga'
. ucfirst($type)
. 'sConfigFile';
$file = new $class();
$file->addObjects($objects);
$this->files[$type . 's.conf'] = $file;
}
return $this;
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace Icinga\Module\Director\IcingaConfig;
use Icinga\Module\Director\Objects\IcingaObject;
class IcingaConfigFile
{
protected $content;
public function getContent()
{
return $this->content;
}
public function getChecksum()
{
return sha1($this->content);
}
public function addObjects($objects)
{
foreach ($objects as $object) {
$this->addObject($object);
}
return $this;
}
public function addObject(IcingaObject $object)
{
$this->content .= $object->toConfigString();
}
}

View File

@ -0,0 +1,7 @@
<?php
namespace Icinga\Module\Director\IcingaConfig;
class IcingaHostsConfigFile extends IcingaConfigFile
{
}

View File

@ -0,0 +1,7 @@
<?php
namespace Icinga\Module\Director\IcingaConfig;
class IcingaServicesConfigFile extends IcingaConfigFile
{
}

View File

@ -0,0 +1,7 @@
<?php
namespace Icinga\Module\Director\IcingaConfig;
class IcingaZonesConfigFile extends IcingaConfigFile
{
}