mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-04-08 17:15:10 +02:00
parent
8e38b1e318
commit
77cbb1040c
@ -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')) {
|
||||
|
@ -6,7 +6,6 @@ class DynamicApplyMatches extends ObjectApplyMatches
|
||||
{
|
||||
protected static $type = '';
|
||||
|
||||
|
||||
public static function setType($type)
|
||||
{
|
||||
static::$type = $type;
|
||||
|
@ -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=<name> and set=<name>, 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"],
|
||||
|
@ -16,4 +16,4 @@ CREATE TABLE icinga_servicegroup_service_resolved (
|
||||
|
||||
INSERT INTO director_schema_migration
|
||||
(schema_version, migration_time)
|
||||
VALUES (155, NOW());
|
||||
VALUES (155, NOW());
|
||||
|
@ -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());
|
||||
VALUES (155, NOW());
|
||||
|
Loading…
x
Reference in New Issue
Block a user