summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-03-12 16:16:53 +0100
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-03-12 17:27:11 +0100
commita609c0214fb4fbeb86ab75e7dff4f4c7deedcc3b (patch)
tree921ee5b30ee91bb14790d1dc0298f4601e1b57f9
parentae60d6d8d818191afba08819c5a62673b98ef29a (diff)
downloadmonitoring-plugins-a609c0214fb4fbeb86ab75e7dff4f4c7deedcc3b.tar.gz
remove nagios reference
Narrow down sscanf expression
-rw-r--r--plugins/check_ping.c49
1 files changed, 25 insertions, 24 deletions
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index fcf68f81..8d8ae7df 100644
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
@@ -162,8 +162,8 @@ int main(int argc, char **argv) {
162 162
163 /* Print performance data */ 163 /* Print performance data */
164 if (pinged.packet_loss != 100) { 164 if (pinged.packet_loss != 100) {
165 printf("|%s", fperfdata("rta", pinged.round_trip_average, "ms", (bool)(config.wrta > 0), config.wrta, 165 printf("|%s", fperfdata("rta", pinged.round_trip_average, "ms", (bool)(config.wrta > 0), config.wrta, (bool)(config.crta > 0),
166 (bool)(config.crta > 0), config.crta, true, 0, false, 0)); 166 config.crta, true, 0, false, 0));
167 } else { 167 } else {
168 printf("| rta=U;%f;%f;;", config.wrta, config.crta); 168 printf("| rta=U;%f;%f;;", config.wrta, config.crta);
169 } 169 }
@@ -470,33 +470,36 @@ ping_result run_ping(const char *cmd, const char *addr, double crta) {
470 470
471 /* get the percent loss statistics */ 471 /* get the percent loss statistics */
472 int match = 0; 472 int match = 0;
473 if ((sscanf(buf, "%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss%n", &result.packet_loss, &match) && 473 if ((sscanf(buf, "%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss%n", &result.packet_loss, &match) ==
474 1 &&
474 match) || 475 match) ||
475 (sscanf(buf, "%*d packets transmitted, %*d packets received, +%*d duplicates, %d%% packet loss%n", &result.packet_loss, 476 (sscanf(buf, "%*d packets transmitted, %*d packets received, +%*d duplicates, %d%% packet loss%n", &result.packet_loss,
476 &match) && 477 &match) == 1 &&
477 match) || 478 match) ||
478 (sscanf(buf, "%*d packets transmitted, %*d received, +%*d duplicates, %d%% packet loss%n", &result.packet_loss, &match) && 479 (sscanf(buf, "%*d packets transmitted, %*d received, +%*d duplicates, %d%% packet loss%n", &result.packet_loss, &match) == 1 &&
479 match) || 480 match) ||
480 (sscanf(buf, "%*d packets transmitted, %*d packets received, %d%% packet loss%n", &result.packet_loss, &match) && match) || 481 (sscanf(buf, "%*d packets transmitted, %*d packets received, %d%% packet loss%n", &result.packet_loss, &match) == 1 && match) ||
481 (sscanf(buf, "%*d packets transmitted, %*d packets received, %d%% loss, time%n", &result.packet_loss, &match) && match) || 482 (sscanf(buf, "%*d packets transmitted, %*d packets received, %d%% loss, time%n", &result.packet_loss, &match) == 1 && match) ||
482 (sscanf(buf, "%*d packets transmitted, %*d received, %d%% loss, time%n", &result.packet_loss, &match) && match) || 483 (sscanf(buf, "%*d packets transmitted, %*d received, %d%% loss, time%n", &result.packet_loss, &match) == 1 && match) ||
483 (sscanf(buf, "%*d packets transmitted, %*d received, %d%% packet loss, time%n", &result.packet_loss, &match) && match) || 484 (sscanf(buf, "%*d packets transmitted, %*d received, %d%% packet loss, time%n", &result.packet_loss, &match) && match) == 1 ||
484 (sscanf(buf, "%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss%n", &result.packet_loss, &match) && match) || 485 (sscanf(buf, "%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss%n", &result.packet_loss, &match) == 1 &&
485 (sscanf(buf, "%*d packets transmitted %*d received, +%*d errors, %d%% packet loss%n", &result.packet_loss, &match) && match) || 486 match) ||
486 (sscanf(buf, "%*[^(](%d%% %*[^)])%n", &result.packet_loss, &match) && match)) { 487 (sscanf(buf, "%*d packets transmitted %*d received, +%*d errors, %d%% packet loss%n", &result.packet_loss, &match) == 1 &&
488 match) ||
489 (sscanf(buf, "%*[^(](%d%% %*[^)])%n", &result.packet_loss, &match) == 1 && match)) {
487 continue; 490 continue;
488 } 491 }
489 492
490 /* get the round trip average */ 493 /* get the round trip average */
491 if ((sscanf(buf, "round-trip min/avg/max = %*f/%lf/%*f%n", &result.round_trip_average, &match) && match) || 494 if ((sscanf(buf, "round-trip min/avg/max = %*f/%lf/%*f%n", &result.round_trip_average, &match) == 1 && match) ||
492 (sscanf(buf, "round-trip min/avg/max/mdev = %*f/%lf/%*f/%*f%n", &result.round_trip_average, &match) && match) || 495 (sscanf(buf, "round-trip min/avg/max/mdev = %*f/%lf/%*f/%*f%n", &result.round_trip_average, &match) == 1 && match) ||
493 (sscanf(buf, "round-trip min/avg/max/sdev = %*f/%lf/%*f/%*f%n", &result.round_trip_average, &match) && match) || 496 (sscanf(buf, "round-trip min/avg/max/sdev = %*f/%lf/%*f/%*f%n", &result.round_trip_average, &match) == 1 && match) ||
494 (sscanf(buf, "round-trip min/avg/max/stddev = %*f/%lf/%*f/%*f%n", &result.round_trip_average, &match) && match) || 497 (sscanf(buf, "round-trip min/avg/max/stddev = %*f/%lf/%*f/%*f%n", &result.round_trip_average, &match) == 1 && match) ||
495 (sscanf(buf, "round-trip min/avg/max/std-dev = %*f/%lf/%*f/%*f%n", &result.round_trip_average, &match) && match) || 498 (sscanf(buf, "round-trip min/avg/max/std-dev = %*f/%lf/%*f/%*f%n", &result.round_trip_average, &match) == 1 && match) ||
496 (sscanf(buf, "round-trip (ms) min/avg/max = %*f/%lf/%*f%n", &result.round_trip_average, &match) && match) || 499 (sscanf(buf, "round-trip (ms) min/avg/max = %*f/%lf/%*f%n", &result.round_trip_average, &match) == 1 && match) ||
497 (sscanf(buf, "round-trip (ms) min/avg/max/stddev = %*f/%lf/%*f/%*f%n", &result.round_trip_average, &match) && match) || 500 (sscanf(buf, "round-trip (ms) min/avg/max/stddev = %*f/%lf/%*f/%*f%n", &result.round_trip_average, &match) == 1 && match) ||
498 (sscanf(buf, "rtt min/avg/max/mdev = %*f/%lf/%*f/%*f ms%n", &result.round_trip_average, &match) && match) || 501 (sscanf(buf, "rtt min/avg/max/mdev = %*f/%lf/%*f/%*f ms%n", &result.round_trip_average, &match) == 1 && match) ||
499 (sscanf(buf, "%*[^=] = %*fms, %*[^=] = %*fms, %*[^=] = %lfms%n", &result.round_trip_average, &match) && match)) { 502 (sscanf(buf, "%*[^=] = %*fms, %*[^=] = %*fms, %*[^=] = %lfms%n", &result.round_trip_average, &match) == 1 && match)) {
500 continue; 503 continue;
501 } 504 }
502 } 505 }
@@ -610,9 +613,7 @@ void print_help(void) {
610 613
611 printf("\n"); 614 printf("\n");
612 printf("%s\n", _("This plugin uses the ping command to probe the specified host for packet loss")); 615 printf("%s\n", _("This plugin uses the ping command to probe the specified host for packet loss"));
613 printf("%s\n", _("(percentage) and round trip average (milliseconds). It can produce HTML output")); 616 printf("%s\n", _("(percentage) and round trip average (milliseconds). It can produce HTML output."));
614 printf("%s\n", _("linking to a traceroute CGI contributed by Ian Cass. The CGI can be found in"));
615 printf("%s\n", _("the contrib area of the downloads section at http://www.nagios.org/"));
616 617
617 printf(UT_SUPPORT); 618 printf(UT_SUPPORT);
618} 619}