Merge pull request #2750 from Icinga/bugfix/click-on-host-in-service-grid-invalid-filter-2523

Servicegrid: assemble filters with the Filter class
This commit is contained in:
Eric Lippmann 2017-03-28 10:22:11 +02:00
commit 302e559aab
2 changed files with 31 additions and 7 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
use Icinga\Data\Filter\Filter;
use Icinga\Module\Monitoring\Object\Service; use Icinga\Module\Monitoring\Object\Service;
use Icinga\Web\Url; use Icinga\Web\Url;
@ -14,7 +15,10 @@ if (! $this->compact): ?>
<p><?= $this->translate('No services found matching the filter.') ?></p> <p><?= $this->translate('No services found matching the filter.') ?></p>
</div> </div>
<?php return; endif; <?php return; endif;
$hostFilter = '(host_name=' . implode('|host_name=', array_keys($pivotData)) . ')'; $hostFilter = Filter::matchAny();
foreach ($pivotData as $hostName => $_) {
$hostFilter->orFilter(Filter::where('host_name', $hostName));
}
?> ?>
<table class="service-grid-table"> <table class="service-grid-table">
<thead> <thead>
@ -30,8 +34,10 @@ $hostFilter = '(host_name=' . implode('|host_name=', array_keys($pivotData)) . '
<?php foreach ($pivotHeader['cols'] as $serviceDescription => $serviceDisplayName): ?> <?php foreach ($pivotHeader['cols'] as $serviceDescription => $serviceDisplayName): ?>
<th class="rotate-45"><div><span><?= $this->qlink( <th class="rotate-45"><div><span><?= $this->qlink(
$this->ellipsis($serviceDisplayName, 18), $this->ellipsis($serviceDisplayName, 18),
'monitoring/list/services?' . $hostFilter, Url::fromPath('monitoring/list/services')->addFilter(
array('service_description' => $serviceDescription), Filter::matchAll($hostFilter, Filter::where('service_description', $serviceDescription))
),
null,
array('title' => sprintf( array('title' => sprintf(
$this->translate('List all services with the name "%s" on all reported hosts'), $this->translate('List all services with the name "%s" on all reported hosts'),
$serviceDisplayName $serviceDisplayName
@ -47,12 +53,16 @@ $hostFilter = '(host_name=' . implode('|host_name=', array_keys($pivotData)) . '
<?php foreach ($pivotHeader['rows'] as $hostName => $hostDisplayName): ?> <?php foreach ($pivotHeader['rows'] as $hostName => $hostDisplayName): ?>
<tr> <tr>
<th><?php <th><?php
$services = $pivotData[$hostName]; $serviceFilter = Filter::matchAny();
$serviceFilter = '(service_description=' . implode('|service_description=', array_keys($services)) . ')'; foreach ($pivotData[$hostName] as $serviceName => $_) {
$serviceFilter->orFilter(Filter::where('service_description', $serviceName));
}
echo $this->qlink( echo $this->qlink(
$hostDisplayName, $hostDisplayName,
'monitoring/list/services?' . $serviceFilter, Url::fromPath('monitoring/list/services')->addFilter(
array('host_name' => $hostName), Filter::matchAll($serviceFilter, Filter::where('host_name', $hostName))
),
null,
array('title' => sprintf($this->translate('List all reported services on host %s'), $hostDisplayName)) array('title' => sprintf($this->translate('List all reported services on host %s'), $hostDisplayName))
); );
?></th> ?></th>

View File

@ -269,6 +269,20 @@ class FilterTest extends BaseTestCase
); );
} }
/**
* Test whether special characters inside values are URL-encoded, but the other ones aren't
*/
public function testSpecialCharacterEscaping()
{
$this->assertSame(
Filter::matchAll(
Filter::expression('host', '!=', 'localhost'),
Filter::matchAny(Filter::where('service', 'ping4'), Filter::where('specialchars', '(|&!=)'))
)->toQueryString(),
'host!=localhost&(service=ping4|specialchars=%28%7C%26%21%3D%29)'
);
}
private function row($idx) private function row($idx)
{ {
return $this->sampleData[$idx]; return $this->sampleData[$idx];