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) || (tmp < 0.0) || (tmp > 100.0))
+ {
+ fprintf (stderr, "Ignoring invalid -Z argument: %s\n", optarg);
+ fprintf (stderr, "The \"-Z\" option requires a numeric argument between 0 and 100.\n");
+ }
+ else
+ opt_exit_status_threshold = tmp / 100.0;
+
+ break;
+ }
+
case 'h':
usage_exit (argv[0], 0);
break;
average = context_get_average (ctx);
deviation = context_get_stddev (ctx);
-
+
mvwprintw (ctx->window, /* y = */ 2, /* x = */ 2,
"rtt min/avg/max/sdev = %.3f/%.3f/%.3f/%.3f ms",
ctx->latency_min,
#endif
} /* }}} void update_host_hook */
-/* returns the number of significant failures: sum over hosts of
- unreturned packets exceeding 50% of the number sent, rounding up. */
+/* Prints statistics for each host, cleans up the contexts and returns the
+ * number of hosts which failed to return more than the fraction
+ * opt_exit_status_threshold of pings. */
static int post_loop_hook (pingobj_t *ping) /* {{{ */
{
pingobj_iter_t *iter;
- /* failures to report: sum over hosts of number of failed
- returns above 50% */
int failure_count = 0;
#if USE_NCURSES
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)
opt_count--;
} /* while (opt_count != 0) */
+ /* Returns the number of failed hosts according to -Z. */
status = post_loop_hook (ping);
ping_destroy (ping);
- if (status)
- return (EXIT_FAILURE + status);
+ if (status == 0)
+ exit (EXIT_SUCCESS);
else
- return (EXIT_SUCCESS);
+ {
+ if (status > 255)
+ status = 255;
+ exit (status);
+ }
} /* }}} int main */
/* vim: set fdm=marker : */