diff --git a/application/controllers/ServicetemplateController.php b/application/controllers/ServicetemplateController.php index ad1007b2f..8a44ca4c7 100644 --- a/application/controllers/ServicetemplateController.php +++ b/application/controllers/ServicetemplateController.php @@ -5,6 +5,7 @@ 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 @@ public function usageAction() $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()