From de4ce7255b4ddc04e8a4abcaea3b57cf0dfd64bc Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Tue, 2 Jul 2024 13:53:07 +0200 Subject: [PATCH] fix using custom variables starting with multiple underlines --- Changes | 1 + MANIFEST | 1 + lib/Thruk/Utils/Status.pm | 1 - .../t/local/020-custom_vars_filter.t | 36 +++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 t/scenarios/backend_naemon/t/local/020-custom_vars_filter.t diff --git a/Changes b/Changes index efbcdca9d..2436e4fdd 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ This file documents the revision history for the Monitoring Webinterface Thruk. next: - fix recurring downtimes crontab entry for 2nd/3rd days of month - fix sessions removed early when using kerberos authentication + - fix using custom variables starting with multiple underlines - Rest: - add transformation and disaggregation functions - add support for timeperiod / time queries in where clause diff --git a/MANIFEST b/MANIFEST index 14298b5b4..3c534df48 100644 --- a/MANIFEST +++ b/MANIFEST @@ -2309,6 +2309,7 @@ t/scenarios/backend_naemon/t/300-controller_extinfo.t t/scenarios/backend_naemon/t/300-controller_status.t t/scenarios/backend_naemon/t/300-controller_tac.t t/scenarios/backend_naemon/t/local/010-custom_vars_default_view.t +t/scenarios/backend_naemon/t/local/020-custom_vars_filter.t t/scenarios/backend_naemon/thruk.conf t/scenarios/backend_naemon/thruk_local.conf t/scenarios/backend_nagios4/docker-compose.yml diff --git a/lib/Thruk/Utils/Status.pm b/lib/Thruk/Utils/Status.pm index 2f8c0de11..5597cdcbb 100644 --- a/lib/Thruk/Utils/Status.pm +++ b/lib/Thruk/Utils/Status.pm @@ -1263,7 +1263,6 @@ sub single_search { } elsif ( $filter->{'type'} eq 'custom variable' ) { my $pre = uc($filter->{'val_pre'}); - if(substr($pre, 0, 1) eq '_') { $pre = substr($pre, 1); } push @hostfilter, { custom_variables => { $op => $pre." ".$value } }; push @hosttotalsfilter, { custom_variables => { $op => $pre." ".$value } }; my $cop = '-or'; diff --git a/t/scenarios/backend_naemon/t/local/020-custom_vars_filter.t b/t/scenarios/backend_naemon/t/local/020-custom_vars_filter.t new file mode 100644 index 000000000..4b9c7521a --- /dev/null +++ b/t/scenarios/backend_naemon/t/local/020-custom_vars_filter.t @@ -0,0 +1,36 @@ +use warnings; +use strict; +use Test::More; + +BEGIN { + use lib('t'); + require TestUtils; + import TestUtils; +} + +plan tests => 27; + +$ENV{'THRUK_TEST_AUTH'} = 'omdadmin:omd'; +$ENV{'PLACK_TEST_EXTERNALSERVER_URI'} = 'http://127.0.0.1/demo'; + +use_ok("Thruk::Utils::IO"); + +########################################################### +# verify that we use the correct thruk binary +TestUtils::test_command({ + cmd => '/bin/bash -c "type thruk"', + like => ['/\/thruk\/script\/thruk/'], +}) or BAIL_OUT("wrong thruk path"); + +########################################################### +TestUtils::test_page( + url => '/thruk/cgi-bin/status.cgi?style=hostdetail&dfl_s0_type=custom variable&dfl_s0_val_pre=TEST&dfl_s0_op=%3D&dfl_s0_value=test var hst', + like => ['host=test'], +); + +TestUtils::test_page( + url => '/thruk/cgi-bin/status.cgi?style=hostdetail&dfl_s0_type=custom variable&dfl_s0_val_pre=_IMPACT&dfl_s0_op=%3D&dfl_s0_value=dbl underscore hst', + like => ['host=test'], +); + +###########################################################