Merge branch 'feature/cnt-apply-12968'

This commit is contained in:
Thomas Gelf 2016-11-03 13:36:30 +01:00
commit c32cc3ca92
8 changed files with 60 additions and 5 deletions

View File

@ -15,6 +15,8 @@ class GeneratedConfigFileTable extends QuickTable
'size' => 'LENGTH(f.content)',
'cnt_object' => 'f.cnt_object',
'cnt_template' => 'f.cnt_template',
'cnt_apply' => 'f.cnt_apply',
'cnt_all' => "f.cnt_object || ' / ' || f.cnt_template || ' / ' || f.cnt_apply",
'checksum' => 'LOWER(HEX(f.checksum))',
'config_checksum' => 'LOWER(HEX(cf.config_checksum))',
);
@ -52,8 +54,12 @@ class GeneratedConfigFileTable extends QuickTable
$view = $this->view();
return array(
'file_path' => $view->translate('File'),
'cnt_all' => $view->translate('Object/Tpl/Apply'),
/*
'cnt_object' => $view->translate('Objects'),
'cnt_template' => $view->translate('Templates'),
'cnt_apply' => $view->translate('Apply rules'),
*/
'size' => $view->translate('Size'),
);
}

View File

@ -85,9 +85,10 @@ function colorize($log, $logLink) {
'deployment_id' => $deployment->id
)
) ?>, <?= sprintf(
$this->translate('%d objects, %d templates'),
$this->translate('%d objects, %d templates, %d apply rules'),
$config->getObjectCount(),
$config->getTemplateCount()
$config->getTemplateCount(),
$config->getApplyCount()
)?>, <?= Format::bytes($config->getSize()) ?></td>
</tr>
<tr>

View File

@ -111,6 +111,15 @@ class IcingaConfig
return $cnt;
}
public function getApplyCount()
{
$cnt = 0;
foreach ($this->getFiles() as $file) {
$cnt += $file->getApplyCount();
}
return $cnt;
}
public function getChecksum()
{
return $this->checksum;
@ -614,6 +623,7 @@ apply Service for (title => params in host.vars["%s"]) {
'content' => 'f.content',
'cnt_object' => 'f.cnt_object',
'cnt_template' => 'f.cnt_template',
'cnt_apply' => 'f.cnt_apply',
)
)->join(
array('f' => 'director_generated_file'),
@ -626,7 +636,8 @@ apply Service for (title => params in host.vars["%s"]) {
$this->files[$row->file_path] = $file
->setContent($row->content)
->setObjectCount($row->cnt_object)
->setTemplateCount($row->cnt_template);
->setTemplateCount($row->cnt_template)
->setApplyCount($row->cnt_apply);
}
return $this;

View File

@ -55,6 +55,11 @@ class IcingaConfigFile
return $this->cntTemplate;
}
public function getApplyCount()
{
return $this->cntApply;
}
public function getSize()
{
return strlen($this->content);
@ -72,6 +77,12 @@ class IcingaConfigFile
return $this;
}
public function setApplyCount($cnt)
{
$this->cntApply = $cnt;
return $this;
}
public function getHexChecksum()
{
return Util::binary2hex($this->getChecksum());

View File

@ -0,0 +1,12 @@
ALTER TABLE director_generated_file
ADD COLUMN cnt_apply INT(10) UNSIGNED NOT NULL DEFAULT 0;
UPDATE director_generated_file
SET cnt_apply = ROUND(
(LENGTH(content) - LENGTH( REPLACE(content, 'apply ', '') ) )
/ LENGTH('apply ')
);
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (122, NOW());

View File

@ -47,6 +47,7 @@ CREATE TABLE director_generated_file (
content MEDIUMTEXT NOT NULL,
cnt_object INT(10) UNSIGNED NOT NULL DEFAULT 0,
cnt_template INT(10) UNSIGNED NOT NULL DEFAULT 0,
cnt_apply INT(10) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (checksum)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@ -1354,4 +1355,4 @@ CREATE TABLE sync_run (
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (121, NOW());
VALUES (122, NOW());

View File

@ -0,0 +1,12 @@
ALTER TABLE director_generated_file
ADD COLUMN cnt_apply SMALLINT NOT NULL DEFAULT 0;
UPDATE director_generated_file
SET cnt_apply = ROUND(
(LENGTH(content) - LENGTH( REPLACE(content, 'apply ', '') ) )
/ LENGTH('apply ')
);
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (122, NOW());

View File

@ -95,6 +95,7 @@ CREATE TABLE director_generated_file (
content text DEFAULT NULL,
cnt_object SMALLINT NOT NULL DEFAULT 0,
cnt_template SMALLINT NOT NULL DEFAULT 0,
cnt_apply SMALLINT NOT NULL DEFAULT 0,
PRIMARY KEY (checksum)
);
@ -1581,4 +1582,4 @@ CREATE UNIQUE INDEX notification_inheritance ON icinga_notification_inheritance
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (121, NOW());
VALUES (122, NOW());