Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Jan 15, 2025
1 parent b957b4a commit 15c63da
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/Thruk/Controller/Rest/V1/outages.pm
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ sub _rest_query_time_filter {
}
}

if($c->req->parameters->{'start'} && !$c->req->parameters->{'end'}) {
$c->req->parameters->{'end'} = time();
}

# combine remaining filter again
$c->req->parameters->{'q'} = Thruk::Utils::Status::filter2text($c, undef, $filter);

Expand Down Expand Up @@ -487,7 +491,11 @@ sub _rest_replace_logs_time_filter {

if($start) {
$c->req->parameters->{'start'} = $start;
$c->req->parameters->{'end'} = $end // time();
}
if($end) {
$c->req->parameters->{'end'} = $end;
}
if($start || $end) {
return 1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Thruk/Controller/rest_v1.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2632,7 +2632,7 @@ sub _match_complex_filter {
for my $op (%{$val}) {
my $localkey = $key;
if(!defined $data->{$localkey}) {
# translate some keys back
# translate some keys back (set from Utils::Status::parse_lexical_filter)
if($localkey eq 'host_name' && defined $data->{'host'}) {
$localkey = 'host';
} elsif($localkey eq 'description' && defined $data->{'service'}) {
Expand Down
5 changes: 4 additions & 1 deletion t/scenarios/rest_api/t/301-controller_rest_scenario.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use Test::More;
die("*** ERROR: this test is meant to be run with PLACK_TEST_EXTERNALSERVER_URI set,\nex.: THRUK_TEST_AUTH=omdadmin:omd PLACK_TEST_EXTERNALSERVER_URI=http://localhost:60080/demo perl t/scenarios/rest_api/t/301-controller_rest_scenario.t") unless defined $ENV{'PLACK_TEST_EXTERNALSERVER_URI'};

BEGIN {
plan tests => 370;
plan tests => 378;

use lib('t');
require TestUtils;
Expand Down Expand Up @@ -66,6 +66,9 @@ my $pages = [{
}, {
url => '/logs?q=***type = "EXTERNAL COMMAND" and time > '.(time() - 600).'***',
like => ['EXTERNAL COMMAND'],
}, {
url => '/services/outages?q=***host = "localhost" and service = "Ping" and timeperiod = "today"***',
like => ['\[\]'],
}, {
url => '/services/localhost/Ping/config',
method => 'PATCH',
Expand Down

0 comments on commit 15c63da

Please sign in to comment.