diff options
Diffstat (limited to 'plugins')
33 files changed, 407 insertions, 404 deletions
diff --git a/plugins/check_cluster.c b/plugins/check_cluster.c index b86e501d..e1ede9f7 100644 --- a/plugins/check_cluster.c +++ b/plugins/check_cluster.c | |||
@@ -143,6 +143,7 @@ int main(int argc, char **argv){ | |||
143 | 143 | ||
144 | int process_arguments(int argc, char **argv){ | 144 | int process_arguments(int argc, char **argv){ |
145 | int c; | 145 | int c; |
146 | char *ptr; | ||
146 | int option=0; | 147 | int option=0; |
147 | static struct option longopts[]={ | 148 | static struct option longopts[]={ |
148 | {"data", required_argument,0,'d'}, | 149 | {"data", required_argument,0,'d'}, |
@@ -188,6 +189,15 @@ int process_arguments(int argc, char **argv){ | |||
188 | 189 | ||
189 | case 'd': /* data values */ | 190 | case 'd': /* data values */ |
190 | data_vals=(char *)strdup(optarg); | 191 | data_vals=(char *)strdup(optarg); |
192 | /* validate data */ | ||
193 | for (ptr=data_vals;ptr!=NULL;ptr+=2){ | ||
194 | if (ptr[0]<'0' || ptr[0]>'3') | ||
195 | return ERROR; | ||
196 | if (ptr[1]=='\0') | ||
197 | break; | ||
198 | if (ptr[1]!=',') | ||
199 | return ERROR; | ||
200 | } | ||
191 | break; | 201 | break; |
192 | 202 | ||
193 | case 'l': /* text label */ | 203 | case 'l': /* text label */ |
diff --git a/plugins/check_dbi.c b/plugins/check_dbi.c index 826eb8d9..ced13d05 100644 --- a/plugins/check_dbi.c +++ b/plugins/check_dbi.c | |||
@@ -35,6 +35,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
35 | 35 | ||
36 | #include "common.h" | 36 | #include "common.h" |
37 | #include "utils.h" | 37 | #include "utils.h" |
38 | #include "utils_cmd.h" | ||
38 | 39 | ||
39 | #include "netutils.h" | 40 | #include "netutils.h" |
40 | 41 | ||
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index e73a0083..1c43e854 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -141,6 +141,7 @@ int erronly = FALSE; | |||
141 | int display_mntp = FALSE; | 141 | int display_mntp = FALSE; |
142 | int exact_match = FALSE; | 142 | int exact_match = FALSE; |
143 | int freespace_ignore_reserved = FALSE; | 143 | int freespace_ignore_reserved = FALSE; |
144 | int display_inodes_perfdata = FALSE; | ||
144 | char *warn_freespace_units = NULL; | 145 | char *warn_freespace_units = NULL; |
145 | char *crit_freespace_units = NULL; | 146 | char *crit_freespace_units = NULL; |
146 | char *warn_freespace_percent = NULL; | 147 | char *warn_freespace_percent = NULL; |
@@ -167,6 +168,7 @@ main (int argc, char **argv) | |||
167 | char *output; | 168 | char *output; |
168 | char *details; | 169 | char *details; |
169 | char *perf; | 170 | char *perf; |
171 | char *perf_ilabel; | ||
170 | char *preamble; | 172 | char *preamble; |
171 | char *flag_header; | 173 | char *flag_header; |
172 | double inode_space_pct; | 174 | double inode_space_pct; |
@@ -186,6 +188,7 @@ main (int argc, char **argv) | |||
186 | output = strdup (""); | 188 | output = strdup (""); |
187 | details = strdup (""); | 189 | details = strdup (""); |
188 | perf = strdup (""); | 190 | perf = strdup (""); |
191 | perf_ilabel = strdup (""); | ||
189 | stat_buf = malloc(sizeof *stat_buf); | 192 | stat_buf = malloc(sizeof *stat_buf); |
190 | 193 | ||
191 | setlocale (LC_ALL, ""); | 194 | setlocale (LC_ALL, ""); |
@@ -348,6 +351,29 @@ main (int argc, char **argv) | |||
348 | TRUE, 0, | 351 | TRUE, 0, |
349 | TRUE, path->dtotal_units)); | 352 | TRUE, path->dtotal_units)); |
350 | 353 | ||
354 | if (display_inodes_perfdata) { | ||
355 | /* *_high_tide must be reinitialized at each run */ | ||
356 | warning_high_tide = UINT_MAX; | ||
357 | critical_high_tide = UINT_MAX; | ||
358 | |||
359 | if (path->freeinodes_percent->warning != NULL) { | ||
360 | warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total )); | ||
361 | } | ||
362 | if (path->freeinodes_percent->critical != NULL) { | ||
363 | critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total )); | ||
364 | } | ||
365 | |||
366 | xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir); | ||
367 | /* Nb: *_high_tide are unset when == UINT_MAX */ | ||
368 | xasprintf (&perf, "%s %s", perf, | ||
369 | perfdata (perf_ilabel, | ||
370 | path->inodes_used, "", | ||
371 | (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, | ||
372 | (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide, | ||
373 | TRUE, 0, | ||
374 | TRUE, path->inodes_total)); | ||
375 | } | ||
376 | |||
351 | if (disk_result==STATE_OK && erronly && !verbose) | 377 | if (disk_result==STATE_OK && erronly && !verbose) |
352 | continue; | 378 | continue; |
353 | 379 | ||
@@ -455,6 +481,7 @@ process_arguments (int argc, char **argv) | |||
455 | {"ignore-eregi-partition", required_argument, 0, 'I'}, | 481 | {"ignore-eregi-partition", required_argument, 0, 'I'}, |
456 | {"local", no_argument, 0, 'l'}, | 482 | {"local", no_argument, 0, 'l'}, |
457 | {"stat-remote-fs", no_argument, 0, 'L'}, | 483 | {"stat-remote-fs", no_argument, 0, 'L'}, |
484 | {"iperfdata", no_argument, 0, 'P'}, | ||
458 | {"mountpoint", no_argument, 0, 'M'}, | 485 | {"mountpoint", no_argument, 0, 'M'}, |
459 | {"errors-only", no_argument, 0, 'e'}, | 486 | {"errors-only", no_argument, 0, 'e'}, |
460 | {"exact-match", no_argument, 0, 'E'}, | 487 | {"exact-match", no_argument, 0, 'E'}, |
@@ -477,7 +504,7 @@ process_arguments (int argc, char **argv) | |||
477 | strcpy (argv[c], "-t"); | 504 | strcpy (argv[c], "-t"); |
478 | 505 | ||
479 | while (1) { | 506 | while (1) { |
480 | c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLg:R:r:i:I:MEA", longopts, &option); | 507 | c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEA", longopts, &option); |
481 | 508 | ||
482 | if (c == -1 || c == EOF) | 509 | if (c == -1 || c == EOF) |
483 | break; | 510 | break; |
@@ -582,9 +609,13 @@ process_arguments (int argc, char **argv) | |||
582 | break; | 609 | break; |
583 | case 'L': | 610 | case 'L': |
584 | stat_remote_fs = 1; | 611 | stat_remote_fs = 1; |
612 | /* fallthrough */ | ||
585 | case 'l': | 613 | case 'l': |
586 | show_local_fs = 1; | 614 | show_local_fs = 1; |
587 | break; | 615 | break; |
616 | case 'P': | ||
617 | display_inodes_perfdata = 1; | ||
618 | break; | ||
588 | case 'p': /* select path */ | 619 | case 'p': /* select path */ |
589 | if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || | 620 | if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || |
590 | crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || | 621 | crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || |
@@ -1012,6 +1043,8 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1012 | p->dtotal_units += p_list->dtotal_units; | 1043 | p->dtotal_units += p_list->dtotal_units; |
1013 | p->inodes_total += p_list->inodes_total; | 1044 | p->inodes_total += p_list->inodes_total; |
1014 | p->inodes_free += p_list->inodes_free; | 1045 | p->inodes_free += p_list->inodes_free; |
1046 | p->inodes_free_to_root += p_list->inodes_free_to_root; | ||
1047 | p->inodes_used += p_list->inodes_used; | ||
1015 | } | 1048 | } |
1016 | first = 0; | 1049 | first = 0; |
1017 | } | 1050 | } |
@@ -1050,7 +1083,18 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1050 | p->dused_units = p->used*fsp->fsu_blocksize/mult; | 1083 | p->dused_units = p->used*fsp->fsu_blocksize/mult; |
1051 | p->dfree_units = p->available*fsp->fsu_blocksize/mult; | 1084 | p->dfree_units = p->available*fsp->fsu_blocksize/mult; |
1052 | p->dtotal_units = p->total*fsp->fsu_blocksize/mult; | 1085 | p->dtotal_units = p->total*fsp->fsu_blocksize/mult; |
1053 | p->inodes_total = fsp->fsu_files; /* Total file nodes. */ | 1086 | /* Free file nodes. Not sure the workaround is required, but in case...*/ |
1054 | p->inodes_free = fsp->fsu_ffree; /* Free file nodes. */ | 1087 | p->inodes_free = fsp->fsu_favail > fsp->fsu_ffree ? 0 : fsp->fsu_favail; |
1088 | p->inodes_free_to_root = fsp->fsu_ffree; /* Free file nodes for root. */ | ||
1089 | p->inodes_used = fsp->fsu_files - fsp->fsu_ffree; | ||
1090 | if (freespace_ignore_reserved) { | ||
1091 | /* option activated : we substract the root-reserved inodes from the total */ | ||
1092 | /* not all OS report fsp->fsu_favail, only the ones with statvfs syscall */ | ||
1093 | /* for others, fsp->fsu_ffree == fsp->fsu_favail */ | ||
1094 | p->inodes_total = fsp->fsu_files - p->inodes_free_to_root + p->inodes_free; | ||
1095 | } else { | ||
1096 | /* default behaviour : take all the inodes into account */ | ||
1097 | p->inodes_total = fsp->fsu_files; | ||
1098 | } | ||
1055 | np_add_name(&seen, p->best_match->me_mountdir); | 1099 | np_add_name(&seen, p->best_match->me_mountdir); |
1056 | } | 1100 | } |
diff --git a/plugins/check_dns.c b/plugins/check_dns.c index f2061636..d4d0b885 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c | |||
@@ -56,6 +56,7 @@ char **expected_address = NULL; | |||
56 | int expected_address_cnt = 0; | 56 | int expected_address_cnt = 0; |
57 | 57 | ||
58 | int expect_authority = FALSE; | 58 | int expect_authority = FALSE; |
59 | int all_match = FALSE; | ||
59 | thresholds *time_thresholds = NULL; | 60 | thresholds *time_thresholds = NULL; |
60 | 61 | ||
61 | static int | 62 | static int |
@@ -168,8 +169,8 @@ main (int argc, char **argv) | |||
168 | temp_buffer++; | 169 | temp_buffer++; |
169 | 170 | ||
170 | /* Strip leading spaces */ | 171 | /* Strip leading spaces */ |
171 | for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++) | 172 | while (*temp_buffer == ' ') |
172 | /* NOOP */; | 173 | temp_buffer++; |
173 | 174 | ||
174 | strip(temp_buffer); | 175 | strip(temp_buffer); |
175 | if (temp_buffer==NULL || strlen(temp_buffer)==0) { | 176 | if (temp_buffer==NULL || strlen(temp_buffer)==0) { |
@@ -228,16 +229,27 @@ main (int argc, char **argv) | |||
228 | if (result == STATE_OK && expected_address_cnt > 0) { | 229 | if (result == STATE_OK && expected_address_cnt > 0) { |
229 | result = STATE_CRITICAL; | 230 | result = STATE_CRITICAL; |
230 | temp_buffer = ""; | 231 | temp_buffer = ""; |
232 | unsigned long expect_match = (1 << expected_address_cnt) - 1; | ||
233 | unsigned long addr_match = (1 << n_addresses) - 1; | ||
231 | 234 | ||
232 | for (i=0; i<expected_address_cnt; i++) { | 235 | for (i=0; i<expected_address_cnt; i++) { |
236 | int j; | ||
233 | /* check if we get a match on 'raw' ip or cidr */ | 237 | /* check if we get a match on 'raw' ip or cidr */ |
234 | if ( strcmp(address, expected_address[i]) == 0 | 238 | for (j=0; j<n_addresses; j++) { |
235 | || ip_match_cidr(address, expected_address[i]) ) | 239 | if ( strcmp(addresses[j], expected_address[i]) == 0 |
236 | result = STATE_OK; | 240 | || ip_match_cidr(addresses[j], expected_address[i]) ) { |
241 | result = STATE_OK; | ||
242 | addr_match &= ~(1 << j); | ||
243 | expect_match &= ~(1 << i); | ||
244 | } | ||
245 | } | ||
237 | 246 | ||
238 | /* prepare an error string */ | 247 | /* prepare an error string */ |
239 | xasprintf(&temp_buffer, "%s%s; ", temp_buffer, expected_address[i]); | 248 | xasprintf(&temp_buffer, "%s%s; ", temp_buffer, expected_address[i]); |
240 | } | 249 | } |
250 | /* check if expected_address must cover all in addresses and none may be missing */ | ||
251 | if (all_match && (expect_match != 0 || addr_match != 0)) | ||
252 | result = STATE_CRITICAL; | ||
241 | if (result == STATE_CRITICAL) { | 253 | if (result == STATE_CRITICAL) { |
242 | /* Strip off last semicolon... */ | 254 | /* Strip off last semicolon... */ |
243 | temp_buffer[strlen(temp_buffer)-2] = '\0'; | 255 | temp_buffer[strlen(temp_buffer)-2] = '\0'; |
@@ -401,6 +413,7 @@ process_arguments (int argc, char **argv) | |||
401 | {"reverse-server", required_argument, 0, 'r'}, | 413 | {"reverse-server", required_argument, 0, 'r'}, |
402 | {"expected-address", required_argument, 0, 'a'}, | 414 | {"expected-address", required_argument, 0, 'a'}, |
403 | {"expect-authority", no_argument, 0, 'A'}, | 415 | {"expect-authority", no_argument, 0, 'A'}, |
416 | {"all", no_argument, 0, 'L'}, | ||
404 | {"warning", required_argument, 0, 'w'}, | 417 | {"warning", required_argument, 0, 'w'}, |
405 | {"critical", required_argument, 0, 'c'}, | 418 | {"critical", required_argument, 0, 'c'}, |
406 | {0, 0, 0, 0} | 419 | {0, 0, 0, 0} |
@@ -414,7 +427,7 @@ process_arguments (int argc, char **argv) | |||
414 | strcpy (argv[c], "-t"); | 427 | strcpy (argv[c], "-t"); |
415 | 428 | ||
416 | while (1) { | 429 | while (1) { |
417 | c = getopt_long (argc, argv, "hVvAt:H:s:r:a:w:c:", long_opts, &opt_index); | 430 | c = getopt_long (argc, argv, "hVvALt:H:s:r:a:w:c:", long_opts, &opt_index); |
418 | 431 | ||
419 | if (c == -1 || c == EOF) | 432 | if (c == -1 || c == EOF) |
420 | break; | 433 | break; |
@@ -462,6 +475,9 @@ process_arguments (int argc, char **argv) | |||
462 | case 'A': /* expect authority */ | 475 | case 'A': /* expect authority */ |
463 | expect_authority = TRUE; | 476 | expect_authority = TRUE; |
464 | break; | 477 | break; |
478 | case 'L': /* all must match */ | ||
479 | all_match = TRUE; | ||
480 | break; | ||
465 | case 'w': | 481 | case 'w': |
466 | warning = optarg; | 482 | warning = optarg; |
467 | break; | 483 | break; |
@@ -530,14 +546,16 @@ print_help (void) | |||
530 | printf (" -a, --expected-address=IP-ADDRESS|CIDR|HOST\n"); | 546 | printf (" -a, --expected-address=IP-ADDRESS|CIDR|HOST\n"); |
531 | printf (" %s\n", _("Optional IP-ADDRESS/CIDR you expect the DNS server to return. HOST must end")); | 547 | printf (" %s\n", _("Optional IP-ADDRESS/CIDR you expect the DNS server to return. HOST must end")); |
532 | printf (" %s\n", _("with a dot (.). This option can be repeated multiple times (Returns OK if any")); | 548 | printf (" %s\n", _("with a dot (.). This option can be repeated multiple times (Returns OK if any")); |
533 | printf (" %s\n", _("value match). If multiple addresses are returned at once, you have to match")); | 549 | printf (" %s\n", _("value matches).")); |
534 | printf (" %s\n", _("the whole string of addresses separated with commas (sorted alphabetically).")); | ||
535 | printf (" -A, --expect-authority\n"); | 550 | printf (" -A, --expect-authority\n"); |
536 | printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup")); | 551 | printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup")); |
537 | printf (" -w, --warning=seconds\n"); | 552 | printf (" -w, --warning=seconds\n"); |
538 | printf (" %s\n", _("Return warning if elapsed time exceeds value. Default off")); | 553 | printf (" %s\n", _("Return warning if elapsed time exceeds value. Default off")); |
539 | printf (" -c, --critical=seconds\n"); | 554 | printf (" -c, --critical=seconds\n"); |
540 | printf (" %s\n", _("Return critical if elapsed time exceeds value. Default off")); | 555 | printf (" %s\n", _("Return critical if elapsed time exceeds value. Default off")); |
556 | printf (" -L, --all\n"); | ||
557 | printf (" %s\n", _("Return critical if the list of expected addresses does not match all addresses")); | ||
558 | printf (" %s\n", _("returned. Default off")); | ||
541 | 559 | ||
542 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 560 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
543 | 561 | ||
@@ -549,5 +567,5 @@ void | |||
549 | print_usage (void) | 567 | print_usage (void) |
550 | { | 568 | { |
551 | printf ("%s\n", _("Usage:")); | 569 | printf ("%s\n", _("Usage:")); |
552 | printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit]\n", progname); | 570 | printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit] [-L]\n", progname); |
553 | } | 571 | } |
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index f159f5a2..65465567 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c | |||
@@ -67,6 +67,7 @@ void print_usage (void); | |||
67 | char *community = NULL; | 67 | char *community = NULL; |
68 | char *address = NULL; | 68 | char *address = NULL; |
69 | char *port = NULL; | 69 | char *port = NULL; |
70 | int check_paper_out = 1; | ||
70 | 71 | ||
71 | int | 72 | int |
72 | main (int argc, char **argv) | 73 | main (int argc, char **argv) |
@@ -240,7 +241,8 @@ main (int argc, char **argv) | |||
240 | strcpy (errmsg, _("Paper Jam")); | 241 | strcpy (errmsg, _("Paper Jam")); |
241 | } | 242 | } |
242 | else if (paper_out) { | 243 | else if (paper_out) { |
243 | result = STATE_WARNING; | 244 | if (check_paper_out) |
245 | result = STATE_WARNING; | ||
244 | strcpy (errmsg, _("Out of Paper")); | 246 | strcpy (errmsg, _("Out of Paper")); |
245 | } | 247 | } |
246 | else if (line_status == OFFLINE) { | 248 | else if (line_status == OFFLINE) { |
@@ -325,7 +327,7 @@ process_arguments (int argc, char **argv) | |||
325 | 327 | ||
326 | 328 | ||
327 | while (1) { | 329 | while (1) { |
328 | c = getopt_long (argc, argv, "+hVH:C:p:", longopts, &option); | 330 | c = getopt_long (argc, argv, "+hVH:C:p:D", longopts, &option); |
329 | 331 | ||
330 | if (c == -1 || c == EOF || c == 1) | 332 | if (c == -1 || c == EOF || c == 1) |
331 | break; | 333 | break; |
@@ -347,6 +349,8 @@ process_arguments (int argc, char **argv) | |||
347 | usage2 (_("Port must be a positive short integer"), optarg); | 349 | usage2 (_("Port must be a positive short integer"), optarg); |
348 | else | 350 | else |
349 | port = atoi(optarg); | 351 | port = atoi(optarg); |
352 | case 'D': /* disable paper out check*/ | ||
353 | check_paper_out = 0; | ||
350 | break; | 354 | break; |
351 | case 'V': /* version */ | 355 | case 'V': /* version */ |
352 | print_revision (progname, NP_VERSION); | 356 | print_revision (progname, NP_VERSION); |
@@ -420,6 +424,8 @@ print_help (void) | |||
420 | printf (" %s", _("Specify the port to check ")); | 424 | printf (" %s", _("Specify the port to check ")); |
421 | printf (_("(default=%s)"), DEFAULT_PORT); | 425 | printf (_("(default=%s)"), DEFAULT_PORT); |
422 | printf ("\n"); | 426 | printf ("\n"); |
427 | printf (" %s\n", "-D"); | ||
428 | printf (" %s", _("Disable paper check ")); | ||
423 | 429 | ||
424 | printf (UT_SUPPORT); | 430 | printf (UT_SUPPORT); |
425 | } | 431 | } |
@@ -430,5 +436,5 @@ void | |||
430 | print_usage (void) | 436 | print_usage (void) |
431 | { | 437 | { |
432 | printf ("%s\n", _("Usage:")); | 438 | printf ("%s\n", _("Usage:")); |
433 | printf ("%s -H host [-C community] [-p port]\n", progname); | 439 | printf ("%s -H host [-C community] [-p port] [-D]\n", progname); |
434 | } | 440 | } |
diff --git a/plugins/check_http.c b/plugins/check_http.c index 86a36c20..de59a068 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -120,12 +120,14 @@ int use_ssl = FALSE; | |||
120 | int use_sni = FALSE; | 120 | int use_sni = FALSE; |
121 | int verbose = FALSE; | 121 | int verbose = FALSE; |
122 | int show_extended_perfdata = FALSE; | 122 | int show_extended_perfdata = FALSE; |
123 | int show_body = FALSE; | ||
123 | int sd; | 124 | int sd; |
124 | int min_page_len = 0; | 125 | int min_page_len = 0; |
125 | int max_page_len = 0; | 126 | int max_page_len = 0; |
126 | int redir_depth = 0; | 127 | int redir_depth = 0; |
127 | int max_depth = 15; | 128 | int max_depth = 15; |
128 | char *http_method; | 129 | char *http_method; |
130 | char *http_method_proxy; | ||
129 | char *http_post_data; | 131 | char *http_post_data; |
130 | char *http_content_type; | 132 | char *http_content_type; |
131 | char buffer[MAX_INPUT_BUFFER]; | 133 | char buffer[MAX_INPUT_BUFFER]; |
@@ -239,6 +241,7 @@ process_arguments (int argc, char **argv) | |||
239 | {"use-ipv4", no_argument, 0, '4'}, | 241 | {"use-ipv4", no_argument, 0, '4'}, |
240 | {"use-ipv6", no_argument, 0, '6'}, | 242 | {"use-ipv6", no_argument, 0, '6'}, |
241 | {"extended-perfdata", no_argument, 0, 'E'}, | 243 | {"extended-perfdata", no_argument, 0, 'E'}, |
244 | {"show-body", no_argument, 0, 'B'}, | ||
242 | {0, 0, 0, 0} | 245 | {0, 0, 0, 0} |
243 | }; | 246 | }; |
244 | 247 | ||
@@ -259,7 +262,7 @@ process_arguments (int argc, char **argv) | |||
259 | } | 262 | } |
260 | 263 | ||
261 | while (1) { | 264 | while (1) { |
262 | c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:nlLS::m:M:NE", longopts, &option); | 265 | c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:nlLS::m:M:NEB", longopts, &option); |
263 | if (c == -1 || c == EOF) | 266 | if (c == -1 || c == EOF) |
264 | break; | 267 | break; |
265 | 268 | ||
@@ -446,6 +449,12 @@ process_arguments (int argc, char **argv) | |||
446 | if (http_method) | 449 | if (http_method) |
447 | free(http_method); | 450 | free(http_method); |
448 | http_method = strdup (optarg); | 451 | http_method = strdup (optarg); |
452 | char *tmp; | ||
453 | if ((tmp = strstr(http_method, ":")) > 0) { | ||
454 | tmp[0] = '\0'; | ||
455 | http_method = http_method; | ||
456 | http_method_proxy = ++tmp; | ||
457 | } | ||
449 | break; | 458 | break; |
450 | case 'd': /* string or substring */ | 459 | case 'd': /* string or substring */ |
451 | strncpy (header_expect, optarg, MAX_INPUT_BUFFER - 1); | 460 | strncpy (header_expect, optarg, MAX_INPUT_BUFFER - 1); |
@@ -540,6 +549,9 @@ process_arguments (int argc, char **argv) | |||
540 | case 'E': /* show extended perfdata */ | 549 | case 'E': /* show extended perfdata */ |
541 | show_extended_perfdata = TRUE; | 550 | show_extended_perfdata = TRUE; |
542 | break; | 551 | break; |
552 | case 'B': /* print body content after status line */ | ||
553 | show_body = TRUE; | ||
554 | break; | ||
543 | } | 555 | } |
544 | } | 556 | } |
545 | 557 | ||
@@ -566,6 +578,9 @@ process_arguments (int argc, char **argv) | |||
566 | if (http_method == NULL) | 578 | if (http_method == NULL) |
567 | http_method = strdup ("GET"); | 579 | http_method = strdup ("GET"); |
568 | 580 | ||
581 | if (http_method_proxy == NULL) | ||
582 | http_method_proxy = strdup ("GET"); | ||
583 | |||
569 | if (client_cert && !client_privkey) | 584 | if (client_cert && !client_privkey) |
570 | usage4 (_("If you use a client certificate you must also specify a private key file")); | 585 | usage4 (_("If you use a client certificate you must also specify a private key file")); |
571 | 586 | ||
@@ -950,7 +965,7 @@ check_http (void) | |||
950 | 965 | ||
951 | if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0 | 966 | if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0 |
952 | && host_name != NULL && use_ssl == TRUE) | 967 | && host_name != NULL && use_ssl == TRUE) |
953 | asprintf (&buf, "%s %s %s\r\n%s\r\n", "GET", server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); | 968 | asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method_proxy, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); |
954 | else | 969 | else |
955 | asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); | 970 | asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); |
956 | 971 | ||
@@ -1140,6 +1155,8 @@ check_http (void) | |||
1140 | xasprintf (&msg, | 1155 | xasprintf (&msg, |
1141 | _("Invalid HTTP response received from host on port %d: %s\n"), | 1156 | _("Invalid HTTP response received from host on port %d: %s\n"), |
1142 | server_port, status_line); | 1157 | server_port, status_line); |
1158 | if (show_body) | ||
1159 | xasprintf (&msg, _("%s\n%s"), msg, page); | ||
1143 | die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg); | 1160 | die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg); |
1144 | } | 1161 | } |
1145 | 1162 | ||
@@ -1290,6 +1307,9 @@ check_http (void) | |||
1290 | perfd_time (elapsed_time), | 1307 | perfd_time (elapsed_time), |
1291 | perfd_size (page_len)); | 1308 | perfd_size (page_len)); |
1292 | 1309 | ||
1310 | if (show_body) | ||
1311 | xasprintf (&msg, _("%s\n%s"), msg, page); | ||
1312 | |||
1293 | result = max_state_alt(get_status(elapsed_time, thlds), result); | 1313 | result = max_state_alt(get_status(elapsed_time, thlds), result); |
1294 | 1314 | ||
1295 | die (result, "HTTP %s: %s\n", state_text(result), msg); | 1315 | die (result, "HTTP %s: %s\n", state_text(result), msg); |
@@ -1581,7 +1601,7 @@ print_help (void) | |||
1581 | printf (" %s\n", _("URL to GET or POST (default: /)")); | 1601 | printf (" %s\n", _("URL to GET or POST (default: /)")); |
1582 | printf (" %s\n", "-P, --post=STRING"); | 1602 | printf (" %s\n", "-P, --post=STRING"); |
1583 | printf (" %s\n", _("URL encoded http POST data")); | 1603 | printf (" %s\n", _("URL encoded http POST data")); |
1584 | printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT)"); | 1604 | printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT, CONNECT:POST)"); |
1585 | printf (" %s\n", _("Set HTTP method.")); | 1605 | printf (" %s\n", _("Set HTTP method.")); |
1586 | printf (" %s\n", "-N, --no-body"); | 1606 | printf (" %s\n", "-N, --no-body"); |
1587 | printf (" %s\n", _("Don't wait for document body: stop reading after headers.")); | 1607 | printf (" %s\n", _("Don't wait for document body: stop reading after headers.")); |
@@ -1611,6 +1631,8 @@ print_help (void) | |||
1611 | printf (" %s\n", _("Any other tags to be sent in http header. Use multiple times for additional headers")); | 1631 | printf (" %s\n", _("Any other tags to be sent in http header. Use multiple times for additional headers")); |
1612 | printf (" %s\n", "-E, --extended-perfdata"); | 1632 | printf (" %s\n", "-E, --extended-perfdata"); |
1613 | printf (" %s\n", _("Print additional performance data")); | 1633 | printf (" %s\n", _("Print additional performance data")); |
1634 | printf (" %s\n", "-B, --show-body"); | ||
1635 | printf (" %s\n", _("Print body content below status line")); | ||
1614 | printf (" %s\n", "-L, --link"); | 1636 | printf (" %s\n", "-L, --link"); |
1615 | printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)")); | 1637 | printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)")); |
1616 | printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport>"); | 1638 | printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport>"); |
@@ -1668,7 +1690,8 @@ print_help (void) | |||
1668 | printf (" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> -S(sl) -j CONNECT -H <webserver>")); | 1690 | printf (" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> -S(sl) -j CONNECT -H <webserver>")); |
1669 | printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds")); | 1691 | printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds")); |
1670 | printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,")); | 1692 | printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,")); |
1671 | printf (" %s\n", _("a STATE_CRITICAL will be returned.")); | 1693 | printf (" %s\n", _("a STATE_CRITICAL will be returned. By adding a colon to the method you can set the method used")); |
1694 | printf (" %s\n", _("inside the proxied connection: -j CONNECT:POST")); | ||
1672 | 1695 | ||
1673 | #endif | 1696 | #endif |
1674 | 1697 | ||
diff --git a/plugins/check_load.c b/plugins/check_load.c index b1cc498f..bf7b94b4 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c | |||
@@ -33,6 +33,7 @@ const char *copyright = "1999-2007"; | |||
33 | const char *email = "devel@monitoring-plugins.org"; | 33 | const char *email = "devel@monitoring-plugins.org"; |
34 | 34 | ||
35 | #include "common.h" | 35 | #include "common.h" |
36 | #include "runcmd.h" | ||
36 | #include "utils.h" | 37 | #include "utils.h" |
37 | #include "popen.h" | 38 | #include "popen.h" |
38 | 39 | ||
@@ -52,6 +53,9 @@ static int process_arguments (int argc, char **argv); | |||
52 | static int validate_arguments (void); | 53 | static int validate_arguments (void); |
53 | void print_help (void); | 54 | void print_help (void); |
54 | void print_usage (void); | 55 | void print_usage (void); |
56 | static int print_top_consuming_processes(); | ||
57 | |||
58 | static int n_procs_to_show = 0; | ||
55 | 59 | ||
56 | /* strictly for pretty-print usage in loops */ | 60 | /* strictly for pretty-print usage in loops */ |
57 | static const int nums[3] = { 1, 5, 15 }; | 61 | static const int nums[3] = { 1, 5, 15 }; |
@@ -210,6 +214,9 @@ main (int argc, char **argv) | |||
210 | printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]); | 214 | printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]); |
211 | 215 | ||
212 | putchar('\n'); | 216 | putchar('\n'); |
217 | if (n_procs_to_show > 0) { | ||
218 | print_top_consuming_processes(); | ||
219 | } | ||
213 | return result; | 220 | return result; |
214 | } | 221 | } |
215 | 222 | ||
@@ -227,6 +234,7 @@ process_arguments (int argc, char **argv) | |||
227 | {"percpu", no_argument, 0, 'r'}, | 234 | {"percpu", no_argument, 0, 'r'}, |
228 | {"version", no_argument, 0, 'V'}, | 235 | {"version", no_argument, 0, 'V'}, |
229 | {"help", no_argument, 0, 'h'}, | 236 | {"help", no_argument, 0, 'h'}, |
237 | {"procs-to-show", required_argument, 0, 'n'}, | ||
230 | {0, 0, 0, 0} | 238 | {0, 0, 0, 0} |
231 | }; | 239 | }; |
232 | 240 | ||
@@ -234,7 +242,7 @@ process_arguments (int argc, char **argv) | |||
234 | return ERROR; | 242 | return ERROR; |
235 | 243 | ||
236 | while (1) { | 244 | while (1) { |
237 | c = getopt_long (argc, argv, "Vhrc:w:", longopts, &option); | 245 | c = getopt_long (argc, argv, "Vhrc:w:n:", longopts, &option); |
238 | 246 | ||
239 | if (c == -1 || c == EOF) | 247 | if (c == -1 || c == EOF) |
240 | break; | 248 | break; |
@@ -255,6 +263,9 @@ process_arguments (int argc, char **argv) | |||
255 | case 'h': /* help */ | 263 | case 'h': /* help */ |
256 | print_help (); | 264 | print_help (); |
257 | exit (STATE_UNKNOWN); | 265 | exit (STATE_UNKNOWN); |
266 | case 'n': | ||
267 | n_procs_to_show = atoi(optarg); | ||
268 | break; | ||
258 | case '?': /* help */ | 269 | case '?': /* help */ |
259 | usage5 (); | 270 | usage5 (); |
260 | } | 271 | } |
@@ -324,6 +335,9 @@ print_help (void) | |||
324 | printf (" %s\n", _("the load average format is the same used by \"uptime\" and \"w\"")); | 335 | printf (" %s\n", _("the load average format is the same used by \"uptime\" and \"w\"")); |
325 | printf (" %s\n", "-r, --percpu"); | 336 | printf (" %s\n", "-r, --percpu"); |
326 | printf (" %s\n", _("Divide the load averages by the number of CPUs (when possible)")); | 337 | printf (" %s\n", _("Divide the load averages by the number of CPUs (when possible)")); |
338 | printf (" %s\n", "-n, --procs-to-show=NUMBER_OF_PROCS"); | ||
339 | printf (" %s\n", _("Number of processes to show when printing the top consuming processes.")); | ||
340 | printf (" %s\n", _("NUMBER_OF_PROCS=0 disables this feature. Default value is 0")); | ||
327 | 341 | ||
328 | printf (UT_SUPPORT); | 342 | printf (UT_SUPPORT); |
329 | } | 343 | } |
@@ -332,5 +346,48 @@ void | |||
332 | print_usage (void) | 346 | print_usage (void) |
333 | { | 347 | { |
334 | printf ("%s\n", _("Usage:")); | 348 | printf ("%s\n", _("Usage:")); |
335 | printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15\n", progname); | 349 | printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15 [-n NUMBER_OF_PROCS]\n", progname); |
350 | } | ||
351 | |||
352 | #ifdef PS_USES_PROCPCPU | ||
353 | int cmpstringp(const void *p1, const void *p2) { | ||
354 | int procuid = 0; | ||
355 | int procpid = 0; | ||
356 | int procppid = 0; | ||
357 | int procvsz = 0; | ||
358 | int procrss = 0; | ||
359 | float procpcpu = 0; | ||
360 | char procstat[8]; | ||
361 | #ifdef PS_USES_PROCETIME | ||
362 | char procetime[MAX_INPUT_BUFFER]; | ||
363 | #endif /* PS_USES_PROCETIME */ | ||
364 | char procprog[MAX_INPUT_BUFFER]; | ||
365 | int pos; | ||
366 | sscanf (* (char * const *) p1, PS_FORMAT, PS_VARLIST); | ||
367 | float procpcpu1 = procpcpu; | ||
368 | sscanf (* (char * const *) p2, PS_FORMAT, PS_VARLIST); | ||
369 | return procpcpu1 < procpcpu; | ||
370 | } | ||
371 | #endif /* PS_USES_PROCPCPU */ | ||
372 | |||
373 | static int print_top_consuming_processes() { | ||
374 | int i = 0; | ||
375 | struct output chld_out, chld_err; | ||
376 | if(np_runcmd(PS_COMMAND, &chld_out, &chld_err, 0) != 0){ | ||
377 | fprintf(stderr, _("'%s' exited with non-zero status.\n"), PS_COMMAND); | ||
378 | return STATE_UNKNOWN; | ||
379 | } | ||
380 | if (chld_out.lines < 2) { | ||
381 | fprintf(stderr, _("some error occurred getting procs list.\n")); | ||
382 | return STATE_UNKNOWN; | ||
383 | } | ||
384 | #ifdef PS_USES_PROCPCPU | ||
385 | qsort(chld_out.line + 1, chld_out.lines - 1, sizeof(char*), cmpstringp); | ||
386 | #endif /* PS_USES_PROCPCPU */ | ||
387 | int lines_to_show = chld_out.lines < (n_procs_to_show + 1) | ||
388 | ? chld_out.lines : n_procs_to_show + 1; | ||
389 | for (i = 0; i < lines_to_show; i += 1) { | ||
390 | printf("%s\n", chld_out.line[i]); | ||
391 | } | ||
392 | return OK; | ||
336 | } | 393 | } |
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index 5cd47093..11ce6916 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c | |||
@@ -34,6 +34,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
34 | 34 | ||
35 | #include "common.h" | 35 | #include "common.h" |
36 | #include "utils.h" | 36 | #include "utils.h" |
37 | #include "utils_cmd.h" | ||
37 | 38 | ||
38 | #include "netutils.h" | 39 | #include "netutils.h" |
39 | #include <libpq-fe.h> | 40 | #include <libpq-fe.h> |
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index 0fcf4c68..d37c57c8 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c | |||
@@ -293,6 +293,7 @@ main (int argc, char **argv) | |||
293 | printf("%s", buffer); | 293 | printf("%s", buffer); |
294 | } | 294 | } |
295 | 295 | ||
296 | n = 0; | ||
296 | while (n < ncommands) { | 297 | while (n < ncommands) { |
297 | xasprintf (&cmd_str, "%s%s", commands[n], "\r\n"); | 298 | xasprintf (&cmd_str, "%s%s", commands[n], "\r\n"); |
298 | my_send(cmd_str, strlen(cmd_str)); | 299 | my_send(cmd_str, strlen(cmd_str)); |
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index da9638c4..e8a21a40 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -1207,8 +1207,9 @@ print_help (void) | |||
1207 | printf (" %s\n", _("Separates output on multiple OID requests")); | 1207 | printf (" %s\n", _("Separates output on multiple OID requests")); |
1208 | 1208 | ||
1209 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 1209 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
1210 | printf (" %s\n", _("NOTE the final timeout value is calculated using this formula: timeout_interval * retries + 5")); | ||
1210 | printf (" %s\n", "-e, --retries=INTEGER"); | 1211 | printf (" %s\n", "-e, --retries=INTEGER"); |
1211 | printf (" %s\n", _("Number of retries to be used in the requests")); | 1212 | printf (" %s%i\n", _("Number of retries to be used in the requests, default: "), DEFAULT_RETRIES); |
1212 | 1213 | ||
1213 | printf (" %s\n", "-O, --perf-oids"); | 1214 | printf (" %s\n", "-O, --perf-oids"); |
1214 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); | 1215 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); |
diff --git a/plugins/common.h b/plugins/common.h index 8719b502..0f08e2f6 100644 --- a/plugins/common.h +++ b/plugins/common.h | |||
@@ -174,6 +174,11 @@ | |||
174 | * | 174 | * |
175 | */ | 175 | */ |
176 | 176 | ||
177 | /* MariaDB 10.2 client does not set MYSQL_PORT */ | ||
178 | #ifndef MYSQL_PORT | ||
179 | # define MYSQL_PORT 3306 | ||
180 | #endif | ||
181 | |||
177 | enum { | 182 | enum { |
178 | OK = 0, | 183 | OK = 0, |
179 | ERROR = -1 | 184 | ERROR = -1 |
@@ -220,4 +225,18 @@ enum { | |||
220 | # define __attribute__(x) /* do nothing */ | 225 | # define __attribute__(x) /* do nothing */ |
221 | #endif | 226 | #endif |
222 | 227 | ||
228 | /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX. | ||
229 | * If that fails and the macro isn't defined, we fall back to an educated | ||
230 | * guess. There's no guarantee that our guess is adequate and the program | ||
231 | * will die with SIGSEGV if it isn't and the upper boundary is breached. */ | ||
232 | #define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */ | ||
233 | #define MAXFD_LIMIT 8192 /* upper limit of open files */ | ||
234 | #ifdef _SC_OPEN_MAX | ||
235 | static long maxfd = 0; | ||
236 | #elif defined(OPEN_MAX) | ||
237 | # define maxfd OPEN_MAX | ||
238 | #else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */ | ||
239 | # define maxfd DEFAULT_MAXFD | ||
240 | #endif | ||
241 | |||
223 | #endif /* _COMMON_H_ */ | 242 | #endif /* _COMMON_H_ */ |
diff --git a/plugins/popen.c b/plugins/popen.c index 592263fd..116d168d 100644 --- a/plugins/popen.c +++ b/plugins/popen.c | |||
@@ -78,7 +78,6 @@ RETSIGTYPE popen_timeout_alarm_handler (int); | |||
78 | 78 | ||
79 | #define min(a,b) ((a) < (b) ? (a) : (b)) | 79 | #define min(a,b) ((a) < (b) ? (a) : (b)) |
80 | #define max(a,b) ((a) > (b) ? (a) : (b)) | 80 | #define max(a,b) ((a) > (b) ? (a) : (b)) |
81 | int open_max (void); /* {Prog openmax} */ | ||
82 | static void err_sys (const char *, ...) __attribute__((noreturn,format(printf, 1, 2))); | 81 | static void err_sys (const char *, ...) __attribute__((noreturn,format(printf, 1, 2))); |
83 | char *rtrim (char *, const char *); | 82 | char *rtrim (char *, const char *); |
84 | 83 | ||
@@ -86,7 +85,6 @@ char *pname = NULL; /* caller can set this from argv[0] */ | |||
86 | 85 | ||
87 | /*int *childerr = NULL;*//* ptr to array allocated at run-time */ | 86 | /*int *childerr = NULL;*//* ptr to array allocated at run-time */ |
88 | /*extern pid_t *childpid = NULL; *//* ptr to array allocated at run-time */ | 87 | /*extern pid_t *childpid = NULL; *//* ptr to array allocated at run-time */ |
89 | static int maxfd; /* from our open_max(), {Prog openmax} */ | ||
90 | 88 | ||
91 | #ifdef REDHAT_SPOPEN_ERROR | 89 | #ifdef REDHAT_SPOPEN_ERROR |
92 | static volatile int childtermd = 0; | 90 | static volatile int childtermd = 0; |
@@ -187,13 +185,11 @@ spopen (const char *cmdstring) | |||
187 | argv[i] = NULL; | 185 | argv[i] = NULL; |
188 | 186 | ||
189 | if (childpid == NULL) { /* first time through */ | 187 | if (childpid == NULL) { /* first time through */ |
190 | maxfd = open_max (); /* allocate zeroed out array for child pids */ | ||
191 | if ((childpid = calloc ((size_t)maxfd, sizeof (pid_t))) == NULL) | 188 | if ((childpid = calloc ((size_t)maxfd, sizeof (pid_t))) == NULL) |
192 | return (NULL); | 189 | return (NULL); |
193 | } | 190 | } |
194 | 191 | ||
195 | if (child_stderr_array == NULL) { /* first time through */ | 192 | if (child_stderr_array == NULL) { /* first time through */ |
196 | maxfd = open_max (); /* allocate zeroed out array for child pids */ | ||
197 | if ((child_stderr_array = calloc ((size_t)maxfd, sizeof (int))) == NULL) | 193 | if ((child_stderr_array = calloc ((size_t)maxfd, sizeof (int))) == NULL) |
198 | return (NULL); | 194 | return (NULL); |
199 | } | 195 | } |
@@ -273,15 +269,6 @@ spclose (FILE * fp) | |||
273 | return (1); | 269 | return (1); |
274 | } | 270 | } |
275 | 271 | ||
276 | #ifdef OPEN_MAX | ||
277 | static int openmax = OPEN_MAX; | ||
278 | #else | ||
279 | static int openmax = 0; | ||
280 | #endif | ||
281 | |||
282 | #define OPEN_MAX_GUESS 256 /* if OPEN_MAX is indeterminate */ | ||
283 | /* no guarantee this is adequate */ | ||
284 | |||
285 | #ifdef REDHAT_SPOPEN_ERROR | 272 | #ifdef REDHAT_SPOPEN_ERROR |
286 | RETSIGTYPE | 273 | RETSIGTYPE |
287 | popen_sigchld_handler (int signo) | 274 | popen_sigchld_handler (int signo) |
@@ -311,22 +298,6 @@ popen_timeout_alarm_handler (int signo) | |||
311 | } | 298 | } |
312 | 299 | ||
313 | 300 | ||
314 | int | ||
315 | open_max (void) | ||
316 | { | ||
317 | if (openmax == 0) { /* first time through */ | ||
318 | errno = 0; | ||
319 | if ((openmax = sysconf (_SC_OPEN_MAX)) < 0) { | ||
320 | if (errno == 0) | ||
321 | openmax = OPEN_MAX_GUESS; /* it's indeterminate */ | ||
322 | else | ||
323 | err_sys (_("sysconf error for _SC_OPEN_MAX")); | ||
324 | } | ||
325 | } | ||
326 | return (openmax); | ||
327 | } | ||
328 | |||
329 | |||
330 | /* Fatal error related to a system call. | 301 | /* Fatal error related to a system call. |
331 | * Print a message and die. */ | 302 | * Print a message and die. */ |
332 | 303 | ||
diff --git a/plugins/runcmd.c b/plugins/runcmd.c index 1a7c904f..c3828678 100644 --- a/plugins/runcmd.c +++ b/plugins/runcmd.c | |||
@@ -67,19 +67,6 @@ | |||
67 | * occur in any number of threads simultaneously. */ | 67 | * occur in any number of threads simultaneously. */ |
68 | static pid_t *np_pids = NULL; | 68 | static pid_t *np_pids = NULL; |
69 | 69 | ||
70 | /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX. | ||
71 | * If that fails and the macro isn't defined, we fall back to an educated | ||
72 | * guess. There's no guarantee that our guess is adequate and the program | ||
73 | * will die with SIGSEGV if it isn't and the upper boundary is breached. */ | ||
74 | #ifdef _SC_OPEN_MAX | ||
75 | static long maxfd = 0; | ||
76 | #elif defined(OPEN_MAX) | ||
77 | # define maxfd OPEN_MAX | ||
78 | #else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */ | ||
79 | # define maxfd 256 | ||
80 | #endif | ||
81 | |||
82 | |||
83 | /** prototypes **/ | 70 | /** prototypes **/ |
84 | static int np_runcmd_open(const char *, int *, int *) | 71 | static int np_runcmd_open(const char *, int *, int *) |
85 | __attribute__((__nonnull__(1, 2, 3))); | 72 | __attribute__((__nonnull__(1, 2, 3))); |
diff --git a/plugins/t/NPTest.cache.travis b/plugins/t/NPTest.cache.travis index e9705f3b..9b9f8059 100644 --- a/plugins/t/NPTest.cache.travis +++ b/plugins/t/NPTest.cache.travis | |||
@@ -1,62 +1,54 @@ | |||
1 | { | 1 | { |
2 | 'MYSQL_LOGIN_DETAILS' => '-u root -d test', | ||
3 | 'NP_ALLOW_SUDO' => 'yes', | 2 | 'NP_ALLOW_SUDO' => 'yes', |
4 | 'NP_DNS_SERVER' => '8.8.8.8', | 3 | 'NP_DNS_SERVER' => '8.8.8.8', |
5 | 'NP_GOOD_NTP_SERVICE' => '', | 4 | 'NP_GOOD_NTP_SERVICE' => '', |
5 | 'NP_HOST_DHCP_RESPONSIVE' => '', | ||
6 | 'NP_HOST_HPJD_PORT_INVALID' => '161', | ||
7 | 'NP_HOST_HPJD_PORT_VALID' => '', | ||
8 | 'NP_HOSTNAME_INVALID_CIDR' => '130.133.8.39/30', | ||
6 | 'NP_HOSTNAME_INVALID' => 'nosuchhost', | 9 | 'NP_HOSTNAME_INVALID' => 'nosuchhost', |
7 | 'NP_HOSTNAME_VALID' => 'monitoring-plugins.org', | ||
8 | 'NP_HOSTNAME_VALID_IP' => '130.133.8.40', | ||
9 | 'NP_HOSTNAME_VALID_CIDR' => '130.133.8.41/30', | 10 | 'NP_HOSTNAME_VALID_CIDR' => '130.133.8.41/30', |
10 | 'NP_HOSTNAME_INVALID_CIDR' => '130.133.8.39/30', | 11 | 'NP_HOSTNAME_VALID_IP' => '130.133.8.40', |
12 | 'NP_HOSTNAME_VALID' => 'monitoring-plugins.org', | ||
11 | 'NP_HOSTNAME_VALID_REVERSE' => 'orwell.monitoring-plugins.org.', | 13 | 'NP_HOSTNAME_VALID_REVERSE' => 'orwell.monitoring-plugins.org.', |
12 | 'NP_HOST_DHCP_RESPONSIVE' => '', | ||
13 | 'NP_HOST_NONRESPONSIVE' => '10.0.0.1', | 14 | 'NP_HOST_NONRESPONSIVE' => '10.0.0.1', |
14 | 'NP_HOST_RESPONSIVE' => 'localhost', | 15 | 'NP_HOST_RESPONSIVE' => 'localhost', |
15 | 'NP_HOST_SMB' => '', | 16 | 'NP_HOST_SMB' => '', |
16 | 'NP_HOST_SNMP' => 'localhost', | 17 | 'NP_HOST_SNMP' => '', |
17 | 'NP_HOST_TCP_FTP' => '', | 18 | 'NP_HOST_TCP_FTP' => '', |
18 | 'NP_HOST_TCP_HPJD' => '', | 19 | 'NP_HOST_TCP_HPJD' => '', |
19 | 'NP_HOST_HPJD_PORT_INVALID' => '161', | ||
20 | 'NP_HOST_HPJD_PORT_VALID' => '', | ||
21 | 'NP_HOST_TCP_HTTP' => 'localhost', | ||
22 | 'NP_HOST_TCP_HTTP2' => 'test.monitoring-plugins.org', | 20 | 'NP_HOST_TCP_HTTP2' => 'test.monitoring-plugins.org', |
21 | 'NP_HOST_TCP_HTTP' => 'localhost', | ||
23 | 'NP_HOST_TCP_IMAP' => 'imap.web.de', | 22 | 'NP_HOST_TCP_IMAP' => 'imap.web.de', |
23 | 'NP_HOST_TCP_JABBER' => 'jabber.org', | ||
24 | 'NP_HOST_TCP_LDAP' => 'localhost', | 24 | 'NP_HOST_TCP_LDAP' => 'localhost', |
25 | 'NP_HOST_TCP_POP' => 'pop.web.de', | 25 | 'NP_HOST_TCP_POP' => 'pop.web.de', |
26 | 'NP_HOST_TCP_PROXY' => 'localhost', | ||
26 | 'NP_HOST_TCP_SMTP' => 'localhost', | 27 | 'NP_HOST_TCP_SMTP' => 'localhost', |
27 | 'NP_HOST_TCP_SMTP_NOTLS' => '', | 28 | 'NP_HOST_TCP_SMTP_NOTLS' => '', |
28 | 'NP_HOST_TCP_SMTP_TLS' => '', | 29 | 'NP_HOST_TCP_SMTP_TLS' => '', |
30 | 'NP_HOST_TLS_CERT' => 'localhost, | ||
31 | 'NP_HOST_TLS_HTTP' => 'localhost', | ||
32 | 'NP_HOST_UDP_TIME' => 'none', | ||
29 | 'NP_INTERNET_ACCESS' => 'yes', | 33 | 'NP_INTERNET_ACCESS' => 'yes', |
30 | 'NP_LDAP_BASE_DN' => 'cn=admin,dc=nodomain', | 34 | 'NP_LDAP_BASE_DN' => 'cn=admin,dc=nodomain', |
31 | 'NP_MOUNTPOINT2_VALID' => '/media/ramdisk', | 35 | 'NP_MOUNTPOINT2_VALID' => '/media/ramdisk', |
32 | 'NP_MOUNTPOINT_VALID' => '/', | 36 | 'NP_MOUNTPOINT_VALID' => '/', |
37 | 'NP_MYSQL_LOGIN_DETAILS' => '-u root -d test', | ||
33 | 'NP_MYSQL_SERVER' => 'localhost', | 38 | 'NP_MYSQL_SERVER' => 'localhost', |
34 | 'NP_HOST_UDP_TIME' => 'localhost', | ||
35 | 'NP_MYSQL_SOCKET' => '/var/run/mysqld/mysqld.sock', | 39 | 'NP_MYSQL_SOCKET' => '/var/run/mysqld/mysqld.sock', |
36 | 'NP_MYSQL_WITH_SLAVE' => '', | 40 | 'NP_MYSQL_WITH_SLAVE' => '', |
37 | 'NP_MYSQL_WITH_SLAVE_LOGIN' => '', | 41 | 'NP_MYSQL_WITH_SLAVE_LOGIN' => '', |
38 | 'NP_NO_NTP_SERVICE' => 'localhost', | 42 | 'NP_NO_NTP_SERVICE' => 'localhost', |
43 | 'NP_PORT_TCP_PROXY' => '3128', | ||
39 | 'NP_SMB_SHARE' => '', | 44 | 'NP_SMB_SHARE' => '', |
40 | 'NP_SMB_SHARE_DENY' => '', | 45 | 'NP_SMB_SHARE_DENY' => '', |
41 | 'NP_SMB_SHARE_SPC' => '', | 46 | 'NP_SMB_SHARE_SPC' => '', |
42 | 'NP_SMB_VALID_USER' => '', | 47 | 'NP_SMB_VALID_USER' => '', |
43 | 'NP_SMB_VALID_USER_PASS' => '', | 48 | 'NP_SMB_VALID_USER_PASS' => '', |
44 | 'NP_SNMP_COMMUNITY' => 'public', | 49 | 'NP_SNMP_COMMUNITY' => '', |
50 | 'NP_SNMP_USER' => '', | ||
45 | 'NP_SSH_CONFIGFILE' => '~/.ssh/config', | 51 | 'NP_SSH_CONFIGFILE' => '~/.ssh/config', |
46 | 'NP_SSH_HOST' => 'localhost', | 52 | 'NP_SSH_HOST' => 'localhost', |
47 | 'NP_SSH_IDENTITY' => '~/.ssh/id_dsa', | 53 | 'NP_SSH_IDENTITY' => '~/.ssh/id_rsa' |
48 | 'NP_HOST_TCP_JABBER' => 'jabber.org', | ||
49 | 'host_nonresponsive' => '10.0.0.1', | ||
50 | 'host_responsive' => 'localhost', | ||
51 | 'host_snmp' => '', | ||
52 | 'host_tcp_ftp' => '', | ||
53 | 'host_tcp_http' => 'localhost', | ||
54 | 'host_tcp_imap' => 'imap.nierlein.de', | ||
55 | 'host_tcp_smtp' => 'localhost', | ||
56 | 'hostname_invalid' => 'nosuchhost', | ||
57 | 'snmp_community' => '', | ||
58 | 'user_snmp' => '', | ||
59 | 'host_udp_time' => 'none', | ||
60 | 'host_tls_http' => 'localhost', | ||
61 | 'host_tls_cert' => 'localhost', | ||
62 | } | 54 | } |
diff --git a/plugins/t/check_by_ssh.t b/plugins/t/check_by_ssh.t index 4797390d..1d2939e9 100644 --- a/plugins/t/check_by_ssh.t +++ b/plugins/t/check_by_ssh.t | |||
@@ -9,17 +9,9 @@ use Test::More; | |||
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | # Required parameters | 11 | # Required parameters |
12 | my $ssh_service = getTestParameter( "NP_SSH_HOST", | 12 | my $ssh_service = getTestParameter("NP_SSH_HOST", "A host providing SSH service", "localhost"); |
13 | "A host providing SSH service", | 13 | my $ssh_key = getTestParameter("NP_SSH_IDENTITY", "A key allowing access to NP_SSH_HOST", "~/.ssh/id_dsa"); |
14 | "localhost"); | 14 | my $ssh_conf = getTestParameter( "NP_SSH_CONFIGFILE", "A config file with ssh settings", "~/.ssh/config"); |
15 | |||
16 | my $ssh_key = getTestParameter( "NP_SSH_IDENTITY", | ||
17 | "A key allowing access to NP_SSH_HOST", | ||
18 | "~/.ssh/id_dsa"); | ||
19 | |||
20 | my $ssh_conf = getTestParameter( "NP_SSH_CONFIGFILE", | ||
21 | "A config file with ssh settings", | ||
22 | "~/.ssh/config"); | ||
23 | 15 | ||
24 | 16 | ||
25 | plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_service && $ssh_key); | 17 | plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_service && $ssh_key); |
diff --git a/plugins/t/check_fping.t b/plugins/t/check_fping.t index 08692e46..342b0a7e 100644 --- a/plugins/t/check_fping.t +++ b/plugins/t/check_fping.t | |||
@@ -15,15 +15,9 @@ BEGIN {$tests = 4; plan tests => $tests} | |||
15 | my $successOutput = '/^FPING OK - /'; | 15 | my $successOutput = '/^FPING OK - /'; |
16 | my $failureOutput = '/^FPING CRITICAL - /'; | 16 | my $failureOutput = '/^FPING CRITICAL - /'; |
17 | 17 | ||
18 | my $host_responsive = getTestParameter( "host_responsive", "NP_HOST_RESPONSIVE", "localhost", | 18 | my $host_responsive = getTestParameter("NP_HOST_RESPONSIVE", "The hostname of system responsive to network requests", "localhost"); |
19 | "The hostname of system responsive to network requests" ); | 19 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); |
20 | 20 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | |
21 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
22 | "The hostname of system not responsive to network requests" ); | ||
23 | |||
24 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
25 | "An invalid (not known to DNS) hostname" ); | ||
26 | |||
27 | 21 | ||
28 | my $t; | 22 | my $t; |
29 | 23 | ||
diff --git a/plugins/t/check_ftp.t b/plugins/t/check_ftp.t index de6831ba..93a7d7c3 100644 --- a/plugins/t/check_ftp.t +++ b/plugins/t/check_ftp.t | |||
@@ -11,14 +11,9 @@ use NPTest; | |||
11 | use vars qw($tests); | 11 | use vars qw($tests); |
12 | BEGIN {$tests = 4; plan tests => $tests} | 12 | BEGIN {$tests = 4; plan tests => $tests} |
13 | 13 | ||
14 | my $host_tcp_ftp = getTestParameter( "host_tcp_ftp", "NP_HOST_TCP_FTP", "localhost", | 14 | my $host_tcp_ftp = getTestParameter("NP_HOST_TCP_FTP", "A host providing the FTP Service (an FTP server)", "localhost"); |
15 | "A host providing the FTP Service (an FTP server)"); | 15 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); |
16 | 16 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | |
17 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
18 | "The hostname of system not responsive to network requests" ); | ||
19 | |||
20 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
21 | "An invalid (not known to DNS) hostname" ); | ||
22 | 17 | ||
23 | my $successOutput = '/FTP OK -\s+[0-9]?\.?[0-9]+ second response time/'; | 18 | my $successOutput = '/FTP OK -\s+[0-9]?\.?[0-9]+ second response time/'; |
24 | 19 | ||
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index 8bd484a0..b3760ebe 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t | |||
@@ -9,38 +9,21 @@ use Test::More; | |||
9 | use POSIX qw/mktime strftime/; | 9 | use POSIX qw/mktime strftime/; |
10 | use NPTest; | 10 | use NPTest; |
11 | 11 | ||
12 | plan tests => 49; | 12 | plan tests => 50; |
13 | 13 | ||
14 | my $successOutput = '/OK.*HTTP.*second/'; | 14 | my $successOutput = '/OK.*HTTP.*second/'; |
15 | 15 | ||
16 | my $res; | 16 | my $res; |
17 | 17 | ||
18 | my $host_tcp_http = getTestParameter( "NP_HOST_TCP_HTTP", | 18 | my $host_tcp_http = getTestParameter("NP_HOST_TCP_HTTP", "A host providing the HTTP Service (a web server)", "localhost"); |
19 | "A host providing the HTTP Service (a web server)", | 19 | my $host_tls_http = getTestParameter("NP_HOST_TLS_HTTP", "A host providing the HTTPS Service (a tls web server)", "localhost"); |
20 | "localhost" ); | 20 | my $host_tls_cert = getTestParameter("NP_HOST_TLS_CERT", "the common name of the certificate.", "localhost"); |
21 | 21 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); | |
22 | my $host_tls_http = getTestParameter( "host_tls_http", "NP_HOST_TLS_HTTP", "localhost", | 22 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); |
23 | "A host providing the HTTPS Service (a tls web server)" ); | 23 | my $internet_access = getTestParameter("NP_INTERNET_ACCESS", "Is this system directly connected to the internet?", "yes"); |
24 | 24 | my $host_tcp_http2 = getTestParameter("NP_HOST_TCP_HTTP2", "A host providing an index page containing the string 'monitoring'", "test.monitoring-plugins.org"); | |
25 | my $host_tls_cert = getTestParameter( "host_tls_cert", "NP_HOST_TLS_CERT", "localhost", | 25 | my $host_tcp_proxy = getTestParameter("NP_HOST_TCP_PROXY", "A host providing a HTTP proxy with CONNECT support", "localhost"); |
26 | "the common name of the certificate." ); | 26 | my $port_tcp_proxy = getTestParameter("NP_PORT_TCP_PROXY", "Port of the proxy with HTTP and CONNECT support", "3128"); |
27 | |||
28 | |||
29 | my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", | ||
30 | "The hostname of system not responsive to network requests", | ||
31 | "10.0.0.1" ); | ||
32 | |||
33 | my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", | ||
34 | "An invalid (not known to DNS) hostname", | ||
35 | "nosuchhost"); | ||
36 | |||
37 | my $internet_access = getTestParameter( "NP_INTERNET_ACCESS", | ||
38 | "Is this system directly connected to the internet?", | ||
39 | "yes"); | ||
40 | |||
41 | my $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2", | ||
42 | "A host providing an index page containing the string 'monitoring'", | ||
43 | "test.monitoring-plugins.org" ); | ||
44 | 27 | ||
45 | my $faketime = -x '/usr/bin/faketime' ? 1 : 0; | 28 | my $faketime = -x '/usr/bin/faketime' ? 1 : 0; |
46 | 29 | ||
@@ -150,7 +133,7 @@ SKIP: { | |||
150 | 133 | ||
151 | # run some certificate checks with faketime | 134 | # run some certificate checks with faketime |
152 | SKIP: { | 135 | SKIP: { |
153 | skip "No faketime binary found", 12 if !$faketime; | 136 | skip "No faketime binary found", 7 if !$faketime; |
154 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./check_http -C 1 $host_tls_http"); | 137 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./check_http -C 1 $host_tls_http"); |
155 | like($res->output, qr/OK - Certificate '$host_tls_cert' will expire on/, "Catch cert output"); | 138 | like($res->output, qr/OK - Certificate '$host_tls_cert' will expire on/, "Catch cert output"); |
156 | is( $res->return_code, 0, "Catch cert output exit code" ); | 139 | is( $res->return_code, 0, "Catch cert output exit code" ); |
@@ -163,23 +146,18 @@ SKIP: { | |||
163 | my $time = strftime("%Y-%m-%d %H:%M:%S", localtime($ts)); | 146 | my $time = strftime("%Y-%m-%d %H:%M:%S", localtime($ts)); |
164 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_http -C 1 $host_tls_http"); | 147 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_http -C 1 $host_tls_http"); |
165 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' just expired/, "Output on expire date"); | 148 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' just expired/, "Output on expire date"); |
166 | is( $res->return_code, 2, "Output on expire date" ); | ||
167 | 149 | ||
168 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-1))."' ./check_http -C 1 $host_tls_http"); | 150 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-1))."' ./check_http -C 1 $host_tls_http"); |
169 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 0 minutes/, "cert expires in 1 second output"); | 151 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 0 minutes/, "cert expires in 1 second output"); |
170 | is( $res->return_code, 2, "cert expires in 1 second exit code" ); | ||
171 | 152 | ||
172 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-120))."' ./check_http -C 1 $host_tls_http"); | 153 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-120))."' ./check_http -C 1 $host_tls_http"); |
173 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 minutes/, "cert expires in 2 minutes output"); | 154 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 minutes/, "cert expires in 2 minutes output"); |
174 | is( $res->return_code, 2, "cert expires in 2 minutes exit code" ); | ||
175 | 155 | ||
176 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-7200))."' ./check_http -C 1 $host_tls_http"); | 156 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-7200))."' ./check_http -C 1 $host_tls_http"); |
177 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 hours/, "cert expires in 2 hours output"); | 157 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 hours/, "cert expires in 2 hours output"); |
178 | is( $res->return_code, 2, "cert expires in 2 hours exit code" ); | ||
179 | 158 | ||
180 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_http -C 1 $host_tls_http"); | 159 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_http -C 1 $host_tls_http"); |
181 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expired on/, "Certificate expired output"); | 160 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expired on/, "Certificate expired output"); |
182 | is( $res->return_code, 2, "Certificate expired exit code" ); | ||
183 | }; | 161 | }; |
184 | 162 | ||
185 | $res = NPTest->testCmd( "./check_http --ssl $host_tls_http -E" ); | 163 | $res = NPTest->testCmd( "./check_http --ssl $host_tls_http -E" ); |
@@ -198,3 +176,19 @@ SKIP: { | |||
198 | $res = NPTest->testCmd( "./check_http -H www.mozilla.com --extended-perfdata" ); | 176 | $res = NPTest->testCmd( "./check_http -H www.mozilla.com --extended-perfdata" ); |
199 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 177 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); |
200 | } | 178 | } |
179 | |||
180 | SKIP: { | ||
181 | skip "No internet access or proxy configured", 6 if $internet_access eq "no" or ! $host_tcp_proxy; | ||
182 | |||
183 | $res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -u http://$host_tcp_http -e 200,301,302"); | ||
184 | is( $res->return_code, 0, "Proxy HTTP works"); | ||
185 | like($res->output, qr/OK: Status line output matched/, "Proxy HTTP Output is sufficent"); | ||
186 | |||
187 | $res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT"); | ||
188 | is( $res->return_code, 0, "Proxy HTTP CONNECT works"); | ||
189 | like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent"); | ||
190 | |||
191 | $res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT:HEAD"); | ||
192 | is( $res->return_code, 0, "Proxy HTTP CONNECT works with override method"); | ||
193 | like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent"); | ||
194 | } | ||
diff --git a/plugins/t/check_imap.t b/plugins/t/check_imap.t index 9c6eae1f..7c74e564 100644 --- a/plugins/t/check_imap.t +++ b/plugins/t/check_imap.t | |||
@@ -8,17 +8,10 @@ use strict; | |||
8 | use Test::More tests => 7; | 8 | use Test::More tests => 7; |
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | my $host_tcp_smtp = getTestParameter( "host_tcp_smtp", "NP_HOST_TCP_SMTP", "mailhost", | 11 | my $host_tcp_smtp = getTestParameter("NP_HOST_TCP_SMTP", "A host providing an STMP Service (a mail server)", "mailhost"); |
12 | "A host providing an STMP Service (a mail server)"); | 12 | my $host_tcp_imap = getTestParameter("NP_HOST_TCP_IMAP", "A host providing an IMAP Service (a mail server)", $host_tcp_smtp); |
13 | 13 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); | |
14 | my $host_tcp_imap = getTestParameter( "host_tcp_imap", "NP_HOST_TCP_IMAP", $host_tcp_smtp, | 14 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); |
15 | "A host providing an IMAP Service (a mail server)"); | ||
16 | |||
17 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
18 | "The hostname of system not responsive to network requests" ); | ||
19 | |||
20 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
21 | "An invalid (not known to DNS) hostname" ); | ||
22 | 15 | ||
23 | my $t; | 16 | my $t; |
24 | 17 | ||
diff --git a/plugins/t/check_jabber.t b/plugins/t/check_jabber.t index 7a708d5b..fcdae179 100644 --- a/plugins/t/check_jabber.t +++ b/plugins/t/check_jabber.t | |||
@@ -10,23 +10,9 @@ use NPTest; | |||
10 | 10 | ||
11 | plan tests => 10; | 11 | plan tests => 10; |
12 | 12 | ||
13 | my $host_tcp_jabber = getTestParameter( | 13 | my $host_tcp_jabber = getTestParameter("NP_HOST_TCP_JABBER", "A host providing the Jabber Service", "jabber.de"); |
14 | "NP_HOST_TCP_JABBER", | 14 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); |
15 | "A host providing the Jabber Service", | 15 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); |
16 | "jabber.org" | ||
17 | ); | ||
18 | |||
19 | my $host_nonresponsive = getTestParameter( | ||
20 | "NP_HOST_NONRESPONSIVE", | ||
21 | "The hostname of system not responsive to network requests", | ||
22 | "10.0.0.1", | ||
23 | ); | ||
24 | |||
25 | my $hostname_invalid = getTestParameter( | ||
26 | "NP_HOSTNAME_INVALID", | ||
27 | "An invalid (not known to DNS) hostname", | ||
28 | "nosuchhost", | ||
29 | ); | ||
30 | 16 | ||
31 | 17 | ||
32 | my $jabberOK = '/JABBER OK\s-\s\d+\.\d+\ssecond response time on '.$host_tcp_jabber.' port 5222/'; | 18 | my $jabberOK = '/JABBER OK\s-\s\d+\.\d+\ssecond response time on '.$host_tcp_jabber.' port 5222/'; |
diff --git a/plugins/t/check_ldap.t b/plugins/t/check_ldap.t index b8944d4b..b8a4a766 100644 --- a/plugins/t/check_ldap.t +++ b/plugins/t/check_ldap.t | |||
@@ -9,19 +9,10 @@ use warnings; | |||
9 | use Test::More; | 9 | use Test::More; |
10 | use NPTest; | 10 | use NPTest; |
11 | 11 | ||
12 | my $host_tcp_ldap = getTestParameter("NP_HOST_TCP_LDAP", | 12 | my $host_tcp_ldap = getTestParameter("NP_HOST_TCP_LDAP", "A host providing the LDAP Service", "localhost"); |
13 | "A host providing the LDAP Service", | 13 | my $ldap_base_dn = getTestParameter("NP_LDAP_BASE_DN", "A base dn for the LDAP Service", "cn=admin"); |
14 | "localhost" ); | 14 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); |
15 | 15 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | |
16 | my $ldap_base_dn = getTestParameter("NP_LDAP_BASE_DN", | ||
17 | "A base dn for the LDAP Service", | ||
18 | "cn=admin" ); | ||
19 | |||
20 | my $host_nonresponsive = getTestParameter("host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
21 | "The hostname of system not responsive to network requests" ); | ||
22 | |||
23 | my $hostname_invalid = getTestParameter("hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
24 | "An invalid (not known to DNS) hostname" ); | ||
25 | 16 | ||
26 | my($result, $cmd); | 17 | my($result, $cmd); |
27 | my $command = './check_ldap'; | 18 | my $command = './check_ldap'; |
diff --git a/plugins/t/check_mysql.t b/plugins/t/check_mysql.t index 28cd4cd0..e426bf59 100644 --- a/plugins/t/check_mysql.t +++ b/plugins/t/check_mysql.t | |||
@@ -21,30 +21,11 @@ plan skip_all => "check_mysql not compiled" unless (-x "check_mysql"); | |||
21 | plan tests => 15; | 21 | plan tests => 15; |
22 | 22 | ||
23 | my $bad_login_output = '/Access denied for user /'; | 23 | my $bad_login_output = '/Access denied for user /'; |
24 | my $mysqlserver = getTestParameter( | 24 | my $mysqlserver = getTestParameter("NP_MYSQL_SERVER", "A MySQL Server hostname or IP with no slaves setup"); |
25 | "NP_MYSQL_SERVER", | 25 | my $mysqlsocket = getTestParameter("NP_MYSQL_SOCKET", "Full path to a MySQL Server socket with no slaves setup"); |
26 | "A MySQL Server hostname or IP with no slaves setup" | 26 | my $mysql_login_details = getTestParameter("NP_MYSQL_LOGIN_DETAILS", "Command line parameters to specify login access (requires REPLICATION CLIENT privleges)", "-u test -ptest"); |
27 | ); | 27 | my $with_slave = getTestParameter("NP_MYSQL_WITH_SLAVE", "MySQL server with slaves setup"); |
28 | my $mysqlsocket = getTestParameter( | 28 | my $with_slave_login = getTestParameter("NP_MYSQL_WITH_SLAVE_LOGIN", "Login details for server with slave (requires REPLICATION CLIENT privleges)", $mysql_login_details || "-u test -ptest"); |
29 | "NP_MYSQL_SOCKET", | ||
30 | "Full path to a MySQL Server socket with no slaves setup" | ||
31 | ); | ||
32 | my $mysql_login_details = getTestParameter( | ||
33 | "MYSQL_LOGIN_DETAILS", | ||
34 | "Command line parameters to specify login access (requires " . | ||
35 | "REPLICATION CLIENT privleges)", | ||
36 | "-u test -ptest", | ||
37 | ); | ||
38 | my $with_slave = getTestParameter( | ||
39 | "NP_MYSQL_WITH_SLAVE", | ||
40 | "MySQL server with slaves setup" | ||
41 | ); | ||
42 | my $with_slave_login = getTestParameter( | ||
43 | "NP_MYSQL_WITH_SLAVE_LOGIN", | ||
44 | "Login details for server with slave (requires REPLICATION CLIENT " . | ||
45 | "privleges)", | ||
46 | $mysql_login_details || "-u test -ptest" | ||
47 | ); | ||
48 | 29 | ||
49 | my $result; | 30 | my $result; |
50 | 31 | ||
diff --git a/plugins/t/check_mysql_query.t b/plugins/t/check_mysql_query.t index 407af881..96899ac6 100644 --- a/plugins/t/check_mysql_query.t +++ b/plugins/t/check_mysql_query.t | |||
@@ -17,15 +17,8 @@ use vars qw($tests); | |||
17 | 17 | ||
18 | plan skip_all => "check_mysql_query not compiled" unless (-x "check_mysql_query"); | 18 | plan skip_all => "check_mysql_query not compiled" unless (-x "check_mysql_query"); |
19 | 19 | ||
20 | my $mysqlserver = getTestParameter( | 20 | my $mysqlserver = getTestParameter("NP_MYSQL_SERVER", "A MySQL Server with no slaves setup"); |
21 | "NP_MYSQL_SERVER", | 21 | my $mysql_login_details = getTestParameter("NP_MYSQL_LOGIN_DETAILS", "Command line parameters to specify login access", "-u user -ppw -d db"); |
22 | "A MySQL Server with no slaves setup" | ||
23 | ); | ||
24 | my $mysql_login_details = getTestParameter( | ||
25 | "MYSQL_LOGIN_DETAILS", | ||
26 | "Command line parameters to specify login access", | ||
27 | "-u user -ppw -d db", | ||
28 | ); | ||
29 | my $result; | 22 | my $result; |
30 | 23 | ||
31 | if (! $mysqlserver) { | 24 | if (! $mysqlserver) { |
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t index 9a6cd2bb..f2f218fd 100644 --- a/plugins/t/check_snmp.t +++ b/plugins/t/check_snmp.t | |||
@@ -15,18 +15,12 @@ BEGIN { | |||
15 | 15 | ||
16 | my $res; | 16 | my $res; |
17 | 17 | ||
18 | my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost", | 18 | my $host_snmp = getTestParameter("NP_HOST_SNMP", "A host providing an SNMP Service", "localhost"); |
19 | "A host providing an SNMP Service"); | 19 | my $snmp_community = getTestParameter("NP_SNMP_COMMUNITY", "The SNMP Community string for SNMP Testing (assumes snmp v1)", "public"); |
20 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); | ||
21 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | ||
22 | my $user_snmp = getTestParameter("NP_SNMP_USER", "An SNMP user", "auth_md5"); | ||
20 | 23 | ||
21 | my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public", | ||
22 | "The SNMP Community string for SNMP Testing (assumes snmp v1)" ); | ||
23 | |||
24 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
25 | "The hostname of system not responsive to network requests" ); | ||
26 | |||
27 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
28 | "An invalid (not known to DNS) hostname" ); | ||
29 | my $user_snmp = getTestParameter( "user_snmp", "NP_SNMP_USER", "auth_md5", "An SNMP user"); | ||
30 | 24 | ||
31 | $res = NPTest->testCmd( "./check_snmp -t 1" ); | 25 | $res = NPTest->testCmd( "./check_snmp -t 1" ); |
32 | is( $res->return_code, 3, "No host name" ); | 26 | is( $res->return_code, 3, "No host name" ); |
diff --git a/plugins/t/check_ssh.t b/plugins/t/check_ssh.t index 80083492..a5cd23ce 100644 --- a/plugins/t/check_ssh.t +++ b/plugins/t/check_ssh.t | |||
@@ -9,17 +9,9 @@ use Test::More; | |||
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | # Required parameters | 11 | # Required parameters |
12 | my $ssh_host = getTestParameter("NP_SSH_HOST", | 12 | my $ssh_host = getTestParameter("NP_SSH_HOST", "A host providing SSH service", "localhost"); |
13 | "A host providing SSH service", | 13 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1" ); |
14 | "localhost"); | 14 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost" ); |
15 | |||
16 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", | ||
17 | "The hostname of system not responsive to network requests", | ||
18 | "10.0.0.1" ); | ||
19 | |||
20 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", | ||
21 | "An invalid (not known to DNS) hostname", | ||
22 | "nosuchhost" ); | ||
23 | 15 | ||
24 | 16 | ||
25 | plan skip_all => "SSH_HOST must be defined" unless $ssh_host; | 17 | plan skip_all => "SSH_HOST must be defined" unless $ssh_host; |
diff --git a/plugins/t/check_tcp.t b/plugins/t/check_tcp.t index 121b0cb3..cb4de53d 100644 --- a/plugins/t/check_tcp.t +++ b/plugins/t/check_tcp.t | |||
@@ -15,21 +15,11 @@ BEGIN { | |||
15 | } | 15 | } |
16 | 16 | ||
17 | 17 | ||
18 | my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost", | 18 | my $host_tcp_http = getTestParameter("NP_HOST_TCP_HTTP", "A host providing the HTTP Service (a web server)", "localhost"); |
19 | "A host providing the HTTP Service (a web server)" ); | 19 | my $host_tls_http = getTestParameter("NP_HOST_TLS_HTTP", "A host providing the HTTPS Service (a tls web server)", "localhost"); |
20 | 20 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); | |
21 | my $host_tls_http = getTestParameter( "host_tls_http", "NP_HOST_TLS_HTTP", "localhost", | 21 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); |
22 | "A host providing the HTTPS Service (a tls web server)" ); | 22 | my $internet_access = getTestParameter("NP_INTERNET_ACCESS", "Is this system directly connected to the internet?", "yes"); |
23 | |||
24 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
25 | "The hostname of system not responsive to network requests" ); | ||
26 | |||
27 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
28 | "An invalid (not known to DNS) hostname" ); | ||
29 | |||
30 | my $internet_access = getTestParameter( "NP_INTERNET_ACCESS", | ||
31 | "Is this system directly connected to the internet?", | ||
32 | "yes"); | ||
33 | 23 | ||
34 | my $successOutput = '/^TCP OK\s-\s+[0-9]?\.?[0-9]+ second response time on port [0-9]+/'; | 24 | my $successOutput = '/^TCP OK\s-\s+[0-9]?\.?[0-9]+ second response time on port [0-9]+/'; |
35 | 25 | ||
diff --git a/plugins/t/check_time.t b/plugins/t/check_time.t index 961f56e6..92c2f891 100644 --- a/plugins/t/check_time.t +++ b/plugins/t/check_time.t | |||
@@ -11,14 +11,9 @@ use NPTest; | |||
11 | use vars qw($tests); | 11 | use vars qw($tests); |
12 | BEGIN {$tests = 8; plan tests => $tests} | 12 | BEGIN {$tests = 8; plan tests => $tests} |
13 | 13 | ||
14 | my $host_udp_time = getTestParameter( "host_udp_time", "NP_HOST_UDP_TIME", "localhost", | 14 | my $host_udp_time = getTestParameter("NP_HOST_UDP_TIME", "A host providing the UDP Time Service", "localhost"); |
15 | "A host providing the UDP Time Service" ); | 15 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); |
16 | 16 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | |
17 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
18 | "The hostname of system not responsive to network requests" ); | ||
19 | |||
20 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
21 | "An invalid (not known to DNS) hostname" ); | ||
22 | 17 | ||
23 | my $successOutput = '/^TIME OK - [0-9]+ second time difference/'; | 18 | my $successOutput = '/^TIME OK - [0-9]+ second time difference/'; |
24 | 19 | ||
diff --git a/plugins/tests/certs/server-cert.pem b/plugins/tests/certs/server-cert.pem index 549e4f7e..b84b91d2 100644 --- a/plugins/tests/certs/server-cert.pem +++ b/plugins/tests/certs/server-cert.pem | |||
@@ -1,21 +1,24 @@ | |||
1 | -----BEGIN CERTIFICATE----- | 1 | -----BEGIN CERTIFICATE----- |
2 | MIIDYzCCAsygAwIBAgIJAL8LkpNwzYdxMA0GCSqGSIb3DQEBBAUAMH8xCzAJBgNV | 2 | MIIEBjCCAu6gAwIBAgIJANbQ5QQrKhUGMA0GCSqGSIb3DQEBCwUAMIGXMQswCQYD |
3 | BAYTAlVLMRMwEQYDVQQIEwpEZXJieXNoaXJlMQ8wDQYDVQQHEwZCZWxwZXIxFzAV | 3 | VQQGEwJERTEQMA4GA1UECAwHQmF2YXJpYTEPMA0GA1UEBwwGTXVuaWNoMRswGQYD |
4 | BgNVBAoTDk5hZ2lvcyBQbHVnaW5zMREwDwYDVQQDEwhUb24gVm9vbjEeMBwGCSqG | 4 | VQQKDBJNb25pdG9yaW5nIFBsdWdpbnMxGzAZBgNVBAMMEk1vbml0b3JpbmcgUGx1 |
5 | SIb3DQEJARYPdG9udm9vbkBtYWMuY29tMB4XDTA5MDMwNTIxNDEyOFoXDTE5MDMw | 5 | Z2luczErMCkGCSqGSIb3DQEJARYcZGV2ZWxAbW9uaXRvcmluZy1wbHVnaW5zLm9y |
6 | MzIxNDEyOFowfzELMAkGA1UEBhMCVUsxEzARBgNVBAgTCkRlcmJ5c2hpcmUxDzAN | 6 | ZzAeFw0xOTAyMTkxNTMxNDRaFw0yOTAyMTYxNTMxNDRaMIGXMQswCQYDVQQGEwJE |
7 | BgNVBAcTBkJlbHBlcjEXMBUGA1UEChMOTmFnaW9zIFBsdWdpbnMxETAPBgNVBAMT | 7 | RTEQMA4GA1UECAwHQmF2YXJpYTEPMA0GA1UEBwwGTXVuaWNoMRswGQYDVQQKDBJN |
8 | CFRvbiBWb29uMR4wHAYJKoZIhvcNAQkBFg90b252b29uQG1hYy5jb20wgZ8wDQYJ | 8 | b25pdG9yaW5nIFBsdWdpbnMxGzAZBgNVBAMMEk1vbml0b3JpbmcgUGx1Z2luczEr |
9 | KoZIhvcNAQEBBQADgY0AMIGJAoGBAKcWMBtNtfY8vZXk0SN6/EYTVN/LOvaOSegy | 9 | MCkGCSqGSIb3DQEJARYcZGV2ZWxAbW9uaXRvcmluZy1wbHVnaW5zLm9yZzCCASIw |
10 | oVdLoGwuwjagk+XmCzvCqHZRp8lnCLay7AO8AQI7TSN02ihCcSrgGA9OT+HciIJ1 | 10 | DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKgV2yp8pQvJuN+aJGdAe6Hd0tja |
11 | l5/kEYUAuA1PR6YKK/T713zUAlMzy2tsugx5+xSsSEwsXkmne52jJiG/wuE5CLT0 | 11 | uteCPcNIcM92WLOF69TLTSYon1XDon4tHTh4Z5d4lD8bfsGzFVBmDSgWidhAUf+v |
12 | 9pF8HQqHAgMBAAGjgeYwgeMwHQYDVR0OBBYEFGioSPQ/rdE19+zaeY2YvHTXlUDI | 12 | EqEXwbp293ej/Frc0pXCvmrz6kI1tWrLtQhL/VdbxFYxhV7JjKb+PY3SxGFpSLPe |
13 | MIGzBgNVHSMEgaswgaiAFGioSPQ/rdE19+zaeY2YvHTXlUDIoYGEpIGBMH8xCzAJ | 13 | PQ/5SwVndv7rZIwcjseL22K5Uy2TIrkgzzm2pRs/IvoxRybYr/+LGoHyrtJC6AO8 |
14 | BgNVBAYTAlVLMRMwEQYDVQQIEwpEZXJieXNoaXJlMQ8wDQYDVQQHEwZCZWxwZXIx | 14 | ylp8A/etL0gwtUvRnrnZeTQ2pA1uZ5QN3anTL8JP/ZRZYNegIkaawqMtTKbhM6pi |
15 | FzAVBgNVBAoTDk5hZ2lvcyBQbHVnaW5zMREwDwYDVQQDEwhUb24gVm9vbjEeMBwG | 15 | u3/4a3Uppvt0y7vmGfQlYejxCpICnMrvHMpw8L58zv/98AbCGjDU3UwCt6MCAwEA |
16 | CSqGSIb3DQEJARYPdG9udm9vbkBtYWMuY29tggkAvwuSk3DNh3EwDAYDVR0TBAUw | 16 | AaNTMFEwHQYDVR0OBBYEFG/UH6nGYPlVcM75UXzXBF5GZyrcMB8GA1UdIwQYMBaA |
17 | AwEB/zANBgkqhkiG9w0BAQQFAAOBgQCdqasaIO6JiV5ONFG6Tr1++85UfEdZKMUX | 17 | FG/UH6nGYPlVcM75UXzXBF5GZyrcMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcN |
18 | N2NHiNNUunolIZEYR+dW99ezKmHlDiQ/tMgoLVYpl2Ubho2pAkLGQR+W0ZASgWQ1 | 18 | AQELBQADggEBAGwitJPOnlIKLndNf+iCLMIs0dxsl8kAaejFcjoT0n4ja7Y6Zrqz |
19 | NjfV27Rv0y6lYQMTA0lVAU93L1x9reo3FMedmL5+H+lIEpLCxEPtAJNISrJOneZB | 19 | VSIidzz9vQWvy24xKJpAOdj/iLRHCUOG+Pf5fA6+/FiuqXr6gE2/lm0eC58BNONr |
20 | W5jDadwkoQ== | 20 | E5OzjQ/VoQ8RX4hDntgu6FYbaVa/vhwn16igt9qmdNGGZXf2/+DM3JADwyaA4EK8 |
21 | vm7KdofX9zkxXecHPNvf3jiVLPiDDt6tkGpHPEsyP/yc+RUdltUeZvHfliV0cCuC | ||
22 | jJX+Fm9ysjSpHIFFr+jUMuMHibWoOD8iy3eYxfCDoWsH488pCbj8MNuAq6vd6DBk | ||
23 | bOZxDz43vjWuYMkwXJTxJQh7Pne6kK0vE1g= | ||
21 | -----END CERTIFICATE----- | 24 | -----END CERTIFICATE----- |
diff --git a/plugins/tests/certs/server-key.pem b/plugins/tests/certs/server-key.pem index eacaeaa3..11947555 100644 --- a/plugins/tests/certs/server-key.pem +++ b/plugins/tests/certs/server-key.pem | |||
@@ -1,15 +1,28 @@ | |||
1 | -----BEGIN RSA PRIVATE KEY----- | 1 | -----BEGIN PRIVATE KEY----- |
2 | MIICWwIBAAKBgQCnFjAbTbX2PL2V5NEjevxGE1Tfyzr2jknoMqFXS6BsLsI2oJPl | 2 | MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCoFdsqfKULybjf |
3 | 5gs7wqh2UafJZwi2suwDvAECO00jdNooQnEq4BgPTk/h3IiCdZef5BGFALgNT0em | 3 | miRnQHuh3dLY2rrXgj3DSHDPdlizhevUy00mKJ9Vw6J+LR04eGeXeJQ/G37BsxVQ |
4 | Civ0+9d81AJTM8trbLoMefsUrEhMLF5Jp3udoyYhv8LhOQi09PaRfB0KhwIDAQAB | 4 | Zg0oFonYQFH/rxKhF8G6dvd3o/xa3NKVwr5q8+pCNbVqy7UIS/1XW8RWMYVeyYym |
5 | AoGAfpxclcP8N3vteXErXURrd7pcXT0GECDgNjhvc9PV20RPXM+vYs1AA+fMeeQE | 5 | /j2N0sRhaUiz3j0P+UsFZ3b+62SMHI7Hi9tiuVMtkyK5IM85tqUbPyL6MUcm2K// |
6 | TaRqwO6x016aMRO4rz5ztYArecTBznkds1k59pkN/Ne/nsueU4tvGK8MNyS2o986 | 6 | ixqB8q7SQugDvMpafAP3rS9IMLVL0Z652Xk0NqQNbmeUDd2p0y/CT/2UWWDXoCJG |
7 | Voohqkaq4Lcy1bcHJb9su1ELjegEr1R76Mz452Hsy+uTbAECQQDcg/tZWKVeh5CQ | 7 | msKjLUym4TOqYrt/+Gt1Kab7dMu75hn0JWHo8QqSApzK7xzKcPC+fM7//fAGwhow |
8 | dOEB3YWHwfn0NDgfPm/X2i2kAZ7n7URaUy/ffdlfsrr1mBtHCfedLoOxmmlNfEpM | 8 | 1N1MArejAgMBAAECggEANuvdTwanTzC8jaNqHaq+OuemS2E9B8nwsGxtH/zFgvNR |
9 | hXAAurSHAkEAwfk7fEb0iN0Sj9gTozO7c6Ky10KwePZyjVzqSQIiJq3NX8BEaIeb | 9 | WZiMPtmrJnTkFWJcV+VPw/iMSAqN4nDHmBugVOb4Z4asxGTKK4T9shXJSnh0rqPU |
10 | 51TXxE5VxaLjjMLRkA0hWTYXClgERFZ6AQJAN7ChPqwzf08PRFwwIw911JY5cOHr | 10 | 00ZsvbmxY6z0+E5TesCJqQ+9GYTY1V357V7JchvaOxIRxWPqg9urHbru8OCtW/I5 |
11 | NoDHMCUql5vNLNdwBruxgGjBB/kUXEfgw60RusFvgt/zLh1wiii844JDawJAGQBF | 11 | Fh5HPUZlgCvlMpjlhyjydIf/oXyVA3RNsXlwe8+2cKuGIrjEzm2j9o3VF0sctTX0 |
12 | sYP3urg7zzx7c3qUe5gJ0wLuefjR1PSX4ecbfb7DDMdcSdjIuG1QDiZGmd2f1KG7 | 12 | ItP8A9qDmDQN7GIWX0MW6gncojpS1omC2wcFsdjj/xfPyiDal1X4aq/2YqG8351c |
13 | nwSCOtxk5dloW2KGAQJAQh/iBn0QhfKLFAP5eZBVk8E8XlZuw+S2DLy5SnBlIiYJ | 13 | YlM/+6Va0u9WWE/i64gASTAVqpMV4Yg8y0gGycuA0QKBgQDbgI2QeLd3FvMcURiU |
14 | GB5I2OClgtudXMv1labFrcST8O9eFrtsrhU1iUGUOw== | 14 | l3w9qJgw/Jp3jaNC/9LkVGGz4f4lKKB67lPZvI4noMK8GqO/LcXgqP/RY1oJojoA |
15 | -----END RSA PRIVATE KEY----- | 15 | /6JKVvzYGASZ7VgMoG9bk1AneP1PGdibuTUEwimGlcObxnDFIC/yjwPFu3jIdqdS |
16 | zZi1RZzyqAogN5y3SBEypSmn9wKBgQDECKsqqlcizmCl8v5aVk875AzGN+DOHZqx | ||
17 | bkmztlnLO/2e2Fmk3G5Vvnui0FYisf8Eq19tUTQCF6lSfJlGQeFAT119wkFZhLu+ | ||
18 | FfLGqoEMH0ijJg/8PpdpFRK3I94YcISoTNN6yxMvE6xdDGfKCt5a+IX5bwQi9Zdc | ||
19 | B242gEc6tQKBgA6tM8n7KFlAIZU9HuWgk2AUC8kKutFPmSD7tgAqXDYI4FNfugs+ | ||
20 | MEEYyHCB4UNujJBV4Ss6YZCAkh6eyD4U2aca1eElCfm40vBVMdzvpqZdAqLtWXxg | ||
21 | D9l3mgszrFaYGCY2Fr6jLV9lP5g3xsxUjudf9jSLY9HvpfzjRrMaNATVAoGBALTl | ||
22 | /vYfPMucwKlC5B7++J0e4/7iv6vUu9SyHocdZh1anb9AjPDKjXLIlZT4RhQ8R0XK | ||
23 | 0wOw5JpttU2uN08TKkbLNk3/vYhbKVjPLjrQSseh8sjDLgsqw1QwIxYnniLVakVY | ||
24 | p+rvjSNrNyqicQCMKQavwgocvSd5lJRTMwxOMezlAoGBAKWj71BX+0CK00/2S6lC | ||
25 | TcNcuUPG0d8y1czZ4q6tUlG4htwq1FMOpaghATXjkdsOGTLS+H1aA0Kt7Ai9zDhc | ||
26 | /bzOJEJ+jvBXV4Gcs7jl1r/HTKv0tT9ZSI5Vzkida0rfqxDGzcMVlLuCdH0cb8Iu | ||
27 | N0wdmCAqlQwHR13+F1zrAD7V | ||
28 | -----END PRIVATE KEY----- | ||
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index d6d31de1..006f1339 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t | |||
@@ -4,13 +4,13 @@ | |||
4 | # | 4 | # |
5 | # To create the https server certificate: | 5 | # To create the https server certificate: |
6 | # openssl req -new -x509 -keyout server-key.pem -out server-cert.pem -days 3650 -nodes | 6 | # openssl req -new -x509 -keyout server-key.pem -out server-cert.pem -days 3650 -nodes |
7 | # Country Name (2 letter code) [AU]:UK | 7 | # Country Name (2 letter code) [AU]:DE |
8 | # State or Province Name (full name) [Some-State]:Derbyshire | 8 | # State or Province Name (full name) [Some-State]:Bavaria |
9 | # Locality Name (eg, city) []:Belper | 9 | # Locality Name (eg, city) []:Munich |
10 | # Organization Name (eg, company) [Internet Widgits Pty Ltd]:Monitoring Plugins | 10 | # Organization Name (eg, company) [Internet Widgits Pty Ltd]:Monitoring Plugins |
11 | # Organizational Unit Name (eg, section) []: | 11 | # Organizational Unit Name (eg, section) []: |
12 | # Common Name (eg, YOUR name) []:Ton Voon | 12 | # Common Name (e.g. server FQDN or YOUR name) []:Monitoring Plugins |
13 | # Email Address []:tonvoon@mac.com | 13 | # Email Address []:devel@monitoring-plugins.org |
14 | 14 | ||
15 | use strict; | 15 | use strict; |
16 | use Test::More; | 16 | use Test::More; |
@@ -194,16 +194,16 @@ SKIP: { | |||
194 | 194 | ||
195 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); | 195 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); |
196 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); | 196 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); |
197 | is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:28 2019 +0000.', "output ok" ); | 197 | is( $result->output, "OK - Certificate 'Monitoring Plugins' will expire on Fri Feb 16 15:31:44 2029 +0000.", "output ok" ); |
198 | 198 | ||
199 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); | 199 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); |
200 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); | 200 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); |
201 | like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019 \+0000\)./', "output ok" ); | 201 | like( $result->output, '/WARNING - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" ); |
202 | 202 | ||
203 | # Expired cert tests | 203 | # Expired cert tests |
204 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); | 204 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); |
205 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); | 205 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); |
206 | like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019 \+0000\)./', "output ok" ); | 206 | like( $result->output, '/CRITICAL - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" ); |
207 | 207 | ||
208 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); | 208 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); |
209 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); | 209 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); |
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index 73a68b20..85d6bf55 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t | |||
@@ -7,6 +7,7 @@ use strict; | |||
7 | use Test::More; | 7 | use Test::More; |
8 | use NPTest; | 8 | use NPTest; |
9 | use FindBin qw($Bin); | 9 | use FindBin qw($Bin); |
10 | use POSIX qw/strftime/; | ||
10 | 11 | ||
11 | my $tests = 67; | 12 | my $tests = 67; |
12 | # Check that all dependent modules are available | 13 | # Check that all dependent modules are available |
@@ -37,6 +38,7 @@ if ($@) { | |||
37 | 38 | ||
38 | my $port_snmp = 16100 + int(rand(100)); | 39 | my $port_snmp = 16100 + int(rand(100)); |
39 | 40 | ||
41 | my $faketime = -x '/usr/bin/faketime' ? 1 : 0; | ||
40 | 42 | ||
41 | # Start up server | 43 | # Start up server |
42 | my @pids; | 44 | my @pids; |
@@ -118,77 +120,81 @@ like($res->output, '/'.quotemeta('SNMP OK - And now have fun with with this: \"C | |||
118 | "And now have fun with with this: \"C:\\\\\" | 120 | "And now have fun with with this: \"C:\\\\\" |
119 | because we\'re not done yet!"').'/m', "Attempt to confuse parser No.3"); | 121 | because we\'re not done yet!"').'/m', "Attempt to confuse parser No.3"); |
120 | 122 | ||
121 | system("rm -f ".$ENV{'MP_STATE_PATH'}."/check_snmp/*"); | 123 | system("rm -f ".$ENV{'MP_STATE_PATH'}."/*/check_snmp/*"); |
122 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); | ||
123 | is($res->return_code, 0, "Returns OK"); | ||
124 | is($res->output, "No previous data to calculate rate - assume okay"); | ||
125 | 124 | ||
126 | # Need to sleep, otherwise duration=0 | 125 | # run rate checks with faketime. rate checks depend on the exact amount of time spend between the |
127 | sleep 1; | 126 | # plugin runs which may fail on busy machines. |
127 | # using faketime removes this race condition and also saves all the sleeps in between. | ||
128 | SKIP: { | ||
129 | skip "No faketime binary found", 28 if !$faketime; | ||
128 | 130 | ||
129 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); | 131 | my $ts = time(); |
130 | is($res->return_code, 1, "WARNING - due to going above rate calculation" ); | 132 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); |
131 | is($res->output, "SNMP RATE WARNING - *666* | iso.3.6.1.4.1.8072.3.2.67.10=666;600 "); | 133 | is($res->return_code, 0, "Returns OK"); |
134 | is($res->output, "No previous data to calculate rate - assume okay"); | ||
132 | 135 | ||
133 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); | 136 | # test rate 1 second later |
134 | is($res->return_code, 3, "UNKNOWN - basically the divide by zero error" ); | 137 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); |
135 | is($res->output, "Time duration between plugin calls is invalid"); | 138 | is($res->return_code, 1, "WARNING - due to going above rate calculation" ); |
139 | is($res->output, "SNMP RATE WARNING - *666* | iso.3.6.1.4.1.8072.3.2.67.10=666;600 "); | ||
136 | 140 | ||
141 | # test rate with same time | ||
142 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); | ||
143 | is($res->return_code, 3, "UNKNOWN - basically the divide by zero error" ); | ||
144 | is($res->output, "Time duration between plugin calls is invalid"); | ||
137 | 145 | ||
138 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); | ||
139 | is($res->return_code, 0, "OK for first call" ); | ||
140 | is($res->output, "No previous data to calculate rate - assume okay" ); | ||
141 | 146 | ||
142 | # Need to sleep, otherwise duration=0 | 147 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); |
143 | sleep 1; | 148 | is($res->return_code, 0, "OK for first call" ); |
149 | is($res->output, "No previous data to calculate rate - assume okay" ); | ||
144 | 150 | ||
145 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); | 151 | # test rate 1 second later |
146 | is($res->return_code, 0, "OK as no thresholds" ); | 152 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); |
147 | is($res->output, "SNMP RATE OK - inoctets 666 | inoctets=666 ", "Check label"); | 153 | is($res->return_code, 0, "OK as no thresholds" ); |
154 | is($res->output, "SNMP RATE OK - inoctets 666 | inoctets=666 ", "Check label"); | ||
148 | 155 | ||
149 | sleep 2; | 156 | # test rate 3 seconds later |
157 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+3))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); | ||
158 | is($res->return_code, 0, "OK as no thresholds" ); | ||
159 | is($res->output, "SNMP RATE OK - inoctets 333 | inoctets=333 ", "Check rate decreases due to longer interval"); | ||
150 | 160 | ||
151 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); | ||
152 | is($res->return_code, 0, "OK as no thresholds" ); | ||
153 | is($res->output, "SNMP RATE OK - inoctets 333 | inoctets=333 ", "Check rate decreases due to longer interval"); | ||
154 | 161 | ||
162 | # label performance data check | ||
163 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l test" ); | ||
164 | is($res->return_code, 0, "OK as no thresholds" ); | ||
165 | is($res->output, "SNMP OK - test 67996 | test=67996c ", "Check label"); | ||
155 | 166 | ||
156 | # label performance data check | 167 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l \"test'test\"" ); |
157 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l test" ); | 168 | is($res->return_code, 0, "OK as no thresholds" ); |
158 | is($res->return_code, 0, "OK as no thresholds" ); | 169 | is($res->output, "SNMP OK - test'test 68662 | \"test'test\"=68662c ", "Check label"); |
159 | is($res->output, "SNMP OK - test 67996 | test=67996c ", "Check label"); | ||
160 | 170 | ||
161 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l \"test'test\"" ); | 171 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l 'test\"test'" ); |
162 | is($res->return_code, 0, "OK as no thresholds" ); | 172 | is($res->return_code, 0, "OK as no thresholds" ); |
163 | is($res->output, "SNMP OK - test'test 68662 | \"test'test\"=68662c ", "Check label"); | 173 | is($res->output, "SNMP OK - test\"test 69328 | 'test\"test'=69328c ", "Check label"); |
164 | 174 | ||
165 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l 'test\"test'" ); | 175 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l test -O" ); |
166 | is($res->return_code, 0, "OK as no thresholds" ); | 176 | is($res->return_code, 0, "OK as no thresholds" ); |
167 | is($res->output, "SNMP OK - test\"test 69328 | 'test\"test'=69328c ", "Check label"); | 177 | is($res->output, "SNMP OK - test 69994 | iso.3.6.1.4.1.8072.3.2.67.10=69994c ", "Check label"); |
168 | 178 | ||
169 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l test -O" ); | 179 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10" ); |
170 | is($res->return_code, 0, "OK as no thresholds" ); | 180 | is($res->return_code, 0, "OK as no thresholds" ); |
171 | is($res->output, "SNMP OK - test 69994 | iso.3.6.1.4.1.8072.3.2.67.10=69994c ", "Check label"); | 181 | is($res->output, "SNMP OK - 70660 | iso.3.6.1.4.1.8072.3.2.67.10=70660c ", "Check label"); |
172 | 182 | ||
173 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10" ); | 183 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l 'test test'" ); |
174 | is($res->return_code, 0, "OK as no thresholds" ); | 184 | is($res->return_code, 0, "OK as no thresholds" ); |
175 | is($res->output, "SNMP OK - 70660 | iso.3.6.1.4.1.8072.3.2.67.10=70660c ", "Check label"); | 185 | is($res->output, "SNMP OK - test test 71326 | 'test test'=71326c ", "Check label"); |
176 | 186 | ||
177 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l 'test test'" ); | ||
178 | is($res->return_code, 0, "OK as no thresholds" ); | ||
179 | is($res->output, "SNMP OK - test test 71326 | 'test test'=71326c ", "Check label"); | ||
180 | 187 | ||
188 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets_per_minute --rate-multiplier=60" ); | ||
189 | is($res->return_code, 0, "OK for first call" ); | ||
190 | is($res->output, "No previous data to calculate rate - assume okay" ); | ||
181 | 191 | ||
182 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets_per_minute --rate-multiplier=60" ); | 192 | # test 1 second later |
183 | is($res->return_code, 0, "OK for first call" ); | 193 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets_per_minute --rate-multiplier=60" ); |
184 | is($res->output, "No previous data to calculate rate - assume okay" ); | 194 | is($res->return_code, 0, "OK as no thresholds" ); |
185 | 195 | is($res->output, "SNMP RATE OK - inoctets_per_minute 39960 | inoctets_per_minute=39960 ", "Checking multiplier"); | |
186 | # Need to sleep, otherwise duration=0 | 196 | }; |
187 | sleep 1; | ||
188 | 197 | ||
189 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets_per_minute --rate-multiplier=60" ); | ||
190 | is($res->return_code, 0, "OK as no thresholds" ); | ||
191 | is($res->output, "SNMP RATE OK - inoctets_per_minute 39960 | inoctets_per_minute=39960 ", "Checking multiplier"); | ||
192 | 198 | ||
193 | 199 | ||
194 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 -s '\"stringtests\"'" ); | 200 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 -s '\"stringtests\"'" ); |
diff --git a/plugins/utils.c b/plugins/utils.c index 231af92b..ee620133 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -36,9 +36,6 @@ extern const char *progname; | |||
36 | #define STRLEN 64 | 36 | #define STRLEN 64 |
37 | #define TXTBLK 128 | 37 | #define TXTBLK 128 |
38 | 38 | ||
39 | unsigned int timeout_state = STATE_CRITICAL; | ||
40 | unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT; | ||
41 | |||
42 | time_t start_time, end_time; | 39 | time_t start_time, end_time; |
43 | 40 | ||
44 | /* ************************************************************************** | 41 | /* ************************************************************************** |
@@ -148,33 +145,6 @@ print_revision (const char *command_name, const char *revision) | |||
148 | command_name, revision, PACKAGE, VERSION); | 145 | command_name, revision, PACKAGE, VERSION); |
149 | } | 146 | } |
150 | 147 | ||
151 | const char * | ||
152 | state_text (int result) | ||
153 | { | ||
154 | switch (result) { | ||
155 | case STATE_OK: | ||
156 | return "OK"; | ||
157 | case STATE_WARNING: | ||
158 | return "WARNING"; | ||
159 | case STATE_CRITICAL: | ||
160 | return "CRITICAL"; | ||
161 | case STATE_DEPENDENT: | ||
162 | return "DEPENDENT"; | ||
163 | default: | ||
164 | return "UNKNOWN"; | ||
165 | } | ||
166 | } | ||
167 | |||
168 | void | ||
169 | timeout_alarm_handler (int signo) | ||
170 | { | ||
171 | if (signo == SIGALRM) { | ||
172 | printf (_("%s - Plugin timed out after %d seconds\n"), | ||
173 | state_text(timeout_state), timeout_interval); | ||
174 | exit (timeout_state); | ||
175 | } | ||
176 | } | ||
177 | |||
178 | int | 148 | int |
179 | is_numeric (char *number) | 149 | is_numeric (char *number) |
180 | { | 150 | { |
@@ -708,4 +678,3 @@ char *sperfdata_int (const char *label, | |||
708 | 678 | ||
709 | return data; | 679 | return data; |
710 | } | 680 | } |
711 | |||
diff --git a/plugins/utils.h b/plugins/utils.h index a436e1ca..6aa316fe 100644 --- a/plugins/utils.h +++ b/plugins/utils.h | |||
@@ -29,13 +29,6 @@ suite of plugins. */ | |||
29 | void support (void); | 29 | void support (void); |
30 | void print_revision (const char *, const char *); | 30 | void print_revision (const char *, const char *); |
31 | 31 | ||
32 | /* Handle timeouts */ | ||
33 | |||
34 | extern unsigned int timeout_state; | ||
35 | extern unsigned int timeout_interval; | ||
36 | |||
37 | RETSIGTYPE timeout_alarm_handler (int); | ||
38 | |||
39 | extern time_t start_time, end_time; | 32 | extern time_t start_time, end_time; |
40 | 33 | ||
41 | /* Test input types */ | 34 | /* Test input types */ |
@@ -89,8 +82,6 @@ void usage4(const char *) __attribute__((noreturn)); | |||
89 | void usage5(void) __attribute__((noreturn)); | 82 | void usage5(void) __attribute__((noreturn)); |
90 | void usage_va(const char *fmt, ...) __attribute__((noreturn)); | 83 | void usage_va(const char *fmt, ...) __attribute__((noreturn)); |
91 | 84 | ||
92 | const char *state_text (int); | ||
93 | |||
94 | #define max(a,b) (((a)>(b))?(a):(b)) | 85 | #define max(a,b) (((a)>(b))?(a):(b)) |
95 | #define min(a,b) (((a)<(b))?(a):(b)) | 86 | #define min(a,b) (((a)<(b))?(a):(b)) |
96 | 87 | ||