Skip to content

Commit

Permalink
Last change timestamp-format
Browse files Browse the repository at this point in the history
  • Loading branch information
gsnw-sebast committed Jun 10, 2024
1 parent b440ad6 commit 665b93f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ci/test-05-options-c-e.pl
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@
});
}

# fping -D --timestamp-format=reltime
# fping -D --timestamp-format=rfc3339
{
my $cmd = Test::Command->new(cmd => "fping -D --timestamp-format=reltime -c 2 -p 100 127.0.0.1");
my $cmd = Test::Command->new(cmd => "fping -D --timestamp-format=rfc3339 -c 2 -p 100 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{\[[\d+-]+\s[\d+:]+\] 127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
\[[\d+-]+\s[\d+:]+\] 127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
Expand Down
10 changes: 10 additions & 0 deletions doc/fping.pod
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ hostnames as target (NAME->IP->NAME).
Add Unix timestamps in front of output lines generated with in looping or counting
modes (B<-l>, B<-c>, or B<-C>).

Subcommand: B<--timestamp-format>=I<ctime|iso|rfc3339>

Changes the timestamp format of the B<-D> option to the following format types.

I<ctime> = "%c" (Example: Mon Jun 10 07:50:00 2024)

I<iso> = "%Y-%m-%dT%T%z" (Example: 2024-06-10T07:50:00+0200)

I<rfc3339> = "%Y-%m-%d %H:%M:%S" (Example: 2024-06-10 07:50:00)

=item B<-e>, B<--elapsed>

Show elapsed (round-trip) time of packets.
Expand Down
7 changes: 5 additions & 2 deletions src/fping.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ int main(int argc, char **argv)
timestamp_format_flag = 1;
}else if(strcmp(optparse_state.optarg, "iso") == 0) {
timestamp_format_flag = 2;
}else if(strcmp(optparse_state.optarg, "reltime") == 0) {
}else if(strcmp(optparse_state.optarg, "rfc3339") == 0) {
timestamp_format_flag = 3;
}else{
usage(1);
Expand Down Expand Up @@ -2970,14 +2970,17 @@ void print_timestamp_format(int64_t current_time_ns, int timestamp_format)
local_time = localtime(&current_time_s);
switch(timestamp_format) {
case 1:
// Timeformat ctime
strftime(time_buffer, sizeof(time_buffer), "%c", local_time);
printf("[%s] ", time_buffer);
break;
case 2:
// Timeformat iso
strftime(time_buffer, sizeof(time_buffer), "%Y-%m-%dT%T%z", local_time);
printf("[%s] ", time_buffer);
break;
case 3:
// Timeformat rfc3339
strftime(time_buffer, sizeof(time_buffer), "%Y-%m-%d %H:%M:%S", local_time);
printf("[%s] ", time_buffer);
break;
Expand Down Expand Up @@ -3039,7 +3042,7 @@ void usage(int is_error)
fprintf(out, " -C, --vcount=N same as -c, report results (not stats) in verbose format\n");
fprintf(out, " -d, --rdns show targets by name (force reverse-DNS lookup)\n");
fprintf(out, " -D, --timestamp print timestamp before each output line\n");
fprintf(out, " --timestamp-format=FORMAT show timestamp in the given format (-D required): ctime|iso|reltime\n");
fprintf(out, " --timestamp-format=FORMAT show timestamp in the given format (-D required): ctime|iso|rfc3339\n");
fprintf(out, " -e, --elapsed show elapsed time on return packets\n");
fprintf(out, " -n, --name show targets by name (reverse-DNS lookup for target IPs)\n");
fprintf(out, " -N, --netdata output compatible for netdata (-l -Q are required)\n");
Expand Down

0 comments on commit 665b93f

Please sign in to comment.