diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index c318af7a..e45916ad 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -32,6 +32,8 @@ class ServiceController extends ObjectController { if ($host = $this->params->get('host')) { $this->host = IcingaHost::load($host, $this->db()); + } elseif ($hostId = $this->params->get('host_id')) { + $this->host = IcingaHost::loadWithAutoIncId($hostId, $this->db()); } elseif ($set = $this->params->get('set')) { $this->set = IcingaServiceSet::load(['object_name' => $set], $this->db()); } elseif ($apply = $this->params->get('apply')) { diff --git a/library/Director/Objects/DynamicApplyMatches.php b/library/Director/Objects/DynamicApplyMatches.php index 917ace07..9341d1ae 100644 --- a/library/Director/Objects/DynamicApplyMatches.php +++ b/library/Director/Objects/DynamicApplyMatches.php @@ -6,7 +6,6 @@ class DynamicApplyMatches extends ObjectApplyMatches { protected static $type = ''; - public static function setType($type) { static::$type = $type; diff --git a/library/Director/Web/Table/GroupMemberTable.php b/library/Director/Web/Table/GroupMemberTable.php index 8c10d84e..e51a62d4 100644 --- a/library/Director/Web/Table/GroupMemberTable.php +++ b/library/Director/Web/Table/GroupMemberTable.php @@ -2,8 +2,11 @@ namespace Icinga\Module\Director\Web\Table; +use Icinga\Data\Filter\Filter; use Icinga\Module\Director\Db; +use Icinga\Module\Director\IcingaConfig\AssignRenderer; use Icinga\Module\Director\Objects\IcingaObjectGroup; +use Exception; use dipl\Html\Link; use dipl\Web\Table\ZfQueryBasedTable; use dipl\Web\Url; @@ -55,12 +58,12 @@ class GroupMemberTable extends ZfQueryBasedTable return [ $this->translate('Group'), $this->translate('Member'), - $this->translate('Type') + $this->translate('via') ]; } else { return [ $this->translate('Member'), - $this->translate('Type') + $this->translate('via') ]; } } @@ -68,24 +71,72 @@ class GroupMemberTable extends ZfQueryBasedTable public function renderRow($row) { $type = $this->getType(); - $url = Url::fromPath("director/${type}", [ - 'name' => $row->object_name - ]); + if ($row->object_type === 'apply') { + $params = [ + 'id' => $row->id + ]; + } elseif (isset($row->host_id)) { + // I would prefer to see host= and set=, but joining + // them here is pointless. We should use DeferredHtml for these, + // remember hosts/sets we need and fetch them in a single query at + // rendering time. For now, this works fine - just... the URLs are + // not so nice + $params = [ + 'name' => $row->object_name, + 'host_id' => $row->host_id + ]; + } elseif (isset($row->service_set_id)) { + $params = [ + 'name' => $row->object_name, + 'set_id' => $row->service_set_id + ]; + } else { + $params = [ + 'name' => $row->object_name + ]; + } + + $url = Url::fromPath("director/${type}", $params); $tr = $this::tr(); if ($this->group === null) { $tr->add($this::td($row->group_name)); } + $link = Link::create($row->object_name, $url); + if ($row->object_type === 'apply') { + $link = [ + $link, + ' (where ', + $this->renderApplyFilter($row->assign_filter), + ')' + ]; + } $tr->add([ - $this::td(Link::create($row->object_name, $url)), + $this::td($link), $this::td($row->membership_type) ]); return $tr; } + protected function renderApplyFilter($assignFilter) + { + try { + $string = AssignRenderer::forFilter( + Filter::fromQueryString($assignFilter) + )->renderAssign(); + // Do not prefix it + $string = preg_replace('/^assign where /', '', $string); + } catch (Exception $e) { + // ignore errors in filter rendering + $string = 'Error in Filter rendering: ' . $e->getMessage(); + } + + return $string; + } + protected function prepareQuery() { // select h.object_name, hg.object_name, @@ -96,6 +147,8 @@ class GroupMemberTable extends ZfQueryBasedTable $type = $this->getType(); $columns = [ + 'o.id', + 'o.object_type', 'o.object_name', 'membership_type' => "CASE WHEN go.${type}_id IS NULL THEN 'apply' ELSE 'direct' END" ]; @@ -103,6 +156,11 @@ class GroupMemberTable extends ZfQueryBasedTable if ($this->group === null) { $columns = ['group_name' => 'g.object_name'] + $columns; } + if ($type === 'service') { + $columns[] = 'o.assign_filter'; + $columns[] = 'o.host_id'; + $columns[] = 'o.service_set_id'; + } $query = $this->db()->select()->from( ['gro' => "icinga_${type}group_${type}_resolved"], diff --git a/schema/mysql-migrations/upgrade_155.sql b/schema/mysql-migrations/upgrade_155.sql index eb436dc5..eab331f8 100644 --- a/schema/mysql-migrations/upgrade_155.sql +++ b/schema/mysql-migrations/upgrade_155.sql @@ -16,4 +16,4 @@ CREATE TABLE icinga_servicegroup_service_resolved ( INSERT INTO director_schema_migration (schema_version, migration_time) - VALUES (155, NOW()); \ No newline at end of file + VALUES (155, NOW()); diff --git a/schema/pgsql-migrations/upgrade_155.sql b/schema/pgsql-migrations/upgrade_155.sql index 0a3dbe61..d967e63c 100644 --- a/schema/pgsql-migrations/upgrade_155.sql +++ b/schema/pgsql-migrations/upgrade_155.sql @@ -19,4 +19,4 @@ CREATE INDEX servicegroup_service_resolved_servicegroup ON icinga_servicegroup_s INSERT INTO director_schema_migration (schema_version, migration_time) - VALUES (155, NOW()); \ No newline at end of file + VALUES (155, NOW());