mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
parent
8e38b1e318
commit
77cbb1040c
@ -32,6 +32,8 @@ class ServiceController extends ObjectController
|
|||||||
{
|
{
|
||||||
if ($host = $this->params->get('host')) {
|
if ($host = $this->params->get('host')) {
|
||||||
$this->host = IcingaHost::load($host, $this->db());
|
$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')) {
|
} elseif ($set = $this->params->get('set')) {
|
||||||
$this->set = IcingaServiceSet::load(['object_name' => $set], $this->db());
|
$this->set = IcingaServiceSet::load(['object_name' => $set], $this->db());
|
||||||
} elseif ($apply = $this->params->get('apply')) {
|
} elseif ($apply = $this->params->get('apply')) {
|
||||||
|
@ -6,7 +6,6 @@ class DynamicApplyMatches extends ObjectApplyMatches
|
|||||||
{
|
{
|
||||||
protected static $type = '';
|
protected static $type = '';
|
||||||
|
|
||||||
|
|
||||||
public static function setType($type)
|
public static function setType($type)
|
||||||
{
|
{
|
||||||
static::$type = $type;
|
static::$type = $type;
|
||||||
|
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Web\Table;
|
namespace Icinga\Module\Director\Web\Table;
|
||||||
|
|
||||||
|
use Icinga\Data\Filter\Filter;
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
|
use Icinga\Module\Director\IcingaConfig\AssignRenderer;
|
||||||
use Icinga\Module\Director\Objects\IcingaObjectGroup;
|
use Icinga\Module\Director\Objects\IcingaObjectGroup;
|
||||||
|
use Exception;
|
||||||
use dipl\Html\Link;
|
use dipl\Html\Link;
|
||||||
use dipl\Web\Table\ZfQueryBasedTable;
|
use dipl\Web\Table\ZfQueryBasedTable;
|
||||||
use dipl\Web\Url;
|
use dipl\Web\Url;
|
||||||
@ -55,12 +58,12 @@ class GroupMemberTable extends ZfQueryBasedTable
|
|||||||
return [
|
return [
|
||||||
$this->translate('Group'),
|
$this->translate('Group'),
|
||||||
$this->translate('Member'),
|
$this->translate('Member'),
|
||||||
$this->translate('Type')
|
$this->translate('via')
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
return [
|
return [
|
||||||
$this->translate('Member'),
|
$this->translate('Member'),
|
||||||
$this->translate('Type')
|
$this->translate('via')
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,24 +71,72 @@ class GroupMemberTable extends ZfQueryBasedTable
|
|||||||
public function renderRow($row)
|
public function renderRow($row)
|
||||||
{
|
{
|
||||||
$type = $this->getType();
|
$type = $this->getType();
|
||||||
$url = Url::fromPath("director/${type}", [
|
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
|
'name' => $row->object_name
|
||||||
]);
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = Url::fromPath("director/${type}", $params);
|
||||||
|
|
||||||
$tr = $this::tr();
|
$tr = $this::tr();
|
||||||
|
|
||||||
if ($this->group === null) {
|
if ($this->group === null) {
|
||||||
$tr->add($this::td($row->group_name));
|
$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([
|
$tr->add([
|
||||||
$this::td(Link::create($row->object_name, $url)),
|
$this::td($link),
|
||||||
$this::td($row->membership_type)
|
$this::td($row->membership_type)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $tr;
|
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()
|
protected function prepareQuery()
|
||||||
{
|
{
|
||||||
// select h.object_name, hg.object_name,
|
// select h.object_name, hg.object_name,
|
||||||
@ -96,6 +147,8 @@ class GroupMemberTable extends ZfQueryBasedTable
|
|||||||
|
|
||||||
$type = $this->getType();
|
$type = $this->getType();
|
||||||
$columns = [
|
$columns = [
|
||||||
|
'o.id',
|
||||||
|
'o.object_type',
|
||||||
'o.object_name',
|
'o.object_name',
|
||||||
'membership_type' => "CASE WHEN go.${type}_id IS NULL THEN 'apply' ELSE 'direct' END"
|
'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) {
|
if ($this->group === null) {
|
||||||
$columns = ['group_name' => 'g.object_name'] + $columns;
|
$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(
|
$query = $this->db()->select()->from(
|
||||||
['gro' => "icinga_${type}group_${type}_resolved"],
|
['gro' => "icinga_${type}group_${type}_resolved"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user