From c810f2bfd114a6bc5546bbcd7ee8187617b65df5 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 13 Feb 2017 12:24:58 +0100 Subject: [PATCH 1/2] Servicegrid: assemble filters with the Filter class refs #2523 --- .../views/scripts/list/servicegrid.phtml | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/modules/monitoring/application/views/scripts/list/servicegrid.phtml b/modules/monitoring/application/views/scripts/list/servicegrid.phtml index 845cac745..0e50855b5 100644 --- a/modules/monitoring/application/views/scripts/list/servicegrid.phtml +++ b/modules/monitoring/application/views/scripts/list/servicegrid.phtml @@ -1,4 +1,5 @@ compact): ?>

translate('No services found matching the filter.') ?>

$_) { + $hostFilter->orFilter(Filter::where('host_name', $hostName)); +} ?> @@ -30,8 +34,10 @@ $hostFilter = '(host_name=' . implode('|host_name=', array_keys($pivotData)) . ' $serviceDisplayName): ?> From 24c8a924e6fd10aeb1b2f957bf64b1623db75f41 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 13 Feb 2017 13:09:12 +0100 Subject: [PATCH 2/2] Add FilterTest::testSpecialCharacterEscaping() refs #2523 --- test/php/library/Icinga/Data/Filter/FilterTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/php/library/Icinga/Data/Filter/FilterTest.php b/test/php/library/Icinga/Data/Filter/FilterTest.php index 3753debb1..2e8a2cff3 100644 --- a/test/php/library/Icinga/Data/Filter/FilterTest.php +++ b/test/php/library/Icinga/Data/Filter/FilterTest.php @@ -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];
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)) . ' $hostDisplayName): ?>
$_) { + $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)) ); ?>