ServicetemplateController: show template usage

First rough implementation, debug-output only for now

refs #895
refs #516
This commit is contained in:
Thomas Gelf 2017-05-16 08:53:31 +02:00
parent d7fc818118
commit b5cdd9de4d
1 changed files with 30 additions and 0 deletions

View File

@ -5,6 +5,7 @@ namespace Icinga\Module\Director\Controllers;
use Icinga\Module\Director\Objects\IcingaService;
use Icinga\Module\Director\Web\Controller\SimpleController;
use Icinga\Module\Director\Web\Table\ServicesOnHostsTable;
use ipl\Html\Html;
class ServicetemplateController extends SimpleController
{
@ -41,6 +42,35 @@ class ServicetemplateController extends SimpleController
$this->translate('Template: %s'),
$template->getObjectName()
);
$this->content()->add(
Html::tag('pre', null, print_r(
$this->getUsageSummary($template),
1
))
);
}
protected function getUsageSummary(IcingaService $template)
{
$ids = $template->templateResolver()->listInheritancePathIds();
$db = $this->db()->getDbAdapter();
$query = $db->select()->from(
['s' => 'icinga_service'],
[
'cnt_templates' => "COALESCE(SUM(CASE WHEN s.object_type = 'template' THEN 1 ELSE 0 END), 0)",
'cnt_objects' => "COALESCE(SUM(CASE WHEN s.object_type = 'object' THEN 1 ELSE 0 END), 0)",
'cnt_apply_rules' => "COALESCE(SUM(CASE WHEN s.object_type = 'apply' AND s.service_set_id IS NULL THEN 1 ELSE 0 END), 0)",
'cnt_set_members' => "COALESCE(SUM(CASE WHEN s.object_type = 'apply' AND s.service_set_id IS NOT NULL THEN 1 ELSE 0 END), 0)",
]
)->joinLeft(
['ps' => 'icinga_service_inheritance'],
'ps.service_id = s.id',
[]
)->where('ps.parent_service_id IN (?)', $ids);
return $db->fetchRow($query);
}
protected function requireTemplate()