Skip to content

Commit

Permalink
ServicetemplateController: show template usage
Browse files Browse the repository at this point in the history
First rough implementation, debug-output only for now

refs #895
refs #516
  • Loading branch information
Thomas-Gelf committed Jul 14, 2017
1 parent d7fc818 commit b5cdd9d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions application/controllers/ServicetemplateController.php
Expand Up @@ -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
{
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b5cdd9d

Please sign in to comment.