diff options
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/check_dig.c | 19 | ||||
| -rw-r--r-- | plugins/check_ldap.c | 5 | ||||
| -rw-r--r-- | plugins/check_ntp.c | 9 | ||||
| -rw-r--r-- | plugins/check_ntp_peer.c | 3 | ||||
| -rw-r--r-- | plugins/check_ntp_time.c | 9 | ||||
| -rw-r--r-- | plugins/check_pgsql.c | 2 | ||||
| -rw-r--r-- | plugins/check_procs.c | 113 | ||||
| -rw-r--r-- | plugins/check_snmp.c | 49 | ||||
| -rw-r--r-- | plugins/check_ssh.c | 2 | ||||
| -rw-r--r-- | plugins/common.h | 1 | ||||
| -rw-r--r-- | plugins/t/check_dig.t | 22 |
11 files changed, 110 insertions, 124 deletions
diff --git a/plugins/check_dig.c b/plugins/check_dig.c index 893e0a14..3c80cb72 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c | |||
| @@ -54,6 +54,7 @@ char *record_type = "A"; | |||
| 54 | char *expected_address = NULL; | 54 | char *expected_address = NULL; |
| 55 | char *dns_server = NULL; | 55 | char *dns_server = NULL; |
| 56 | char *dig_args = ""; | 56 | char *dig_args = ""; |
| 57 | char *query_transport = ""; | ||
| 57 | int verbose = FALSE; | 58 | int verbose = FALSE; |
| 58 | int server_port = DEFAULT_PORT; | 59 | int server_port = DEFAULT_PORT; |
| 59 | double warning_interval = UNDEFINED; | 60 | double warning_interval = UNDEFINED; |
| @@ -87,8 +88,8 @@ main (int argc, char **argv) | |||
| 87 | usage_va(_("Could not parse arguments")); | 88 | usage_va(_("Could not parse arguments")); |
| 88 | 89 | ||
| 89 | /* get the command to run */ | 90 | /* get the command to run */ |
| 90 | xasprintf (&command_line, "%s @%s -p %d %s -t %s %s", | 91 | xasprintf (&command_line, "%s @%s -p %d %s -t %s %s %s", |
| 91 | PATH_TO_DIG, dns_server, server_port, query_address, record_type, dig_args); | 92 | PATH_TO_DIG, dns_server, server_port, query_address, record_type, dig_args, query_transport); |
| 92 | 93 | ||
| 93 | alarm (timeout_interval); | 94 | alarm (timeout_interval); |
| 94 | gettimeofday (&tv, NULL); | 95 | gettimeofday (&tv, NULL); |
| @@ -199,6 +200,8 @@ process_arguments (int argc, char **argv) | |||
| 199 | {"record_type", required_argument, 0, 'T'}, | 200 | {"record_type", required_argument, 0, 'T'}, |
| 200 | {"expected_address", required_argument, 0, 'a'}, | 201 | {"expected_address", required_argument, 0, 'a'}, |
| 201 | {"port", required_argument, 0, 'p'}, | 202 | {"port", required_argument, 0, 'p'}, |
| 203 | {"use-ipv4", no_argument, 0, '4'}, | ||
| 204 | {"use-ipv6", no_argument, 0, '6'}, | ||
| 202 | {0, 0, 0, 0} | 205 | {0, 0, 0, 0} |
| 203 | }; | 206 | }; |
| 204 | 207 | ||
| @@ -206,7 +209,7 @@ process_arguments (int argc, char **argv) | |||
| 206 | return ERROR; | 209 | return ERROR; |
| 207 | 210 | ||
| 208 | while (1) { | 211 | while (1) { |
| 209 | c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:p:a:A:", longopts, &option); | 212 | c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:p:a:A:46", longopts, &option); |
| 210 | 213 | ||
| 211 | if (c == -1 || c == EOF) | 214 | if (c == -1 || c == EOF) |
| 212 | break; | 215 | break; |
| @@ -269,6 +272,12 @@ process_arguments (int argc, char **argv) | |||
| 269 | case 'a': | 272 | case 'a': |
| 270 | expected_address = optarg; | 273 | expected_address = optarg; |
| 271 | break; | 274 | break; |
| 275 | case '4': | ||
| 276 | query_transport = "-4"; | ||
| 277 | break; | ||
| 278 | case '6': | ||
| 279 | query_transport = "-6"; | ||
| 280 | break; | ||
| 272 | default: /* usage5 */ | 281 | default: /* usage5 */ |
| 273 | usage5(); | 282 | usage5(); |
| 274 | } | 283 | } |
| @@ -325,6 +334,10 @@ print_help (void) | |||
| 325 | 334 | ||
| 326 | printf (UT_HOST_PORT, 'p', myport); | 335 | printf (UT_HOST_PORT, 'p', myport); |
| 327 | 336 | ||
| 337 | printf (" %s\n","-4, --use-ipv4"); | ||
| 338 | printf (" %s\n",_("Force dig to only use IPv4 query transport")); | ||
| 339 | printf (" %s\n","-6, --use-ipv6"); | ||
| 340 | printf (" %s\n",_("Force dig to only use IPv6 query transport")); | ||
| 328 | printf (" %s\n","-l, --query_address=STRING"); | 341 | printf (" %s\n","-l, --query_address=STRING"); |
| 329 | printf (" %s\n",_("Machine name to lookup")); | 342 | printf (" %s\n",_("Machine name to lookup")); |
| 330 | printf (" %s\n","-T, --record_type=STRING"); | 343 | printf (" %s\n","-T, --record_type=STRING"); |
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index 65db8517..b05aca9a 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c | |||
| @@ -445,11 +445,6 @@ print_help (void) | |||
| 445 | printf (UT_SUPPORT); | 445 | printf (UT_SUPPORT); |
| 446 | } | 446 | } |
| 447 | 447 | ||
| 448 | /* todo | ||
| 449 | * add option -4 and -6 to the long manual | ||
| 450 | * | ||
| 451 | */ | ||
| 452 | |||
| 453 | void | 448 | void |
| 454 | print_usage (void) | 449 | print_usage (void) |
| 455 | { | 450 | { |
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c index 76d19ba3..16be7c51 100644 --- a/plugins/check_ntp.c +++ b/plugins/check_ntp.c | |||
| @@ -398,7 +398,11 @@ double offset_request(const char *host, int *status){ | |||
| 398 | die(STATE_UNKNOWN, "can not create new socket"); | 398 | die(STATE_UNKNOWN, "can not create new socket"); |
| 399 | } | 399 | } |
| 400 | if(connect(socklist[i], ai_tmp->ai_addr, ai_tmp->ai_addrlen)){ | 400 | if(connect(socklist[i], ai_tmp->ai_addr, ai_tmp->ai_addrlen)){ |
| 401 | die(STATE_UNKNOWN, "can't create socket connection"); | 401 | /* don't die here, because it is enough if there is one server |
| 402 | answering in time. This also would break for dual ipv4/6 stacked | ||
| 403 | ntp servers when the client only supports on of them. | ||
| 404 | */ | ||
| 405 | DBG(printf("can't create socket connection on peer %i: %s\n", i, strerror(errno))); | ||
| 402 | } else { | 406 | } else { |
| 403 | ufds[i].fd=socklist[i]; | 407 | ufds[i].fd=socklist[i]; |
| 404 | ufds[i].events=POLLIN; | 408 | ufds[i].events=POLLIN; |
| @@ -845,6 +849,7 @@ void print_help(void){ | |||
| 845 | printf (UT_HELP_VRSN); | 849 | printf (UT_HELP_VRSN); |
| 846 | printf (UT_EXTRA_OPTS); | 850 | printf (UT_EXTRA_OPTS); |
| 847 | printf (UT_HOST_PORT, 'p', "123"); | 851 | printf (UT_HOST_PORT, 'p', "123"); |
| 852 | printf (UT_IPv46); | ||
| 848 | printf (" %s\n", "-w, --warning=THRESHOLD"); | 853 | printf (" %s\n", "-w, --warning=THRESHOLD"); |
| 849 | printf (" %s\n", _("Offset to result in warning status (seconds)")); | 854 | printf (" %s\n", _("Offset to result in warning status (seconds)")); |
| 850 | printf (" %s\n", "-c, --critical=THRESHOLD"); | 855 | printf (" %s\n", "-c, --critical=THRESHOLD"); |
| @@ -881,5 +886,5 @@ print_usage(void) | |||
| 881 | printf ("%s\n", _("WARNING: check_ntp is deprecated. Please use check_ntp_peer or")); | 886 | printf ("%s\n", _("WARNING: check_ntp is deprecated. Please use check_ntp_peer or")); |
| 882 | printf ("%s\n\n", _("check_ntp_time instead.")); | 887 | printf ("%s\n\n", _("check_ntp_time instead.")); |
| 883 | printf ("%s\n", _("Usage:")); | 888 | printf ("%s\n", _("Usage:")); |
| 884 | printf(" %s -H <host> [-w <warn>] [-c <crit>] [-j <warn>] [-k <crit>] [-v verbose]\n", progname); | 889 | printf(" %s -H <host> [-w <warn>] [-c <crit>] [-j <warn>] [-k <crit>] [-4|-6] [-v verbose]\n", progname); |
| 885 | } | 890 | } |
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c index 50cb7b19..b59c056d 100644 --- a/plugins/check_ntp_peer.c +++ b/plugins/check_ntp_peer.c | |||
| @@ -660,6 +660,7 @@ void print_help(void){ | |||
| 660 | print_usage(); | 660 | print_usage(); |
| 661 | printf (UT_HELP_VRSN); | 661 | printf (UT_HELP_VRSN); |
| 662 | printf (UT_EXTRA_OPTS); | 662 | printf (UT_EXTRA_OPTS); |
| 663 | printf (UT_IPv46); | ||
| 663 | printf (UT_HOST_PORT, 'p', "123"); | 664 | printf (UT_HOST_PORT, 'p', "123"); |
| 664 | printf (" %s\n", "-q, --quiet"); | 665 | printf (" %s\n", "-q, --quiet"); |
| 665 | printf (" %s\n", _("Returns UNKNOWN instead of CRITICAL or WARNING if server isn't synchronized")); | 666 | printf (" %s\n", _("Returns UNKNOWN instead of CRITICAL or WARNING if server isn't synchronized")); |
| @@ -716,6 +717,6 @@ void | |||
| 716 | print_usage(void) | 717 | print_usage(void) |
| 717 | { | 718 | { |
| 718 | printf ("%s\n", _("Usage:")); | 719 | printf ("%s\n", _("Usage:")); |
| 719 | printf(" %s -H <host> [-w <warn>] [-c <crit>] [-W <warn>] [-C <crit>]\n", progname); | 720 | printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-W <warn>] [-C <crit>]\n", progname); |
| 720 | printf(" [-j <warn>] [-k <crit>] [-v verbose]\n"); | 721 | printf(" [-j <warn>] [-k <crit>] [-v verbose]\n"); |
| 721 | } | 722 | } |
diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c index d543d6b5..bbcaa0ba 100644 --- a/plugins/check_ntp_time.c +++ b/plugins/check_ntp_time.c | |||
| @@ -344,7 +344,11 @@ double offset_request(const char *host, int *status){ | |||
| 344 | die(STATE_UNKNOWN, "can not create new socket"); | 344 | die(STATE_UNKNOWN, "can not create new socket"); |
| 345 | } | 345 | } |
| 346 | if(connect(socklist[i], ai_tmp->ai_addr, ai_tmp->ai_addrlen)){ | 346 | if(connect(socklist[i], ai_tmp->ai_addr, ai_tmp->ai_addrlen)){ |
| 347 | die(STATE_UNKNOWN, "can't create socket connection"); | 347 | /* don't die here, because it is enough if there is one server |
| 348 | answering in time. This also would break for dual ipv4/6 stacked | ||
| 349 | ntp servers when the client only supports on of them. | ||
| 350 | */ | ||
| 351 | DBG(printf("can't create socket connection on peer %i: %s\n", i, strerror(errno))); | ||
| 348 | } else { | 352 | } else { |
| 349 | ufds[i].fd=socklist[i]; | 353 | ufds[i].fd=socklist[i]; |
| 350 | ufds[i].events=POLLIN; | 354 | ufds[i].events=POLLIN; |
| @@ -602,6 +606,7 @@ void print_help(void){ | |||
| 602 | print_usage(); | 606 | print_usage(); |
| 603 | printf (UT_HELP_VRSN); | 607 | printf (UT_HELP_VRSN); |
| 604 | printf (UT_EXTRA_OPTS); | 608 | printf (UT_EXTRA_OPTS); |
| 609 | printf (UT_IPv46); | ||
| 605 | printf (UT_HOST_PORT, 'p', "123"); | 610 | printf (UT_HOST_PORT, 'p', "123"); |
| 606 | printf (" %s\n", "-q, --quiet"); | 611 | printf (" %s\n", "-q, --quiet"); |
| 607 | printf (" %s\n", _("Returns UNKNOWN instead of CRITICAL if offset cannot be found")); | 612 | printf (" %s\n", _("Returns UNKNOWN instead of CRITICAL if offset cannot be found")); |
| @@ -635,6 +640,6 @@ void | |||
| 635 | print_usage(void) | 640 | print_usage(void) |
| 636 | { | 641 | { |
| 637 | printf ("%s\n", _("Usage:")); | 642 | printf ("%s\n", _("Usage:")); |
| 638 | printf(" %s -H <host> [-w <warn>] [-c <crit>] [-v verbose]\n", progname); | 643 | printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-v verbose]\n", progname); |
| 639 | } | 644 | } |
| 640 | 645 | ||
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index 69edae75..8b0769f1 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c | |||
| @@ -475,6 +475,6 @@ void | |||
| 475 | print_usage (void) | 475 | print_usage (void) |
| 476 | { | 476 | { |
| 477 | printf ("%s\n", _("Usage:")); | 477 | printf ("%s\n", _("Usage:")); |
| 478 | printf ("%s [-H <host>] [-P <port>] [-c <critical time>] [-w <warning time>]\n", progname); | 478 | printf ("%s [-H <host>] [-4|-6] [-P <port>] [-c <critical time>] [-w <warning time>]\n", progname); |
| 479 | printf (" [-t <timeout>] [-d <database>] [-l <logname>] [-p <password>]\n"); | 479 | printf (" [-t <timeout>] [-d <database>] [-l <logname>] [-p <password>]\n"); |
| 480 | } | 480 | } |
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 2f2dcc58..00b032a7 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
| @@ -45,15 +45,13 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
| 45 | 45 | ||
| 46 | int process_arguments (int, char **); | 46 | int process_arguments (int, char **); |
| 47 | int validate_arguments (void); | 47 | int validate_arguments (void); |
| 48 | int check_thresholds (int); | ||
| 49 | int convert_to_seconds (char *); | 48 | int convert_to_seconds (char *); |
| 50 | void print_help (void); | 49 | void print_help (void); |
| 51 | void print_usage (void); | 50 | void print_usage (void); |
| 52 | 51 | ||
| 53 | int wmax = -1; | 52 | char *warning_range = NULL; |
| 54 | int cmax = -1; | 53 | char *critical_range = NULL; |
| 55 | int wmin = -1; | 54 | thresholds *procs_thresholds = NULL; |
| 56 | int cmin = -1; | ||
| 57 | 55 | ||
| 58 | int options = 0; /* bitmask of filter criteria to test against */ | 56 | int options = 0; /* bitmask of filter criteria to test against */ |
| 59 | #define ALL 1 | 57 | #define ALL 1 |
| @@ -238,14 +236,14 @@ main (int argc, char **argv) | |||
| 238 | } | 236 | } |
| 239 | 237 | ||
| 240 | if (metric == METRIC_VSZ) | 238 | if (metric == METRIC_VSZ) |
| 241 | i = check_thresholds (procvsz); | 239 | i = get_status ((double)procvsz, procs_thresholds); |
| 242 | else if (metric == METRIC_RSS) | 240 | else if (metric == METRIC_RSS) |
| 243 | i = check_thresholds (procrss); | 241 | i = get_status ((double)procrss, procs_thresholds); |
| 244 | /* TODO? float thresholds for --metric=CPU */ | 242 | /* TODO? float thresholds for --metric=CPU */ |
| 245 | else if (metric == METRIC_CPU) | 243 | else if (metric == METRIC_CPU) |
| 246 | i = check_thresholds ((int)procpcpu); | 244 | i = get_status (procpcpu, procs_thresholds); |
| 247 | else if (metric == METRIC_ELAPSED) | 245 | else if (metric == METRIC_ELAPSED) |
| 248 | i = check_thresholds (procseconds); | 246 | i = get_status ((double)procseconds, procs_thresholds); |
| 249 | 247 | ||
| 250 | if (metric != METRIC_PROCS) { | 248 | if (metric != METRIC_PROCS) { |
| 251 | if (i == STATE_WARNING) { | 249 | if (i == STATE_WARNING) { |
| @@ -276,7 +274,7 @@ main (int argc, char **argv) | |||
| 276 | 274 | ||
| 277 | /* Needed if procs found, but none match filter */ | 275 | /* Needed if procs found, but none match filter */ |
| 278 | if ( metric == METRIC_PROCS ) { | 276 | if ( metric == METRIC_PROCS ) { |
| 279 | result = max_state (result, check_thresholds (procs) ); | 277 | result = max_state (result, get_status ((double)procs, procs_thresholds) ); |
| 280 | } | 278 | } |
| 281 | 279 | ||
| 282 | if ( result == STATE_OK ) { | 280 | if ( result == STATE_OK ) { |
| @@ -301,6 +299,13 @@ main (int argc, char **argv) | |||
| 301 | if ( verbose >= 1 && strcmp(fails,"") ) | 299 | if ( verbose >= 1 && strcmp(fails,"") ) |
| 302 | printf (" [%s]", fails); | 300 | printf (" [%s]", fails); |
| 303 | 301 | ||
| 302 | if (metric == METRIC_PROCS) | ||
| 303 | printf (" | procs=%d;%s;%s;0;", procs, | ||
| 304 | warning_range ? warning_range : "", | ||
| 305 | critical_range ? critical_range : ""); | ||
| 306 | else | ||
| 307 | printf (" | procs=%d;;;0; procs_warn=%d;;;0; procs_crit=%d;;;0;", procs, warn, crit); | ||
| 308 | |||
| 304 | printf ("\n"); | 309 | printf ("\n"); |
| 305 | return result; | 310 | return result; |
| 306 | } | 311 | } |
| @@ -368,28 +373,10 @@ process_arguments (int argc, char **argv) | |||
| 368 | timeout_interval = atoi (optarg); | 373 | timeout_interval = atoi (optarg); |
| 369 | break; | 374 | break; |
| 370 | case 'c': /* critical threshold */ | 375 | case 'c': /* critical threshold */ |
| 371 | if (is_integer (optarg)) | 376 | critical_range = optarg; |
| 372 | cmax = atoi (optarg); | ||
| 373 | else if (sscanf (optarg, ":%d", &cmax) == 1) | ||
| 374 | break; | ||
| 375 | else if (sscanf (optarg, "%d:%d", &cmin, &cmax) == 2) | ||
| 376 | break; | ||
| 377 | else if (sscanf (optarg, "%d:", &cmin) == 1) | ||
| 378 | break; | ||
| 379 | else | ||
| 380 | usage4 (_("Critical Process Count must be an integer!")); | ||
| 381 | break; | 377 | break; |
| 382 | case 'w': /* warning threshold */ | 378 | case 'w': /* warning threshold */ |
| 383 | if (is_integer (optarg)) | 379 | warning_range = optarg; |
| 384 | wmax = atoi (optarg); | ||
| 385 | else if (sscanf (optarg, ":%d", &wmax) == 1) | ||
| 386 | break; | ||
| 387 | else if (sscanf (optarg, "%d:%d", &wmin, &wmax) == 2) | ||
| 388 | break; | ||
| 389 | else if (sscanf (optarg, "%d:", &wmin) == 1) | ||
| 390 | break; | ||
| 391 | else | ||
| 392 | usage4 (_("Warning Process Count must be an integer!")); | ||
| 393 | break; | 380 | break; |
| 394 | case 'p': /* process id */ | 381 | case 'p': /* process id */ |
| 395 | if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) { | 382 | if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) { |
| @@ -518,16 +505,19 @@ process_arguments (int argc, char **argv) | |||
| 518 | } | 505 | } |
| 519 | 506 | ||
| 520 | c = optind; | 507 | c = optind; |
| 521 | if (wmax == -1 && argv[c]) | 508 | if ((! warning_range) && argv[c]) |
| 522 | wmax = atoi (argv[c++]); | 509 | warning_range = argv[c++]; |
| 523 | if (cmax == -1 && argv[c]) | 510 | if ((! critical_range) && argv[c]) |
| 524 | cmax = atoi (argv[c++]); | 511 | critical_range = argv[c++]; |
| 525 | if (statopts == NULL && argv[c]) { | 512 | if (statopts == NULL && argv[c]) { |
| 526 | xasprintf (&statopts, "%s", argv[c++]); | 513 | xasprintf (&statopts, "%s", argv[c++]); |
| 527 | xasprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts); | 514 | xasprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts); |
| 528 | options |= STAT; | 515 | options |= STAT; |
| 529 | } | 516 | } |
| 530 | 517 | ||
| 518 | /* this will abort in case of invalid ranges */ | ||
| 519 | set_thresholds (&procs_thresholds, warning_range, critical_range); | ||
| 520 | |||
| 531 | return validate_arguments (); | 521 | return validate_arguments (); |
| 532 | } | 522 | } |
| 533 | 523 | ||
| @@ -536,27 +526,6 @@ process_arguments (int argc, char **argv) | |||
| 536 | int | 526 | int |
| 537 | validate_arguments () | 527 | validate_arguments () |
| 538 | { | 528 | { |
| 539 | |||
| 540 | if (wmax >= 0 && wmin == -1) | ||
| 541 | wmin = 0; | ||
| 542 | if (cmax >= 0 && cmin == -1) | ||
| 543 | cmin = 0; | ||
| 544 | if (wmax >= wmin && cmax >= cmin) { /* standard ranges */ | ||
| 545 | if (wmax > cmax && cmax != -1) { | ||
| 546 | printf (_("wmax (%d) cannot be greater than cmax (%d)\n"), wmax, cmax); | ||
| 547 | return ERROR; | ||
| 548 | } | ||
| 549 | if (cmin > wmin && wmin != -1) { | ||
| 550 | printf (_("wmin (%d) cannot be less than cmin (%d)\n"), wmin, cmin); | ||
| 551 | return ERROR; | ||
| 552 | } | ||
| 553 | } | ||
| 554 | |||
| 555 | /* if (wmax == -1 && cmax == -1 && wmin == -1 && cmin == -1) { */ | ||
| 556 | /* printf ("At least one threshold must be set\n"); */ | ||
| 557 | /* return ERROR; */ | ||
| 558 | /* } */ | ||
| 559 | |||
| 560 | if (options == 0) | 529 | if (options == 0) |
| 561 | options = ALL; | 530 | options = ALL; |
| 562 | 531 | ||
| @@ -579,40 +548,6 @@ validate_arguments () | |||
| 579 | } | 548 | } |
| 580 | 549 | ||
| 581 | 550 | ||
| 582 | |||
| 583 | /* Check thresholds against value */ | ||
| 584 | int | ||
| 585 | check_thresholds (int value) | ||
| 586 | { | ||
| 587 | if (wmax == -1 && cmax == -1 && wmin == -1 && cmin == -1) { | ||
| 588 | return OK; | ||
| 589 | } | ||
| 590 | else if (cmax >= 0 && cmin >= 0 && cmax < cmin) { | ||
| 591 | if (value > cmax && value < cmin) | ||
| 592 | return STATE_CRITICAL; | ||
| 593 | } | ||
| 594 | else if (cmax >= 0 && value > cmax) { | ||
| 595 | return STATE_CRITICAL; | ||
| 596 | } | ||
| 597 | else if (cmin >= 0 && value < cmin) { | ||
| 598 | return STATE_CRITICAL; | ||
| 599 | } | ||
| 600 | |||
| 601 | if (wmax >= 0 && wmin >= 0 && wmax < wmin) { | ||
| 602 | if (value > wmax && value < wmin) { | ||
| 603 | return STATE_WARNING; | ||
| 604 | } | ||
| 605 | } | ||
| 606 | else if (wmax >= 0 && value > wmax) { | ||
| 607 | return STATE_WARNING; | ||
| 608 | } | ||
| 609 | else if (wmin >= 0 && value < wmin) { | ||
| 610 | return STATE_WARNING; | ||
| 611 | } | ||
| 612 | return STATE_OK; | ||
| 613 | } | ||
| 614 | |||
| 615 | |||
| 616 | /* convert the elapsed time to seconds */ | 551 | /* convert the elapsed time to seconds */ |
| 617 | int | 552 | int |
| 618 | convert_to_seconds(char *etime) { | 553 | convert_to_seconds(char *etime) { |
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 2d9861bc..7c5d0ec5 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
| @@ -144,6 +144,25 @@ double previous_value[MAX_OIDS]; | |||
| 144 | int perf_labels = 1; | 144 | int perf_labels = 1; |
| 145 | 145 | ||
| 146 | 146 | ||
| 147 | static char *fix_snmp_range(char *th) | ||
| 148 | { | ||
| 149 | double left, right; | ||
| 150 | char *colon, *ret; | ||
| 151 | if (!(colon = strchr(th, ':'))) | ||
| 152 | return th; | ||
| 153 | *colon = 0; | ||
| 154 | |||
| 155 | left = strtod(th, NULL); | ||
| 156 | right = strtod(colon + 1, NULL); | ||
| 157 | if (right >= left) { | ||
| 158 | return th; | ||
| 159 | } | ||
| 160 | ret = malloc(strlen(th) + strlen(colon + 1) + 2); | ||
| 161 | sprintf(ret, "@%s:%s", colon + 1, th); | ||
| 162 | free(th); | ||
| 163 | return ret; | ||
| 164 | } | ||
| 165 | |||
| 147 | int | 166 | int |
| 148 | main (int argc, char **argv) | 167 | main (int argc, char **argv) |
| 149 | { | 168 | { |
| @@ -181,8 +200,8 @@ main (int argc, char **argv) | |||
| 181 | bindtextdomain (PACKAGE, LOCALEDIR); | 200 | bindtextdomain (PACKAGE, LOCALEDIR); |
| 182 | textdomain (PACKAGE); | 201 | textdomain (PACKAGE); |
| 183 | 202 | ||
| 184 | labels = malloc (labels_size); | 203 | labels = malloc (labels_size * sizeof(*labels)); |
| 185 | unitv = malloc (unitv_size); | 204 | unitv = malloc (unitv_size * sizeof(*unitv)); |
| 186 | for (i = 0; i < MAX_OIDS; i++) | 205 | for (i = 0; i < MAX_OIDS; i++) |
| 187 | eval_method[i] = CHECK_UNDEF; | 206 | eval_method[i] = CHECK_UNDEF; |
| 188 | 207 | ||
| @@ -228,6 +247,10 @@ main (int argc, char **argv) | |||
| 228 | for (i=0; i<numoids; i++) { | 247 | for (i=0; i<numoids; i++) { |
| 229 | char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL; | 248 | char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL; |
| 230 | char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL; | 249 | char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL; |
| 250 | /* translate "2:1" to "@1:2" for backwards compatibility */ | ||
| 251 | w = w ? fix_snmp_range(w) : NULL; | ||
| 252 | c = c ? fix_snmp_range(c) : NULL; | ||
| 253 | |||
| 231 | /* Skip empty thresholds, while avoiding segfault */ | 254 | /* Skip empty thresholds, while avoiding segfault */ |
| 232 | set_thresholds(&thlds[i], | 255 | set_thresholds(&thlds[i], |
| 233 | w ? strpbrk(w, NP_THRESHOLDS_CHARS) : NULL, | 256 | w ? strpbrk(w, NP_THRESHOLDS_CHARS) : NULL, |
| @@ -396,7 +419,7 @@ main (int argc, char **argv) | |||
| 396 | show = strstr (response, "Timeticks: "); | 419 | show = strstr (response, "Timeticks: "); |
| 397 | } | 420 | } |
| 398 | else | 421 | else |
| 399 | show = response; | 422 | show = response + 3; |
| 400 | 423 | ||
| 401 | iresult = STATE_DEPENDENT; | 424 | iresult = STATE_DEPENDENT; |
| 402 | 425 | ||
| @@ -405,7 +428,7 @@ main (int argc, char **argv) | |||
| 405 | if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { | 428 | if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { |
| 406 | ptr = strpbrk (show, "0123456789"); | 429 | ptr = strpbrk (show, "0123456789"); |
| 407 | if (ptr == NULL) | 430 | if (ptr == NULL) |
| 408 | die (STATE_UNKNOWN,_("No valid data returned")); | 431 | die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); |
| 409 | response_value[i] = strtod (ptr, NULL); | 432 | response_value[i] = strtod (ptr, NULL); |
| 410 | 433 | ||
| 411 | if(calculate_rate) { | 434 | if(calculate_rate) { |
| @@ -745,9 +768,9 @@ process_arguments (int argc, char **argv) | |||
| 745 | break; | 768 | break; |
| 746 | case 'l': /* label */ | 769 | case 'l': /* label */ |
| 747 | nlabels++; | 770 | nlabels++; |
| 748 | if (nlabels >= labels_size) { | 771 | if (nlabels > labels_size) { |
| 749 | labels_size += 8; | 772 | labels_size += 8; |
| 750 | labels = realloc (labels, labels_size); | 773 | labels = realloc (labels, labels_size * sizeof(*labels)); |
| 751 | if (labels == NULL) | 774 | if (labels == NULL) |
| 752 | die (STATE_UNKNOWN, _("Could not reallocate labels[%d]"), (int)nlabels); | 775 | die (STATE_UNKNOWN, _("Could not reallocate labels[%d]"), (int)nlabels); |
| 753 | } | 776 | } |
| @@ -757,13 +780,13 @@ process_arguments (int argc, char **argv) | |||
| 757 | if (ptr[0] == '\'') | 780 | if (ptr[0] == '\'') |
| 758 | labels[nlabels - 1] = ptr + 1; | 781 | labels[nlabels - 1] = ptr + 1; |
| 759 | while (ptr && (ptr = nextarg (ptr))) { | 782 | while (ptr && (ptr = nextarg (ptr))) { |
| 760 | if (nlabels >= labels_size) { | 783 | nlabels++; |
| 784 | if (nlabels > labels_size) { | ||
| 761 | labels_size += 8; | 785 | labels_size += 8; |
| 762 | labels = realloc (labels, labels_size); | 786 | labels = realloc (labels, labels_size * sizeof(*labels)); |
| 763 | if (labels == NULL) | 787 | if (labels == NULL) |
| 764 | die (STATE_UNKNOWN, _("Could not reallocate labels\n")); | 788 | die (STATE_UNKNOWN, _("Could not reallocate labels\n")); |
| 765 | } | 789 | } |
| 766 | nlabels++; | ||
| 767 | ptr = thisarg (ptr); | 790 | ptr = thisarg (ptr); |
| 768 | if (ptr[0] == '\'') | 791 | if (ptr[0] == '\'') |
| 769 | labels[nlabels - 1] = ptr + 1; | 792 | labels[nlabels - 1] = ptr + 1; |
| @@ -774,9 +797,9 @@ process_arguments (int argc, char **argv) | |||
| 774 | case 'u': /* units */ | 797 | case 'u': /* units */ |
| 775 | units = optarg; | 798 | units = optarg; |
| 776 | nunits++; | 799 | nunits++; |
| 777 | if (nunits >= unitv_size) { | 800 | if (nunits > unitv_size) { |
| 778 | unitv_size += 8; | 801 | unitv_size += 8; |
| 779 | unitv = realloc (unitv, unitv_size); | 802 | unitv = realloc (unitv, unitv_size * sizeof(*unitv)); |
| 780 | if (unitv == NULL) | 803 | if (unitv == NULL) |
| 781 | die (STATE_UNKNOWN, _("Could not reallocate units [%d]\n"), (int)nunits); | 804 | die (STATE_UNKNOWN, _("Could not reallocate units [%d]\n"), (int)nunits); |
| 782 | } | 805 | } |
| @@ -786,9 +809,9 @@ process_arguments (int argc, char **argv) | |||
| 786 | if (ptr[0] == '\'') | 809 | if (ptr[0] == '\'') |
| 787 | unitv[nunits - 1] = ptr + 1; | 810 | unitv[nunits - 1] = ptr + 1; |
| 788 | while (ptr && (ptr = nextarg (ptr))) { | 811 | while (ptr && (ptr = nextarg (ptr))) { |
| 789 | if (nunits >= unitv_size) { | 812 | if (nunits > unitv_size) { |
| 790 | unitv_size += 8; | 813 | unitv_size += 8; |
| 791 | unitv = realloc (unitv, unitv_size); | 814 | unitv = realloc (unitv, unitv_size * sizeof(*unitv)); |
| 792 | if (units == NULL) | 815 | if (units == NULL) |
| 793 | die (STATE_UNKNOWN, _("Could not realloc() units\n")); | 816 | die (STATE_UNKNOWN, _("Could not realloc() units\n")); |
| 794 | } | 817 | } |
diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c index 4d633949..6e8a5fc5 100644 --- a/plugins/check_ssh.c +++ b/plugins/check_ssh.c | |||
| @@ -307,6 +307,6 @@ void | |||
| 307 | print_usage (void) | 307 | print_usage (void) |
| 308 | { | 308 | { |
| 309 | printf ("%s\n", _("Usage:")); | 309 | printf ("%s\n", _("Usage:")); |
| 310 | printf ("%s [-46] [-t <timeout>] [-r <remote version>] [-p <port>] <host>\n", progname); | 310 | printf ("%s [-4|-6] [-t <timeout>] [-r <remote version>] [-p <port>] <host>\n", progname); |
| 311 | } | 311 | } |
| 312 | 312 | ||
diff --git a/plugins/common.h b/plugins/common.h index 09af7e7e..c0dc2f41 100644 --- a/plugins/common.h +++ b/plugins/common.h | |||
| @@ -141,6 +141,7 @@ | |||
| 141 | #ifdef HAVE_GNUTLS_OPENSSL_H | 141 | #ifdef HAVE_GNUTLS_OPENSSL_H |
| 142 | # include <gnutls/openssl.h> | 142 | # include <gnutls/openssl.h> |
| 143 | #else | 143 | #else |
| 144 | # define OPENSSL_LOAD_CONF /* See the OPENSSL_config(3) man page. */ | ||
| 144 | # ifdef HAVE_SSL_H | 145 | # ifdef HAVE_SSL_H |
| 145 | # include <rsa.h> | 146 | # include <rsa.h> |
| 146 | # include <crypto.h> | 147 | # include <crypto.h> |
diff --git a/plugins/t/check_dig.t b/plugins/t/check_dig.t index 323859e8..1ab4b426 100644 --- a/plugins/t/check_dig.t +++ b/plugins/t/check_dig.t | |||
| @@ -10,30 +10,30 @@ use NPTest; | |||
| 10 | 10 | ||
| 11 | plan skip_all => "check_dig not compiled" unless (-x "check_dig"); | 11 | plan skip_all => "check_dig not compiled" unless (-x "check_dig"); |
| 12 | 12 | ||
| 13 | plan tests => 12; | 13 | plan tests => 16; |
| 14 | 14 | ||
| 15 | my $successOutput = '/DNS OK - [\.0-9]+ seconds? response time/'; | 15 | my $successOutput = '/DNS OK - [\.0-9]+ seconds? response time/'; |
| 16 | 16 | ||
| 17 | my $hostname_valid = getTestParameter( | 17 | my $hostname_valid = getTestParameter( |
| 18 | "NP_HOSTNAME_VALID", | 18 | "NP_HOSTNAME_VALID", |
| 19 | "A valid (known to DNS) hostname", | 19 | "A valid (known to DNS) hostname", |
| 20 | "nagios.com" | 20 | "nagiosplugins.org" |
| 21 | ); | 21 | ); |
| 22 | 22 | ||
| 23 | my $hostname_valid_ip = getTestParameter( | 23 | my $hostname_valid_ip = getTestParameter( |
| 24 | "NP_HOSTNAME_VALID_IP", | 24 | "NP_HOSTNAME_VALID_IP", |
| 25 | "The IP address of the valid hostname $hostname_valid", | 25 | "The IP address of the valid hostname $hostname_valid", |
| 26 | "66.118.156.50", | 26 | "67.207.143.200", |
| 27 | ); | 27 | ); |
| 28 | 28 | ||
| 29 | my $hostname_valid_reverse = getTestParameter( | 29 | my $hostname_valid_reverse = getTestParameter( |
| 30 | "NP_HOSTNAME_VALID_REVERSE", | 30 | "NP_HOSTNAME_VALID_REVERSE", |
| 31 | "The hostname of $hostname_valid_ip", | 31 | "The hostname of $hostname_valid_ip", |
| 32 | "66-118-156-50.static.sagonet.net.", | 32 | "nagiosplugins.org.", |
| 33 | ); | 33 | ); |
| 34 | 34 | ||
| 35 | my $hostname_invalid = getTestParameter( | 35 | my $hostname_invalid = getTestParameter( |
| 36 | "NP_HOSTNAME_INVALID", | 36 | "NP_HOSTNAME_INVALID", |
| 37 | "An invalid (not known to DNS) hostname", | 37 | "An invalid (not known to DNS) hostname", |
| 38 | "nosuchhost.altinity.com", | 38 | "nosuchhost.altinity.com", |
| 39 | ); | 39 | ); |
| @@ -69,6 +69,14 @@ SKIP: { | |||
| 69 | cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server"); | 69 | cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server"); |
| 70 | like ( $res->output, $successOutput, "Output OK" ); | 70 | like ( $res->output, $successOutput, "Output OK" ); |
| 71 | 71 | ||
| 72 | $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -4"); | ||
| 73 | cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server"); | ||
| 74 | like ( $res->output, $successOutput, "Output OK for IPv4" ); | ||
| 75 | |||
| 76 | $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -6"); | ||
| 77 | cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server"); | ||
| 78 | like ( $res->output, $successOutput, "Output OK for IPv6" ); | ||
| 79 | |||
| 72 | $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -a $hostname_valid_ip -t 5"); | 80 | $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -a $hostname_valid_ip -t 5"); |
| 73 | cmp_ok( $res->return_code, '==', 0, "Got expected address"); | 81 | cmp_ok( $res->return_code, '==', 0, "Got expected address"); |
| 74 | 82 | ||
