diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2020-02-19 10:49:11 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2020-02-19 10:49:11 +0200 |
commit | 998bea5d31b60f39c54f716063b44a5713fbc1c0 (patch) | |
tree | 12d8a50f05fbe2a0631dab0e9eedbb4828b54103 /src/ping903q.c | |
parent | f6be3cd55490eab72be3e497877b5de5758d9911 (diff) | |
download | ping903-998bea5d31b60f39c54f716063b44a5713fbc1c0.tar.gz ping903-998bea5d31b60f39c54f716063b44a5713fbc1c0.tar.bz2 |
Fix handling of missing replies.
* src/ping903.h (hostaddr): New member recv_tv.
* src/ping903q.c (print_host_status): gracefully handle absense of
the "stddev" attribute.
Include IP address (or host name) to the nagios check output.
* src/pinger.c: Get rid of the send queue. Send echo requests in
batches each ping_interval. Correctly handle missing replies.
Diffstat (limited to 'src/ping903q.c')
-rw-r--r-- | src/ping903q.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/ping903q.c b/src/ping903q.c index 53358b4..9e7a350 100644 --- a/src/ping903q.c +++ b/src/ping903q.c @@ -436,17 +436,18 @@ print_host_status(struct json_value *obj, void *unused) json_number)->v.n; double stop_ts = ejson_get(obj, "stop-timestamp", json_number)->v.n; - + printf("--- %s ping statistics ---\n", name); printf("%lu packets transmitted, %lu received, %d%% packet loss, time %.0fms\n", (unsigned long) xmit, (unsigned long) recv, - (int)(100 * (xmit - recv) / recv), + (int)(100 * (xmit - recv) / xmit), (stop_ts - start_ts) * 1000); - printf("rtt min/avg/max/mdev = %.3f/%.3f/%.3f/%.3f ms\n", - ejson_get(obj, "tmin", json_number)->v.n, - ejson_get(obj, "avg", json_number)->v.n, - ejson_get(obj, "tmax", json_number)->v.n, - ejson_get(obj, "stddev", json_number)->v.n); + if (!json_object_get(obj, "stddev", &jv)) + printf("rtt min/avg/max/mdev = %.3f/%.3f/%.3f/%.3f ms\n", + ejson_get(obj, "tmin", json_number)->v.n, + ejson_get(obj, "avg", json_number)->v.n, + ejson_get(obj, "tmax", json_number)->v.n, + ejson_get(obj, "stddev", json_number)->v.n); } return alive ? EX_NAGIOS_OK : EX_NAGIOS_CRITICAL; } @@ -536,6 +537,9 @@ match_host(char const *name) size_t i, len; n = snprintf(url, sizeof(url), "/match/%s", name); + if (n == -1 || n == sizeof(url)) { + abend("url buffer overflow"); + } http_query("GET", url, std_headers); http_resp_init(&resp); http_recv(&resp); @@ -677,11 +681,11 @@ nagios_check(struct json_value *obj, void *data) jv = ejson_get(obj, "status", json_string); if (strcmp(jv->v.s, "init") == 0) { - printf("PING UNKNOWN - waiting for data to arrive\n"); + printf("PING %s UNKNOWN - waiting for data to arrive\n", name); exit(EX_NAGIOS_UNKNOWN); } if (strcmp(jv->v.s, "invalid") == 0) { - printf("PING CRITICAL - Packet loss = 100%%"); + printf("PING %s CRITICAL - Packet loss = 100%%", name); print_perfdata(cd->cth.round_trip, 100.0, cd); exit(EX_NAGIOS_CRITICAL); } @@ -698,8 +702,8 @@ nagios_check(struct json_value *obj, void *data) status = newstatus(status, EX_NAGIOS_CRITICAL); if (loss >= cd->wth.loss_pct) status = newstatus(status, EX_NAGIOS_WARNING); - printf("PING %s Packet loss = %d%%, RTA = %.2f ms", - status_str[status], (int)loss, rta); + printf("PING %s %s Packet loss = %d%%, RTA = %.2f ms", + name, status_str[status], (int)loss, rta); print_perfdata(rta, loss, cd); exit(status); } |