[Nagiosplug-devel] [PATCH] check_fping and network unreachable

Roel van Meer roel.vanmeer at bokxing.nl
Fri Mar 22 10:58:26 CET 2013


Hi list,

I ran into a problem where check_fping falsely reports nodes to be OK. This  
happened when no packets could be transmitted due to a prohibiting route.  
This patch fixes that by checking if the number of transmitted packets is  
greater than zero.

Best regards,

Roel


-------------- next part --------------
If a host cannot be contacted due to a prohibiting route, check_fping falsely
reports OK. This patch fixes that by only reporting OK if packet loss is 0 if
the number of transmitted packets is > 0. If the number of transmitted packets
is 0 report CRITICAL and set loss to 100%.


root at polar:~# ip route show | grep 10
prohibit 10.0.0.0/8


root at polar:~# ip route get 10.17.5.1
RTNETLINK answers: Network is unreachable


root at polar:~# ping 10.17.5.1
connect: Network is unreachable


root at polar:~# fping 10.17.5.1
10.17.5.1 error while sending ping: Network is unreachable

10.17.5.1 is unreachable


root at polar:~# fping -b 56 -c 3 10.17.5.1

10.17.5.1 : xmt/rcv/%loss = 0/0/0%


root at polar:~# check_fping 10.17.5.1
FPING OK - 10.17.5.1 (loss=0% )|loss=0%;;;0;100


root at polar:~# fping -v       
fping: Version 2.4b2_to $Date: 2013/03/22 09:57:13 $
fping: comments to noc at zerohype.com


diff -ruN nagios-plugins-1.4.15.a/plugins/check_fping.c nagios-plugins-1.4.15.b/plugins/check_fping.c
--- nagios-plugins-1.4.15.a/plugins/check_fping.c	2010-07-27 22:47:16.000000000 +0200
+++ nagios-plugins-1.4.15.b/plugins/check_fping.c	2013-03-22 10:34:03.469606400 +0100
@@ -146,7 +146,9 @@
 {
   char *rtastr = NULL;
   char *losstr = NULL;
+  char *xmtstr = NULL;
   double loss;
+  double xmt;
   double rta;
   int status = STATE_UNKNOWN;
 
@@ -198,14 +200,20 @@
     losstr = strstr (buf, "=");
     losstr = 1 + strstr (losstr, "/");
     losstr = 1 + strstr (losstr, "/");
+    xmtstr = strstr (buf, "=");
+    xmtstr = 1 + strstr (xmtstr, " ");
     loss = strtod (losstr, NULL);
+    xmt = strtod (xmtstr, NULL);
     if (atoi(losstr) == 100)
       status = STATE_CRITICAL;
     else if (cpl_p == TRUE && loss > cpl)
       status = STATE_CRITICAL;
     else if (wpl_p == TRUE && loss > wpl)
       status = STATE_WARNING;
-    else
+    else if (atoi(losstr) == 0 && atoi(xmtstr) == 0) {
+      status = STATE_CRITICAL;
+      loss = 100;
+    } else
       status = STATE_OK;
     /* loss=%.0f%%;%d;%d;0;100 */
     die (status, _("FPING %s - %s (loss=%.0f%% )|%s\n"),


More information about the Devel mailing list