summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Nierlein <sven@consol.de>2024-02-28 14:37:27 (GMT)
committerSven Nierlein <sven@nierlein.org>2024-03-01 08:03:17 (GMT)
commit0488426c7e8018d77734fb0e46328182de28f76a (patch)
tree157d97cab7fdeabdab304af540e40de92774b3d7
parent117cd8e4b826e471e795536228628d817df33f5a (diff)
downloadmonitoring-plugins-0488426c7e8018d77734fb0e46328182de28f76a.tar.gz
check_icmp: keep performance data order in case of none-reachable hosts
For responding hosts nothing changes: ./check_icmp -H 10.0.0.1 OK - 10.0.0.1 rta 0.336ms lost 0%|rta=0.336ms;200.000;500.000;0; rtmax=0.471ms;;;; rtmin=0.000ms;;;; pl=0%;40;80;0;100 In case the host is down, the performance data now contain 'U' according to: https://www.monitoring-plugins.org/doc/guidelines.html#AEN201 Old: ./check_icmp -H 10.0.0.99 CRITICAL - 10.0.0.99: Host unreachable @ 10.0.1.138. rta nan, lost 100%|pl=100%;40;80;0;100 Old: ./check_icmp -H 10.0.0.99 CRITICAL - 10.0.0.99: Host unreachable @ 10.0.1.138. rta nan, lost 100%|rta=U;;;; rtmax=U;;;; rtmin=U;;;; pl=100%;40;80;0;100 This confuses some performance graphing tools, ex.: pnp. Signed-off-by: Sven Nierlein <sven@consol.de>
-rw-r--r--plugins-root/check_icmp.c80
-rw-r--r--plugins-root/t/check_icmp.t5
2 files changed, 53 insertions, 32 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 303241d..f788d42 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -1547,46 +1547,66 @@ finish(int sig)
1547 while(host) { 1547 while(host) {
1548 if(debug) puts(""); 1548 if(debug) puts("");
1549 1549
1550 if (rta_mode && host->pl<100) { 1550 if (rta_mode) {
1551 printf("%srta=%0.3fms;%0.3f;%0.3f;0; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ", 1551 if (host->pl<100) {
1552 (targets > 1) ? host->name : "", 1552 printf("%srta=%0.3fms;%0.3f;%0.3f;0; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ",
1553 host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000, 1553 (targets > 1) ? host->name : "",
1554 (targets > 1) ? host->name : "", (float)host->rtmax / 1000, 1554 host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000,
1555 (targets > 1) ? host->name : "", (host->rtmin < INFINITY) ? (float)host->rtmin / 1000 : (float)0); 1555 (targets > 1) ? host->name : "", (float)host->rtmax / 1000,
1556 (targets > 1) ? host->name : "", (host->rtmin < INFINITY) ? (float)host->rtmin / 1000 : (float)0);
1557 } else {
1558 printf("%srta=U;;;; %srtmax=U;;;; %srtmin=U;;;; ",
1559 (targets > 1) ? host->name : "",
1560 (targets > 1) ? host->name : "",
1561 (targets > 1) ? host->name : "");
1562 }
1556 } 1563 }
1557 1564
1558 if (pl_mode) { 1565 if (pl_mode) {
1559 printf("%spl=%u%%;%u;%u;0;100 ", (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl); 1566 printf("%spl=%u%%;%u;%u;0;100 ", (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl);
1560 } 1567 }
1561 1568
1562 if (jitter_mode && host->pl<100) { 1569 if (jitter_mode) {
1563 printf("%sjitter_avg=%0.3fms;%0.3f;%0.3f;0; %sjitter_max=%0.3fms;;;; %sjitter_min=%0.3fms;;;; ", 1570 if (host->pl<100) {
1564 (targets > 1) ? host->name : "", 1571 printf("%sjitter_avg=%0.3fms;%0.3f;%0.3f;0; %sjitter_max=%0.3fms;;;; %sjitter_min=%0.3fms;;;; ",
1565 (float)host->jitter, 1572 (targets > 1) ? host->name : "",
1566 (float)warn.jitter, 1573 (float)host->jitter,
1567 (float)crit.jitter, 1574 (float)warn.jitter,
1568 (targets > 1) ? host->name : "", 1575 (float)crit.jitter,
1569 (float)host->jitter_max / 1000, (targets > 1) ? host->name : "", 1576 (targets > 1) ? host->name : "",
1570 (float)host->jitter_min / 1000 1577 (float)host->jitter_max / 1000, (targets > 1) ? host->name : "",
1571 ); 1578 (float)host->jitter_min / 1000
1579 );
1580 } else {
1581 printf("%sjitter_avg=U;;;; %sjitter_max=U;;;; %sjitter_min=U;;;; ",
1582 (targets > 1) ? host->name : "",
1583 (targets > 1) ? host->name : "",
1584 (targets > 1) ? host->name : "");
1585 }
1572 } 1586 }
1573 1587
1574 if (mos_mode && host->pl<100) { 1588 if (mos_mode) {
1575 printf("%smos=%0.1f;%0.1f;%0.1f;0;5 ", 1589 if (host->pl<100) {
1576 (targets > 1) ? host->name : "", 1590 printf("%smos=%0.1f;%0.1f;%0.1f;0;5 ",
1577 (float)host->mos, 1591 (targets > 1) ? host->name : "",
1578 (float)warn.mos, 1592 (float)host->mos,
1579 (float)crit.mos 1593 (float)warn.mos,
1580 ); 1594 (float)crit.mos);
1595 } else {
1596 printf("%smos=U;;;; ", (targets > 1) ? host->name : "");
1597 }
1581 } 1598 }
1582 1599
1583 if (score_mode && host->pl<100) { 1600 if (score_mode) {
1584 printf("%sscore=%u;%u;%u;0;100 ", 1601 if (host->pl<100) {
1585 (targets > 1) ? host->name : "", 1602 printf("%sscore=%u;%u;%u;0;100 ",
1586 (int)host->score, 1603 (targets > 1) ? host->name : "",
1587 (int)warn.score, 1604 (int)host->score,
1588 (int)crit.score 1605 (int)warn.score,
1589 ); 1606 (int)crit.score);
1607 } else {
1608 printf("%sscore=U;;;; ", (targets > 1) ? host->name : "");
1609 }
1590 } 1610 }
1591 1611
1592 host = host->next; 1612 host = host->next;
diff --git a/plugins-root/t/check_icmp.t b/plugins-root/t/check_icmp.t
index 4f9db86..de1d88d 100644
--- a/plugins-root/t/check_icmp.t
+++ b/plugins-root/t/check_icmp.t
@@ -12,7 +12,7 @@ my $allow_sudo = getTestParameter( "NP_ALLOW_SUDO",
12 "no" ); 12 "no" );
13 13
14if ($allow_sudo eq "yes" or $> == 0) { 14if ($allow_sudo eq "yes" or $> == 0) {
15 plan tests => 39; 15 plan tests => 40;
16} else { 16} else {
17 plan skip_all => "Need sudo to test check_icmp"; 17 plan skip_all => "Need sudo to test check_icmp";
18} 18}
@@ -57,7 +57,8 @@ $res = NPTest->testCmd(
57 "$sudo ./check_icmp -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -t 2" 57 "$sudo ./check_icmp -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -t 2"
58 ); 58 );
59is( $res->return_code, 2, "Timeout - host nonresponsive" ); 59is( $res->return_code, 2, "Timeout - host nonresponsive" );
60like( $res->output, '/100%/', "Error contains '100%' string (for 100% packet loss)" ); 60like( $res->output, '/pl=100%/', "Error contains 'pl=100%' string (for 100% packet loss)" );
61like( $res->output, '/rta=U/', "Error contains 'rta=U' string" );
61 62
62$res = NPTest->testCmd( 63$res = NPTest->testCmd(
63 "$sudo ./check_icmp -w 10000ms,100% -c 10000ms,100%" 64 "$sudo ./check_icmp -w 10000ms,100% -c 10000ms,100%"