Skip to content

Commit 9e67cb3

Browse files
committed
fix downtime duration in rest commands (fixes #1340)
the plus sign has been url decoded as space, the remaining 1m has then been parsed as one month instead of one minute.
1 parent b4aec41 commit 9e67cb3

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/Thruk/Utils/CLI/Rest.pm

+1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ sub _set_postdata {
256256

257257
my($key,$val) = split(/=/mx, $data, 2);
258258
if($src && $src eq 'local' && defined $val) {
259+
$val =~ s/^\+/%2B/gmx;
259260
$val =~ s/\+/ /gmx;
260261
$val = Thruk::Request->unescape($val);
261262
}

t/scenarios/rest_api/t/local/rest_commands.t

+19-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ BEGIN {
88
import TestUtils;
99
}
1010

11-
plan tests => 26;
11+
plan tests => 33;
1212

1313
###########################################################
1414
# test thruks script path
@@ -41,4 +41,21 @@ TestUtils::test_command({
4141
TestUtils::test_command({
4242
cmd => '/usr/bin/env sed -i etc/thruk/thruk_local.d/lmd.conf -e s/^.*use_lmd_core=.*/#use_lmd_core=1/g',
4343
like => ['/^$/'],
44-
});
44+
});
45+
46+
###########################################################
47+
# rest downtime duration
48+
{
49+
my $test = {
50+
cmd => '/usr/bin/env thruk r -d "comment_data=test" -d "end_time=+1m" /hosts/localhost/cmd/schedule_host_downtime',
51+
like => ['/COMMAND/', '/Command successfully submitted/', '/SCHEDULE_HOST_DOWNTIME/'],
52+
};
53+
TestUtils::test_command($test);
54+
my($t1, $t2) = ($test->{'stdout'} =~ m/SCHEDULE_HOST_DOWNTIME;localhost;(\d+);(\d+);/gmx);
55+
if(!$t1) {
56+
fail("cannot parse timestamps from stdout: ".$test->{'stdout'});
57+
} else {
58+
my $duration = $t2 - $t1;
59+
ok($duration == 60, "downtime duration should be 60s but is ".$duration."s");
60+
}
61+
}

0 commit comments

Comments
 (0)