[Nagiosplug-devel] check_ping timeout calculation

Thomas Guyot-Sionnest dermoth at aei.ca
Thu Jan 4 23:46:50 CET 2007


While testing the previous patch for check_ping I noticed the the
max_seconds calculation was way off what it could calculate as max_seconds.

The part shown in the patch below is to increase the timeout_interval
used in alarm() if the other ping parameters does not make sense with
the supplied or default timeout value set.

In the patch below I calculate max_seconds my simply multiplying the
critical time by the number of packets. If max_seconds is not an integer
I round it up to the higher value. In the previous patch I comited I
also add one second to the alarm so that it does not trigger it when
ping take the expected time for a non-responding host (when max_seconds
== timeout_interval).

Alternatively I could undo the last patch and add one second in the part
below if max_seconds == (int)max_seconds, but I fear that it trigger the
alarm in some cases, like if max_seconds == 1.9999.. which is very close
to the 2 seconds that would be set in the alarm.

Any comments before I submit this patch?

Thomas

diff -u -r1.54 check_ping.c
--- plugins/check_ping.c        4 Jan 2007 11:35:56 -0000       1.54
+++ plugins/check_ping.c        4 Jan 2007 22:32:24 -0000
@@ -399,7 +399,11 @@
        if (max_packets == -1)
                max_packets = DEFAULT_MAX_PACKETS;

-       max_seconds = crta / 1000.0 * max_packets + max_packets;
+       max_seconds = crta * max_packets;
+       /* Round up max_seconds because we use only the int part */
+       if (max_seconds != (int)max_seconds)
+               max_seconds = (int)max_seconds + 1;
+
        if (max_seconds > timeout_interval)
                timeout_interval = (int)max_seconds;





More information about the Devel mailing list