diff options
-rw-r--r-- | plugins/check_icmp.c | 166 | ||||
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | po/fr.po | 4 |
3 files changed, 105 insertions, 66 deletions
diff --git a/plugins/check_icmp.c b/plugins/check_icmp.c index 361e924e..cbd68642 100644 --- a/plugins/check_icmp.c +++ b/plugins/check_icmp.c | |||
@@ -21,6 +21,15 @@ | |||
21 | * The fping website can be found at http://www.fping.com | 21 | * The fping website can be found at http://www.fping.com |
22 | */ | 22 | */ |
23 | 23 | ||
24 | const char *progname = "check_icmp"; | ||
25 | const char *revision = "$Revision$"; | ||
26 | const char *copyright = "2004"; | ||
27 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | ||
28 | |||
29 | #include "common.h" | ||
30 | #include "netutils.h" | ||
31 | #include "utils.h" | ||
32 | |||
24 | #include <stdio.h> | 33 | #include <stdio.h> |
25 | #include <errno.h> | 34 | #include <errno.h> |
26 | #include <time.h> | 35 | #include <time.h> |
@@ -66,8 +75,8 @@ extern char *optarg; | |||
66 | extern int optind, opterr; | 75 | extern int optind, opterr; |
67 | 76 | ||
68 | /*** Constants ***/ | 77 | /*** Constants ***/ |
69 | #define EMAIL "ae@op5.se" | 78 | //#define EMAIL "ae@op5.se" |
70 | #define VERSION "0.8.1" | 79 | //#define VERSION "0.8.1" |
71 | 80 | ||
72 | #ifndef INADDR_NONE | 81 | #ifndef INADDR_NONE |
73 | # define INADDR_NONE 0xffffffU | 82 | # define INADDR_NONE 0xffffffU |
@@ -219,9 +228,9 @@ int num_pingsent = 0; /* total pings sent */ | |||
219 | int num_pingreceived = 0; /* total pings received */ | 228 | int num_pingreceived = 0; /* total pings received */ |
220 | int num_othericmprcvd = 0; /* total non-echo-reply ICMP received */ | 229 | int num_othericmprcvd = 0; /* total non-echo-reply ICMP received */ |
221 | 230 | ||
222 | struct timeval current_time; /* current time (pseudo) */ | 231 | struct timeval current_time; /* current time (pseudo) */ |
223 | struct timeval start_time; | 232 | struct timeval my_start_time; /* conflict with utils.c 33, but not found ?? */ |
224 | struct timeval end_time; | 233 | struct timeval my_end_time; /* conflict with utils.c 33, but not found ?? */ |
225 | struct timeval last_send_time; /* time last ping was sent */ | 234 | struct timeval last_send_time; /* time last ping was sent */ |
226 | struct timezone tz; | 235 | struct timezone tz; |
227 | 236 | ||
@@ -245,23 +254,29 @@ int recvfrom_wto(int, char *, int, struct sockaddr *, int); | |||
245 | void remove_job(HOST_ENTRY *); | 254 | void remove_job(HOST_ENTRY *); |
246 | void send_ping(int, HOST_ENTRY *); | 255 | void send_ping(int, HOST_ENTRY *); |
247 | long timeval_diff(struct timeval *, struct timeval *); | 256 | long timeval_diff(struct timeval *, struct timeval *); |
248 | void usage(void); | 257 | //void usage(void); |
249 | int wait_for_reply(int); | 258 | int wait_for_reply(int); |
250 | void finish(void); | 259 | void finish(void); |
251 | int handle_random_icmp(struct icmp *, struct sockaddr_in *); | 260 | int handle_random_icmp(struct icmp *, struct sockaddr_in *); |
252 | char *sprint_tm(int); | 261 | char *sprint_tm(int); |
253 | int get_threshold(char *, threshold *); | 262 | int get_threshold(char *, threshold *); |
254 | 263 | ||
264 | /* common functions */ | ||
265 | void print_help (void); | ||
266 | void print_usage (void); | ||
267 | |||
255 | /*** the various exit-states */ | 268 | /*** the various exit-states */ |
256 | enum { | 269 | /*enum { |
257 | STATE_OK = 0, | 270 | STATE_OK = 0, |
258 | STATE_WARNING, | 271 | STATE_WARNING, |
259 | STATE_CRITICAL, | 272 | STATE_CRITICAL, |
260 | STATE_UNKNOWN, | 273 | STATE_UNKNOWN, |
261 | STATE_DEPENDANT, | 274 | STATE_DEPENDANT, |
262 | STATE_OOB | 275 | STATE_OOB |
263 | }; | 276 | };*/ |
277 | |||
264 | /* the strings that correspond to them */ | 278 | /* the strings that correspond to them */ |
279 | /* | ||
265 | char *status_string[STATE_OOB] = { | 280 | char *status_string[STATE_OOB] = { |
266 | "OK", | 281 | "OK", |
267 | "WARNING", | 282 | "WARNING", |
@@ -269,6 +284,7 @@ char *status_string[STATE_OOB] = { | |||
269 | "UNKNOWN", | 284 | "UNKNOWN", |
270 | "DEPENDANT" | 285 | "DEPENDANT" |
271 | }; | 286 | }; |
287 | */ | ||
272 | 288 | ||
273 | int status = STATE_OK; | 289 | int status = STATE_OK; |
274 | int fin_stat = STATE_OK; | 290 | int fin_stat = STATE_OK; |
@@ -288,6 +304,10 @@ int main(int argc, char **argv) | |||
288 | if(strchr(argv[0], '/')) prog = strrchr(argv[0], '/') + 1; | 304 | if(strchr(argv[0], '/')) prog = strrchr(argv[0], '/') + 1; |
289 | else prog = argv[0]; | 305 | else prog = argv[0]; |
290 | 306 | ||
307 | setlocale (LC_ALL, ""); | ||
308 | bindtextdomain (PACKAGE, LOCALEDIR); | ||
309 | textdomain (PACKAGE); | ||
310 | |||
291 | /* check if we are root */ | 311 | /* check if we are root */ |
292 | if(geteuid()) { | 312 | if(geteuid()) { |
293 | printf("Root access needed (for raw sockets)\n"); | 313 | printf("Root access needed (for raw sockets)\n"); |
@@ -309,7 +329,7 @@ int main(int argc, char **argv) | |||
309 | seteuid(uid); | 329 | seteuid(uid); |
310 | } | 330 | } |
311 | 331 | ||
312 | if(argc < 2) usage(); | 332 | if(argc < 2) print_usage(); |
313 | 333 | ||
314 | ident = getpid() & 0xFFFF; | 334 | ident = getpid() & 0xFFFF; |
315 | 335 | ||
@@ -356,35 +376,35 @@ int main(int argc, char **argv) | |||
356 | case 'w': | 376 | case 'w': |
357 | if(get_threshold(optarg, &warn)) { | 377 | if(get_threshold(optarg, &warn)) { |
358 | printf("Illegal threshold pair specified for -%c", c); | 378 | printf("Illegal threshold pair specified for -%c", c); |
359 | usage(); | 379 | print_usage(); |
360 | } | 380 | } |
361 | break; | 381 | break; |
362 | 382 | ||
363 | case 'c': | 383 | case 'c': |
364 | if(get_threshold(optarg, &crit)) { | 384 | if(get_threshold(optarg, &crit)) { |
365 | printf("Illegal threshold pair specified for -%c", c); | 385 | printf("Illegal threshold pair specified for -%c", c); |
366 | usage(); | 386 | print_usage(); |
367 | } | 387 | } |
368 | break; | 388 | break; |
369 | 389 | ||
370 | case 't': | 390 | case 't': |
371 | if(!(timeout = (u_int) strtoul(optarg, NULL, 0) * 100)) { | 391 | if(!(timeout = (u_int) strtoul(optarg, NULL, 0) * 100)) { |
372 | printf("option -%c requires integer argument\n", c); | 392 | printf("option -%c requires integer argument\n", c); |
373 | usage(); | 393 | print_usage(); |
374 | } | 394 | } |
375 | break; | 395 | break; |
376 | 396 | ||
377 | case 'r': | 397 | case 'r': |
378 | if(!(retry = (u_int) strtoul(optarg, NULL, 0))) { | 398 | if(!(retry = (u_int) strtoul(optarg, NULL, 0))) { |
379 | printf("option -%c requires integer argument\n", c); | 399 | printf("option -%c requires integer argument\n", c); |
380 | usage(); | 400 | print_usage(); |
381 | } | 401 | } |
382 | break; | 402 | break; |
383 | 403 | ||
384 | case 'i': | 404 | case 'i': |
385 | if(!(interval = (u_int) strtoul(optarg, NULL, 0) * 100)) { | 405 | if(!(interval = (u_int) strtoul(optarg, NULL, 0) * 100)) { |
386 | printf("option -%c requires positive non-zero integer argument\n", c); | 406 | printf("option -%c requires positive non-zero integer argument\n", c); |
387 | usage(); | 407 | print_usage(); |
388 | } | 408 | } |
389 | break; | 409 | break; |
390 | 410 | ||
@@ -392,19 +412,19 @@ int main(int argc, char **argv) | |||
392 | case 'n': | 412 | case 'n': |
393 | if(!(count = (u_int) strtoul(optarg, NULL, 0))) { | 413 | if(!(count = (u_int) strtoul(optarg, NULL, 0))) { |
394 | printf("option -%c requires positive non-zero integer argument\n", c); | 414 | printf("option -%c requires positive non-zero integer argument\n", c); |
395 | usage(); | 415 | print_usage(); |
396 | } | 416 | } |
397 | break; | 417 | break; |
398 | 418 | ||
399 | case 'b': | 419 | case 'b': |
400 | if(!(ping_data_size = (u_int) strtoul(optarg, NULL, 0))) { | 420 | if(!(ping_data_size = (u_int) strtoul(optarg, NULL, 0))) { |
401 | printf("option -%c requires integer argument\n", c); | 421 | printf("option -%c requires integer argument\n", c); |
402 | usage(); | 422 | print_usage(); |
403 | } | 423 | } |
404 | break; | 424 | break; |
405 | 425 | ||
406 | case 'h': | 426 | case 'h': |
407 | usage(); | 427 | print_usage(); |
408 | break; | 428 | break; |
409 | 429 | ||
410 | case 'e': | 430 | case 'e': |
@@ -437,7 +457,7 @@ int main(int argc, char **argv) | |||
437 | 457 | ||
438 | case 'v': | 458 | case 'v': |
439 | printf("%s: Version %s $Date$\n", prog, VERSION); | 459 | printf("%s: Version %s $Date$\n", prog, VERSION); |
440 | printf("%s: comments to %s\n", prog, EMAIL); | 460 | printf("%s: comments to %s\n", prog, email); |
441 | exit(STATE_OK); | 461 | exit(STATE_OK); |
442 | 462 | ||
443 | case 'g': | 463 | case 'g': |
@@ -448,7 +468,7 @@ int main(int argc, char **argv) | |||
448 | 468 | ||
449 | default: | 469 | default: |
450 | printf("option flag -%c specified, but not recognized\n", c); | 470 | printf("option flag -%c specified, but not recognized\n", c); |
451 | usage(); | 471 | print_usage(); |
452 | break; | 472 | break; |
453 | } | 473 | } |
454 | } | 474 | } |
@@ -479,27 +499,27 @@ int main(int argc, char **argv) | |||
479 | prog, MIN_INTERVAL, MAX_RETRY); | 499 | prog, MIN_INTERVAL, MAX_RETRY); |
480 | printf("Current settings; i = %d, r = %d\n", | 500 | printf("Current settings; i = %d, r = %d\n", |
481 | interval / 100, retry); | 501 | interval / 100, retry); |
482 | usage(); | 502 | print_usage(); |
483 | } | 503 | } |
484 | 504 | ||
485 | if((ping_data_size > MAX_PING_DATA) || (ping_data_size < MIN_PING_DATA)) { | 505 | if((ping_data_size > MAX_PING_DATA) || (ping_data_size < MIN_PING_DATA)) { |
486 | printf("%s: data size %u not valid, must be between %u and %u\n", | 506 | printf("%s: data size %u not valid, must be between %u and %u\n", |
487 | prog, ping_data_size, MIN_PING_DATA, MAX_PING_DATA); | 507 | prog, ping_data_size, MIN_PING_DATA, MAX_PING_DATA); |
488 | usage(); | 508 | print_usage(); |
489 | 509 | ||
490 | } | 510 | } |
491 | 511 | ||
492 | if((backoff > MAX_BACKOFF_FACTOR) || (backoff < MIN_BACKOFF_FACTOR)) { | 512 | if((backoff > MAX_BACKOFF_FACTOR) || (backoff < MIN_BACKOFF_FACTOR)) { |
493 | printf("%s: backoff factor %.1f not valid, must be between %.1f and %.1f\n", | 513 | printf("%s: backoff factor %.1f not valid, must be between %.1f and %.1f\n", |
494 | prog, backoff, MIN_BACKOFF_FACTOR, MAX_BACKOFF_FACTOR); | 514 | prog, backoff, MIN_BACKOFF_FACTOR, MAX_BACKOFF_FACTOR); |
495 | usage(); | 515 | print_usage(); |
496 | 516 | ||
497 | } | 517 | } |
498 | 518 | ||
499 | if(count > MAX_COUNT) { | 519 | if(count > MAX_COUNT) { |
500 | printf("%s: count %u not valid, must be less than %u\n", | 520 | printf("%s: count %u not valid, must be less than %u\n", |
501 | prog, count, MAX_COUNT); | 521 | prog, count, MAX_COUNT); |
502 | usage(); | 522 | print_usage(); |
503 | } | 523 | } |
504 | 524 | ||
505 | if(count_flag) { | 525 | if(count_flag) { |
@@ -517,7 +537,7 @@ int main(int argc, char **argv) | |||
517 | /* generate requires command line parameters beyond the switches */ | 537 | /* generate requires command line parameters beyond the switches */ |
518 | if(generate_flag && !*argv) { | 538 | if(generate_flag && !*argv) { |
519 | printf("generate flag requires command line parameters beyond switches\n"); | 539 | printf("generate flag requires command line parameters beyond switches\n"); |
520 | usage(); | 540 | print_usage(); |
521 | } | 541 | } |
522 | 542 | ||
523 | if(*argv && !generate_flag) { | 543 | if(*argv && !generate_flag) { |
@@ -546,7 +566,7 @@ int main(int argc, char **argv) | |||
546 | 566 | ||
547 | if(!num_hosts) { | 567 | if(!num_hosts) { |
548 | printf("No hosts to work with!\n\n"); | 568 | printf("No hosts to work with!\n\n"); |
549 | usage(); | 569 | print_usage(); |
550 | } | 570 | } |
551 | 571 | ||
552 | /* allocate array to hold outstanding ping requests */ | 572 | /* allocate array to hold outstanding ping requests */ |
@@ -566,8 +586,8 @@ int main(int argc, char **argv) | |||
566 | 586 | ||
567 | signal(SIGINT, (void *)finish); | 587 | signal(SIGINT, (void *)finish); |
568 | 588 | ||
569 | gettimeofday(&start_time, &tz); | 589 | gettimeofday(&my_start_time, &tz); |
570 | current_time = start_time; | 590 | current_time = my_start_time; |
571 | 591 | ||
572 | last_send_time.tv_sec = current_time.tv_sec - 10000; | 592 | last_send_time.tv_sec = current_time.tv_sec - 10000; |
573 | 593 | ||
@@ -666,7 +686,7 @@ void finish() | |||
666 | int i; | 686 | int i; |
667 | HOST_ENTRY *h; | 687 | HOST_ENTRY *h; |
668 | 688 | ||
669 | gettimeofday(&end_time, &tz); | 689 | gettimeofday(&my_end_time, &tz); |
670 | 690 | ||
671 | /* tot up unreachables */ | 691 | /* tot up unreachables */ |
672 | for(i=0; i<num_hosts; i++) { | 692 | for(i=0; i<num_hosts; i++) { |
@@ -712,7 +732,7 @@ void finish() | |||
712 | 732 | ||
713 | if(num_hosts == 1 || status != STATE_OK) { | 733 | if(num_hosts == 1 || status != STATE_OK) { |
714 | printf("%s - %s: rta %s ms, lost %d%%", | 734 | printf("%s - %s: rta %s ms, lost %d%%", |
715 | status_string[status], h->host, | 735 | state_text(status), h->host, |
716 | sprint_tm(h->total_time / h->num_recv), | 736 | sprint_tm(h->total_time / h->num_recv), |
717 | h->num_sent > 0 ? ((h->num_sent - h->num_recv) * 100) / h->num_sent : 0 | 737 | h->num_sent > 0 ? ((h->num_sent - h->num_recv) * 100) / h->num_sent : 0 |
718 | ); | 738 | ); |
@@ -735,7 +755,7 @@ void finish() | |||
735 | 755 | ||
736 | if(num_noaddress) { | 756 | if(num_noaddress) { |
737 | printf("No hostaddress specified.\n"); | 757 | printf("No hostaddress specified.\n"); |
738 | usage(); | 758 | print_usage(); |
739 | } | 759 | } |
740 | else if(num_alive != num_hosts) { | 760 | else if(num_alive != num_hosts) { |
741 | /* for future multi-check support */ | 761 | /* for future multi-check support */ |
@@ -1340,37 +1360,57 @@ int get_threshold(char *str, threshold *th) | |||
1340 | return 0; | 1360 | return 0; |
1341 | } | 1361 | } |
1342 | 1362 | ||
1343 | /* make a blahblah */ | 1363 | void |
1344 | void usage(void) | 1364 | print_help (void) |
1345 | { | 1365 | { |
1346 | printf("\nUsage: %s [options] [targets]\n", prog); | 1366 | print_revision (progname, revision); |
1347 | printf(" -H host target host\n"); | 1367 | |
1348 | printf(" -b n ping packet size in bytes (default %d)\n", ping_data_size); | 1368 | printf ("Copyright (c) 2004 Andreas Ericsson <ae@op5.se>\n"); |
1349 | printf(" -n|p n number of pings to send to each target (default %d)\n", count); | 1369 | printf (COPYRIGHT, copyright, email); |
1350 | printf(" -r n number of retries (default %d)\n", retry); | 1370 | |
1351 | printf(" -t n timeout value (in msec) (default %d)\n", timeout / 100); | 1371 | printf (_("This plugin will check hosts sending icmp pings\n\n")); |
1352 | printf(" -i n packet interval (in msec) (default %d)\n", DEFAULT_INTERVAL); | 1372 | |
1353 | /* XXX - possibly on todo-list | 1373 | print_usage (); |
1354 | printf(" -m ping multiple interfaces on target host\n"); | 1374 | |
1355 | printf(" -a show targets that are alive\n"); | 1375 | printf (_(UT_HELP_VRSN)); |
1356 | printf(" -d show dead targets\n"); | 1376 | |
1357 | */ printf(" -v show version\n"); | 1377 | printf (_("\ |
1358 | printf(" -D increase debug output level\n"); | 1378 | -H, \n\ |
1359 | printf(" -w warning threshold pair, given as RTA[ums],PL[%%]\n"); | 1379 | Host name argument for servers\n\ |
1360 | printf(" -c critical threshold pair, given as RTA[ums],PL[%%]\n"); | 1380 | -b \n\ |
1361 | printf("\n"); | 1381 | ping packet size in bytes (default %d)\n\ |
1362 | printf("Note:\n"); | 1382 | -n \n\ |
1363 | printf("* This program requires root privileges to run properly.\n"); | 1383 | number of pings to send to each target (default %d)\n\ |
1364 | printf(" If it is run as setuid root it will halt with an error if;\n"); | 1384 | -r \n\ |
1365 | printf(" interval < 25 || retries > 5\n\n"); | 1385 | number of retries (default %d)\n\ |
1366 | printf("* Threshold pairs are given as such;\n"); | 1386 | -t \n\ |
1367 | printf(" 100,40%%\n"); | 1387 | timeout value (in msec) (default %d)\n\ |
1368 | printf(" to set a threshold value pair of 100 milliseconds and 40%% packetloss\n"); | 1388 | -i \n\ |
1369 | printf(" The '%%' sign is optional, and if rta value is suffixed by;\n"); | 1389 | packet interval (in msec) (default %d)\n\ |
1370 | printf(" s, rta time is set in seconds\n"); | 1390 | -w \n\ |
1371 | printf(" m, rta time will be set in milliseconds (this is default)\n"); | 1391 | warning threshold pair, given as RTA[ums],PL[%%]\n\ |
1372 | printf(" u, rta time will be set in microseconds\n"); | 1392 | -c \n\ |
1373 | printf(" Decimal points are silently ignored for sideways compatibility.\n"); | 1393 | critical threshold pair, given as RTA[ums],PL[%%]\n\ |
1374 | printf("\n"); | 1394 | -D \n\ |
1375 | exit(3); | 1395 | increase debug output level\n\n"),ping_data_size,count,retry,(timeout / 100),DEFAULT_INTERVAL); |
1376 | } /* usage() */ | 1396 | |
1397 | printf (_(UT_WARN_CRIT)); | ||
1398 | |||
1399 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
1400 | |||
1401 | printf (_(UT_VERBOSE)); | ||
1402 | |||
1403 | // printf (_("This plugin will check hosts sending icmp pings\n")); | ||
1404 | |||
1405 | printf (_(UT_SUPPORT)); | ||
1406 | } | ||
1407 | |||
1408 | void | ||
1409 | print_usage (void) | ||
1410 | { | ||
1411 | printf ("\ | ||
1412 | Usage: %s -H <vhost> | [-b <ping packet size in bytes>] [-n <number of pings>]\n\ | ||
1413 | [-r <number of retries>] [-t <timeout>] [-i packet interval]\n\ | ||
1414 | [-w <warning threshold>] [-c <critical threshold>]\n\ | ||
1415 | [-D <debug>] \n", progname); | ||
1416 | } | ||
diff --git a/po/POTFILES.in b/po/POTFILES.in index 3697da4e..ba5b8c4d 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in | |||
@@ -7,6 +7,7 @@ plugins/check_fping.c | |||
7 | plugins/check_game.c | 7 | plugins/check_game.c |
8 | plugins/check_hpjd.c | 8 | plugins/check_hpjd.c |
9 | plugins/check_http.c | 9 | plugins/check_http.c |
10 | plugins/check_icmp.c | ||
10 | plugins/check_ldap.c | 11 | plugins/check_ldap.c |
11 | plugins/check_load.c | 12 | plugins/check_load.c |
12 | plugins/check_mrtg.c | 13 | plugins/check_mrtg.c |
@@ -12,7 +12,7 @@ msgstr "" | |||
12 | "POT-Creation-Date: 2004-12-20 19:49+1100\n" | 12 | "POT-Creation-Date: 2004-12-20 19:49+1100\n" |
13 | "PO-Revision-Date: 2004-12-20 21:03+0100\n" | 13 | "PO-Revision-Date: 2004-12-20 21:03+0100\n" |
14 | "Last-Translator: Benoit Mortier <benoit.mortier@opensides.be>\n" | 14 | "Last-Translator: Benoit Mortier <benoit.mortier@opensides.be>\n" |
15 | "Language-Team: Français <fr@li.org>\n" | 15 | "Language-Team: Français <benoit.mortier@opensides.be>\n" |
16 | "MIME-Version: 1.0\n" | 16 | "MIME-Version: 1.0\n" |
17 | "Content-Type: text/plain; charset=UTF-8\n" | 17 | "Content-Type: text/plain; charset=UTF-8\n" |
18 | "Content-Transfer-Encoding: 8bit\n" | 18 | "Content-Transfer-Encoding: 8bit\n" |
@@ -1633,8 +1633,6 @@ msgid "" | |||
1633 | "this plugin works well for monitoring that kind of data as well.\n" | 1633 | "this plugin works well for monitoring that kind of data as well.\n" |
1634 | "\n" | 1634 | "\n" |
1635 | msgstr "" | 1635 | msgstr "" |
1636 | "Ce plugin est utile pour surveiller des données MRTG qui ne correspond pas\n" | ||
1637 | "à de la bande passante. (Utilisez le plugin check_mrtgtraf" | ||
1638 | 1636 | ||
1639 | #: plugins/check_mrtg.c:359 | 1637 | #: plugins/check_mrtg.c:359 |
1640 | #, c-format | 1638 | #, c-format |