GeneratedConfig: add simple "show" support
This commit is contained in:
parent
4ca3583fff
commit
48d876556c
|
@ -8,13 +8,7 @@ class Director_ConfigController extends ActionController
|
|||
{
|
||||
public function showAction()
|
||||
{
|
||||
/** @var IcingaConfig $config */
|
||||
$config = IcingaConfig::generate($this->db());
|
||||
$this->view->files = array();
|
||||
|
||||
foreach ($config->getFiles() as $filename => $config) {
|
||||
$this->view->files[$filename] = $config->getContent();
|
||||
}
|
||||
$this->view->config = IcingaConfig::fromDb(pack('H*', $this->params->get('checksum')), $this->db());
|
||||
}
|
||||
|
||||
public function storeAction()
|
||||
|
|
|
@ -186,4 +186,11 @@ class Director_ListController extends ActionController
|
|||
$this->view->table = $this->loadTable('activityLog')->setConnection($this->db());
|
||||
$this->render('table');
|
||||
}
|
||||
|
||||
public function generatedconfigAction()
|
||||
{
|
||||
$this->view->title = $this->translate('Generated Configs');
|
||||
$this->view->table = $this->loadTable('generatedConfig')->setConnection($this->db());
|
||||
$this->render('table');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,28 @@
|
|||
<div class="controls">
|
||||
<?= $this->tabs ?>
|
||||
<h1>Config: <?= $this->config->getHexChecksum() ?></h1>
|
||||
|
||||
<table class="avp">
|
||||
<tr>
|
||||
<th><?= $this->translate('Last related activity') ?></th>
|
||||
<td><?= $this->qlink(
|
||||
$this->config->getLastActivityHexChecksum(),
|
||||
'director/show/activitylog',
|
||||
array('checksum' => $this->config->getLastActivityHexChecksum())
|
||||
) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?= $this->translate('Generated files') ?></th>
|
||||
<td><?= count($this->config->getFiles()) ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<?php foreach ($this->files as $file => $content): ?>
|
||||
<h2><?= $this->escape($file) ?></h2>
|
||||
<?php foreach ($this->config->getFiles() as $filename => $file): ?>
|
||||
<h2><?= $this->escape($filename) ?></h2>
|
||||
<pre>
|
||||
<?= $this->escape($content) ?>
|
||||
<?= $this->escape($file->getContent()) ?>
|
||||
</pre>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
|
|
|
@ -52,8 +52,8 @@ $section->add($this->translate('Endpoints'))
|
|||
$section->add($this->translate('Activity Log'))
|
||||
->setUrl('director/list/activitylog')
|
||||
->setPriority(900);
|
||||
$section->add($this->translate('Show config'))
|
||||
->setUrl('director/config/show')
|
||||
$section->add($this->translate('Show configs'))
|
||||
->setUrl('director/list/generatedconfig')
|
||||
->setPriority(902);
|
||||
$section->add($this->translate('Store config'))
|
||||
->setUrl('director/config/store')
|
||||
|
|
|
@ -60,6 +60,13 @@ class IcingaConfig
|
|||
return $files;
|
||||
}
|
||||
|
||||
public static function fromDb($checksum, DbConnection $connection)
|
||||
{
|
||||
$config = new static($connection);
|
||||
$config->loadFromDb($checksum);
|
||||
return $config;
|
||||
}
|
||||
|
||||
public static function generate(DbConnection $connection)
|
||||
{
|
||||
$config = new static($connection);
|
||||
|
@ -187,6 +194,36 @@ class IcingaConfig
|
|||
return $this;
|
||||
}
|
||||
|
||||
protected function loadFromDb($checksum)
|
||||
{
|
||||
$query = $this->db->select()->from(
|
||||
self::$table,
|
||||
array('checksum', 'last_activity_checksum')
|
||||
)->where('checksum = ?', $checksum);
|
||||
$result = $this->db->fetchRow($query);
|
||||
$this->checksum = $result->checksum;
|
||||
$this->last_activity_checksum = $result->last_activity_checksum;
|
||||
$query = $this->db->select()->from(
|
||||
array('cf' => 'director_generated_config_file'),
|
||||
array(
|
||||
'file_path' => 'cf.file_path',
|
||||
'checksum' => 'f.checksum',
|
||||
'content' => 'f.content',
|
||||
)
|
||||
)->join(
|
||||
array('f' => 'director_generated_file'),
|
||||
'cf.file_checksum = f.checksum',
|
||||
array()
|
||||
)->where('cf.config_checksum = ?', $checksum);
|
||||
|
||||
foreach ($this->db->fetchAll($query) as $row) {
|
||||
$file = new IcingaConfigFile();
|
||||
$this->files[$row->file_path] = $file->setContent($row->content);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function createFileFromDb($type)
|
||||
{
|
||||
$class = 'Icinga\\Module\\Director\\Objects\\Icinga' . ucfirst($type);
|
||||
|
|
|
@ -7,13 +7,17 @@ use Icinga\Module\Director\Objects\IcingaObject;
|
|||
class IcingaConfigFile
|
||||
{
|
||||
public static $table = 'director_generated_file';
|
||||
|
||||
public static $keyName = 'checksum';
|
||||
|
||||
protected $content;
|
||||
|
||||
protected $checksum;
|
||||
|
||||
public function prepend($content)
|
||||
{
|
||||
$this->content = $content . $this->content;
|
||||
$this->checksum = null;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -22,14 +26,25 @@ class IcingaConfigFile
|
|||
return $this->content;
|
||||
}
|
||||
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
$this->checksum = null;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHexChecksum()
|
||||
{
|
||||
return sha1($this->content);
|
||||
return current(unpack('H*', $this->getChecksum()));
|
||||
}
|
||||
|
||||
public function getChecksum()
|
||||
{
|
||||
return sha1($this->content, true);
|
||||
if ($this->checksum === null) {
|
||||
$this->checksum = sha1($this->content, true);
|
||||
}
|
||||
|
||||
return $this->checksum;
|
||||
}
|
||||
|
||||
public function addObjects($objects)
|
||||
|
@ -44,5 +59,7 @@ class IcingaConfigFile
|
|||
public function addObject(IcingaObject $object)
|
||||
{
|
||||
$this->content .= $object->toConfigString();
|
||||
$this->checksum = null;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue