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