IcingaConfig: add a couple of config files
This commit is contained in:
parent
e4e31268c2
commit
a250d4730b
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\IcingaConfig;
|
||||
|
||||
class IcingaCommandsConfigFile extends IcingaConfigFile
|
||||
{
|
||||
protected $content = "library \"methods\"\n\n";
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\IcingaConfig;
|
||||
|
||||
class IcingaHostsConfigFile extends IcingaConfigFile
|
||||
{
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\IcingaConfig;
|
||||
|
||||
class IcingaServicesConfigFile extends IcingaConfigFile
|
||||
{
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\IcingaConfig;
|
||||
|
||||
class IcingaZonesConfigFile extends IcingaConfigFile
|
||||
{
|
||||
}
|
Loading…
Reference in New Issue