summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6cf6907)
raw | patch | inline | side by side (parent: 6cf6907)
author | Florian Forster <ff@octo.it> | |
Mon, 5 Sep 2011 02:51:14 +0000 (22:51 -0400) | ||
committer | Barak A. Pearlmutter <barak+git@cs.nuim.ie> | |
Mon, 5 Sep 2011 08:01:09 +0000 (09:01 +0100) |
This makes it possible to configure the threshold for exiting with a non-zero
exit status due to missing replies.
exit status due to missing replies.
src/mans/oping.pod | patch | blob | history | |
src/oping.c | patch | blob | history |
diff --git a/src/mans/oping.pod b/src/mans/oping.pod
index 56712fd5311d251138cddf47a81fe22692fc6d44..f0af718dc92bd47adc672bd1a5e38d411ae22b7f 100644 (file)
--- a/src/mans/oping.pod
+++ b/src/mans/oping.pod
I<Type of Service> (ToS) aliases were used to specify the bits of outgoing
packets.
+=item B<-Z> I<percent>
+
+If any hosts have a drop rate higher than I<percent>, where I<percent> is a
+number between zero and 100 inclusively, exit with a non-zero exit status.
+Since it is not possible to have a higher drop rate than 100%, passing this
+limit will effectively disable the feature (the default). Setting the option to
+zero means that the exit status will only be zero if I<all> replies for I<all>
+hosts have been received.
+
=back
=head1 COLORS
diff --git a/src/oping.c b/src/oping.c
index 5b75dae02efe461849361c8716d9e493b5c6690e..09167882b46837cd361f6ec71d6b55c567936e3f 100644 (file)
--- a/src/oping.c
+++ b/src/oping.c
static int opt_count = -1;
static int opt_send_ttl = 64;
static uint8_t opt_send_qos = 0;
+static double opt_exit_status_threshold = 1.0;
static int host_num = 0;
" -I srcaddr source address\n"
" -D device outgoing interface name\n"
" -f filename filename to read hosts from\n"
+ " -Z percent Exit with non-zero exit status if more than this percentage of\n"
+ " probes timed out. (default: never)\n"
"\noping "PACKAGE_VERSION", http://verplant.org/liboping/\n"
"by Florian octo Forster <octo@verplant.org>\n"
while (1)
{
- optchar = getopt (argc, argv, "46c:hi:I:t:Q:f:D:");
+ optchar = getopt (argc, argv, "46c:hi:I:t:Q:f:D:Z:");
if (optchar == -1)
break;
set_opt_send_qos (optarg);
break;
+ case 'Z':
+ {
+ char *endptr = NULL;
+ double tmp;
+
+ errno = 0;
+ tmp = strtod (optarg, &endptr);
+ if ((errno != 0) || (endptr == NULL) || (*endptr != 0))
+ fprintf (stderr, "The \"-Z\" option requires a numeric argument.\n");
+ else if ((tmp >= 0.0) && (tmp <= 100.0))
+ opt_exit_status_threshold = tmp / 100.0;
+ else
+ fprintf (stderr, "The argument of the \"-Z\" option must be between 0 and 100.\n");
+
+ break;
+ }
+
case 'h':
usage_exit (argv[0], 0);
break;
context->latency_total);
{
- /* threshold for counting failed returns is 50%, rounding up */
- int threshold = (context->req_sent + 1) / 2;
- if (context->req_rcvd < threshold)
- failure_count += threshold - context->req_rcvd;
+ double pct_failed = 1.0 - (((double) context->req_rcvd)
+ / ((double) context->req_sent));
+ if (pct_failed > opt_exit_status_threshold)
+ failure_count++;
}
if (context->req_rcvd != 0)