aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGravatar Holger Weiss <holger@zedat.fu-berlin.de> 2012-06-11 23:40:04 +0200
committerGravatar Holger Weiss <holger@zedat.fu-berlin.de> 2012-06-11 23:40:04 +0200
commita80eafbf9cab9d80c526c504edf2ee4446a072d9 (patch)
tree505a6caeb312d63e8b2d9f1814c9b2e807258d51 /plugins
parent4e9eedc8debe1388996bd5631f2df6e057854061 (diff)
downloadmonitoring-plugins-a80eafbf9cab9d80c526c504edf2ee4446a072d9.tar.gz
Improve parsing of ping6(1) output
The ping6(1) implementation provided by Debian's iputils-ping package may produce output such as the following: | 3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2009ms There's a corresponding pattern in check_ping.c:458: | "%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss" Without this fix, the pattern in check_ping.c:456 matched first (as sscanf(3) interprets "+3" as a match for "%d"): | "%*d packets transmitted, %*d received, %d%% loss, time" (#1894850 - Debian bug report #514588 - Matej Vela)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_ping.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index ecdd6183..1367e903 100644
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
@@ -432,6 +432,7 @@ run_ping (const char *cmd, const char *addr)
{
char buf[MAX_INPUT_BUFFER];
int result = STATE_UNKNOWN;
+ int match;
if ((child_process = spopen (cmd)) == NULL)
die (STATE_UNKNOWN, _("Could not open pipe: %s\n"), cmd);
@@ -448,28 +449,29 @@ run_ping (const char *cmd, const char *addr)
result = max_state (result, error_scan (buf, addr));
/* get the percent loss statistics */
- if(sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss",&pl)==1 ||
- sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d duplicates, %d%% packet loss", &pl) == 1 ||
- sscanf(buf,"%*d packets transmitted, %*d received, +%*d duplicates, %d%% packet loss", &pl) == 1 ||
- sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% packet loss",&pl)==1 ||
- sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% loss, time",&pl)==1 ||
- sscanf(buf,"%*d packets transmitted, %*d received, %d%% loss, time", &pl)==1 ||
- sscanf(buf,"%*d packets transmitted, %*d received, %d%% packet loss, time", &pl)==1 ||
- sscanf(buf,"%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss", &pl) == 1 ||
- sscanf(buf,"%*d packets transmitted %*d received, +%*d errors, %d%% packet loss", &pl) == 1
+ match = 0;
+ if((sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss%n",&pl,&match) && match) ||
+ (sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d duplicates, %d%% packet loss%n",&pl,&match) && match) ||
+ (sscanf(buf,"%*d packets transmitted, %*d received, +%*d duplicates, %d%% packet loss%n",&pl,&match) && match) ||
+ (sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% packet loss%n",&pl,&match) && match) ||
+ (sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% loss, time%n",&pl,&match) && match) ||
+ (sscanf(buf,"%*d packets transmitted, %*d received, %d%% loss, time%n",&pl,&match) && match) ||
+ (sscanf(buf,"%*d packets transmitted, %*d received, %d%% packet loss, time%n",&pl,&match) && match) ||
+ (sscanf(buf,"%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss%n",&pl,&match) && match) ||
+ (sscanf(buf,"%*d packets transmitted %*d received, +%*d errors, %d%% packet loss%n",&pl,&match) && match)
)
continue;
/* get the round trip average */
else
- if(sscanf(buf,"round-trip min/avg/max = %*f/%f/%*f",&rta)==1 ||
- sscanf(buf,"round-trip min/avg/max/mdev = %*f/%f/%*f/%*f",&rta)==1 ||
- sscanf(buf,"round-trip min/avg/max/sdev = %*f/%f/%*f/%*f",&rta)==1 ||
- sscanf(buf,"round-trip min/avg/max/stddev = %*f/%f/%*f/%*f",&rta)==1 ||
- sscanf(buf,"round-trip min/avg/max/std-dev = %*f/%f/%*f/%*f",&rta)==1 ||
- sscanf(buf,"round-trip (ms) min/avg/max = %*f/%f/%*f",&rta)==1 ||
- sscanf(buf,"round-trip (ms) min/avg/max/stddev = %*f/%f/%*f/%*f",&rta)==1 ||
- sscanf(buf,"rtt min/avg/max/mdev = %*f/%f/%*f/%*f ms",&rta)==1)
+ if((sscanf(buf,"round-trip min/avg/max = %*f/%f/%*f%n",&rta,&match) && match) ||
+ (sscanf(buf,"round-trip min/avg/max/mdev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
+ (sscanf(buf,"round-trip min/avg/max/sdev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
+ (sscanf(buf,"round-trip min/avg/max/stddev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
+ (sscanf(buf,"round-trip min/avg/max/std-dev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
+ (sscanf(buf,"round-trip (ms) min/avg/max = %*f/%f/%*f%n",&rta,&match) && match) ||
+ (sscanf(buf,"round-trip (ms) min/avg/max/stddev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
+ (sscanf(buf,"rtt min/avg/max/mdev = %*f/%f/%*f/%*f ms%n",&rta,&match) && match))
continue;
}