diff options
author | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-10-09 13:32:04 +0200 |
---|---|---|
committer | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-10-09 14:03:36 +0200 |
commit | eb6c83a6501151fcd4e01256e71415c25b25b7da (patch) | |
tree | b4d110d167e5cddf99d5f7b4e27a734cbefc2d4f | |
parent | 9da06d562515d6b443e4bbb54652a88f6a1cb4ca (diff) | |
download | monitoring-plugins-eb6c83a6501151fcd4e01256e71415c25b25b7da.tar.gz |
Even more code formatting and cleanup
-rw-r--r-- | plugins-root/check_icmp.c | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 1573dcae..915710bd 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c | |||
@@ -609,7 +609,6 @@ main(int argc, char **argv) | |||
609 | break; | 609 | break; |
610 | case 'R': /* RTA mode */ | 610 | case 'R': /* RTA mode */ |
611 | err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_rta_mode); | 611 | err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_rta_mode); |
612 | |||
613 | if (!err) { | 612 | if (!err) { |
614 | crash("Failed to parse RTA threshold"); | 613 | crash("Failed to parse RTA threshold"); |
615 | } | 614 | } |
@@ -618,7 +617,6 @@ main(int argc, char **argv) | |||
618 | break; | 617 | break; |
619 | case 'P': /* packet loss mode */ | 618 | case 'P': /* packet loss mode */ |
620 | err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_packet_loss_mode); | 619 | err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_packet_loss_mode); |
621 | |||
622 | if (!err) { | 620 | if (!err) { |
623 | crash("Failed to parse packet loss threshold"); | 621 | crash("Failed to parse packet loss threshold"); |
624 | } | 622 | } |
@@ -627,7 +625,6 @@ main(int argc, char **argv) | |||
627 | break; | 625 | break; |
628 | case 'J': /* jitter mode */ | 626 | case 'J': /* jitter mode */ |
629 | err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_jitter_mode); | 627 | err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_jitter_mode); |
630 | |||
631 | if (!err) { | 628 | if (!err) { |
632 | crash("Failed to parse jitter threshold"); | 629 | crash("Failed to parse jitter threshold"); |
633 | } | 630 | } |
@@ -636,7 +633,6 @@ main(int argc, char **argv) | |||
636 | break; | 633 | break; |
637 | case 'M': /* MOS mode */ | 634 | case 'M': /* MOS mode */ |
638 | err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_mos_mode); | 635 | err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_mos_mode); |
639 | |||
640 | if (!err) { | 636 | if (!err) { |
641 | crash("Failed to parse MOS threshold"); | 637 | crash("Failed to parse MOS threshold"); |
642 | } | 638 | } |
@@ -645,7 +641,6 @@ main(int argc, char **argv) | |||
645 | break; | 641 | break; |
646 | case 'S': /* score mode */ | 642 | case 'S': /* score mode */ |
647 | err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_score_mode); | 643 | err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_score_mode); |
648 | |||
649 | if (!err) { | 644 | if (!err) { |
650 | crash("Failed to parse score threshold"); | 645 | crash("Failed to parse score threshold"); |
651 | } | 646 | } |
@@ -675,10 +670,10 @@ main(int argc, char **argv) | |||
675 | add_target(*argv); | 670 | add_target(*argv); |
676 | argv++; | 671 | argv++; |
677 | } | 672 | } |
673 | |||
678 | if(!targets) { | 674 | if(!targets) { |
679 | errno = 0; | 675 | errno = 0; |
680 | crash("No hosts to check"); | 676 | crash("No hosts to check"); |
681 | exit(3); | ||
682 | } | 677 | } |
683 | 678 | ||
684 | // add_target might change address_family | 679 | // add_target might change address_family |
@@ -1023,21 +1018,24 @@ wait_for_reply(int sock, u_int t) | |||
1023 | /* Calculate jitter */ | 1018 | /* Calculate jitter */ |
1024 | if (host->last_tdiff > tdiff) { | 1019 | if (host->last_tdiff > tdiff) { |
1025 | jitter_tmp = host->last_tdiff - tdiff; | 1020 | jitter_tmp = host->last_tdiff - tdiff; |
1026 | } | 1021 | } else { |
1027 | else { | ||
1028 | jitter_tmp = tdiff - host->last_tdiff; | 1022 | jitter_tmp = tdiff - host->last_tdiff; |
1029 | } | 1023 | } |
1024 | |||
1030 | if (host->jitter==0) { | 1025 | if (host->jitter==0) { |
1031 | host->jitter=jitter_tmp; | 1026 | host->jitter=jitter_tmp; |
1032 | host->jitter_max=jitter_tmp; | 1027 | host->jitter_max=jitter_tmp; |
1033 | host->jitter_min=jitter_tmp; | 1028 | host->jitter_min=jitter_tmp; |
1034 | } | 1029 | } else { |
1035 | else { | ||
1036 | host->jitter+=jitter_tmp; | 1030 | host->jitter+=jitter_tmp; |
1037 | if (jitter_tmp < host->jitter_min) | 1031 | |
1032 | if (jitter_tmp < host->jitter_min) { | ||
1038 | host->jitter_min=jitter_tmp; | 1033 | host->jitter_min=jitter_tmp; |
1039 | if (jitter_tmp > host->jitter_max) | 1034 | } |
1035 | |||
1036 | if (jitter_tmp > host->jitter_max) { | ||
1040 | host->jitter_max=jitter_tmp; | 1037 | host->jitter_max=jitter_tmp; |
1038 | } | ||
1041 | } | 1039 | } |
1042 | 1040 | ||
1043 | /* Check if packets in order */ | 1041 | /* Check if packets in order */ |
@@ -1048,8 +1046,6 @@ wait_for_reply(int sock, u_int t) | |||
1048 | 1046 | ||
1049 | host->last_icmp_seq=packet.icp->icmp_seq; | 1047 | host->last_icmp_seq=packet.icp->icmp_seq; |
1050 | 1048 | ||
1051 | //printf("%d tdiff %d host->jitter %u host->last_tdiff %u\n", icp.icmp_seq, tdiff, host->jitter, host->last_tdiff); | ||
1052 | |||
1053 | host->time_waited += tdiff; | 1049 | host->time_waited += tdiff; |
1054 | host->icmp_recv++; | 1050 | host->icmp_recv++; |
1055 | icmp_recv++; | 1051 | icmp_recv++; |
@@ -1311,6 +1307,7 @@ finish(int sig) | |||
1311 | 1307 | ||
1312 | while(host) { | 1308 | while(host) { |
1313 | this_status = STATE_OK; | 1309 | this_status = STATE_OK; |
1310 | |||
1314 | if(!host->icmp_recv) { | 1311 | if(!host->icmp_recv) { |
1315 | /* rta 0 is ofcourse not entirely correct, but will still show up | 1312 | /* rta 0 is ofcourse not entirely correct, but will still show up |
1316 | * conspicuously as missing entries in perfparse and cacti */ | 1313 | * conspicuously as missing entries in perfparse and cacti */ |
@@ -1319,11 +1316,11 @@ finish(int sig) | |||
1319 | status = STATE_CRITICAL; | 1316 | status = STATE_CRITICAL; |
1320 | /* up the down counter if not already counted */ | 1317 | /* up the down counter if not already counted */ |
1321 | if(!(host->flags & FLAG_LOST_CAUSE) && targets_alive) targets_down++; | 1318 | if(!(host->flags & FLAG_LOST_CAUSE) && targets_alive) targets_down++; |
1322 | } | 1319 | } else { |
1323 | else { | ||
1324 | pl = ((host->icmp_sent - host->icmp_recv) * 100) / host->icmp_sent; | 1320 | pl = ((host->icmp_sent - host->icmp_recv) * 100) / host->icmp_sent; |
1325 | rta = (double)host->time_waited / host->icmp_recv; | 1321 | rta = (double)host->time_waited / host->icmp_recv; |
1326 | } | 1322 | } |
1323 | |||
1327 | if (host->icmp_recv>1) { | 1324 | if (host->icmp_recv>1) { |
1328 | host->jitter=(host->jitter / (host->icmp_recv - 1)/1000); | 1325 | host->jitter=(host->jitter / (host->icmp_recv - 1)/1000); |
1329 | host->EffectiveLatency = (rta/1000) + host->jitter * 2 + 10; | 1326 | host->EffectiveLatency = (rta/1000) + host->jitter * 2 + 10; |
@@ -1335,7 +1332,11 @@ finish(int sig) | |||
1335 | } | 1332 | } |
1336 | 1333 | ||
1337 | R = R - (pl * 2.5); | 1334 | R = R - (pl * 2.5); |
1338 | if (R<0) R=0; | 1335 | |
1336 | if (R < 0) { | ||
1337 | R = 0; | ||
1338 | } | ||
1339 | |||
1339 | host->score = R; | 1340 | host->score = R; |
1340 | host->mos= 1 + ((0.035) * R) + ((.000007) * R * (R-60) * (100-R)); | 1341 | host->mos= 1 + ((0.035) * R) + ((.000007) * R * (R-60) * (100-R)); |
1341 | } else { | 1342 | } else { |
@@ -1454,12 +1455,10 @@ finish(int sig) | |||
1454 | get_icmp_error_msg(host->icmp_type, host->icmp_code), | 1455 | get_icmp_error_msg(host->icmp_type, host->icmp_code), |
1455 | address, | 1456 | address, |
1456 | 100); | 1457 | 100); |
1457 | } | 1458 | } else { /* not marked as lost cause, so we have no flags for it */ |
1458 | else { /* not marked as lost cause, so we have no flags for it */ | ||
1459 | printf("%s: rta nan, lost 100%%", host->name); | 1459 | printf("%s: rta nan, lost 100%%", host->name); |
1460 | } | 1460 | } |
1461 | } | 1461 | } else { /* !icmp_recv */ |
1462 | else { /* !icmp_recv */ | ||
1463 | printf("%s", host->name); | 1462 | printf("%s", host->name); |
1464 | /* rta text output */ | 1463 | /* rta text output */ |
1465 | if (rta_mode) { | 1464 | if (rta_mode) { |
@@ -1525,6 +1524,7 @@ finish(int sig) | |||
1525 | host = list; | 1524 | host = list; |
1526 | while(host) { | 1525 | while(host) { |
1527 | if(debug) puts(""); | 1526 | if(debug) puts(""); |
1527 | |||
1528 | if (rta_mode && host->pl<100) { | 1528 | if (rta_mode && host->pl<100) { |
1529 | printf("%srta=%0.3fms;%0.3f;%0.3f;0; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ", | 1529 | printf("%srta=%0.3fms;%0.3f;%0.3f;0; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ", |
1530 | (targets > 1) ? host->name : "", | 1530 | (targets > 1) ? host->name : "", |
@@ -1532,9 +1532,11 @@ finish(int sig) | |||
1532 | (targets > 1) ? host->name : "", (float)host->rtmax / 1000, | 1532 | (targets > 1) ? host->name : "", (float)host->rtmax / 1000, |
1533 | (targets > 1) ? host->name : "", (host->rtmin < INFINITY) ? (float)host->rtmin / 1000 : (float)0); | 1533 | (targets > 1) ? host->name : "", (host->rtmin < INFINITY) ? (float)host->rtmin / 1000 : (float)0); |
1534 | } | 1534 | } |
1535 | |||
1535 | if (pl_mode) { | 1536 | if (pl_mode) { |
1536 | printf("%spl=%u%%;%u;%u;0;100 ", (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl); | 1537 | printf("%spl=%u%%;%u;%u;0;100 ", (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl); |
1537 | } | 1538 | } |
1539 | |||
1538 | if (jitter_mode && host->pl<100) { | 1540 | if (jitter_mode && host->pl<100) { |
1539 | printf("%sjitter_avg=%0.3fms;%0.3f;%0.3f;0; %sjitter_max=%0.3fms;;;; %sjitter_min=%0.3fms;;;; ", | 1541 | printf("%sjitter_avg=%0.3fms;%0.3f;%0.3f;0; %sjitter_max=%0.3fms;;;; %sjitter_min=%0.3fms;;;; ", |
1540 | (targets > 1) ? host->name : "", | 1542 | (targets > 1) ? host->name : "", |
@@ -1546,6 +1548,7 @@ finish(int sig) | |||
1546 | (float)host->jitter_min / 1000 | 1548 | (float)host->jitter_min / 1000 |
1547 | ); | 1549 | ); |
1548 | } | 1550 | } |
1551 | |||
1549 | if (mos_mode && host->pl<100) { | 1552 | if (mos_mode && host->pl<100) { |
1550 | printf("%smos=%0.1f;%0.1f;%0.1f;0;5 ", | 1553 | printf("%smos=%0.1f;%0.1f;%0.1f;0;5 ", |
1551 | (targets > 1) ? host->name : "", | 1554 | (targets > 1) ? host->name : "", |
@@ -1554,6 +1557,7 @@ finish(int sig) | |||
1554 | (float)crit.mos | 1557 | (float)crit.mos |
1555 | ); | 1558 | ); |
1556 | } | 1559 | } |
1560 | |||
1557 | if (score_mode && host->pl<100) { | 1561 | if (score_mode && host->pl<100) { |
1558 | printf("%sscore=%u;%u;%u;0;100 ", | 1562 | printf("%sscore=%u;%u;%u;0;100 ", |
1559 | (targets > 1) ? host->name : "", | 1563 | (targets > 1) ? host->name : "", |
@@ -1562,6 +1566,7 @@ finish(int sig) | |||
1562 | (int)crit.score | 1566 | (int)crit.score |
1563 | ); | 1567 | ); |
1564 | } | 1568 | } |
1569 | |||
1565 | host = host->next; | 1570 | host = host->next; |
1566 | } | 1571 | } |
1567 | 1572 | ||