From 2def6c1361d9caeb8b808875f0594b3bdb0c722b Mon Sep 17 00:00:00 2001 From: German Service Network Date: Sat, 26 Apr 2025 11:45:02 +0200 Subject: [PATCH] Format change for handle JSON output for invalid hosts --- ci/test-16-json-output.pl | 4 ++-- src/fping.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ci/test-16-json-output.pl b/ci/test-16-json-output.pl index b6d1c20..1622920 100644 --- a/ci/test-16-json-output.pl +++ b/ci/test-16-json-output.pl @@ -108,8 +108,8 @@ $cmd->stderr_is_eq(""); { my $cmd = Test::Command->new(cmd => "fping -J -c 1 -q host.invalid"); $cmd->exit_is_num(2); # Exit code 2 indicates name resolution error -$cmd->stdout_is_eq(""); -$cmd->stderr_like(qr/^\{"host":\s"host\.invalid", "error":\s"(?:Name or service not known|Temporary failure in name resolution|nodename nor servname provided, or not known)"\}$/); +$cmd->stdout_like(qr/^\{"warning":\s\{"host":\s"host\.invalid",\s"message":\s"(?:Name or service not known|Temporary failure in name resolution|nodename nor servname provided, or not known)"\}\}$/); +$cmd->stderr_is_eq(""); } # fping -J -c 1 -q -g 127.0.0.1/30 diff --git a/src/fping.c b/src/fping.c index 97b3341..6f6b3f8 100644 --- a/src/fping.c +++ b/src/fping.c @@ -3261,7 +3261,7 @@ void add_name(char *name) // Handle JSON output for invalid hosts if (json_flag) { - fprintf(stderr, "{\"host\": \"%s\", \"error\": \"%s\"}", name, gai_strerror(ret_ga)); + fprintf(stdout, "{\"warning\": {\"host\": \"%s\", \"message\": \"%s\"}}", name, gai_strerror(ret_ga)); return; } -- 2.43.0