diff options
Diffstat (limited to 'plugins-root')
-rw-r--r-- | plugins-root/check_icmp.c | 399 |
1 files changed, 371 insertions, 28 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 1d47e9f..a537c9c 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c | |||
@@ -42,6 +42,10 @@ char *progname; | |||
42 | const char *copyright = "2005-2008"; | 42 | const char *copyright = "2005-2008"; |
43 | const char *email = "devel@monitoring-plugins.org"; | 43 | const char *email = "devel@monitoring-plugins.org"; |
44 | 44 | ||
45 | #ifdef __sun | ||
46 | #define _XPG4_2 | ||
47 | #endif | ||
48 | |||
45 | /** Monitoring Plugins basic includes */ | 49 | /** Monitoring Plugins basic includes */ |
46 | #include "common.h" | 50 | #include "common.h" |
47 | #include "netutils.h" | 51 | #include "netutils.h" |
@@ -109,18 +113,35 @@ typedef struct rta_host { | |||
109 | unsigned char icmp_type, icmp_code; /* type and code from errors */ | 113 | unsigned char icmp_type, icmp_code; /* type and code from errors */ |
110 | unsigned short flags; /* control/status flags */ | 114 | unsigned short flags; /* control/status flags */ |
111 | double rta; /* measured RTA */ | 115 | double rta; /* measured RTA */ |
116 | int rta_status; | ||
112 | double rtmax; /* max rtt */ | 117 | double rtmax; /* max rtt */ |
113 | double rtmin; /* min rtt */ | 118 | double rtmin; /* min rtt */ |
119 | double jitter; /* measured jitter */ | ||
120 | int jitter_status; | ||
121 | double jitter_max; /* jitter rtt */ | ||
122 | double jitter_min; /* jitter rtt */ | ||
123 | double EffectiveLatency; | ||
124 | double mos; /* Mean opnion score */ | ||
125 | int mos_status; | ||
126 | double score; /* score */ | ||
127 | int score_status; | ||
128 | u_int last_tdiff; | ||
129 | u_int last_icmp_seq; /* Last ICMP_SEQ to check out of order pkts */ | ||
114 | unsigned char pl; /* measured packet loss */ | 130 | unsigned char pl; /* measured packet loss */ |
131 | int pl_status; | ||
115 | struct rta_host *next; /* linked list */ | 132 | struct rta_host *next; /* linked list */ |
133 | int order_status; | ||
116 | } rta_host; | 134 | } rta_host; |
117 | 135 | ||
118 | #define FLAG_LOST_CAUSE 0x01 /* decidedly dead target. */ | 136 | #define FLAG_LOST_CAUSE 0x01 /* decidedly dead target. */ |
119 | 137 | ||
120 | /* threshold structure. all values are maximum allowed, exclusive */ | 138 | /* threshold structure. all values are maximum allowed, exclusive */ |
121 | typedef struct threshold { | 139 | typedef struct threshold { |
122 | unsigned char pl; /* max allowed packet loss in percent */ | 140 | unsigned char pl; /* max allowed packet loss in percent */ |
123 | unsigned int rta; /* roundtrip time average, microseconds */ | 141 | unsigned int rta; /* roundtrip time average, microseconds */ |
142 | double jitter; /* jitter time average, microseconds */ | ||
143 | double mos; /* MOS */ | ||
144 | double score; /* Score */ | ||
124 | } threshold; | 145 | } threshold; |
125 | 146 | ||
126 | /* the data structure */ | 147 | /* the data structure */ |
@@ -188,6 +209,7 @@ static int wait_for_reply(int, u_int); | |||
188 | static int recvfrom_wto(int, void *, unsigned int, struct sockaddr *, u_int *, struct timeval*); | 209 | static int recvfrom_wto(int, void *, unsigned int, struct sockaddr *, u_int *, struct timeval*); |
189 | static int send_icmp_ping(int, struct rta_host *); | 210 | static int send_icmp_ping(int, struct rta_host *); |
190 | static int get_threshold(char *str, threshold *th); | 211 | static int get_threshold(char *str, threshold *th); |
212 | static int get_threshold2(char *str, threshold *, threshold *, int type); | ||
191 | static void run_checks(void); | 213 | static void run_checks(void); |
192 | static void set_source_ip(char *); | 214 | static void set_source_ip(char *); |
193 | static int add_target(char *); | 215 | static int add_target(char *); |
@@ -224,6 +246,12 @@ static unsigned int warn_down = 1, crit_down = 1; /* host down threshold values | |||
224 | static int min_hosts_alive = -1; | 246 | static int min_hosts_alive = -1; |
225 | float pkt_backoff_factor = 1.5; | 247 | float pkt_backoff_factor = 1.5; |
226 | float target_backoff_factor = 1.5; | 248 | float target_backoff_factor = 1.5; |
249 | int rta_mode=0; | ||
250 | int pl_mode=0; | ||
251 | int jitter_mode=0; | ||
252 | int score_mode=0; | ||
253 | int mos_mode=0; | ||
254 | int order_mode=0; | ||
227 | 255 | ||
228 | /** code start **/ | 256 | /** code start **/ |
229 | static void | 257 | static void |
@@ -393,12 +421,14 @@ main(int argc, char **argv) | |||
393 | int icmp_sockerrno, udp_sockerrno, tcp_sockerrno; | 421 | int icmp_sockerrno, udp_sockerrno, tcp_sockerrno; |
394 | int result; | 422 | int result; |
395 | struct rta_host *host; | 423 | struct rta_host *host; |
424 | #ifdef HAVE_SIGACTION | ||
425 | struct sigaction sig_action; | ||
426 | #endif | ||
396 | #ifdef SO_TIMESTAMP | 427 | #ifdef SO_TIMESTAMP |
397 | int on = 1; | 428 | int on = 1; |
398 | #endif | 429 | #endif |
399 | char *source_ip = NULL; | 430 | char *source_ip = NULL; |
400 | char * opts_str = "vhVw:c:n:p:t:H:s:i:b:I:l:m:64"; | 431 | char * opts_str = "vhVw:c:n:p:t:H:s:i:b:I:l:m:P:R:J:S:M:O64"; |
401 | |||
402 | setlocale (LC_ALL, ""); | 432 | setlocale (LC_ALL, ""); |
403 | bindtextdomain (PACKAGE, LOCALEDIR); | 433 | bindtextdomain (PACKAGE, LOCALEDIR); |
404 | textdomain (PACKAGE); | 434 | textdomain (PACKAGE); |
@@ -422,10 +452,19 @@ main(int argc, char **argv) | |||
422 | table = NULL; | 452 | table = NULL; |
423 | 453 | ||
424 | mode = MODE_RTA; | 454 | mode = MODE_RTA; |
455 | /* Default critical thresholds */ | ||
425 | crit.rta = 500000; | 456 | crit.rta = 500000; |
426 | crit.pl = 80; | 457 | crit.pl = 80; |
458 | crit.jitter = 50; | ||
459 | crit.mos= 3; | ||
460 | crit.score=70; | ||
461 | /* Default warning thresholds */ | ||
427 | warn.rta = 200000; | 462 | warn.rta = 200000; |
428 | warn.pl = 40; | 463 | warn.pl = 40; |
464 | warn.jitter = 40; | ||
465 | warn.mos= 3.5; | ||
466 | warn.score=80; | ||
467 | |||
429 | protocols = HAVE_ICMP | HAVE_UDP | HAVE_TCP; | 468 | protocols = HAVE_ICMP | HAVE_UDP | HAVE_TCP; |
430 | pkt_interval = 80000; /* 80 msec packet interval by default */ | 469 | pkt_interval = 80000; /* 80 msec packet interval by default */ |
431 | packets = 5; | 470 | packets = 5; |
@@ -481,7 +520,7 @@ main(int argc, char **argv) | |||
481 | /* Reset argument scanning */ | 520 | /* Reset argument scanning */ |
482 | optind = 1; | 521 | optind = 1; |
483 | 522 | ||
484 | unsigned short size; | 523 | unsigned long size; |
485 | /* parse the arguments */ | 524 | /* parse the arguments */ |
486 | for(i = 1; i < argc; i++) { | 525 | for(i = 1; i < argc; i++) { |
487 | while((arg = getopt(argc, argv, opts_str)) != EOF) { | 526 | while((arg = getopt(argc, argv, opts_str)) != EOF) { |
@@ -490,7 +529,7 @@ main(int argc, char **argv) | |||
490 | debug++; | 529 | debug++; |
491 | break; | 530 | break; |
492 | case 'b': | 531 | case 'b': |
493 | size = (unsigned short)strtol(optarg,NULL,0); | 532 | size = strtol(optarg,NULL,0); |
494 | if (size >= (sizeof(struct icmp) + sizeof(struct icmp_ping_data)) && | 533 | if (size >= (sizeof(struct icmp) + sizeof(struct icmp_ping_data)) && |
495 | size < MAX_PING_DATA) { | 534 | size < MAX_PING_DATA) { |
496 | icmp_data_size = size; | 535 | icmp_data_size = size; |
@@ -545,6 +584,29 @@ main(int argc, char **argv) | |||
545 | print_help (); | 584 | print_help (); |
546 | exit (STATE_UNKNOWN); | 585 | exit (STATE_UNKNOWN); |
547 | break; | 586 | break; |
587 | case 'R': /* RTA mode */ | ||
588 | get_threshold2(optarg, &warn, &crit,1); | ||
589 | rta_mode=1; | ||
590 | break; | ||
591 | case 'P': /* packet loss mode */ | ||
592 | get_threshold2(optarg, &warn, &crit,2); | ||
593 | pl_mode=1; | ||
594 | break; | ||
595 | case 'J': /* jitter mode */ | ||
596 | get_threshold2(optarg, &warn, &crit,3); | ||
597 | jitter_mode=1; | ||
598 | break; | ||
599 | case 'M': /* MOS mode */ | ||
600 | get_threshold2(optarg, &warn, &crit,4); | ||
601 | mos_mode=1; | ||
602 | break; | ||
603 | case 'S': /* score mode */ | ||
604 | get_threshold2(optarg, &warn, &crit,5); | ||
605 | score_mode=1; | ||
606 | break; | ||
607 | case 'O': /* out of order mode */ | ||
608 | order_mode=1; | ||
609 | break; | ||
548 | } | 610 | } |
549 | } | 611 | } |
550 | } | 612 | } |
@@ -631,11 +693,25 @@ main(int argc, char **argv) | |||
631 | if(warn.pl > crit.pl) warn.pl = crit.pl; | 693 | if(warn.pl > crit.pl) warn.pl = crit.pl; |
632 | if(warn.rta > crit.rta) warn.rta = crit.rta; | 694 | if(warn.rta > crit.rta) warn.rta = crit.rta; |
633 | if(warn_down > crit_down) crit_down = warn_down; | 695 | if(warn_down > crit_down) crit_down = warn_down; |
634 | 696 | if(warn.jitter > crit.jitter) crit.jitter = warn.jitter; | |
697 | if(warn.mos < crit.mos) warn.mos = crit.mos; | ||
698 | if(warn.score < crit.score) warn.score = crit.score; | ||
699 | |||
700 | #ifdef HAVE_SIGACTION | ||
701 | sig_action.sa_sigaction = NULL; | ||
702 | sig_action.sa_handler = finish; | ||
703 | sigfillset(&sig_action.sa_mask); | ||
704 | sig_action.sa_flags = SA_NODEFER|SA_RESTART; | ||
705 | sigaction(SIGINT, &sig_action, NULL); | ||
706 | sigaction(SIGHUP, &sig_action, NULL); | ||
707 | sigaction(SIGTERM, &sig_action, NULL); | ||
708 | sigaction(SIGALRM, &sig_action, NULL); | ||
709 | #else /* HAVE_SIGACTION */ | ||
635 | signal(SIGINT, finish); | 710 | signal(SIGINT, finish); |
636 | signal(SIGHUP, finish); | 711 | signal(SIGHUP, finish); |
637 | signal(SIGTERM, finish); | 712 | signal(SIGTERM, finish); |
638 | signal(SIGALRM, finish); | 713 | signal(SIGALRM, finish); |
714 | #endif /* HAVE_SIGACTION */ | ||
639 | if(debug) printf("Setting alarm timeout to %u seconds\n", timeout); | 715 | if(debug) printf("Setting alarm timeout to %u seconds\n", timeout); |
640 | alarm(timeout); | 716 | alarm(timeout); |
641 | 717 | ||
@@ -685,7 +761,11 @@ main(int argc, char **argv) | |||
685 | } | 761 | } |
686 | 762 | ||
687 | host = list; | 763 | host = list; |
764 | //<<<<<<< HEAD FIXME | ||
688 | table = (struct rta_host**)malloc(sizeof(struct rta_host **) * targets); | 765 | table = (struct rta_host**)malloc(sizeof(struct rta_host **) * targets); |
766 | //======= | ||
767 | // table = malloc(sizeof(struct rta_host *) * targets); | ||
768 | //>>>>>>> jitter-orig | ||
689 | i = 0; | 769 | i = 0; |
690 | while(host) { | 770 | while(host) { |
691 | host->id = i*packets; | 771 | host->id = i*packets; |
@@ -772,6 +852,7 @@ wait_for_reply(int sock, u_int t) | |||
772 | struct icmp_ping_data data; | 852 | struct icmp_ping_data data; |
773 | struct timeval wait_start, now; | 853 | struct timeval wait_start, now; |
774 | u_int tdiff, i, per_pkt_wait; | 854 | u_int tdiff, i, per_pkt_wait; |
855 | double jitter_tmp; | ||
775 | 856 | ||
776 | if (!(packet.buf = malloc(icmp_pkt_size))) { | 857 | if (!(packet.buf = malloc(icmp_pkt_size))) { |
777 | crash("send_icmp_ping(): failed to malloc %d bytes for send buffer", | 858 | crash("send_icmp_ping(): failed to malloc %d bytes for send buffer", |
@@ -890,12 +971,43 @@ wait_for_reply(int sock, u_int t) | |||
890 | 971 | ||
891 | tdiff = get_timevaldiff(&data.stime, &now); | 972 | tdiff = get_timevaldiff(&data.stime, &now); |
892 | 973 | ||
974 | if (host->last_tdiff>0) { | ||
975 | /* Calculate jitter */ | ||
976 | if (host->last_tdiff > tdiff) { | ||
977 | jitter_tmp = host->last_tdiff - tdiff; | ||
978 | } | ||
979 | else { | ||
980 | jitter_tmp = tdiff - host->last_tdiff; | ||
981 | } | ||
982 | if (host->jitter==0) { | ||
983 | host->jitter=jitter_tmp; | ||
984 | host->jitter_max=jitter_tmp; | ||
985 | host->jitter_min=jitter_tmp; | ||
986 | } | ||
987 | else { | ||
988 | host->jitter+=jitter_tmp; | ||
989 | if (jitter_tmp < host->jitter_min) | ||
990 | host->jitter_min=jitter_tmp; | ||
991 | if (jitter_tmp > host->jitter_max) | ||
992 | host->jitter_max=jitter_tmp; | ||
993 | } | ||
994 | |||
995 | /* Check if packets in order */ | ||
996 | if (host->last_icmp_seq >= packet.icp->icmp_seq) | ||
997 | host->order_status=STATE_CRITICAL; | ||
998 | } | ||
999 | host->last_tdiff=tdiff; | ||
1000 | |||
1001 | host->last_icmp_seq=packet.icp->icmp_seq; | ||
1002 | |||
1003 | //printf("%d tdiff %d host->jitter %u host->last_tdiff %u\n", icp.icmp_seq, tdiff, host->jitter, host->last_tdiff); | ||
1004 | |||
893 | host->time_waited += tdiff; | 1005 | host->time_waited += tdiff; |
894 | host->icmp_recv++; | 1006 | host->icmp_recv++; |
895 | icmp_recv++; | 1007 | icmp_recv++; |
896 | if (tdiff > host->rtmax) | 1008 | if (tdiff > (int)host->rtmax) |
897 | host->rtmax = tdiff; | 1009 | host->rtmax = tdiff; |
898 | if (tdiff < host->rtmin) | 1010 | if (tdiff < (int)host->rtmin) |
899 | host->rtmin = tdiff; | 1011 | host->rtmin = tdiff; |
900 | 1012 | ||
901 | if(debug) { | 1013 | if(debug) { |
@@ -1094,8 +1206,10 @@ recvfrom_wto(int sock, void *buf, unsigned int len, struct sockaddr *saddr, | |||
1094 | hdr.msg_namelen = slen; | 1206 | hdr.msg_namelen = slen; |
1095 | hdr.msg_iov = &iov; | 1207 | hdr.msg_iov = &iov; |
1096 | hdr.msg_iovlen = 1; | 1208 | hdr.msg_iovlen = 1; |
1209 | #ifdef HAVE_MSGHDR_MSG_CONTROL | ||
1097 | hdr.msg_control = ans_data; | 1210 | hdr.msg_control = ans_data; |
1098 | hdr.msg_controllen = sizeof(ans_data); | 1211 | hdr.msg_controllen = sizeof(ans_data); |
1212 | #endif | ||
1099 | 1213 | ||
1100 | ret = recvmsg(sock, &hdr, 0); | 1214 | ret = recvmsg(sock, &hdr, 0); |
1101 | #ifdef SO_TIMESTAMP | 1215 | #ifdef SO_TIMESTAMP |
@@ -1125,6 +1239,7 @@ finish(int sig) | |||
1125 | {"OK", "WARNING", "CRITICAL", "UNKNOWN", "DEPENDENT"}; | 1239 | {"OK", "WARNING", "CRITICAL", "UNKNOWN", "DEPENDENT"}; |
1126 | int hosts_ok = 0; | 1240 | int hosts_ok = 0; |
1127 | int hosts_warn = 0; | 1241 | int hosts_warn = 0; |
1242 | double R; | ||
1128 | 1243 | ||
1129 | alarm(0); | 1244 | alarm(0); |
1130 | if(debug > 1) printf("finish(%d) called\n", sig); | 1245 | if(debug > 1) printf("finish(%d) called\n", sig); |
@@ -1140,6 +1255,7 @@ finish(int sig) | |||
1140 | } | 1255 | } |
1141 | 1256 | ||
1142 | /* iterate thrice to calculate values, give output, and print perfparse */ | 1257 | /* iterate thrice to calculate values, give output, and print perfparse */ |
1258 | status=STATE_OK; | ||
1143 | host = list; | 1259 | host = list; |
1144 | 1260 | ||
1145 | while(host) { | 1261 | while(host) { |
@@ -1156,19 +1272,104 @@ finish(int sig) | |||
1156 | pl = ((host->icmp_sent - host->icmp_recv) * 100) / host->icmp_sent; | 1272 | pl = ((host->icmp_sent - host->icmp_recv) * 100) / host->icmp_sent; |
1157 | rta = (double)host->time_waited / host->icmp_recv; | 1273 | rta = (double)host->time_waited / host->icmp_recv; |
1158 | } | 1274 | } |
1275 | if (host->icmp_recv>1) { | ||
1276 | host->jitter=(host->jitter / (host->icmp_recv - 1)/1000); | ||
1277 | host->EffectiveLatency = (rta/1000) + host->jitter * 2 + 10; | ||
1278 | if (host->EffectiveLatency < 160) | ||
1279 | R = 93.2 - (host->EffectiveLatency / 40); | ||
1280 | else | ||
1281 | R = 93.2 - ((host->EffectiveLatency - 120) / 10); | ||
1282 | R = R - (pl * 2.5); | ||
1283 | if (R<0) R=0; | ||
1284 | host->score = R; | ||
1285 | host->mos= 1 + ((0.035) * R) + ((.000007) * R * (R-60) * (100-R)); | ||
1286 | } | ||
1287 | else { | ||
1288 | host->jitter=0; | ||
1289 | host->jitter_min=0; | ||
1290 | host->jitter_max=0; | ||
1291 | host->mos=0; | ||
1292 | } | ||
1159 | host->pl = pl; | 1293 | host->pl = pl; |
1160 | host->rta = rta; | 1294 | host->rta = rta; |
1161 | if(pl >= crit.pl || rta >= crit.rta) { | 1295 | |
1162 | status = STATE_CRITICAL; | 1296 | /* if no new mode selected, use old schema */ |
1297 | if (!rta_mode && !pl_mode && !jitter_mode && !score_mode && !mos_mode && !order_mode) { | ||
1298 | rta_mode=1; | ||
1299 | pl_mode=1; | ||
1163 | } | 1300 | } |
1164 | else if(!status && (pl >= warn.pl || rta >= warn.rta)) { | 1301 | |
1165 | status = STATE_WARNING; | 1302 | /* Check which mode is on and do the warn / Crit stuff */ |
1166 | hosts_warn++; | 1303 | if (rta_mode) { |
1304 | if(rta >= crit.rta) { | ||
1305 | status = STATE_CRITICAL; | ||
1306 | host->rta_status=STATE_CRITICAL; | ||
1307 | } | ||
1308 | else if(status!=STATE_CRITICAL && (rta >= warn.rta)) { | ||
1309 | status = STATE_WARNING; | ||
1310 | hosts_warn++; | ||
1311 | host->rta_status=STATE_WARNING; | ||
1312 | } | ||
1313 | else { | ||
1314 | hosts_ok++; | ||
1315 | } | ||
1167 | } | 1316 | } |
1168 | else { | 1317 | if (pl_mode) { |
1169 | hosts_ok++; | 1318 | if(pl >= crit.pl) { |
1319 | status = STATE_CRITICAL; | ||
1320 | host->pl_status=STATE_CRITICAL; | ||
1321 | } | ||
1322 | else if(status!=STATE_CRITICAL && (pl >= warn.pl)) { | ||
1323 | status = STATE_WARNING; | ||
1324 | hosts_warn++; | ||
1325 | host->pl_status=STATE_WARNING; | ||
1326 | } | ||
1327 | else { | ||
1328 | hosts_ok++; | ||
1329 | } | ||
1330 | } | ||
1331 | if (jitter_mode) { | ||
1332 | if(host->jitter >= crit.jitter) { | ||
1333 | status = STATE_CRITICAL; | ||
1334 | host->jitter_status=STATE_CRITICAL; | ||
1335 | } | ||
1336 | else if(status!=STATE_CRITICAL && (host->jitter >= warn.jitter)) { | ||
1337 | status = STATE_WARNING; | ||
1338 | hosts_warn++; | ||
1339 | host->jitter_status=STATE_WARNING; | ||
1340 | } | ||
1341 | else { | ||
1342 | hosts_ok++; | ||
1343 | } | ||
1344 | } | ||
1345 | if (mos_mode) { | ||
1346 | if(host->mos <= crit.mos) { | ||
1347 | status = STATE_CRITICAL; | ||
1348 | host->mos_status=STATE_CRITICAL; | ||
1349 | } | ||
1350 | else if(status!=STATE_CRITICAL && (host->mos <= warn.mos)) { | ||
1351 | status = STATE_WARNING; | ||
1352 | hosts_warn++; | ||
1353 | host->mos_status=STATE_WARNING; | ||
1354 | } | ||
1355 | else { | ||
1356 | hosts_ok++; | ||
1357 | } | ||
1358 | } | ||
1359 | if (score_mode) { | ||
1360 | if(host->score <= crit.score) { | ||
1361 | status = STATE_CRITICAL; | ||
1362 | host->score_status=STATE_CRITICAL; | ||
1363 | } | ||
1364 | else if(status!=STATE_CRITICAL && (host->score <= warn.score)) { | ||
1365 | status = STATE_WARNING; | ||
1366 | score_mode++; | ||
1367 | host->score_status=STATE_WARNING; | ||
1368 | } | ||
1369 | else { | ||
1370 | hosts_ok++; | ||
1371 | } | ||
1170 | } | 1372 | } |
1171 | |||
1172 | host = host->next; | 1373 | host = host->next; |
1173 | } | 1374 | } |
1174 | /* this is inevitable */ | 1375 | /* this is inevitable */ |
@@ -1181,6 +1382,7 @@ finish(int sig) | |||
1181 | 1382 | ||
1182 | host = list; | 1383 | host = list; |
1183 | while(host) { | 1384 | while(host) { |
1385 | |||
1184 | if(debug) puts(""); | 1386 | if(debug) puts(""); |
1185 | if(i) { | 1387 | if(i) { |
1186 | if(i < targets) printf(" :: "); | 1388 | if(i < targets) printf(" :: "); |
@@ -1189,6 +1391,8 @@ finish(int sig) | |||
1189 | i++; | 1391 | i++; |
1190 | if(!host->icmp_recv) { | 1392 | if(!host->icmp_recv) { |
1191 | status = STATE_CRITICAL; | 1393 | status = STATE_CRITICAL; |
1394 | host->rtmin=0; | ||
1395 | host->jitter_min=0; | ||
1192 | if(host->flags & FLAG_LOST_CAUSE) { | 1396 | if(host->flags & FLAG_LOST_CAUSE) { |
1193 | char address[INET6_ADDRSTRLEN]; | 1397 | char address[INET6_ADDRSTRLEN]; |
1194 | parse_address(&host->error_addr, address, sizeof(address)); | 1398 | parse_address(&host->error_addr, address, sizeof(address)); |
@@ -1203,26 +1407,92 @@ finish(int sig) | |||
1203 | } | 1407 | } |
1204 | } | 1408 | } |
1205 | else { /* !icmp_recv */ | 1409 | else { /* !icmp_recv */ |
1206 | printf("%s: rta %0.3fms, lost %u%%", | 1410 | printf("%s ", host->name); |
1207 | host->name, host->rta / 1000, host->pl); | 1411 | /* rta text output */ |
1412 | if (rta_mode) { | ||
1413 | if (status == STATE_OK) | ||
1414 | printf(" rta %0.3fms", host->rta / 1000); | ||
1415 | else if (status==STATE_WARNING && host->rta_status==status) | ||
1416 | printf(" rta %0.3fms > %0.3fms", (float)host->rta / 1000, (float)warn.rta/1000); | ||
1417 | else if (status==STATE_CRITICAL && host->rta_status==status) | ||
1418 | printf(" rta %0.3fms > %0.3fms", (float)host->rta / 1000, (float)crit.rta/1000); | ||
1419 | } | ||
1420 | /* pl text output */ | ||
1421 | if (pl_mode) { | ||
1422 | if (status == STATE_OK) | ||
1423 | printf(" lost %u%%", host->pl); | ||
1424 | else if (status==STATE_WARNING && host->pl_status==status) | ||
1425 | printf(" lost %u%% > %u%%", host->pl, warn.pl); | ||
1426 | else if (status==STATE_CRITICAL && host->pl_status==status) | ||
1427 | printf(" lost %u%% > %u%%", host->pl, crit.pl); | ||
1428 | } | ||
1429 | /* jitter text output */ | ||
1430 | if (jitter_mode) { | ||
1431 | if (status == STATE_OK) | ||
1432 | printf(" jitter %0.3fms", (float)host->jitter); | ||
1433 | else if (status==STATE_WARNING && host->jitter_status==status) | ||
1434 | printf(" jitter %0.3fms > %0.3fms", (float)host->jitter, warn.jitter); | ||
1435 | else if (status==STATE_CRITICAL && host->jitter_status==status) | ||
1436 | printf(" jitter %0.3fms > %0.3fms", (float)host->jitter, crit.jitter); | ||
1437 | } | ||
1438 | /* mos text output */ | ||
1439 | if (mos_mode) { | ||
1440 | if (status == STATE_OK) | ||
1441 | printf(" MOS %0.1f", (float)host->mos); | ||
1442 | else if (status==STATE_WARNING && host->mos_status==status) | ||
1443 | printf(" MOS %0.1f < %0.1f", (float)host->mos, (float)warn.mos); | ||
1444 | else if (status==STATE_CRITICAL && host->mos_status==status) | ||
1445 | printf(" MOS %0.1f < %0.1f", (float)host->mos, (float)crit.mos); | ||
1446 | } | ||
1447 | /* score text output */ | ||
1448 | if (score_mode) { | ||
1449 | if (status == STATE_OK) | ||
1450 | printf(" Score %u", (int)host->score); | ||
1451 | else if (status==STATE_WARNING && host->score_status==status ) | ||
1452 | printf(" Score %u < %u", (int)host->score, (int)warn.score); | ||
1453 | else if (status==STATE_CRITICAL && host->score_status==status ) | ||
1454 | printf(" Score %u < %u", (int)host->score, (int)crit.score); | ||
1455 | } | ||
1456 | /* order statis text output */ | ||
1457 | if (order_mode) { | ||
1458 | if (status == STATE_OK) | ||
1459 | printf(" Packets in order"); | ||
1460 | else if (status==STATE_CRITICAL && host->order_status==status) | ||
1461 | printf(" Packets out of order"); | ||
1462 | } | ||
1208 | } | 1463 | } |
1209 | |||
1210 | host = host->next; | 1464 | host = host->next; |
1211 | } | 1465 | } |
1212 | 1466 | ||
1213 | /* iterate once more for pretty perfparse output */ | 1467 | /* iterate once more for pretty perfparse output */ |
1214 | printf("|"); | 1468 | if (!(!rta_mode && !pl_mode && !jitter_mode && !score_mode && !mos_mode && order_mode)) { |
1469 | printf("|"); | ||
1470 | } | ||
1215 | i = 0; | 1471 | i = 0; |
1216 | host = list; | 1472 | host = list; |
1217 | while(host) { | 1473 | while(host) { |
1218 | if(debug) puts(""); | 1474 | if(debug) puts(""); |
1219 | printf("%srta=%0.3fms;%0.3f;%0.3f;0; %spl=%u%%;%u;%u;; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ", | 1475 | if (rta_mode && host->pl<100) { |
1476 | // FIXME printf("%srta=%0.3fms;%0.3f;%0.3f;0; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ",(targets > 1) ? host->name : "", (float)host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000, (targets > 1) ? host->name : "", (float)host->rtmax / 1000, (targets > 1) ? host->name : "", (float)host->rtmin / 1000); | ||
1477 | printf("%srta=%0.3fms;%0.3f;%0.3f;0; %spl=%u%%;%u;%u;; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ", | ||
1220 | (targets > 1) ? host->name : "", | 1478 | (targets > 1) ? host->name : "", |
1221 | host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000, | 1479 | host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000, |
1222 | (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl, | 1480 | (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl, |
1223 | (targets > 1) ? host->name : "", (float)host->rtmax / 1000, | 1481 | (targets > 1) ? host->name : "", (float)host->rtmax / 1000, |
1224 | (targets > 1) ? host->name : "", (host->rtmin < INFINITY) ? (float)host->rtmin / 1000 : (float)0); | 1482 | (targets > 1) ? host->name : "", (host->rtmin < INFINITY) ? (float)host->rtmin / 1000 : (float)0); |
1225 | 1483 | } | |
1484 | if (pl_mode) { | ||
1485 | printf("%spl=%u%%;%u;%u;0;100 ", (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl); | ||
1486 | } | ||
1487 | if (jitter_mode && host->pl<100) { | ||
1488 | printf("%sjitter_avg=%0.3fms;%0.3f;%0.3f;0; %sjitter_max=%0.3fms;;;; %sjitter_min=%0.3fms;;;; ", (targets > 1) ? host->name : "", (float)host->jitter, (float)warn.jitter, (float)crit.jitter, (targets > 1) ? host->name : "", (float)host->jitter_max / 1000, (targets > 1) ? host->name : "",(float)host->jitter_min / 1000); | ||
1489 | } | ||
1490 | if (mos_mode && host->pl<100) { | ||
1491 | printf("%smos=%0.1f;%0.1f;%0.1f;0;5 ", (targets > 1) ? host->name : "", (float)host->mos, (float)warn.mos, (float)crit.mos); | ||
1492 | } | ||
1493 | if (score_mode && host->pl<100) { | ||
1494 | printf("%sscore=%u;%u;%u;0;100 ", (targets > 1) ? host->name : "", (int)host->score, (int)warn.score, (int)crit.score); | ||
1495 | } | ||
1226 | host = host->next; | 1496 | host = host->next; |
1227 | } | 1497 | } |
1228 | 1498 | ||
@@ -1312,6 +1582,7 @@ add_target_ip(char *arg, struct sockaddr_storage *in) | |||
1312 | /* set the values. use calling name for output */ | 1582 | /* set the values. use calling name for output */ |
1313 | host->name = strdup(arg); | 1583 | host->name = strdup(arg); |
1314 | 1584 | ||
1585 | |||
1315 | /* fill out the sockaddr_storage struct */ | 1586 | /* fill out the sockaddr_storage struct */ |
1316 | if(address_family == AF_INET) { | 1587 | if(address_family == AF_INET) { |
1317 | host_sin = (struct sockaddr_in *)&host->saddr_in; | 1588 | host_sin = (struct sockaddr_in *)&host->saddr_in; |
@@ -1324,7 +1595,22 @@ add_target_ip(char *arg, struct sockaddr_storage *in) | |||
1324 | memcpy(host_sin6->sin6_addr.s6_addr, sin6->sin6_addr.s6_addr, sizeof host_sin6->sin6_addr.s6_addr); | 1595 | memcpy(host_sin6->sin6_addr.s6_addr, sin6->sin6_addr.s6_addr, sizeof host_sin6->sin6_addr.s6_addr); |
1325 | } | 1596 | } |
1326 | 1597 | ||
1598 | /* fill out the sockaddr_in struct */ | ||
1327 | host->rtmin = INFINITY; | 1599 | host->rtmin = INFINITY; |
1600 | host->rtmax = 0; | ||
1601 | host->jitter=0; | ||
1602 | host->jitter_max=0; | ||
1603 | host->jitter_min=INFINITY; | ||
1604 | host->last_tdiff=0; | ||
1605 | host->order_status=STATE_OK; | ||
1606 | host->last_icmp_seq=0; | ||
1607 | host->rta_status=0; | ||
1608 | host->pl_status=0; | ||
1609 | host->jitter_status=0; | ||
1610 | host->mos_status=0; | ||
1611 | host->score_status=0; | ||
1612 | host->pl_status=0; | ||
1613 | |||
1328 | 1614 | ||
1329 | if(!list) list = cursor = host; | 1615 | if(!list) list = cursor = host; |
1330 | else cursor->next = host; | 1616 | else cursor->next = host; |
@@ -1472,7 +1758,7 @@ get_timevar(const char *str) | |||
1472 | 1758 | ||
1473 | /* unit might be given as ms|m (millisec), | 1759 | /* unit might be given as ms|m (millisec), |
1474 | * us|u (microsec) or just plain s, for seconds */ | 1760 | * us|u (microsec) or just plain s, for seconds */ |
1475 | u = p = '\0'; | 1761 | p = '\0'; |
1476 | u = str[len - 1]; | 1762 | u = str[len - 1]; |
1477 | if(len >= 2 && !isdigit((int)str[len - 2])) p = str[len - 2]; | 1763 | if(len >= 2 && !isdigit((int)str[len - 2])) p = str[len - 2]; |
1478 | if(p && u == 's') u = p; | 1764 | if(p && u == 's') u = p; |
@@ -1484,7 +1770,7 @@ get_timevar(const char *str) | |||
1484 | else if(u == 's') factor = 1000000; /* seconds */ | 1770 | else if(u == 's') factor = 1000000; /* seconds */ |
1485 | if(debug > 2) printf("factor is %u\n", factor); | 1771 | if(debug > 2) printf("factor is %u\n", factor); |
1486 | 1772 | ||
1487 | i = strtoul(str, &ptr, 0); | 1773 | i = strtoul(str, &ptr, 0); |
1488 | if(!ptr || *ptr != '.' || strlen(ptr) < 2 || factor == 1) | 1774 | if(!ptr || *ptr != '.' || strlen(ptr) < 2 || factor == 1) |
1489 | return i * factor; | 1775 | return i * factor; |
1490 | 1776 | ||
@@ -1530,6 +1816,46 @@ get_threshold(char *str, threshold *th) | |||
1530 | return 0; | 1816 | return 0; |
1531 | } | 1817 | } |
1532 | 1818 | ||
1819 | /* not too good at checking errors, but it'll do (main() should barfe on -1) */ | ||
1820 | static int | ||
1821 | get_threshold2(char *str, threshold *warn, threshold *crit, int type) | ||
1822 | { | ||
1823 | char *p = NULL, i = 0; | ||
1824 | |||
1825 | if(!str || !strlen(str) || !warn || !crit) return -1; | ||
1826 | /* pointer magic slims code by 10 lines. i is bof-stop on stupid libc's */ | ||
1827 | p = &str[strlen(str) - 1]; | ||
1828 | while(p != &str[0]) { | ||
1829 | if( (*p == 'm') || (*p == '%') ) *p = '\0'; | ||
1830 | else if(*p == ',' && i) { | ||
1831 | *p = '\0'; /* reset it so get_timevar(str) works nicely later */ | ||
1832 | if (type==1) | ||
1833 | crit->rta = atof(p+1)*1000; | ||
1834 | else if (type==2) | ||
1835 | crit->pl = (unsigned char)strtoul(p+1, NULL, 0); | ||
1836 | else if (type==3) | ||
1837 | crit->jitter = atof(p+1); | ||
1838 | else if (type==4) | ||
1839 | crit->mos = atof(p+1); | ||
1840 | else if (type==5) | ||
1841 | crit->score = atof(p+1); | ||
1842 | } | ||
1843 | i = 1; | ||
1844 | p--; | ||
1845 | } | ||
1846 | if (type==1) | ||
1847 | warn->rta = atof(p)*1000; | ||
1848 | else if (type==2) | ||
1849 | warn->pl = (unsigned char)strtoul(p, NULL, 0); | ||
1850 | if (type==3) | ||
1851 | warn->jitter = atof(p); | ||
1852 | else if (type==4) | ||
1853 | warn->mos = atof(p); | ||
1854 | else if (type==5) | ||
1855 | warn->score = atof(p); | ||
1856 | return 0; | ||
1857 | } | ||
1858 | |||
1533 | unsigned short | 1859 | unsigned short |
1534 | icmp_checksum(uint16_t *p, size_t n) | 1860 | icmp_checksum(uint16_t *p, size_t n) |
1535 | { | 1861 | { |
@@ -1555,10 +1881,9 @@ icmp_checksum(uint16_t *p, size_t n) | |||
1555 | void | 1881 | void |
1556 | print_help(void) | 1882 | print_help(void) |
1557 | { | 1883 | { |
1558 | |||
1559 | /*print_revision (progname);*/ /* FIXME: Why? */ | 1884 | /*print_revision (progname);*/ /* FIXME: Why? */ |
1560 | |||
1561 | printf ("Copyright (c) 2005 Andreas Ericsson <ae@op5.se>\n"); | 1885 | printf ("Copyright (c) 2005 Andreas Ericsson <ae@op5.se>\n"); |
1886 | |||
1562 | printf (COPYRIGHT, copyright, email); | 1887 | printf (COPYRIGHT, copyright, email); |
1563 | 1888 | ||
1564 | printf ("\n\n"); | 1889 | printf ("\n\n"); |
@@ -1578,11 +1903,29 @@ print_help(void) | |||
1578 | printf (" %s\n", "-c"); | 1903 | printf (" %s\n", "-c"); |
1579 | printf (" %s", _("critical threshold (currently ")); | 1904 | printf (" %s", _("critical threshold (currently ")); |
1580 | printf ("%0.3fms,%u%%)\n", (float)crit.rta / 1000, crit.pl); | 1905 | printf ("%0.3fms,%u%%)\n", (float)crit.rta / 1000, crit.pl); |
1906 | |||
1907 | printf (" %s\n", "-R"); | ||
1908 | printf (" %s\n", _("RTA, round trip average, mode warning,critical, ex. 100ms,200ms unit in ms")); | ||
1909 | printf (" %s\n", "-P"); | ||
1910 | printf (" %s\n", _("packet loss mode, ex. 40%,50% , unit in %")); | ||
1911 | printf (" %s\n", "-J"); | ||
1912 | printf (" %s\n", _("jitter mode warning,critical, ex. 40.000ms,50.000ms , unit in ms ")); | ||
1913 | printf (" %s\n", "-M"); | ||
1914 | printf (" %s\n", _("MOS mode, between 0 and 4.4 warning,critical, ex. 3.5,3.0")); | ||
1915 | printf (" %s\n", "-S"); | ||
1916 | printf (" %s\n", _("score mode, max value 100 warning,critical, ex. 80,70 ")); | ||
1917 | printf (" %s\n", "-O"); | ||
1918 | printf (" %s\n", _("detect out of order ICMP packts ")); | ||
1919 | printf (" %s\n", "-H"); | ||
1920 | printf (" %s\n", _("specify a target")); | ||
1581 | printf (" %s\n", "-s"); | 1921 | printf (" %s\n", "-s"); |
1582 | printf (" %s\n", _("specify a source IP address or device name")); | 1922 | printf (" %s\n", _("specify a source IP address or device name")); |
1583 | printf (" %s\n", "-n"); | 1923 | printf (" %s\n", "-n"); |
1584 | printf (" %s", _("number of packets to send (currently ")); | 1924 | printf (" %s", _("number of packets to send (currently ")); |
1585 | printf ("%u)\n",packets); | 1925 | printf ("%u)\n",packets); |
1926 | printf (" %s\n", "-p"); | ||
1927 | printf (" %s", _("number of packets to send (currently ")); | ||
1928 | printf ("%u)\n",packets); | ||
1586 | printf (" %s\n", "-i"); | 1929 | printf (" %s\n", "-i"); |
1587 | printf (" %s", _("max packet interval (currently ")); | 1930 | printf (" %s", _("max packet interval (currently ")); |
1588 | printf ("%0.3fms)\n",(float)pkt_interval / 1000); | 1931 | printf ("%0.3fms)\n",(float)pkt_interval / 1000); |
@@ -1603,9 +1946,9 @@ print_help(void) | |||
1603 | printf (" %s %u + %d)\n", _("Packet size will be data bytes + icmp header (currently"),icmp_data_size, ICMP_MINLEN); | 1946 | printf (" %s %u + %d)\n", _("Packet size will be data bytes + icmp header (currently"),icmp_data_size, ICMP_MINLEN); |
1604 | printf (" %s\n", "-v"); | 1947 | printf (" %s\n", "-v"); |
1605 | printf (" %s\n", _("verbose")); | 1948 | printf (" %s\n", _("verbose")); |
1606 | |||
1607 | printf ("\n"); | 1949 | printf ("\n"); |
1608 | printf ("%s\n", _("Notes:")); | 1950 | printf ("%s\n", _("Notes:")); |
1951 | printf ("%s\n", _("If not mode R,P,J,M,S or O is informed, default icmp behavior, RTA and packet loss")); | ||
1609 | printf (" %s\n", _("The -H switch is optional. Naming a host (or several) to check is not.")); | 1952 | printf (" %s\n", _("The -H switch is optional. Naming a host (or several) to check is not.")); |
1610 | printf ("\n"); | 1953 | printf ("\n"); |
1611 | printf (" %s\n", _("Threshold format for -w and -c is 200.25,60% for 200.25 msec RTA and 60%")); | 1954 | printf (" %s\n", _("Threshold format for -w and -c is 200.25,60% for 200.25 msec RTA and 60%")); |