From: German Service Network Date: Wed, 30 Apr 2025 16:39:15 +0000 (+0200) Subject: Fix JSON output print_per_system_stats_json dash to null X-Git-Url: https://git.gsnw.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3bc0e40404251a4c5b8bc0e84182b33399c4bc4;p=fping.git Fix JSON output print_per_system_stats_json dash to null --- diff --git a/ci/test-16-json-output.pl b/ci/test-16-json-output.pl index f1cd5ba..1fd2191 100644 --- a/ci/test-16-json-output.pl +++ b/ci/test-16-json-output.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::Command tests => 48; +use Test::Command tests => 54; use Test::More; # fping -J -c 2 127.0.0.1 @@ -79,6 +79,24 @@ $cmd->stdout_like(qr/^\{"summary":\s\{"host":\s"127\.0\.0\.1",\s"xmt":\s\d+,\s"r $cmd->stderr_is_eq(""); } +# fping -J -C 1 127.0.0.1 +{ +my $cmd = Test::Command->new(cmd => "fping -J -C 1 127.0.0.1"); +$cmd->exit_is_num(0); +$cmd->stdout_like(qr/^\{"resp":\s\{"host":\s"127\.0\.0\.1",\s"seq":\s\d+,\s"size":\s\d+,\s"rtt":\s\d+.\d+,\s"rttAvg":\s\d+.\d+,\s"loss":\s\d+\}\} +\{"vSum":\s\{"host":\s"127\.0\.0\.1",\s"values":\s\[\d+.\d+\]\}\}?$/); +$cmd->stderr_is_eq(""); +} + +# fping -J -C 1 192.0.2.47 +{ +my $cmd = Test::Command->new(cmd => "fping -J -C 1 192.0.2.47"); +$cmd->exit_is_num(1); +$cmd->stdout_like(qr/^\{"timeout":\s\{"host":\s"192\.0\.2\.47",\s"seq":\s\d+,\s"rttAvg":\s"NaN",\s"loss":\s\d+\}\} +\{"vSum":\s\{"host":\s"192\.0\.2\.47",\s"values":\s\[null\]\}\}?$/); +$cmd->stderr_is_eq(""); +} + # fping -J -C 1 -q 127.0.0.1 { my $cmd = Test::Command->new(cmd => "fping -J -C 1 -q 127.0.0.1"); diff --git a/src/fping.c b/src/fping.c index c632fb0..4595fa8 100644 --- a/src/fping.c +++ b/src/fping.c @@ -2123,7 +2123,7 @@ void print_per_system_stats_json(void) if ((resp = h->resp_times[j]) >= 0) fprintf(stdout, "%s", sprint_tm(resp)); else - fprintf(stdout, "-"); + fprintf(stdout, "null"); } fprintf(stdout, "]}");