diff options
Diffstat (limited to 'plugins')
38 files changed, 514 insertions, 218 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 3fde54d6..ab59eb73 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am | |||
| @@ -51,10 +51,10 @@ noinst_LIBRARIES = libnpcommon.a | |||
| 51 | libnpcommon_a_SOURCES = utils.c netutils.c sslutils.c runcmd.c \ | 51 | libnpcommon_a_SOURCES = utils.c netutils.c sslutils.c runcmd.c \ |
| 52 | popen.c utils.h netutils.h popen.h common.h runcmd.c runcmd.h | 52 | popen.c utils.h netutils.h popen.h common.h runcmd.c runcmd.h |
| 53 | 53 | ||
| 54 | BASEOBJS = libnpcommon.a ../lib/libmonitoringplug.a ../gl/libgnu.a | 54 | BASEOBJS = libnpcommon.a ../lib/libmonitoringplug.a ../gl/libgnu.a $(LIB_CRYPTO) |
| 55 | NETOBJS = $(BASEOBJS) $(EXTRA_NETOBLS) | 55 | NETOBJS = $(BASEOBJS) $(EXTRA_NETOBLS) |
| 56 | NETLIBS = $(NETOBJS) $(SOCKETLIBS) | 56 | NETLIBS = $(NETOBJS) $(SOCKETLIBS) |
| 57 | SSLOBJS = $(BASEOBJS) $(NETLIBS) $(SSLLIBS) | 57 | SSLOBJS = $(BASEOBJS) $(NETLIBS) $(SSLLIBS) $(LIB_CRYPTO) |
| 58 | 58 | ||
| 59 | TESTS_ENVIRONMENT = perl -I $(top_builddir) -I $(top_srcdir) | 59 | TESTS_ENVIRONMENT = perl -I $(top_builddir) -I $(top_srcdir) |
| 60 | 60 | ||
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index c6593df1..100a97aa 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
| @@ -37,6 +37,7 @@ const char *progname = "check_curl"; | |||
| 37 | const char *copyright = "2006-2019"; | 37 | const char *copyright = "2006-2019"; |
| 38 | const char *email = "devel@monitoring-plugins.org"; | 38 | const char *email = "devel@monitoring-plugins.org"; |
| 39 | 39 | ||
| 40 | #include <stdbool.h> | ||
| 40 | #include <ctype.h> | 41 | #include <ctype.h> |
| 41 | 42 | ||
| 42 | #include "common.h" | 43 | #include "common.h" |
| @@ -54,6 +55,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
| 54 | #include "uriparser/Uri.h" | 55 | #include "uriparser/Uri.h" |
| 55 | 56 | ||
| 56 | #include <arpa/inet.h> | 57 | #include <arpa/inet.h> |
| 58 | #include <netinet/in.h> | ||
| 57 | 59 | ||
| 58 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) | 60 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) |
| 59 | #include <openssl/opensslv.h> | 61 | #include <openssl/opensslv.h> |
| @@ -131,14 +133,14 @@ regmatch_t pmatch[REGS]; | |||
| 131 | char regexp[MAX_RE_SIZE]; | 133 | char regexp[MAX_RE_SIZE]; |
| 132 | int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; | 134 | int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; |
| 133 | int errcode; | 135 | int errcode; |
| 134 | int invert_regex = 0; | 136 | bool invert_regex = false; |
| 135 | 137 | ||
| 136 | char *server_address = NULL; | 138 | char *server_address = NULL; |
| 137 | char *host_name = NULL; | 139 | char *host_name = NULL; |
| 138 | char *server_url = 0; | 140 | char *server_url = 0; |
| 139 | char server_ip[DEFAULT_BUFFER_SIZE]; | 141 | char server_ip[DEFAULT_BUFFER_SIZE]; |
| 140 | struct curl_slist *server_ips = NULL; | 142 | struct curl_slist *server_ips = NULL; |
| 141 | int specify_port = FALSE; | 143 | bool specify_port = false; |
| 142 | unsigned short server_port = HTTP_PORT; | 144 | unsigned short server_port = HTTP_PORT; |
| 143 | unsigned short virtual_port = 0; | 145 | unsigned short virtual_port = 0; |
| 144 | int host_name_length; | 146 | int host_name_length; |
| @@ -150,8 +152,8 @@ int days_till_exp_warn, days_till_exp_crit; | |||
| 150 | thresholds *thlds; | 152 | thresholds *thlds; |
| 151 | char user_agent[DEFAULT_BUFFER_SIZE]; | 153 | char user_agent[DEFAULT_BUFFER_SIZE]; |
| 152 | int verbose = 0; | 154 | int verbose = 0; |
| 153 | int show_extended_perfdata = FALSE; | 155 | bool show_extended_perfdata = false; |
| 154 | int show_body = FALSE; | 156 | bool show_body = false; |
| 155 | int min_page_len = 0; | 157 | int min_page_len = 0; |
| 156 | int max_page_len = 0; | 158 | int max_page_len = 0; |
| 157 | int redir_depth = 0; | 159 | int redir_depth = 0; |
| @@ -160,10 +162,16 @@ char *http_method = NULL; | |||
| 160 | char *http_post_data = NULL; | 162 | char *http_post_data = NULL; |
| 161 | char *http_content_type = NULL; | 163 | char *http_content_type = NULL; |
| 162 | CURL *curl; | 164 | CURL *curl; |
| 165 | bool curl_global_initialized = false; | ||
| 166 | bool curl_easy_initialized = false; | ||
| 163 | struct curl_slist *header_list = NULL; | 167 | struct curl_slist *header_list = NULL; |
| 168 | bool body_buf_initialized = false; | ||
| 164 | curlhelp_write_curlbuf body_buf; | 169 | curlhelp_write_curlbuf body_buf; |
| 170 | bool header_buf_initialized = false; | ||
| 165 | curlhelp_write_curlbuf header_buf; | 171 | curlhelp_write_curlbuf header_buf; |
| 172 | bool status_line_initialized = false; | ||
| 166 | curlhelp_statusline status_line; | 173 | curlhelp_statusline status_line; |
| 174 | bool put_buf_initialized = false; | ||
| 167 | curlhelp_read_curlbuf put_buf; | 175 | curlhelp_read_curlbuf put_buf; |
| 168 | char http_header[DEFAULT_BUFFER_SIZE]; | 176 | char http_header[DEFAULT_BUFFER_SIZE]; |
| 169 | long code; | 177 | long code; |
| @@ -173,7 +181,7 @@ double time_connect; | |||
| 173 | double time_appconnect; | 181 | double time_appconnect; |
| 174 | double time_headers; | 182 | double time_headers; |
| 175 | double time_firstbyte; | 183 | double time_firstbyte; |
| 176 | char errbuf[CURL_ERROR_SIZE+1]; | 184 | char errbuf[MAX_INPUT_BUFFER]; |
| 177 | CURLcode res; | 185 | CURLcode res; |
| 178 | char url[DEFAULT_BUFFER_SIZE]; | 186 | char url[DEFAULT_BUFFER_SIZE]; |
| 179 | char msg[DEFAULT_BUFFER_SIZE]; | 187 | char msg[DEFAULT_BUFFER_SIZE]; |
| @@ -186,14 +194,14 @@ char user_auth[MAX_INPUT_BUFFER] = ""; | |||
| 186 | char proxy_auth[MAX_INPUT_BUFFER] = ""; | 194 | char proxy_auth[MAX_INPUT_BUFFER] = ""; |
| 187 | char **http_opt_headers; | 195 | char **http_opt_headers; |
| 188 | int http_opt_headers_count = 0; | 196 | int http_opt_headers_count = 0; |
| 189 | int display_html = FALSE; | 197 | bool display_html = false; |
| 190 | int onredirect = STATE_OK; | 198 | int onredirect = STATE_OK; |
| 191 | int followmethod = FOLLOW_HTTP_CURL; | 199 | int followmethod = FOLLOW_HTTP_CURL; |
| 192 | int followsticky = STICKY_NONE; | 200 | int followsticky = STICKY_NONE; |
| 193 | int use_ssl = FALSE; | 201 | bool use_ssl = false; |
| 194 | int use_sni = TRUE; | 202 | bool use_sni = true; |
| 195 | int check_cert = FALSE; | 203 | bool check_cert = false; |
| 196 | int continue_after_check_cert = FALSE; | 204 | bool continue_after_check_cert = false; |
| 197 | typedef union { | 205 | typedef union { |
| 198 | struct curl_slist* to_info; | 206 | struct curl_slist* to_info; |
| 199 | struct curl_certinfo* to_certinfo; | 207 | struct curl_certinfo* to_certinfo; |
| @@ -203,19 +211,20 @@ int ssl_version = CURL_SSLVERSION_DEFAULT; | |||
| 203 | char *client_cert = NULL; | 211 | char *client_cert = NULL; |
| 204 | char *client_privkey = NULL; | 212 | char *client_privkey = NULL; |
| 205 | char *ca_cert = NULL; | 213 | char *ca_cert = NULL; |
| 206 | int verify_peer_and_host = FALSE; | 214 | bool verify_peer_and_host = false; |
| 207 | int is_openssl_callback = FALSE; | 215 | bool is_openssl_callback = false; |
| 208 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) | 216 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) |
| 209 | X509 *cert = NULL; | 217 | X509 *cert = NULL; |
| 210 | #endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ | 218 | #endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ |
| 211 | int no_body = FALSE; | 219 | bool no_body = false; |
| 212 | int maximum_age = -1; | 220 | int maximum_age = -1; |
| 213 | int address_family = AF_UNSPEC; | 221 | int address_family = AF_UNSPEC; |
| 214 | curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; | 222 | curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; |
| 215 | int curl_http_version = CURL_HTTP_VERSION_NONE; | 223 | int curl_http_version = CURL_HTTP_VERSION_NONE; |
| 216 | int automatic_decompression = FALSE; | 224 | bool automatic_decompression = false; |
| 225 | char *cookie_jar_file = NULL; | ||
| 217 | 226 | ||
| 218 | int process_arguments (int, char**); | 227 | bool process_arguments (int, char**); |
| 219 | void handle_curl_option_return_code (CURLcode res, const char* option); | 228 | void handle_curl_option_return_code (CURLcode res, const char* option); |
| 220 | int check_http (void); | 229 | int check_http (void); |
| 221 | void redir (curlhelp_write_curlbuf*); | 230 | void redir (curlhelp_write_curlbuf*); |
| @@ -269,10 +278,10 @@ main (int argc, char **argv) | |||
| 269 | progname, NP_VERSION, VERSION, curl_version()); | 278 | progname, NP_VERSION, VERSION, curl_version()); |
| 270 | 279 | ||
| 271 | /* parse arguments */ | 280 | /* parse arguments */ |
| 272 | if (process_arguments (argc, argv) == ERROR) | 281 | if (process_arguments (argc, argv) == false) |
| 273 | usage4 (_("Could not parse arguments")); | 282 | usage4 (_("Could not parse arguments")); |
| 274 | 283 | ||
| 275 | if (display_html == TRUE) | 284 | if (display_html) |
| 276 | printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">", | 285 | printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">", |
| 277 | use_ssl ? "https" : "http", | 286 | use_ssl ? "https" : "http", |
| 278 | host_name ? host_name : server_address, | 287 | host_name ? host_name : server_address, |
| @@ -376,8 +385,11 @@ int | |||
| 376 | lookup_host (const char *host, char *buf, size_t buflen) | 385 | lookup_host (const char *host, char *buf, size_t buflen) |
| 377 | { | 386 | { |
| 378 | struct addrinfo hints, *res, *result; | 387 | struct addrinfo hints, *res, *result; |
| 388 | char addrstr[100]; | ||
| 389 | size_t addrstr_len; | ||
| 379 | int errcode; | 390 | int errcode; |
| 380 | void *ptr; | 391 | void *ptr; |
| 392 | size_t buflen_remaining = buflen - 1; | ||
| 381 | 393 | ||
| 382 | memset (&hints, 0, sizeof (hints)); | 394 | memset (&hints, 0, sizeof (hints)); |
| 383 | hints.ai_family = address_family; | 395 | hints.ai_family = address_family; |
| @@ -387,31 +399,62 @@ lookup_host (const char *host, char *buf, size_t buflen) | |||
| 387 | errcode = getaddrinfo (host, NULL, &hints, &result); | 399 | errcode = getaddrinfo (host, NULL, &hints, &result); |
| 388 | if (errcode != 0) | 400 | if (errcode != 0) |
| 389 | return errcode; | 401 | return errcode; |
| 390 | 402 | ||
| 403 | strcpy(buf, ""); | ||
| 391 | res = result; | 404 | res = result; |
| 392 | 405 | ||
| 393 | while (res) { | 406 | while (res) { |
| 394 | inet_ntop (res->ai_family, res->ai_addr->sa_data, buf, buflen); | 407 | switch (res->ai_family) { |
| 395 | switch (res->ai_family) { | 408 | case AF_INET: |
| 396 | case AF_INET: | 409 | ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr; |
| 397 | ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr; | 410 | break; |
| 398 | break; | 411 | case AF_INET6: |
| 399 | case AF_INET6: | 412 | ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; |
| 400 | ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; | 413 | break; |
| 401 | break; | ||
| 402 | } | 414 | } |
| 403 | inet_ntop (res->ai_family, ptr, buf, buflen); | 415 | |
| 404 | if (verbose >= 1) | 416 | inet_ntop (res->ai_family, ptr, addrstr, 100); |
| 417 | if (verbose >= 1) { | ||
| 405 | printf ("* getaddrinfo IPv%d address: %s\n", | 418 | printf ("* getaddrinfo IPv%d address: %s\n", |
| 406 | res->ai_family == PF_INET6 ? 6 : 4, buf); | 419 | res->ai_family == PF_INET6 ? 6 : 4, addrstr); |
| 420 | } | ||
| 421 | |||
| 422 | // Append all IPs to buf as a comma-separated string | ||
| 423 | addrstr_len = strlen(addrstr); | ||
| 424 | if (buflen_remaining > addrstr_len + 1) { | ||
| 425 | if (buf[0] != '\0') { | ||
| 426 | strncat(buf, ",", buflen_remaining); | ||
| 427 | buflen_remaining -= 1; | ||
| 428 | } | ||
| 429 | strncat(buf, addrstr, buflen_remaining); | ||
| 430 | buflen_remaining -= addrstr_len; | ||
| 431 | } | ||
| 432 | |||
| 407 | res = res->ai_next; | 433 | res = res->ai_next; |
| 408 | } | 434 | } |
| 409 | 435 | ||
| 410 | freeaddrinfo(result); | 436 | freeaddrinfo(result); |
| 411 | 437 | ||
| 412 | return 0; | 438 | return 0; |
| 413 | } | 439 | } |
| 414 | 440 | ||
| 441 | static void | ||
| 442 | cleanup (void) | ||
| 443 | { | ||
| 444 | if (status_line_initialized) curlhelp_free_statusline(&status_line); | ||
| 445 | status_line_initialized = false; | ||
| 446 | if (curl_easy_initialized) curl_easy_cleanup (curl); | ||
| 447 | curl_easy_initialized = false; | ||
| 448 | if (curl_global_initialized) curl_global_cleanup (); | ||
| 449 | curl_global_initialized = false; | ||
| 450 | if (body_buf_initialized) curlhelp_freewritebuffer (&body_buf); | ||
| 451 | body_buf_initialized = false; | ||
| 452 | if (header_buf_initialized) curlhelp_freewritebuffer (&header_buf); | ||
| 453 | header_buf_initialized = false; | ||
| 454 | if (put_buf_initialized) curlhelp_freereadbuffer (&put_buf); | ||
| 455 | put_buf_initialized = false; | ||
| 456 | } | ||
| 457 | |||
| 415 | int | 458 | int |
| 416 | check_http (void) | 459 | check_http (void) |
| 417 | { | 460 | { |
| @@ -420,18 +463,24 @@ check_http (void) | |||
| 420 | int i; | 463 | int i; |
| 421 | char *force_host_header = NULL; | 464 | char *force_host_header = NULL; |
| 422 | struct curl_slist *host = NULL; | 465 | struct curl_slist *host = NULL; |
| 423 | char addrstr[100]; | 466 | char addrstr[DEFAULT_BUFFER_SIZE/2]; |
| 424 | char dnscache[DEFAULT_BUFFER_SIZE]; | 467 | char dnscache[DEFAULT_BUFFER_SIZE]; |
| 425 | 468 | ||
| 426 | /* initialize curl */ | 469 | /* initialize curl */ |
| 427 | if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) | 470 | if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) |
| 428 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_global_init failed\n"); | 471 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_global_init failed\n"); |
| 472 | curl_global_initialized = true; | ||
| 429 | 473 | ||
| 430 | if ((curl = curl_easy_init()) == NULL) | 474 | if ((curl = curl_easy_init()) == NULL) { |
| 431 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_easy_init failed\n"); | 475 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_easy_init failed\n"); |
| 476 | } | ||
| 477 | curl_easy_initialized = true; | ||
| 432 | 478 | ||
| 479 | /* register cleanup function to shut down libcurl properly */ | ||
| 480 | atexit (cleanup); | ||
| 481 | |||
| 433 | if (verbose >= 1) | 482 | if (verbose >= 1) |
| 434 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_VERBOSE, TRUE), "CURLOPT_VERBOSE"); | 483 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_VERBOSE, 1), "CURLOPT_VERBOSE"); |
| 435 | 484 | ||
| 436 | /* print everything on stdout like check_http would do */ | 485 | /* print everything on stdout like check_http would do */ |
| 437 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_STDERR, stdout), "CURLOPT_STDERR"); | 486 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_STDERR, stdout), "CURLOPT_STDERR"); |
| @@ -446,12 +495,14 @@ check_http (void) | |||
| 446 | /* initialize buffer for body of the answer */ | 495 | /* initialize buffer for body of the answer */ |
| 447 | if (curlhelp_initwritebuffer(&body_buf) < 0) | 496 | if (curlhelp_initwritebuffer(&body_buf) < 0) |
| 448 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for body\n"); | 497 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for body\n"); |
| 498 | body_buf_initialized = true; | ||
| 449 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_WRITEFUNCTION"); | 499 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_WRITEFUNCTION"); |
| 450 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *)&body_buf), "CURLOPT_WRITEDATA"); | 500 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *)&body_buf), "CURLOPT_WRITEDATA"); |
| 451 | 501 | ||
| 452 | /* initialize buffer for header of the answer */ | 502 | /* initialize buffer for header of the answer */ |
| 453 | if (curlhelp_initwritebuffer( &header_buf ) < 0) | 503 | if (curlhelp_initwritebuffer( &header_buf ) < 0) |
| 454 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for header\n" ); | 504 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for header\n" ); |
| 505 | header_buf_initialized = true; | ||
| 455 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_HEADERFUNCTION"); | 506 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_HEADERFUNCTION"); |
| 456 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEHEADER, (void *)&header_buf), "CURLOPT_WRITEHEADER"); | 507 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEHEADER, (void *)&header_buf), "CURLOPT_WRITEHEADER"); |
| 457 | 508 | ||
| @@ -464,7 +515,7 @@ check_http (void) | |||
| 464 | 515 | ||
| 465 | // fill dns resolve cache to make curl connect to the given server_address instead of the host_name, only required for ssl, because we use the host_name later on to make SNI happy | 516 | // fill dns resolve cache to make curl connect to the given server_address instead of the host_name, only required for ssl, because we use the host_name later on to make SNI happy |
| 466 | if(use_ssl && host_name != NULL) { | 517 | if(use_ssl && host_name != NULL) { |
| 467 | if ( (res=lookup_host (server_address, addrstr, 100)) != 0) { | 518 | if ( (res=lookup_host (server_address, addrstr, DEFAULT_BUFFER_SIZE/2)) != 0) { |
| 468 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"), | 519 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"), |
| 469 | server_address, res, gai_strerror (res)); | 520 | server_address, res, gai_strerror (res)); |
| 470 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | 521 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); |
| @@ -491,7 +542,7 @@ check_http (void) | |||
| 491 | /* compose URL: use the address we want to connect to, set Host: header later */ | 542 | /* compose URL: use the address we want to connect to, set Host: header later */ |
| 492 | snprintf (url, DEFAULT_BUFFER_SIZE, "%s://%s:%d%s", | 543 | snprintf (url, DEFAULT_BUFFER_SIZE, "%s://%s:%d%s", |
| 493 | use_ssl ? "https" : "http", | 544 | use_ssl ? "https" : "http", |
| 494 | use_ssl & host_name != NULL ? host_name : server_address, | 545 | ( use_ssl & ( host_name != NULL ) ) ? host_name : server_address, |
| 495 | server_port, | 546 | server_port, |
| 496 | server_url | 547 | server_url |
| 497 | ); | 548 | ); |
| @@ -512,7 +563,7 @@ check_http (void) | |||
| 512 | 563 | ||
| 513 | /* disable body for HEAD request */ | 564 | /* disable body for HEAD request */ |
| 514 | if (http_method && !strcmp (http_method, "HEAD" )) { | 565 | if (http_method && !strcmp (http_method, "HEAD" )) { |
| 515 | no_body = TRUE; | 566 | no_body = true; |
| 516 | } | 567 | } |
| 517 | 568 | ||
| 518 | /* set HTTP protocol version */ | 569 | /* set HTTP protocol version */ |
| @@ -567,7 +618,7 @@ check_http (void) | |||
| 567 | 618 | ||
| 568 | #ifdef LIBCURL_FEATURE_SSL | 619 | #ifdef LIBCURL_FEATURE_SSL |
| 569 | 620 | ||
| 570 | /* set SSL version, warn about unsecure or unsupported versions */ | 621 | /* set SSL version, warn about insecure or unsupported versions */ |
| 571 | if (use_ssl) { | 622 | if (use_ssl) { |
| 572 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_SSLVERSION, ssl_version), "CURLOPT_SSLVERSION"); | 623 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_SSLVERSION, ssl_version), "CURLOPT_SSLVERSION"); |
| 573 | } | 624 | } |
| @@ -609,7 +660,7 @@ check_http (void) | |||
| 609 | #ifdef USE_OPENSSL | 660 | #ifdef USE_OPENSSL |
| 610 | /* libcurl and monitoring plugins built with OpenSSL, good */ | 661 | /* libcurl and monitoring plugins built with OpenSSL, good */ |
| 611 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun), "CURLOPT_SSL_CTX_FUNCTION"); | 662 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun), "CURLOPT_SSL_CTX_FUNCTION"); |
| 612 | is_openssl_callback = TRUE; | 663 | is_openssl_callback = true; |
| 613 | #else /* USE_OPENSSL */ | 664 | #else /* USE_OPENSSL */ |
| 614 | #endif /* USE_OPENSSL */ | 665 | #endif /* USE_OPENSSL */ |
| 615 | /* libcurl is built with OpenSSL, monitoring plugins, so falling | 666 | /* libcurl is built with OpenSSL, monitoring plugins, so falling |
| @@ -688,9 +739,11 @@ check_http (void) | |||
| 688 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_MAXREDIRS, max_depth+1), "CURLOPT_MAXREDIRS"); | 739 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_MAXREDIRS, max_depth+1), "CURLOPT_MAXREDIRS"); |
| 689 | 740 | ||
| 690 | /* for now allow only http and https (we are a http(s) check plugin in the end) */ | 741 | /* for now allow only http and https (we are a http(s) check plugin in the end) */ |
| 691 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4) | 742 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 85, 0) |
| 743 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS_STR, "http,https"), "CURLOPT_REDIR_PROTOCOLS_STR"); | ||
| 744 | #elif LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4) | ||
| 692 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS), "CURLOPT_REDIRECT_PROTOCOLS"); | 745 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS), "CURLOPT_REDIRECT_PROTOCOLS"); |
| 693 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4) */ | 746 | #endif |
| 694 | 747 | ||
| 695 | /* TODO: handle the following aspects of redirection, make them | 748 | /* TODO: handle the following aspects of redirection, make them |
| 696 | * command line options too later: | 749 | * command line options too later: |
| @@ -734,11 +787,19 @@ check_http (void) | |||
| 734 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_POSTFIELDS, http_post_data), "CURLOPT_POSTFIELDS"); | 787 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_POSTFIELDS, http_post_data), "CURLOPT_POSTFIELDS"); |
| 735 | } else if (!strcmp(http_method, "PUT")) { | 788 | } else if (!strcmp(http_method, "PUT")) { |
| 736 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READFUNCTION, (curl_read_callback)curlhelp_buffer_read_callback), "CURLOPT_READFUNCTION"); | 789 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READFUNCTION, (curl_read_callback)curlhelp_buffer_read_callback), "CURLOPT_READFUNCTION"); |
| 737 | curlhelp_initreadbuffer (&put_buf, http_post_data, strlen (http_post_data)); | 790 | if (curlhelp_initreadbuffer (&put_buf, http_post_data, strlen (http_post_data)) < 0) |
| 791 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating read buffer for PUT\n"); | ||
| 792 | put_buf_initialized = true; | ||
| 738 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READDATA, (void *)&put_buf), "CURLOPT_READDATA"); | 793 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READDATA, (void *)&put_buf), "CURLOPT_READDATA"); |
| 739 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_INFILESIZE, (curl_off_t)strlen (http_post_data)), "CURLOPT_INFILESIZE"); | 794 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_INFILESIZE, (curl_off_t)strlen (http_post_data)), "CURLOPT_INFILESIZE"); |
| 740 | } | 795 | } |
| 741 | } | 796 | } |
| 797 | |||
| 798 | /* cookie handling */ | ||
| 799 | if (cookie_jar_file != NULL) { | ||
| 800 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_COOKIEJAR, cookie_jar_file), "CURLOPT_COOKIEJAR"); | ||
| 801 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_COOKIEFILE, cookie_jar_file), "CURLOPT_COOKIEFILE"); | ||
| 802 | } | ||
| 742 | 803 | ||
| 743 | /* do the request */ | 804 | /* do the request */ |
| 744 | res = curl_easy_perform(curl); | 805 | res = curl_easy_perform(curl); |
| @@ -749,6 +810,9 @@ check_http (void) | |||
| 749 | /* free header and server IP resolve lists, we don't need it anymore */ | 810 | /* free header and server IP resolve lists, we don't need it anymore */ |
| 750 | curl_slist_free_all (header_list); header_list = NULL; | 811 | curl_slist_free_all (header_list); header_list = NULL; |
| 751 | curl_slist_free_all (server_ips); server_ips = NULL; | 812 | curl_slist_free_all (server_ips); server_ips = NULL; |
| 813 | if (host) { | ||
| 814 | curl_slist_free_all (host); host = NULL; | ||
| 815 | } | ||
| 752 | 816 | ||
| 753 | /* Curl errors, result in critical Nagios state */ | 817 | /* Curl errors, result in critical Nagios state */ |
| 754 | if (res != CURLE_OK) { | 818 | if (res != CURLE_OK) { |
| @@ -759,15 +823,15 @@ check_http (void) | |||
| 759 | 823 | ||
| 760 | /* certificate checks */ | 824 | /* certificate checks */ |
| 761 | #ifdef LIBCURL_FEATURE_SSL | 825 | #ifdef LIBCURL_FEATURE_SSL |
| 762 | if (use_ssl == TRUE) { | 826 | if (use_ssl) { |
| 763 | if (check_cert == TRUE) { | 827 | if (check_cert) { |
| 764 | if (is_openssl_callback) { | 828 | if (is_openssl_callback) { |
| 765 | #ifdef USE_OPENSSL | 829 | #ifdef USE_OPENSSL |
| 766 | /* check certificate with OpenSSL functions, curl has been built against OpenSSL | 830 | /* check certificate with OpenSSL functions, curl has been built against OpenSSL |
| 767 | * and we actually have OpenSSL in the monitoring tools | 831 | * and we actually have OpenSSL in the monitoring tools |
| 768 | */ | 832 | */ |
| 769 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); | 833 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); |
| 770 | if (continue_after_check_cert == FALSE) { | 834 | if (!continue_after_check_cert) { |
| 771 | return result; | 835 | return result; |
| 772 | } | 836 | } |
| 773 | #else /* USE_OPENSSL */ | 837 | #else /* USE_OPENSSL */ |
| @@ -809,7 +873,7 @@ GOT_FIRST_CERT: | |||
| 809 | } | 873 | } |
| 810 | BIO_free (cert_BIO); | 874 | BIO_free (cert_BIO); |
| 811 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); | 875 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); |
| 812 | if (continue_after_check_cert == FALSE) { | 876 | if (!continue_after_check_cert) { |
| 813 | return result; | 877 | return result; |
| 814 | } | 878 | } |
| 815 | #else /* USE_OPENSSL */ | 879 | #else /* USE_OPENSSL */ |
| @@ -817,7 +881,7 @@ GOT_FIRST_CERT: | |||
| 817 | * so we use the libcurl CURLINFO data | 881 | * so we use the libcurl CURLINFO data |
| 818 | */ | 882 | */ |
| 819 | result = net_noopenssl_check_certificate(&cert_ptr, days_till_exp_warn, days_till_exp_crit); | 883 | result = net_noopenssl_check_certificate(&cert_ptr, days_till_exp_warn, days_till_exp_crit); |
| 820 | if (continue_after_check_cert == FALSE) { | 884 | if (!continue_after_check_cert) { |
| 821 | return result; | 885 | return result; |
| 822 | } | 886 | } |
| 823 | #endif /* USE_OPENSSL */ | 887 | #endif /* USE_OPENSSL */ |
| @@ -845,7 +909,7 @@ GOT_FIRST_CERT: | |||
| 845 | perfd_time(total_time), | 909 | perfd_time(total_time), |
| 846 | perfd_size(page_len), | 910 | perfd_size(page_len), |
| 847 | perfd_time_connect(time_connect), | 911 | perfd_time_connect(time_connect), |
| 848 | use_ssl == TRUE ? perfd_time_ssl (time_appconnect-time_connect) : "", | 912 | use_ssl ? perfd_time_ssl (time_appconnect-time_connect) : "", |
| 849 | perfd_time_headers(time_headers - time_appconnect), | 913 | perfd_time_headers(time_headers - time_appconnect), |
| 850 | perfd_time_firstbyte(time_firstbyte - time_headers), | 914 | perfd_time_firstbyte(time_firstbyte - time_headers), |
| 851 | perfd_time_transfer(total_time-time_firstbyte) | 915 | perfd_time_transfer(total_time-time_firstbyte) |
| @@ -868,6 +932,7 @@ GOT_FIRST_CERT: | |||
| 868 | /* we cannot know the major/minor version here for sure as we cannot parse the first line */ | 932 | /* we cannot know the major/minor version here for sure as we cannot parse the first line */ |
| 869 | die (STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg); | 933 | die (STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg); |
| 870 | } | 934 | } |
| 935 | status_line_initialized = true; | ||
| 871 | 936 | ||
| 872 | /* get result code from cURL */ | 937 | /* get result code from cURL */ |
| 873 | handle_curl_option_return_code (curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &code), "CURLINFO_RESPONSE_CODE"); | 938 | handle_curl_option_return_code (curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &code), "CURLINFO_RESPONSE_CODE"); |
| @@ -921,7 +986,7 @@ GOT_FIRST_CERT: | |||
| 921 | } | 986 | } |
| 922 | } else { | 987 | } else { |
| 923 | /* this is a specific code in the command line to | 988 | /* this is a specific code in the command line to |
| 924 | * be returned when a redirection is encoutered | 989 | * be returned when a redirection is encountered |
| 925 | */ | 990 | */ |
| 926 | } | 991 | } |
| 927 | result = max_state_alt (onredirect, result); | 992 | result = max_state_alt (onredirect, result); |
| @@ -980,12 +1045,12 @@ GOT_FIRST_CERT: | |||
| 980 | 1045 | ||
| 981 | if (strlen (regexp)) { | 1046 | if (strlen (regexp)) { |
| 982 | errcode = regexec (&preg, body_buf.buf, REGS, pmatch, 0); | 1047 | errcode = regexec (&preg, body_buf.buf, REGS, pmatch, 0); |
| 983 | if ((errcode == 0 && invert_regex == 0) || (errcode == REG_NOMATCH && invert_regex == 1)) { | 1048 | if ((errcode == 0 && !invert_regex) || (errcode == REG_NOMATCH && invert_regex)) { |
| 984 | /* OK - No-op to avoid changing the logic around it */ | 1049 | /* OK - No-op to avoid changing the logic around it */ |
| 985 | result = max_state_alt(STATE_OK, result); | 1050 | result = max_state_alt(STATE_OK, result); |
| 986 | } | 1051 | } |
| 987 | else if ((errcode == REG_NOMATCH && invert_regex == 0) || (errcode == 0 && invert_regex == 1)) { | 1052 | else if ((errcode == REG_NOMATCH && !invert_regex) || (errcode == 0 && invert_regex)) { |
| 988 | if (invert_regex == 0) | 1053 | if (!invert_regex) |
| 989 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern not found, "), msg); | 1054 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern not found, "), msg); |
| 990 | else | 1055 | else |
| 991 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern found, "), msg); | 1056 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern found, "), msg); |
| @@ -1017,7 +1082,7 @@ GOT_FIRST_CERT: | |||
| 1017 | else | 1082 | else |
| 1018 | msg[strlen(msg)-3] = '\0'; | 1083 | msg[strlen(msg)-3] = '\0'; |
| 1019 | } | 1084 | } |
| 1020 | 1085 | ||
| 1021 | /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */ | 1086 | /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */ |
| 1022 | die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n%s%s", | 1087 | die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n%s%s", |
| 1023 | state_text(result), string_statuscode (status_line.http_major, status_line.http_minor), | 1088 | state_text(result), string_statuscode (status_line.http_major, status_line.http_minor), |
| @@ -1029,16 +1094,6 @@ GOT_FIRST_CERT: | |||
| 1029 | (show_body ? body_buf.buf : ""), | 1094 | (show_body ? body_buf.buf : ""), |
| 1030 | (show_body ? "\n" : "") ); | 1095 | (show_body ? "\n" : "") ); |
| 1031 | 1096 | ||
| 1032 | /* proper cleanup after die? */ | ||
| 1033 | curlhelp_free_statusline(&status_line); | ||
| 1034 | curl_easy_cleanup (curl); | ||
| 1035 | curl_global_cleanup (); | ||
| 1036 | curlhelp_freewritebuffer (&body_buf); | ||
| 1037 | curlhelp_freewritebuffer (&header_buf); | ||
| 1038 | if (!strcmp (http_method, "PUT")) { | ||
| 1039 | curlhelp_freereadbuffer (&put_buf); | ||
| 1040 | } | ||
| 1041 | |||
| 1042 | return result; | 1097 | return result; |
| 1043 | } | 1098 | } |
| 1044 | 1099 | ||
| @@ -1134,7 +1189,10 @@ redir (curlhelp_write_curlbuf* header_buf) | |||
| 1134 | } | 1189 | } |
| 1135 | } | 1190 | } |
| 1136 | 1191 | ||
| 1137 | use_ssl = !uri_strcmp (uri.scheme, "https"); | 1192 | if (!uri_strcmp (uri.scheme, "https")) |
| 1193 | use_ssl = true; | ||
| 1194 | else | ||
| 1195 | use_ssl = false; | ||
| 1138 | 1196 | ||
| 1139 | /* we do a sloppy test here only, because uriparser would have failed | 1197 | /* we do a sloppy test here only, because uriparser would have failed |
| 1140 | * above, if the port would be invalid, we just check for MAX_PORT | 1198 | * above, if the port would be invalid, we just check for MAX_PORT |
| @@ -1209,6 +1267,7 @@ redir (curlhelp_write_curlbuf* header_buf) | |||
| 1209 | * attached to the URL in Location | 1267 | * attached to the URL in Location |
| 1210 | */ | 1268 | */ |
| 1211 | 1269 | ||
| 1270 | cleanup (); | ||
| 1212 | check_http (); | 1271 | check_http (); |
| 1213 | } | 1272 | } |
| 1214 | 1273 | ||
| @@ -1221,7 +1280,7 @@ test_file (char *path) | |||
| 1221 | usage2 (_("file does not exist or is not readable"), path); | 1280 | usage2 (_("file does not exist or is not readable"), path); |
| 1222 | } | 1281 | } |
| 1223 | 1282 | ||
| 1224 | int | 1283 | bool |
| 1225 | process_arguments (int argc, char **argv) | 1284 | process_arguments (int argc, char **argv) |
| 1226 | { | 1285 | { |
| 1227 | char *p; | 1286 | char *p; |
| @@ -1235,7 +1294,8 @@ process_arguments (int argc, char **argv) | |||
| 1235 | CONTINUE_AFTER_CHECK_CERT, | 1294 | CONTINUE_AFTER_CHECK_CERT, |
| 1236 | CA_CERT_OPTION, | 1295 | CA_CERT_OPTION, |
| 1237 | HTTP_VERSION_OPTION, | 1296 | HTTP_VERSION_OPTION, |
| 1238 | AUTOMATIC_DECOMPRESSION | 1297 | AUTOMATIC_DECOMPRESSION, |
| 1298 | COOKIE_JAR | ||
| 1239 | }; | 1299 | }; |
| 1240 | 1300 | ||
| 1241 | int option = 0; | 1301 | int option = 0; |
| @@ -1281,11 +1341,12 @@ process_arguments (int argc, char **argv) | |||
| 1281 | {"max-redirs", required_argument, 0, MAX_REDIRS_OPTION}, | 1341 | {"max-redirs", required_argument, 0, MAX_REDIRS_OPTION}, |
| 1282 | {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, | 1342 | {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, |
| 1283 | {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION}, | 1343 | {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION}, |
| 1344 | {"cookie-jar", required_argument, 0, COOKIE_JAR}, | ||
| 1284 | {0, 0, 0, 0} | 1345 | {0, 0, 0, 0} |
| 1285 | }; | 1346 | }; |
| 1286 | 1347 | ||
| 1287 | if (argc < 2) | 1348 | if (argc < 2) |
| 1288 | return ERROR; | 1349 | return false; |
| 1289 | 1350 | ||
| 1290 | /* support check_http compatible arguments */ | 1351 | /* support check_http compatible arguments */ |
| 1291 | for (c = 1; c < argc; c++) { | 1352 | for (c = 1; c < argc; c++) { |
| @@ -1365,7 +1426,7 @@ process_arguments (int argc, char **argv) | |||
| 1365 | if( strtol(optarg, NULL, 10) > MAX_PORT) | 1426 | if( strtol(optarg, NULL, 10) > MAX_PORT) |
| 1366 | usage2 (_("Invalid port number, supplied port number is too big"), optarg); | 1427 | usage2 (_("Invalid port number, supplied port number is too big"), optarg); |
| 1367 | server_port = (unsigned short)strtol(optarg, NULL, 10); | 1428 | server_port = (unsigned short)strtol(optarg, NULL, 10); |
| 1368 | specify_port = TRUE; | 1429 | specify_port = true; |
| 1369 | } | 1430 | } |
| 1370 | break; | 1431 | break; |
| 1371 | case 'a': /* authorization info */ | 1432 | case 'a': /* authorization info */ |
| @@ -1399,10 +1460,10 @@ process_arguments (int argc, char **argv) | |||
| 1399 | http_opt_headers[http_opt_headers_count - 1] = optarg; | 1460 | http_opt_headers[http_opt_headers_count - 1] = optarg; |
| 1400 | break; | 1461 | break; |
| 1401 | case 'L': /* show html link */ | 1462 | case 'L': /* show html link */ |
| 1402 | display_html = TRUE; | 1463 | display_html = true; |
| 1403 | break; | 1464 | break; |
| 1404 | case 'n': /* do not show html link */ | 1465 | case 'n': /* do not show html link */ |
| 1405 | display_html = FALSE; | 1466 | display_html = false; |
| 1406 | break; | 1467 | break; |
| 1407 | case 'C': /* Check SSL cert validity */ | 1468 | case 'C': /* Check SSL cert validity */ |
| 1408 | #ifdef LIBCURL_FEATURE_SSL | 1469 | #ifdef LIBCURL_FEATURE_SSL |
| @@ -1423,12 +1484,12 @@ process_arguments (int argc, char **argv) | |||
| 1423 | usage2 (_("Invalid certificate expiration period"), optarg); | 1484 | usage2 (_("Invalid certificate expiration period"), optarg); |
| 1424 | days_till_exp_warn = atoi (optarg); | 1485 | days_till_exp_warn = atoi (optarg); |
| 1425 | } | 1486 | } |
| 1426 | check_cert = TRUE; | 1487 | check_cert = true; |
| 1427 | goto enable_ssl; | 1488 | goto enable_ssl; |
| 1428 | #endif | 1489 | #endif |
| 1429 | case CONTINUE_AFTER_CHECK_CERT: /* don't stop after the certificate is checked */ | 1490 | case CONTINUE_AFTER_CHECK_CERT: /* don't stop after the certificate is checked */ |
| 1430 | #ifdef HAVE_SSL | 1491 | #ifdef HAVE_SSL |
| 1431 | continue_after_check_cert = TRUE; | 1492 | continue_after_check_cert = true; |
| 1432 | break; | 1493 | break; |
| 1433 | #endif | 1494 | #endif |
| 1434 | case 'J': /* use client certificate */ | 1495 | case 'J': /* use client certificate */ |
| @@ -1451,13 +1512,13 @@ process_arguments (int argc, char **argv) | |||
| 1451 | #endif | 1512 | #endif |
| 1452 | #ifdef LIBCURL_FEATURE_SSL | 1513 | #ifdef LIBCURL_FEATURE_SSL |
| 1453 | case 'D': /* verify peer certificate & host */ | 1514 | case 'D': /* verify peer certificate & host */ |
| 1454 | verify_peer_and_host = TRUE; | 1515 | verify_peer_and_host = true; |
| 1455 | break; | 1516 | break; |
| 1456 | #endif | 1517 | #endif |
| 1457 | case 'S': /* use SSL */ | 1518 | case 'S': /* use SSL */ |
| 1458 | #ifdef LIBCURL_FEATURE_SSL | 1519 | #ifdef LIBCURL_FEATURE_SSL |
| 1459 | enable_ssl: | 1520 | enable_ssl: |
| 1460 | use_ssl = TRUE; | 1521 | use_ssl = true; |
| 1461 | /* ssl_version initialized to CURL_SSLVERSION_DEFAULT as a default. | 1522 | /* ssl_version initialized to CURL_SSLVERSION_DEFAULT as a default. |
| 1462 | * Only set if it's non-zero. This helps when we include multiple | 1523 | * Only set if it's non-zero. This helps when we include multiple |
| 1463 | * parameters, like -S and -C combinations */ | 1524 | * parameters, like -S and -C combinations */ |
| @@ -1531,15 +1592,15 @@ process_arguments (int argc, char **argv) | |||
| 1531 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 54, 0) */ | 1592 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 54, 0) */ |
| 1532 | if (verbose >= 2) | 1593 | if (verbose >= 2) |
| 1533 | printf(_("* Set SSL/TLS version to %d\n"), ssl_version); | 1594 | printf(_("* Set SSL/TLS version to %d\n"), ssl_version); |
| 1534 | if (specify_port == FALSE) | 1595 | if (!specify_port) |
| 1535 | server_port = HTTPS_PORT; | 1596 | server_port = HTTPS_PORT; |
| 1536 | break; | 1597 | break; |
| 1537 | #else /* LIBCURL_FEATURE_SSL */ | 1598 | #else /* LIBCURL_FEATURE_SSL */ |
| 1538 | /* -C -J and -K fall through to here without SSL */ | 1599 | /* -C -J and -K fall through to here without SSL */ |
| 1539 | usage4 (_("Invalid option - SSL is not available")); | 1600 | usage4 (_("Invalid option - SSL is not available")); |
| 1540 | break; | 1601 | break; |
| 1541 | case SNI_OPTION: /* --sni is parsed, but ignored, the default is TRUE with libcurl */ | 1602 | case SNI_OPTION: /* --sni is parsed, but ignored, the default is true with libcurl */ |
| 1542 | use_sni = TRUE; | 1603 | use_sni = true; |
| 1543 | break; | 1604 | break; |
| 1544 | #endif /* LIBCURL_FEATURE_SSL */ | 1605 | #endif /* LIBCURL_FEATURE_SSL */ |
| 1545 | case MAX_REDIRS_OPTION: | 1606 | case MAX_REDIRS_OPTION: |
| @@ -1600,11 +1661,11 @@ process_arguments (int argc, char **argv) | |||
| 1600 | if (errcode != 0) { | 1661 | if (errcode != 0) { |
| 1601 | (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); | 1662 | (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); |
| 1602 | printf (_("Could Not Compile Regular Expression: %s"), errbuf); | 1663 | printf (_("Could Not Compile Regular Expression: %s"), errbuf); |
| 1603 | return ERROR; | 1664 | return false; |
| 1604 | } | 1665 | } |
| 1605 | break; | 1666 | break; |
| 1606 | case INVERT_REGEX: | 1667 | case INVERT_REGEX: |
| 1607 | invert_regex = 1; | 1668 | invert_regex = true; |
| 1608 | break; | 1669 | break; |
| 1609 | case '4': | 1670 | case '4': |
| 1610 | address_family = AF_INET; | 1671 | address_family = AF_INET; |
| @@ -1639,7 +1700,7 @@ process_arguments (int argc, char **argv) | |||
| 1639 | break; | 1700 | break; |
| 1640 | } | 1701 | } |
| 1641 | case 'N': /* no-body */ | 1702 | case 'N': /* no-body */ |
| 1642 | no_body = TRUE; | 1703 | no_body = true; |
| 1643 | break; | 1704 | break; |
| 1644 | case 'M': /* max-age */ | 1705 | case 'M': /* max-age */ |
| 1645 | { | 1706 | { |
| @@ -1662,10 +1723,10 @@ process_arguments (int argc, char **argv) | |||
| 1662 | } | 1723 | } |
| 1663 | break; | 1724 | break; |
| 1664 | case 'E': /* show extended perfdata */ | 1725 | case 'E': /* show extended perfdata */ |
| 1665 | show_extended_perfdata = TRUE; | 1726 | show_extended_perfdata = true; |
| 1666 | break; | 1727 | break; |
| 1667 | case 'B': /* print body content after status line */ | 1728 | case 'B': /* print body content after status line */ |
| 1668 | show_body = TRUE; | 1729 | show_body = true; |
| 1669 | break; | 1730 | break; |
| 1670 | case HTTP_VERSION_OPTION: | 1731 | case HTTP_VERSION_OPTION: |
| 1671 | curl_http_version = CURL_HTTP_VERSION_NONE; | 1732 | curl_http_version = CURL_HTTP_VERSION_NONE; |
| @@ -1685,7 +1746,10 @@ process_arguments (int argc, char **argv) | |||
| 1685 | } | 1746 | } |
| 1686 | break; | 1747 | break; |
| 1687 | case AUTOMATIC_DECOMPRESSION: | 1748 | case AUTOMATIC_DECOMPRESSION: |
| 1688 | automatic_decompression = TRUE; | 1749 | automatic_decompression = true; |
| 1750 | break; | ||
| 1751 | case COOKIE_JAR: | ||
| 1752 | cookie_jar_file = optarg; | ||
| 1689 | break; | 1753 | break; |
| 1690 | case '?': | 1754 | case '?': |
| 1691 | /* print short usage statement if args not parsable */ | 1755 | /* print short usage statement if args not parsable */ |
| @@ -1726,52 +1790,52 @@ process_arguments (int argc, char **argv) | |||
| 1726 | virtual_port = server_port; | 1790 | virtual_port = server_port; |
| 1727 | else { | 1791 | else { |
| 1728 | if ((use_ssl && server_port == HTTPS_PORT) || (!use_ssl && server_port == HTTP_PORT)) | 1792 | if ((use_ssl && server_port == HTTPS_PORT) || (!use_ssl && server_port == HTTP_PORT)) |
| 1729 | if(specify_port == FALSE) | 1793 | if(!specify_port) |
| 1730 | server_port = virtual_port; | 1794 | server_port = virtual_port; |
| 1731 | } | 1795 | } |
| 1732 | 1796 | ||
| 1733 | return TRUE; | 1797 | return true; |
| 1734 | } | 1798 | } |
| 1735 | 1799 | ||
| 1736 | char *perfd_time (double elapsed_time) | 1800 | char *perfd_time (double elapsed_time) |
| 1737 | { | 1801 | { |
| 1738 | return fperfdata ("time", elapsed_time, "s", | 1802 | return fperfdata ("time", elapsed_time, "s", |
| 1739 | thlds->warning?TRUE:FALSE, thlds->warning?thlds->warning->end:0, | 1803 | thlds->warning?true:false, thlds->warning?thlds->warning->end:0, |
| 1740 | thlds->critical?TRUE:FALSE, thlds->critical?thlds->critical->end:0, | 1804 | thlds->critical?true:false, thlds->critical?thlds->critical->end:0, |
| 1741 | TRUE, 0, TRUE, socket_timeout); | 1805 | true, 0, true, socket_timeout); |
| 1742 | } | 1806 | } |
| 1743 | 1807 | ||
| 1744 | char *perfd_time_connect (double elapsed_time_connect) | 1808 | char *perfd_time_connect (double elapsed_time_connect) |
| 1745 | { | 1809 | { |
| 1746 | return fperfdata ("time_connect", elapsed_time_connect, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | 1810 | return fperfdata ("time_connect", elapsed_time_connect, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
| 1747 | } | 1811 | } |
| 1748 | 1812 | ||
| 1749 | char *perfd_time_ssl (double elapsed_time_ssl) | 1813 | char *perfd_time_ssl (double elapsed_time_ssl) |
| 1750 | { | 1814 | { |
| 1751 | return fperfdata ("time_ssl", elapsed_time_ssl, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | 1815 | return fperfdata ("time_ssl", elapsed_time_ssl, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
| 1752 | } | 1816 | } |
| 1753 | 1817 | ||
| 1754 | char *perfd_time_headers (double elapsed_time_headers) | 1818 | char *perfd_time_headers (double elapsed_time_headers) |
| 1755 | { | 1819 | { |
| 1756 | return fperfdata ("time_headers", elapsed_time_headers, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | 1820 | return fperfdata ("time_headers", elapsed_time_headers, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
| 1757 | } | 1821 | } |
| 1758 | 1822 | ||
| 1759 | char *perfd_time_firstbyte (double elapsed_time_firstbyte) | 1823 | char *perfd_time_firstbyte (double elapsed_time_firstbyte) |
| 1760 | { | 1824 | { |
| 1761 | return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | 1825 | return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
| 1762 | } | 1826 | } |
| 1763 | 1827 | ||
| 1764 | char *perfd_time_transfer (double elapsed_time_transfer) | 1828 | char *perfd_time_transfer (double elapsed_time_transfer) |
| 1765 | { | 1829 | { |
| 1766 | return fperfdata ("time_transfer", elapsed_time_transfer, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | 1830 | return fperfdata ("time_transfer", elapsed_time_transfer, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
| 1767 | } | 1831 | } |
| 1768 | 1832 | ||
| 1769 | char *perfd_size (int page_len) | 1833 | char *perfd_size (int page_len) |
| 1770 | { | 1834 | { |
| 1771 | return perfdata ("size", page_len, "B", | 1835 | return perfdata ("size", page_len, "B", |
| 1772 | (min_page_len>0?TRUE:FALSE), min_page_len, | 1836 | (min_page_len>0?true:false), min_page_len, |
| 1773 | (min_page_len>0?TRUE:FALSE), 0, | 1837 | (min_page_len>0?true:false), 0, |
| 1774 | TRUE, 0, FALSE, 0); | 1838 | true, 0, false, 0); |
| 1775 | } | 1839 | } |
| 1776 | 1840 | ||
| 1777 | void | 1841 | void |
| @@ -1906,6 +1970,8 @@ print_help (void) | |||
| 1906 | printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)")); | 1970 | printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)")); |
| 1907 | printf (" %s\n", "--enable-automatic-decompression"); | 1971 | printf (" %s\n", "--enable-automatic-decompression"); |
| 1908 | printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING).")); | 1972 | printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING).")); |
| 1973 | printf (" %s\n", "---cookie-jar=FILE"); | ||
| 1974 | printf (" %s\n", _("Store cookies in the cookie jar and send them out when requested.")); | ||
| 1909 | printf ("\n"); | 1975 | printf ("\n"); |
| 1910 | 1976 | ||
| 1911 | printf (UT_WARN_CRIT); | 1977 | printf (UT_WARN_CRIT); |
| @@ -1985,12 +2051,13 @@ print_usage (void) | |||
| 1985 | printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname); | 2051 | printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname); |
| 1986 | printf (" [-J <client certificate file>] [-K <private key>] [--ca-cert <CA certificate file>] [-D]\n"); | 2052 | printf (" [-J <client certificate file>] [-K <private key>] [--ca-cert <CA certificate file>] [-D]\n"); |
| 1987 | printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-E] [-a auth]\n"); | 2053 | printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-E] [-a auth]\n"); |
| 1988 | printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport|curl>]\n"); | 2054 | printf (" [-b proxy_auth] [-f <ok|warning|critical|follow|sticky|stickyport|curl>]\n"); |
| 1989 | printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); | 2055 | printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); |
| 1990 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); | 2056 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); |
| 1991 | printf (" [-A string] [-k string] [-S <version>] [--sni]\n"); | 2057 | printf (" [-A string] [-k string] [-S <version>] [--sni]\n"); |
| 1992 | printf (" [-T <content-type>] [-j method]\n"); | 2058 | printf (" [-T <content-type>] [-j method]\n"); |
| 1993 | printf (" [--http-version=<version>]\n"); | 2059 | printf (" [--http-version=<version>] [--enable-automatic-decompression]\n"); |
| 2060 | printf (" [--cookie-jar=<cookie jar file>\n"); | ||
| 1994 | printf (" %s -H <vhost> | -I <IP-address> -C <warn_age>[,<crit_age>]\n",progname); | 2061 | printf (" %s -H <vhost> | -I <IP-address> -C <warn_age>[,<crit_age>]\n",progname); |
| 1995 | printf (" [-p <port>] [-t <timeout>] [-4|-6] [--sni]\n"); | 2062 | printf (" [-p <port>] [-t <timeout>] [-4|-6] [--sni]\n"); |
| 1996 | printf ("\n"); | 2063 | printf ("\n"); |
| @@ -2150,11 +2217,10 @@ curlhelp_parse_statusline (const char *buf, curlhelp_statusline *status_line) | |||
| 2150 | if( strchr( p, '.' ) != NULL ) { | 2217 | if( strchr( p, '.' ) != NULL ) { |
| 2151 | 2218 | ||
| 2152 | /* HTTP 1.x case */ | 2219 | /* HTTP 1.x case */ |
| 2153 | char *ppp; | 2220 | strtok( p, "." ); |
| 2154 | ppp = strtok( p, "." ); | ||
| 2155 | status_line->http_major = (int)strtol( p, &pp, 10 ); | 2221 | status_line->http_major = (int)strtol( p, &pp, 10 ); |
| 2156 | if( *pp != '\0' ) { free( first_line_buf ); return -1; } | 2222 | if( *pp != '\0' ) { free( first_line_buf ); return -1; } |
| 2157 | ppp = strtok( NULL, " " ); | 2223 | strtok( NULL, " " ); |
| 2158 | status_line->http_minor = (int)strtol( p, &pp, 10 ); | 2224 | status_line->http_minor = (int)strtol( p, &pp, 10 ); |
| 2159 | if( *pp != '\0' ) { free( first_line_buf ); return -1; } | 2225 | if( *pp != '\0' ) { free( first_line_buf ); return -1; } |
| 2160 | p += 4; /* 1.x SP */ | 2226 | p += 4; /* 1.x SP */ |
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 6de17f86..a99f35e3 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
| @@ -112,11 +112,12 @@ enum | |||
| 112 | { | 112 | { |
| 113 | SYNC_OPTION = CHAR_MAX + 1, | 113 | SYNC_OPTION = CHAR_MAX + 1, |
| 114 | NO_SYNC_OPTION, | 114 | NO_SYNC_OPTION, |
| 115 | BLOCK_SIZE_OPTION | 115 | BLOCK_SIZE_OPTION, |
| 116 | IGNORE_MISSING | ||
| 116 | }; | 117 | }; |
| 117 | 118 | ||
| 118 | #ifdef _AIX | 119 | #ifdef _AIX |
| 119 | #pragma alloca | 120 | #pragma alloca |
| 120 | #endif | 121 | #endif |
| 121 | 122 | ||
| 122 | int process_arguments (int, char **); | 123 | int process_arguments (int, char **); |
| @@ -126,7 +127,7 @@ int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, ch | |||
| 126 | void print_help (void); | 127 | void print_help (void); |
| 127 | void print_usage (void); | 128 | void print_usage (void); |
| 128 | double calculate_percent(uintmax_t, uintmax_t); | 129 | double calculate_percent(uintmax_t, uintmax_t); |
| 129 | void stat_path (struct parameter_list *p); | 130 | bool stat_path (struct parameter_list *p); |
| 130 | void get_stats (struct parameter_list *p, struct fs_usage *fsp); | 131 | void get_stats (struct parameter_list *p, struct fs_usage *fsp); |
| 131 | void get_path_stats (struct parameter_list *p, struct fs_usage *fsp); | 132 | void get_path_stats (struct parameter_list *p, struct fs_usage *fsp); |
| 132 | 133 | ||
| @@ -140,6 +141,7 @@ int verbose = 0; | |||
| 140 | int erronly = FALSE; | 141 | int erronly = FALSE; |
| 141 | int display_mntp = FALSE; | 142 | int display_mntp = FALSE; |
| 142 | int exact_match = FALSE; | 143 | int exact_match = FALSE; |
| 144 | bool ignore_missing = false; | ||
| 143 | int freespace_ignore_reserved = FALSE; | 145 | int freespace_ignore_reserved = FALSE; |
| 144 | int display_inodes_perfdata = FALSE; | 146 | int display_inodes_perfdata = FALSE; |
| 145 | char *warn_freespace_units = NULL; | 147 | char *warn_freespace_units = NULL; |
| @@ -155,6 +157,7 @@ char *crit_usedinodes_percent = NULL; | |||
| 155 | char *warn_freeinodes_percent = NULL; | 157 | char *warn_freeinodes_percent = NULL; |
| 156 | char *crit_freeinodes_percent = NULL; | 158 | char *crit_freeinodes_percent = NULL; |
| 157 | int path_selected = FALSE; | 159 | int path_selected = FALSE; |
| 160 | bool path_ignored = false; | ||
| 158 | char *group = NULL; | 161 | char *group = NULL; |
| 159 | struct stat *stat_buf; | 162 | struct stat *stat_buf; |
| 160 | struct name_list *seen = NULL; | 163 | struct name_list *seen = NULL; |
| @@ -166,10 +169,12 @@ main (int argc, char **argv) | |||
| 166 | int result = STATE_UNKNOWN; | 169 | int result = STATE_UNKNOWN; |
| 167 | int disk_result = STATE_UNKNOWN; | 170 | int disk_result = STATE_UNKNOWN; |
| 168 | char *output; | 171 | char *output; |
| 172 | char *ignored; | ||
| 169 | char *details; | 173 | char *details; |
| 170 | char *perf; | 174 | char *perf; |
| 171 | char *perf_ilabel; | 175 | char *perf_ilabel; |
| 172 | char *preamble; | 176 | char *preamble = " - free space:"; |
| 177 | char *ignored_preamble = " - ignored paths:"; | ||
| 173 | char *flag_header; | 178 | char *flag_header; |
| 174 | int temp_result; | 179 | int temp_result; |
| 175 | 180 | ||
| @@ -181,8 +186,8 @@ main (int argc, char **argv) | |||
| 181 | char mountdir[32]; | 186 | char mountdir[32]; |
| 182 | #endif | 187 | #endif |
| 183 | 188 | ||
| 184 | preamble = strdup (" - free space:"); | ||
| 185 | output = strdup (""); | 189 | output = strdup (""); |
| 190 | ignored = strdup (""); | ||
| 186 | details = strdup (""); | 191 | details = strdup (""); |
| 187 | perf = strdup (""); | 192 | perf = strdup (""); |
| 188 | perf_ilabel = strdup (""); | 193 | perf_ilabel = strdup (""); |
| @@ -203,7 +208,7 @@ main (int argc, char **argv) | |||
| 203 | /* If a list of paths has not been selected, find entire | 208 | /* If a list of paths has not been selected, find entire |
| 204 | mount list and create list of paths | 209 | mount list and create list of paths |
| 205 | */ | 210 | */ |
| 206 | if (path_selected == FALSE) { | 211 | if (path_selected == FALSE && path_ignored == false) { |
| 207 | for (me = mount_list; me; me = me->me_next) { | 212 | for (me = mount_list; me; me = me->me_next) { |
| 208 | if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) { | 213 | if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) { |
| 209 | path = np_add_parameter(&path_select_list, me->me_mountdir); | 214 | path = np_add_parameter(&path_select_list, me->me_mountdir); |
| @@ -213,17 +218,40 @@ main (int argc, char **argv) | |||
| 213 | set_all_thresholds(path); | 218 | set_all_thresholds(path); |
| 214 | } | 219 | } |
| 215 | } | 220 | } |
| 216 | np_set_best_match(path_select_list, mount_list, exact_match); | 221 | |
| 222 | if (path_ignored == false) { | ||
| 223 | np_set_best_match(path_select_list, mount_list, exact_match); | ||
| 224 | } | ||
| 217 | 225 | ||
| 218 | /* Error if no match found for specified paths */ | 226 | /* Error if no match found for specified paths */ |
| 219 | temp_list = path_select_list; | 227 | temp_list = path_select_list; |
| 220 | 228 | ||
| 221 | while (temp_list) { | 229 | while (path_select_list) { |
| 222 | if (! temp_list->best_match) { | 230 | if (! path_select_list->best_match && ignore_missing == true) { |
| 223 | die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), temp_list->name); | 231 | /* If the first element will be deleted, the temp_list must be updated with the new start address as well */ |
| 232 | if (path_select_list == temp_list) { | ||
| 233 | temp_list = path_select_list->name_next; | ||
| 234 | } | ||
| 235 | /* Add path argument to list of ignored paths to inform about missing paths being ignored and not alerted */ | ||
| 236 | xasprintf (&ignored, "%s %s;", ignored, path_select_list->name); | ||
| 237 | /* Delete the path from the list so that it is not stat-checked later in the code. */ | ||
| 238 | path_select_list = np_del_parameter(path_select_list, path_select_list->name_prev); | ||
| 239 | } else if (! path_select_list->best_match) { | ||
| 240 | /* Without --ignore-missing option, exit with Critical state. */ | ||
| 241 | die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), path_select_list->name); | ||
| 242 | } else { | ||
| 243 | /* Continue jumping through the list */ | ||
| 244 | path_select_list = path_select_list->name_next; | ||
| 224 | } | 245 | } |
| 246 | } | ||
| 247 | |||
| 248 | path_select_list = temp_list; | ||
| 225 | 249 | ||
| 226 | temp_list = temp_list->name_next; | 250 | if (! path_select_list && ignore_missing == true) { |
| 251 | result = STATE_OK; | ||
| 252 | if (verbose >= 2) { | ||
| 253 | printf ("None of the provided paths were found\n"); | ||
| 254 | } | ||
| 227 | } | 255 | } |
| 228 | 256 | ||
| 229 | /* Process for every path in list */ | 257 | /* Process for every path in list */ |
| @@ -242,6 +270,10 @@ main (int argc, char **argv) | |||
| 242 | 270 | ||
| 243 | me = path->best_match; | 271 | me = path->best_match; |
| 244 | 272 | ||
| 273 | if (!me) { | ||
| 274 | continue; | ||
| 275 | } | ||
| 276 | |||
| 245 | #ifdef __CYGWIN__ | 277 | #ifdef __CYGWIN__ |
| 246 | if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11) | 278 | if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11) |
| 247 | continue; | 279 | continue; |
| @@ -260,8 +292,12 @@ main (int argc, char **argv) | |||
| 260 | if (path->group == NULL) { | 292 | if (path->group == NULL) { |
| 261 | /* Skip remote filesystems if we're not interested in them */ | 293 | /* Skip remote filesystems if we're not interested in them */ |
| 262 | if (me->me_remote && show_local_fs) { | 294 | if (me->me_remote && show_local_fs) { |
| 263 | if (stat_remote_fs) | 295 | if (stat_remote_fs) { |
| 264 | stat_path(path); | 296 | if (!stat_path(path) && ignore_missing == true) { |
| 297 | result = STATE_OK; | ||
| 298 | xasprintf (&ignored, "%s %s;", ignored, path->name); | ||
| 299 | } | ||
| 300 | } | ||
| 265 | continue; | 301 | continue; |
| 266 | /* Skip pseudo fs's if we haven't asked for all fs's */ | 302 | /* Skip pseudo fs's if we haven't asked for all fs's */ |
| 267 | } else if (me->me_dummy && !show_all_fs) { | 303 | } else if (me->me_dummy && !show_all_fs) { |
| @@ -280,7 +316,13 @@ main (int argc, char **argv) | |||
| 280 | } | 316 | } |
| 281 | } | 317 | } |
| 282 | 318 | ||
| 283 | stat_path(path); | 319 | if (!stat_path(path)) { |
| 320 | if (ignore_missing == true) { | ||
| 321 | result = STATE_OK; | ||
| 322 | xasprintf (&ignored, "%s %s;", ignored, path->name); | ||
| 323 | } | ||
| 324 | continue; | ||
| 325 | } | ||
| 284 | get_fs_usage (me->me_mountdir, me->me_devname, &fsp); | 326 | get_fs_usage (me->me_mountdir, me->me_devname, &fsp); |
| 285 | 327 | ||
| 286 | if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) { | 328 | if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) { |
| @@ -411,8 +453,12 @@ main (int argc, char **argv) | |||
| 411 | if (verbose >= 2) | 453 | if (verbose >= 2) |
| 412 | xasprintf (&output, "%s%s", output, details); | 454 | xasprintf (&output, "%s%s", output, details); |
| 413 | 455 | ||
| 456 | if (strcmp(output, "") == 0 && ! erronly) { | ||
| 457 | preamble = ""; | ||
| 458 | xasprintf (&output, " - No disks were found for provided parameters;"); | ||
| 459 | } | ||
| 414 | 460 | ||
| 415 | printf ("DISK %s%s%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf); | 461 | printf ("DISK %s%s%s%s%s|%s\n", state_text (result), ((erronly && result==STATE_OK)) ? "" : preamble, output, (strcmp(ignored, "") == 0) ? "" : ignored_preamble, ignored, perf); |
| 416 | return result; | 462 | return result; |
| 417 | } | 463 | } |
| 418 | 464 | ||
| @@ -481,6 +527,7 @@ process_arguments (int argc, char **argv) | |||
| 481 | {"ignore-ereg-partition", required_argument, 0, 'i'}, | 527 | {"ignore-ereg-partition", required_argument, 0, 'i'}, |
| 482 | {"ignore-eregi-path", required_argument, 0, 'I'}, | 528 | {"ignore-eregi-path", required_argument, 0, 'I'}, |
| 483 | {"ignore-eregi-partition", required_argument, 0, 'I'}, | 529 | {"ignore-eregi-partition", required_argument, 0, 'I'}, |
| 530 | {"ignore-missing", no_argument, 0, IGNORE_MISSING}, | ||
| 484 | {"local", no_argument, 0, 'l'}, | 531 | {"local", no_argument, 0, 'l'}, |
| 485 | {"stat-remote-fs", no_argument, 0, 'L'}, | 532 | {"stat-remote-fs", no_argument, 0, 'L'}, |
| 486 | {"iperfdata", no_argument, 0, 'P'}, | 533 | {"iperfdata", no_argument, 0, 'P'}, |
| @@ -540,7 +587,7 @@ process_arguments (int argc, char **argv) | |||
| 540 | 587 | ||
| 541 | /* Awful mistake where the range values do not make sense. Normally, | 588 | /* Awful mistake where the range values do not make sense. Normally, |
| 542 | you alert if the value is within the range, but since we are using | 589 | you alert if the value is within the range, but since we are using |
| 543 | freespace, we have to alert if outside the range. Thus we artifically | 590 | freespace, we have to alert if outside the range. Thus we artificially |
| 544 | force @ at the beginning of the range, so that it is backwards compatible | 591 | force @ at the beginning of the range, so that it is backwards compatible |
| 545 | */ | 592 | */ |
| 546 | case 'c': /* critical threshold */ | 593 | case 'c': /* critical threshold */ |
| @@ -632,12 +679,19 @@ process_arguments (int argc, char **argv) | |||
| 632 | /* add parameter if not found. overwrite thresholds if path has already been added */ | 679 | /* add parameter if not found. overwrite thresholds if path has already been added */ |
| 633 | if (! (se = np_find_parameter(path_select_list, optarg))) { | 680 | if (! (se = np_find_parameter(path_select_list, optarg))) { |
| 634 | se = np_add_parameter(&path_select_list, optarg); | 681 | se = np_add_parameter(&path_select_list, optarg); |
| 682 | |||
| 683 | if (stat(optarg, &stat_buf[0]) && ignore_missing == true) { | ||
| 684 | path_ignored = true; | ||
| 685 | break; | ||
| 686 | } | ||
| 635 | } | 687 | } |
| 636 | se->group = group; | 688 | se->group = group; |
| 637 | set_all_thresholds(se); | 689 | set_all_thresholds(se); |
| 638 | 690 | ||
| 639 | /* With autofs, it is required to stat() the path before re-populating the mount_list */ | 691 | /* With autofs, it is required to stat() the path before re-populating the mount_list */ |
| 640 | stat_path(se); | 692 | if (!stat_path(se)) { |
| 693 | break; | ||
| 694 | } | ||
| 641 | /* NB: We can't free the old mount_list "just like that": both list pointers and struct | 695 | /* NB: We can't free the old mount_list "just like that": both list pointers and struct |
| 642 | * pointers are copied around. One of the reason it wasn't done yet is that other parts | 696 | * pointers are copied around. One of the reason it wasn't done yet is that other parts |
| 643 | * of check_disk need the same kind of cleanup so it'd better be done as a whole */ | 697 | * of check_disk need the same kind of cleanup so it'd better be done as a whole */ |
| @@ -718,6 +772,9 @@ process_arguments (int argc, char **argv) | |||
| 718 | cflags = default_cflags; | 772 | cflags = default_cflags; |
| 719 | break; | 773 | break; |
| 720 | 774 | ||
| 775 | case IGNORE_MISSING: | ||
| 776 | ignore_missing = true; | ||
| 777 | break; | ||
| 721 | case 'A': | 778 | case 'A': |
| 722 | optarg = strdup(".*"); | 779 | optarg = strdup(".*"); |
| 723 | // Intentional fallthrough | 780 | // Intentional fallthrough |
| @@ -753,7 +810,11 @@ process_arguments (int argc, char **argv) | |||
| 753 | } | 810 | } |
| 754 | } | 811 | } |
| 755 | 812 | ||
| 756 | if (!fnd) | 813 | if (!fnd && ignore_missing == true) { |
| 814 | path_ignored = true; | ||
| 815 | /* path_selected = TRUE;*/ | ||
| 816 | break; | ||
| 817 | } else if (!fnd) | ||
| 757 | die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), | 818 | die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), |
| 758 | _("Regular expression did not match any path or disk"), optarg); | 819 | _("Regular expression did not match any path or disk"), optarg); |
| 759 | 820 | ||
| @@ -923,6 +984,9 @@ print_help (void) | |||
| 923 | printf (" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)")); | 984 | printf (" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)")); |
| 924 | printf (" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION"); | 985 | printf (" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION"); |
| 925 | printf (" %s\n", _("Regular expression to ignore selected path or partition (may be repeated)")); | 986 | printf (" %s\n", _("Regular expression to ignore selected path or partition (may be repeated)")); |
| 987 | printf (" %s\n", "--ignore-missing"); | ||
| 988 | printf (" %s\n", _("Return OK if no filesystem matches, filesystem does not exist or is inaccessible.")); | ||
| 989 | printf (" %s\n", _("(Provide this option before -p / -r / --ereg-path if used)")); | ||
| 926 | printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 990 | printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
| 927 | printf (" %s\n", "-u, --units=STRING"); | 991 | printf (" %s\n", "-u, --units=STRING"); |
| 928 | printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)")); | 992 | printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)")); |
| @@ -956,7 +1020,7 @@ print_usage (void) | |||
| 956 | printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type]\n"); | 1020 | printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type]\n"); |
| 957 | } | 1021 | } |
| 958 | 1022 | ||
| 959 | void | 1023 | bool |
| 960 | stat_path (struct parameter_list *p) | 1024 | stat_path (struct parameter_list *p) |
| 961 | { | 1025 | { |
| 962 | /* Stat entry to check that dir exists and is accessible */ | 1026 | /* Stat entry to check that dir exists and is accessible */ |
| @@ -965,9 +1029,14 @@ stat_path (struct parameter_list *p) | |||
| 965 | if (stat (p->name, &stat_buf[0])) { | 1029 | if (stat (p->name, &stat_buf[0])) { |
| 966 | if (verbose >= 3) | 1030 | if (verbose >= 3) |
| 967 | printf("stat failed on %s\n", p->name); | 1031 | printf("stat failed on %s\n", p->name); |
| 968 | printf("DISK %s - ", _("CRITICAL")); | 1032 | if (ignore_missing == true) { |
| 969 | die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno)); | 1033 | return false; |
| 1034 | } else { | ||
| 1035 | printf("DISK %s - ", _("CRITICAL")); | ||
| 1036 | die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno)); | ||
| 1037 | } | ||
| 970 | } | 1038 | } |
| 1039 | return true; | ||
| 971 | } | 1040 | } |
| 972 | 1041 | ||
| 973 | 1042 | ||
| @@ -987,7 +1056,8 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
| 987 | continue; | 1056 | continue; |
| 988 | #endif | 1057 | #endif |
| 989 | if (p_list->group && ! (strcmp(p_list->group, p->group))) { | 1058 | if (p_list->group && ! (strcmp(p_list->group, p->group))) { |
| 990 | stat_path(p_list); | 1059 | if (! stat_path(p_list)) |
| 1060 | continue; | ||
| 991 | get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp); | 1061 | get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp); |
| 992 | get_path_stats(p_list, &tmpfsp); | 1062 | get_path_stats(p_list, &tmpfsp); |
| 993 | if (verbose >= 3) | 1063 | if (verbose >= 3) |
| @@ -1045,7 +1115,7 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
| 1045 | p->available_to_root = fsp->fsu_bfree; | 1115 | p->available_to_root = fsp->fsu_bfree; |
| 1046 | p->used = fsp->fsu_blocks - fsp->fsu_bfree; | 1116 | p->used = fsp->fsu_blocks - fsp->fsu_bfree; |
| 1047 | if (freespace_ignore_reserved) { | 1117 | if (freespace_ignore_reserved) { |
| 1048 | /* option activated : we substract the root-reserved space from the total */ | 1118 | /* option activated : we subtract the root-reserved space from the total */ |
| 1049 | p->total = fsp->fsu_blocks - p->available_to_root + p->available; | 1119 | p->total = fsp->fsu_blocks - p->available_to_root + p->available; |
| 1050 | } else { | 1120 | } else { |
| 1051 | /* default behaviour : take all the blocks into account */ | 1121 | /* default behaviour : take all the blocks into account */ |
| @@ -1056,11 +1126,11 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
| 1056 | p->dfree_units = p->available*fsp->fsu_blocksize/mult; | 1126 | p->dfree_units = p->available*fsp->fsu_blocksize/mult; |
| 1057 | p->dtotal_units = p->total*fsp->fsu_blocksize/mult; | 1127 | p->dtotal_units = p->total*fsp->fsu_blocksize/mult; |
| 1058 | /* Free file nodes. Not sure the workaround is required, but in case...*/ | 1128 | /* Free file nodes. Not sure the workaround is required, but in case...*/ |
| 1059 | p->inodes_free = fsp->fsu_favail > fsp->fsu_ffree ? 0 : fsp->fsu_favail; | 1129 | p->inodes_free = fsp->fsu_ffree; |
| 1060 | p->inodes_free_to_root = fsp->fsu_ffree; /* Free file nodes for root. */ | 1130 | p->inodes_free_to_root = fsp->fsu_ffree; /* Free file nodes for root. */ |
| 1061 | p->inodes_used = fsp->fsu_files - fsp->fsu_ffree; | 1131 | p->inodes_used = fsp->fsu_files - fsp->fsu_ffree; |
| 1062 | if (freespace_ignore_reserved) { | 1132 | if (freespace_ignore_reserved) { |
| 1063 | /* option activated : we substract the root-reserved inodes from the total */ | 1133 | /* option activated : we subtract the root-reserved inodes from the total */ |
| 1064 | /* not all OS report fsp->fsu_favail, only the ones with statvfs syscall */ | 1134 | /* not all OS report fsp->fsu_favail, only the ones with statvfs syscall */ |
| 1065 | /* for others, fsp->fsu_ffree == fsp->fsu_favail */ | 1135 | /* for others, fsp->fsu_ffree == fsp->fsu_favail */ |
| 1066 | p->inodes_total = fsp->fsu_files - p->inodes_free_to_root + p->inodes_free; | 1136 | p->inodes_total = fsp->fsu_files - p->inodes_free_to_root + p->inodes_free; |
diff --git a/plugins/check_dns.c b/plugins/check_dns.c index 9de6caf5..7ffce98b 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c | |||
| @@ -75,7 +75,7 @@ main (int argc, char **argv) | |||
| 75 | { | 75 | { |
| 76 | char *command_line = NULL; | 76 | char *command_line = NULL; |
| 77 | char input_buffer[MAX_INPUT_BUFFER]; | 77 | char input_buffer[MAX_INPUT_BUFFER]; |
| 78 | char *address = NULL; /* comma seperated str with addrs/ptrs (sorted) */ | 78 | char *address = NULL; /* comma separated str with addrs/ptrs (sorted) */ |
| 79 | char **addresses = NULL; | 79 | char **addresses = NULL; |
| 80 | int n_addresses = 0; | 80 | int n_addresses = 0; |
| 81 | char *msg = NULL; | 81 | char *msg = NULL; |
diff --git a/plugins/check_fping.c b/plugins/check_fping.c index db433162..6f5656ef 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c | |||
| @@ -73,7 +73,7 @@ int wrta_p = FALSE; | |||
| 73 | int | 73 | int |
| 74 | main (int argc, char **argv) | 74 | main (int argc, char **argv) |
| 75 | { | 75 | { |
| 76 | /* normaly should be int result = STATE_UNKNOWN; */ | 76 | /* normally should be int result = STATE_UNKNOWN; */ |
| 77 | 77 | ||
| 78 | int status = STATE_UNKNOWN; | 78 | int status = STATE_UNKNOWN; |
| 79 | int result = 0; | 79 | int result = 0; |
diff --git a/plugins/check_http.c b/plugins/check_http.c index 5fa310f5..6956a726 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
| @@ -198,7 +198,7 @@ test_file (char *path) | |||
| 198 | 198 | ||
| 199 | /* | 199 | /* |
| 200 | * process command-line arguments | 200 | * process command-line arguments |
| 201 | * returns true on succes, false otherwise | 201 | * returns true on success, false otherwise |
| 202 | */ | 202 | */ |
| 203 | bool process_arguments (int argc, char **argv) | 203 | bool process_arguments (int argc, char **argv) |
| 204 | { | 204 | { |
| @@ -1391,7 +1391,6 @@ char *unchunk_content(const char *content) { | |||
| 1391 | // https://en.wikipedia.org/wiki/Chunked_transfer_encoding | 1391 | // https://en.wikipedia.org/wiki/Chunked_transfer_encoding |
| 1392 | // https://www.rfc-editor.org/rfc/rfc7230#section-4.1 | 1392 | // https://www.rfc-editor.org/rfc/rfc7230#section-4.1 |
| 1393 | char *result = NULL; | 1393 | char *result = NULL; |
| 1394 | size_t content_length = strlen(content); | ||
| 1395 | char *start_of_chunk; | 1394 | char *start_of_chunk; |
| 1396 | char* end_of_chunk; | 1395 | char* end_of_chunk; |
| 1397 | long size_of_chunk; | 1396 | long size_of_chunk; |
| @@ -1462,7 +1461,13 @@ char *unchunk_content(const char *content) { | |||
| 1462 | memcpy(result + (overall_size - size_of_chunk), start_of_chunk, size_of_chunk); | 1461 | memcpy(result + (overall_size - size_of_chunk), start_of_chunk, size_of_chunk); |
| 1463 | } | 1462 | } |
| 1464 | 1463 | ||
| 1465 | result[overall_size] = '\0'; | 1464 | if (overall_size == 0 && result == NULL) { |
| 1465 | // We might just have received the end chunk without previous content, so result is never allocated | ||
| 1466 | result = calloc(1, sizeof(char)); | ||
| 1467 | // No error handling here, we can only return NULL anyway | ||
| 1468 | } else { | ||
| 1469 | result[overall_size] = '\0'; | ||
| 1470 | } | ||
| 1466 | return result; | 1471 | return result; |
| 1467 | } | 1472 | } |
| 1468 | 1473 | ||
| @@ -1879,7 +1884,7 @@ print_usage (void) | |||
| 1879 | printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname); | 1884 | printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname); |
| 1880 | printf (" [-J <client certificate file>] [-K <private key>]\n"); | 1885 | printf (" [-J <client certificate file>] [-K <private key>]\n"); |
| 1881 | printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-E] [-a auth]\n"); | 1886 | printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-E] [-a auth]\n"); |
| 1882 | printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n"); | 1887 | printf (" [-b proxy_auth] [-f <ok|warning|critical|follow|sticky|stickyport>]\n"); |
| 1883 | printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); | 1888 | printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); |
| 1884 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); | 1889 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); |
| 1885 | printf (" [-A string] [-k string] [-S <version>] [--sni]\n"); | 1890 | printf (" [-A string] [-k string] [-S <version>] [--sni]\n"); |
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index 845a4f52..a1bfe1be 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c | |||
| @@ -222,7 +222,7 @@ main (int argc, char *argv[]) | |||
| 222 | /* reset the alarm handler */ | 222 | /* reset the alarm handler */ |
| 223 | alarm (0); | 223 | alarm (0); |
| 224 | 224 | ||
| 225 | /* calcutate the elapsed time and compare to thresholds */ | 225 | /* calculate the elapsed time and compare to thresholds */ |
| 226 | 226 | ||
| 227 | microsec = deltime (tv); | 227 | microsec = deltime (tv); |
| 228 | elapsed_time = (double)microsec / 1.0e6; | 228 | elapsed_time = (double)microsec / 1.0e6; |
diff --git a/plugins/check_load.c b/plugins/check_load.c index 00f7c877..313df8ad 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c | |||
| @@ -107,7 +107,7 @@ main (int argc, char **argv) | |||
| 107 | int i; | 107 | int i; |
| 108 | long numcpus; | 108 | long numcpus; |
| 109 | 109 | ||
| 110 | double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about unitialized arrays */ | 110 | double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about uninitialized arrays */ |
| 111 | #ifndef HAVE_GETLOADAVG | 111 | #ifndef HAVE_GETLOADAVG |
| 112 | char input_buffer[MAX_INPUT_BUFFER]; | 112 | char input_buffer[MAX_INPUT_BUFFER]; |
| 113 | # ifdef HAVE_PROC_LOADAVG | 113 | # ifdef HAVE_PROC_LOADAVG |
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 0cba50e6..6cfa70ed 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c | |||
| @@ -551,7 +551,7 @@ print_help (void) | |||
| 551 | printf (" %s\n", _("Exit with CRITICAL status if slave server is more then INTEGER seconds")); | 551 | printf (" %s\n", _("Exit with CRITICAL status if slave server is more then INTEGER seconds")); |
| 552 | printf (" %s\n", _("behind master")); | 552 | printf (" %s\n", _("behind master")); |
| 553 | printf (" %s\n", "-l, --ssl"); | 553 | printf (" %s\n", "-l, --ssl"); |
| 554 | printf (" %s\n", _("Use ssl encryptation")); | 554 | printf (" %s\n", _("Use ssl encryption")); |
| 555 | printf (" %s\n", "-C, --ca-cert=STRING"); | 555 | printf (" %s\n", "-C, --ca-cert=STRING"); |
| 556 | printf (" %s\n", _("Path to CA signing the cert")); | 556 | printf (" %s\n", _("Path to CA signing the cert")); |
| 557 | printf (" %s\n", "-a, --cert=STRING"); | 557 | printf (" %s\n", "-a, --cert=STRING"); |
diff --git a/plugins/check_nt.c b/plugins/check_nt.c index 59c135db..d73d83ce 100644 --- a/plugins/check_nt.c +++ b/plugins/check_nt.c | |||
| @@ -341,7 +341,7 @@ int main(int argc, char **argv){ | |||
| 341 | 341 | ||
| 342 | 2) If the counter you're going to measure is percent-based, the code will detect | 342 | 2) If the counter you're going to measure is percent-based, the code will detect |
| 343 | the percent sign in its name and will attribute minimum (0%) and maximum (100%) | 343 | the percent sign in its name and will attribute minimum (0%) and maximum (100%) |
| 344 | values automagically, as well the ¨%" sign to graph units. | 344 | values automagically, as well the "%" sign to graph units. |
| 345 | 345 | ||
| 346 | 3) OTOH, if the counter is "absolute", you'll have to provide the following | 346 | 3) OTOH, if the counter is "absolute", you'll have to provide the following |
| 347 | the counter unit - that is, the dimensions of the counter you're getting. Examples: | 347 | the counter unit - that is, the dimensions of the counter you're getting. Examples: |
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c index 8b776ba1..36146505 100644 --- a/plugins/check_ntp.c +++ b/plugins/check_ntp.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | * | 10 | * |
| 11 | * This file contains the check_ntp plugin | 11 | * This file contains the check_ntp plugin |
| 12 | * | 12 | * |
| 13 | * This plugin to check ntp servers independant of any commandline | 13 | * This plugin to check ntp servers independent of any commandline |
| 14 | * programs or external libraries. | 14 | * programs or external libraries. |
| 15 | * | 15 | * |
| 16 | * | 16 | * |
| @@ -79,7 +79,7 @@ typedef struct { | |||
| 79 | /* this structure holds data about results from querying offset from a peer */ | 79 | /* this structure holds data about results from querying offset from a peer */ |
| 80 | typedef struct { | 80 | typedef struct { |
| 81 | time_t waiting; /* ts set when we started waiting for a response */ | 81 | time_t waiting; /* ts set when we started waiting for a response */ |
| 82 | int num_responses; /* number of successfully recieved responses */ | 82 | int num_responses; /* number of successfully received responses */ |
| 83 | uint8_t stratum; /* copied verbatim from the ntp_message */ | 83 | uint8_t stratum; /* copied verbatim from the ntp_message */ |
| 84 | double rtdelay; /* converted from the ntp_message */ | 84 | double rtdelay; /* converted from the ntp_message */ |
| 85 | double rtdisp; /* converted from the ntp_message */ | 85 | double rtdisp; /* converted from the ntp_message */ |
| @@ -100,7 +100,7 @@ typedef struct { | |||
| 100 | /* NB: not necessarily NULL terminated! */ | 100 | /* NB: not necessarily NULL terminated! */ |
| 101 | } ntp_control_message; | 101 | } ntp_control_message; |
| 102 | 102 | ||
| 103 | /* this is an association/status-word pair found in control packet reponses */ | 103 | /* this is an association/status-word pair found in control packet responses */ |
| 104 | typedef struct { | 104 | typedef struct { |
| 105 | uint16_t assoc; | 105 | uint16_t assoc; |
| 106 | uint16_t status; | 106 | uint16_t status; |
| @@ -575,7 +575,7 @@ double jitter_request(int *status){ | |||
| 575 | } | 575 | } |
| 576 | } | 576 | } |
| 577 | } | 577 | } |
| 578 | if(verbose) printf("%d candiate peers available\n", num_candidates); | 578 | if(verbose) printf("%d candidate peers available\n", num_candidates); |
| 579 | if(verbose && syncsource_found) printf("synchronization source found\n"); | 579 | if(verbose && syncsource_found) printf("synchronization source found\n"); |
| 580 | if(! syncsource_found){ | 580 | if(! syncsource_found){ |
| 581 | *status = STATE_UNKNOWN; | 581 | *status = STATE_UNKNOWN; |
| @@ -597,7 +597,7 @@ double jitter_request(int *status){ | |||
| 597 | /* By spec, putting the variable name "jitter" in the request | 597 | /* By spec, putting the variable name "jitter" in the request |
| 598 | * should cause the server to provide _only_ the jitter value. | 598 | * should cause the server to provide _only_ the jitter value. |
| 599 | * thus reducing net traffic, guaranteeing us only a single | 599 | * thus reducing net traffic, guaranteeing us only a single |
| 600 | * datagram in reply, and making intepretation much simpler | 600 | * datagram in reply, and making interpretation much simpler |
| 601 | */ | 601 | */ |
| 602 | /* Older servers doesn't know what jitter is, so if we get an | 602 | /* Older servers doesn't know what jitter is, so if we get an |
| 603 | * error on the first pass we redo it with "dispersion" */ | 603 | * error on the first pass we redo it with "dispersion" */ |
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c index 6842842f..eafafdc0 100644 --- a/plugins/check_ntp_peer.c +++ b/plugins/check_ntp_peer.c | |||
| @@ -86,7 +86,7 @@ typedef struct { | |||
| 86 | /* NB: not necessarily NULL terminated! */ | 86 | /* NB: not necessarily NULL terminated! */ |
| 87 | } ntp_control_message; | 87 | } ntp_control_message; |
| 88 | 88 | ||
| 89 | /* this is an association/status-word pair found in control packet reponses */ | 89 | /* this is an association/status-word pair found in control packet responses */ |
| 90 | typedef struct { | 90 | typedef struct { |
| 91 | uint16_t assoc; | 91 | uint16_t assoc; |
| 92 | uint16_t status; | 92 | uint16_t status; |
| @@ -189,7 +189,7 @@ setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){ | |||
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | /* This function does all the actual work; roughly here's what it does | 191 | /* This function does all the actual work; roughly here's what it does |
| 192 | * beside setting the offest, jitter and stratum passed as argument: | 192 | * beside setting the offset, jitter and stratum passed as argument: |
| 193 | * - offset can be negative, so if it cannot get the offset, offset_result | 193 | * - offset can be negative, so if it cannot get the offset, offset_result |
| 194 | * is set to UNKNOWN, otherwise OK. | 194 | * is set to UNKNOWN, otherwise OK. |
| 195 | * - jitter and stratum are set to -1 if they cannot be retrieved so any | 195 | * - jitter and stratum are set to -1 if they cannot be retrieved so any |
| @@ -306,7 +306,7 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji | |||
| 306 | /* Putting the wanted variable names in the request | 306 | /* Putting the wanted variable names in the request |
| 307 | * cause the server to provide _only_ the requested values. | 307 | * cause the server to provide _only_ the requested values. |
| 308 | * thus reducing net traffic, guaranteeing us only a single | 308 | * thus reducing net traffic, guaranteeing us only a single |
| 309 | * datagram in reply, and making intepretation much simpler | 309 | * datagram in reply, and making interpretation much simpler |
| 310 | */ | 310 | */ |
| 311 | /* Older servers doesn't know what jitter is, so if we get an | 311 | /* Older servers doesn't know what jitter is, so if we get an |
| 312 | * error on the first pass we redo it with "dispersion" */ | 312 | * error on the first pass we redo it with "dispersion" */ |
| @@ -585,7 +585,7 @@ int main(int argc, char *argv[]){ | |||
| 585 | /* set socket timeout */ | 585 | /* set socket timeout */ |
| 586 | alarm (socket_timeout); | 586 | alarm (socket_timeout); |
| 587 | 587 | ||
| 588 | /* This returns either OK or WARNING (See comment preceeding ntp_request) */ | 588 | /* This returns either OK or WARNING (See comment proceeding ntp_request) */ |
| 589 | result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum, &num_truechimers); | 589 | result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum, &num_truechimers); |
| 590 | 590 | ||
| 591 | if(offset_result == STATE_UNKNOWN) { | 591 | if(offset_result == STATE_UNKNOWN) { |
diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c index 391b2df2..46cc604f 100644 --- a/plugins/check_ntp_time.c +++ b/plugins/check_ntp_time.c | |||
| @@ -81,7 +81,7 @@ typedef struct { | |||
| 81 | /* this structure holds data about results from querying offset from a peer */ | 81 | /* this structure holds data about results from querying offset from a peer */ |
| 82 | typedef struct { | 82 | typedef struct { |
| 83 | time_t waiting; /* ts set when we started waiting for a response */ | 83 | time_t waiting; /* ts set when we started waiting for a response */ |
| 84 | int num_responses; /* number of successfully recieved responses */ | 84 | int num_responses; /* number of successfully received responses */ |
| 85 | uint8_t stratum; /* copied verbatim from the ntp_message */ | 85 | uint8_t stratum; /* copied verbatim from the ntp_message */ |
| 86 | double rtdelay; /* converted from the ntp_message */ | 86 | double rtdelay; /* converted from the ntp_message */ |
| 87 | double rtdisp; /* converted from the ntp_message */ | 87 | double rtdisp; /* converted from the ntp_message */ |
diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c index e7e8de05..3c9d23e2 100644 --- a/plugins/check_nwstat.c +++ b/plugins/check_nwstat.c | |||
| @@ -1668,7 +1668,7 @@ void print_help(void) | |||
| 1668 | 1668 | ||
| 1669 | printf ("\n"); | 1669 | printf ("\n"); |
| 1670 | printf ("%s\n", _("Notes:")); | 1670 | printf ("%s\n", _("Notes:")); |
| 1671 | printf (" %s\n", _("- This plugin requres that the MRTGEXT.NLM file from James Drews' MRTG")); | 1671 | printf (" %s\n", _("- This plugin requires that the MRTGEXT.NLM file from James Drews' MRTG")); |
| 1672 | printf (" %s\n", _(" extension for NetWare be loaded on the Novell servers you wish to check.")); | 1672 | printf (" %s\n", _(" extension for NetWare be loaded on the Novell servers you wish to check.")); |
| 1673 | printf (" %s\n", _(" (available from http://www.engr.wisc.edu/~drews/mrtg/)")); | 1673 | printf (" %s\n", _(" (available from http://www.engr.wisc.edu/~drews/mrtg/)")); |
| 1674 | printf (" %s\n", _("- Values for critical thresholds should be lower than warning thresholds")); | 1674 | printf (" %s\n", _("- Values for critical thresholds should be lower than warning thresholds")); |
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index 05fdc156..61990335 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c | |||
| @@ -93,7 +93,7 @@ int verbose = 0; | |||
| 93 | 93 | ||
| 94 | /****************************************************************************** | 94 | /****************************************************************************** |
| 95 | 95 | ||
| 96 | The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@ | 96 | The (pseudo?)literate programming XML is contained within \@\@\- <XML> \-\@\@ |
| 97 | tags in the comments. With in the tags, the XML is assembled sequentially. | 97 | tags in the comments. With in the tags, the XML is assembled sequentially. |
| 98 | You can define entities in tags. You also have all the #defines available as | 98 | You can define entities in tags. You also have all the #defines available as |
| 99 | entities. | 99 | entities. |
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index a025ee89..c17c6996 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
| @@ -70,6 +70,7 @@ int options = 0; /* bitmask of filter criteria to test against */ | |||
| 70 | #define PCPU 256 | 70 | #define PCPU 256 |
| 71 | #define ELAPSED 512 | 71 | #define ELAPSED 512 |
| 72 | #define EREG_ARGS 1024 | 72 | #define EREG_ARGS 1024 |
| 73 | #define EXCLUDE_PROGS 2048 | ||
| 73 | 74 | ||
| 74 | #define KTHREAD_PARENT "kthreadd" /* the parent process of kernel threads: | 75 | #define KTHREAD_PARENT "kthreadd" /* the parent process of kernel threads: |
| 75 | ppid of procs are compared to pid of this proc*/ | 76 | ppid of procs are compared to pid of this proc*/ |
| @@ -93,6 +94,9 @@ int rss; | |||
| 93 | float pcpu; | 94 | float pcpu; |
| 94 | char *statopts; | 95 | char *statopts; |
| 95 | char *prog; | 96 | char *prog; |
| 97 | char *exclude_progs; | ||
| 98 | char **exclude_progs_arr = NULL; | ||
| 99 | char exclude_progs_counter = 0; | ||
| 96 | char *args; | 100 | char *args; |
| 97 | char *input_filename = NULL; | 101 | char *input_filename = NULL; |
| 98 | regex_t re_args; | 102 | regex_t re_args; |
| @@ -250,7 +254,26 @@ main (int argc, char **argv) | |||
| 250 | continue; | 254 | continue; |
| 251 | } | 255 | } |
| 252 | 256 | ||
| 253 | /* filter kernel threads (childs of KTHREAD_PARENT)*/ | 257 | /* Ignore excluded processes by name */ |
| 258 | if(options & EXCLUDE_PROGS) { | ||
| 259 | int found = 0; | ||
| 260 | int i = 0; | ||
| 261 | |||
| 262 | for(i=0; i < (exclude_progs_counter); i++) { | ||
| 263 | if(!strcmp(procprog, exclude_progs_arr[i])) { | ||
| 264 | found = 1; | ||
| 265 | } | ||
| 266 | } | ||
| 267 | if(found == 0) { | ||
| 268 | resultsum |= EXCLUDE_PROGS; | ||
| 269 | } else | ||
| 270 | { | ||
| 271 | if(verbose >= 3) | ||
| 272 | printf("excluding - by ignorelist\n"); | ||
| 273 | } | ||
| 274 | } | ||
| 275 | |||
| 276 | /* filter kernel threads (children of KTHREAD_PARENT)*/ | ||
| 254 | /* TODO adapt for other OSes than GNU/Linux | 277 | /* TODO adapt for other OSes than GNU/Linux |
| 255 | sorry for not doing that, but I've no other OSes to test :-( */ | 278 | sorry for not doing that, but I've no other OSes to test :-( */ |
| 256 | if (kthread_filter == 1) { | 279 | if (kthread_filter == 1) { |
| @@ -409,6 +432,7 @@ process_arguments (int argc, char **argv) | |||
| 409 | {"input-file", required_argument, 0, CHAR_MAX+2}, | 432 | {"input-file", required_argument, 0, CHAR_MAX+2}, |
| 410 | {"no-kthreads", required_argument, 0, 'k'}, | 433 | {"no-kthreads", required_argument, 0, 'k'}, |
| 411 | {"traditional-filter", no_argument, 0, 'T'}, | 434 | {"traditional-filter", no_argument, 0, 'T'}, |
| 435 | {"exclude-process", required_argument, 0, 'X'}, | ||
| 412 | {0, 0, 0, 0} | 436 | {0, 0, 0, 0} |
| 413 | }; | 437 | }; |
| 414 | 438 | ||
| @@ -417,7 +441,7 @@ process_arguments (int argc, char **argv) | |||
| 417 | strcpy (argv[c], "-t"); | 441 | strcpy (argv[c], "-t"); |
| 418 | 442 | ||
| 419 | while (1) { | 443 | while (1) { |
| 420 | c = getopt_long (argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:T", | 444 | c = getopt_long (argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:T:X:", |
| 421 | longopts, &option); | 445 | longopts, &option); |
| 422 | 446 | ||
| 423 | if (c == -1 || c == EOF) | 447 | if (c == -1 || c == EOF) |
| @@ -490,6 +514,23 @@ process_arguments (int argc, char **argv) | |||
| 490 | prog); | 514 | prog); |
| 491 | options |= PROG; | 515 | options |= PROG; |
| 492 | break; | 516 | break; |
| 517 | case 'X': | ||
| 518 | if(exclude_progs) | ||
| 519 | break; | ||
| 520 | else | ||
| 521 | exclude_progs = optarg; | ||
| 522 | xasprintf (&fmt, _("%s%sexclude progs '%s'"), (fmt ? fmt : ""), (options ? ", " : ""), | ||
| 523 | exclude_progs); | ||
| 524 | char *p = strtok(exclude_progs, ","); | ||
| 525 | |||
| 526 | while(p){ | ||
| 527 | exclude_progs_arr = realloc(exclude_progs_arr, sizeof(char*) * ++exclude_progs_counter); | ||
| 528 | exclude_progs_arr[exclude_progs_counter-1] = p; | ||
| 529 | p = strtok(NULL, ","); | ||
| 530 | } | ||
| 531 | |||
| 532 | options |= EXCLUDE_PROGS; | ||
| 533 | break; | ||
| 493 | case 'a': /* args (full path name with args) */ | 534 | case 'a': /* args (full path name with args) */ |
| 494 | /* TODO: allow this to be passed in with --metric */ | 535 | /* TODO: allow this to be passed in with --metric */ |
| 495 | if (args) | 536 | if (args) |
| @@ -745,6 +786,8 @@ print_help (void) | |||
| 745 | printf (" %s\n", _("Only scan for processes with args that contain the regex STRING.")); | 786 | printf (" %s\n", _("Only scan for processes with args that contain the regex STRING.")); |
| 746 | printf (" %s\n", "-C, --command=COMMAND"); | 787 | printf (" %s\n", "-C, --command=COMMAND"); |
| 747 | printf (" %s\n", _("Only scan for exact matches of COMMAND (without path).")); | 788 | printf (" %s\n", _("Only scan for exact matches of COMMAND (without path).")); |
| 789 | printf (" %s\n", "-X, --exclude-process"); | ||
| 790 | printf (" %s\n", _("Exclude processes which match this comma separated list")); | ||
| 748 | printf (" %s\n", "-k, --no-kthreads"); | 791 | printf (" %s\n", "-k, --no-kthreads"); |
| 749 | printf (" %s\n", _("Only scan for non kernel threads (works on Linux only).")); | 792 | printf (" %s\n", _("Only scan for non kernel threads (works on Linux only).")); |
| 750 | 793 | ||
| @@ -786,5 +829,5 @@ print_usage (void) | |||
| 786 | printf ("%s\n", _("Usage:")); | 829 | printf ("%s\n", _("Usage:")); |
| 787 | printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n", progname); | 830 | printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n", progname); |
| 788 | printf (" [-u user] [-r rss] [-z vsz] [-P %%cpu] [-a argument-array]\n"); | 831 | printf (" [-u user] [-r rss] [-z vsz] [-P %%cpu] [-a argument-array]\n"); |
| 789 | printf (" [-C command] [-k] [-t timeout] [-v]\n"); | 832 | printf (" [-C command] [-X process_to_exclude] [-k] [-t timeout] [-v]\n"); |
| 790 | } | 833 | } |
diff --git a/plugins/check_radius.c b/plugins/check_radius.c index be1001b4..984aa37e 100644 --- a/plugins/check_radius.c +++ b/plugins/check_radius.c | |||
| @@ -97,7 +97,7 @@ int verbose = FALSE; | |||
| 97 | 97 | ||
| 98 | /****************************************************************************** | 98 | /****************************************************************************** |
| 99 | 99 | ||
| 100 | The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@ | 100 | The (pseudo?)literate programming XML is contained within \@\@\- <XML> \-\@\@ |
| 101 | tags in the comments. With in the tags, the XML is assembled sequentially. | 101 | tags in the comments. With in the tags, the XML is assembled sequentially. |
| 102 | You can define entities in tags. You also have all the #defines available as | 102 | You can define entities in tags. You also have all the #defines available as |
| 103 | entities. | 103 | entities. |
| @@ -155,7 +155,11 @@ main (int argc, char **argv) | |||
| 155 | { | 155 | { |
| 156 | struct sockaddr_storage ss; | 156 | struct sockaddr_storage ss; |
| 157 | char name[HOST_NAME_MAX]; | 157 | char name[HOST_NAME_MAX]; |
| 158 | #ifdef RC_BUFFER_LEN | ||
| 159 | char msg[RC_BUFFER_LEN]; | ||
| 160 | #else | ||
| 158 | char msg[BUFFER_LEN]; | 161 | char msg[BUFFER_LEN]; |
| 162 | #endif | ||
| 159 | SEND_DATA data; | 163 | SEND_DATA data; |
| 160 | int result = STATE_UNKNOWN; | 164 | int result = STATE_UNKNOWN; |
| 161 | uint32_t client_id, service; | 165 | uint32_t client_id, service; |
diff --git a/plugins/check_real.c b/plugins/check_real.c index 0f1a1ba7..fbdb70f3 100644 --- a/plugins/check_real.c +++ b/plugins/check_real.c | |||
| @@ -178,7 +178,7 @@ main (int argc, char **argv) | |||
| 178 | 178 | ||
| 179 | /* watch for the REAL connection string */ | 179 | /* watch for the REAL connection string */ |
| 180 | result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); | 180 | result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); |
| 181 | buffer[result] = '\0'; /* null terminate recieved buffer */ | 181 | buffer[result] = '\0'; /* null terminate received buffer */ |
| 182 | 182 | ||
| 183 | /* return a CRITICAL status if we couldn't read any data */ | 183 | /* return a CRITICAL status if we couldn't read any data */ |
| 184 | if (result == -1) { | 184 | if (result == -1) { |
| @@ -436,7 +436,7 @@ print_help (void) | |||
| 436 | 436 | ||
| 437 | printf ("\n"); | 437 | printf ("\n"); |
| 438 | printf ("%s\n", _("This plugin will attempt to open an RTSP connection with the host.")); | 438 | printf ("%s\n", _("This plugin will attempt to open an RTSP connection with the host.")); |
| 439 | printf ("%s\n", _("Successul connects return STATE_OK, refusals and timeouts return")); | 439 | printf ("%s\n", _("Successful connects return STATE_OK, refusals and timeouts return")); |
| 440 | printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful connects,")); | 440 | printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful connects,")); |
| 441 | printf ("%s\n", _("but incorrect response messages from the host result in STATE_WARNING return")); | 441 | printf ("%s\n", _("but incorrect response messages from the host result in STATE_WARNING return")); |
| 442 | printf ("%s\n", _("values.")); | 442 | printf ("%s\n", _("values.")); |
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index c1e92dff..eaa7eeba 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c | |||
| @@ -844,7 +844,7 @@ print_help (void) | |||
| 844 | printf (UT_VERBOSE); | 844 | printf (UT_VERBOSE); |
| 845 | 845 | ||
| 846 | printf("\n"); | 846 | printf("\n"); |
| 847 | printf ("%s\n", _("Successul connects return STATE_OK, refusals and timeouts return")); | 847 | printf ("%s\n", _("Successful connects return STATE_OK, refusals and timeouts return")); |
| 848 | printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful")); | 848 | printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful")); |
| 849 | printf ("%s\n", _("connects, but incorrect response messages from the host result in")); | 849 | printf ("%s\n", _("connects, but incorrect response messages from the host result in")); |
| 850 | printf ("%s\n", _("STATE_WARNING return values.")); | 850 | printf ("%s\n", _("STATE_WARNING return values.")); |
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index d3968a27..c425df3c 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
| @@ -46,6 +46,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
| 46 | #define DEFAULT_PRIV_PROTOCOL "DES" | 46 | #define DEFAULT_PRIV_PROTOCOL "DES" |
| 47 | #define DEFAULT_DELIMITER "=" | 47 | #define DEFAULT_DELIMITER "=" |
| 48 | #define DEFAULT_OUTPUT_DELIMITER " " | 48 | #define DEFAULT_OUTPUT_DELIMITER " " |
| 49 | #define DEFAULT_BUFFER_SIZE 100 | ||
| 49 | 50 | ||
| 50 | #define mark(a) ((a)!=0?"*":"") | 51 | #define mark(a) ((a)!=0?"*":"") |
| 51 | 52 | ||
| @@ -157,6 +158,7 @@ int perf_labels = 1; | |||
| 157 | char* ip_version = ""; | 158 | char* ip_version = ""; |
| 158 | double multiplier = 1.0; | 159 | double multiplier = 1.0; |
| 159 | char *fmtstr = ""; | 160 | char *fmtstr = ""; |
| 161 | char buffer[DEFAULT_BUFFER_SIZE]; | ||
| 160 | 162 | ||
| 161 | static char *fix_snmp_range(char *th) | 163 | static char *fix_snmp_range(char *th) |
| 162 | { | 164 | { |
| @@ -1169,15 +1171,15 @@ multiply (char *str) | |||
| 1169 | double val; | 1171 | double val; |
| 1170 | char *conv = "%f"; | 1172 | char *conv = "%f"; |
| 1171 | 1173 | ||
| 1174 | if(multiplier == 1) | ||
| 1175 | return(str); | ||
| 1176 | |||
| 1172 | if(verbose>2) | 1177 | if(verbose>2) |
| 1173 | printf(" multiply input: %s\n", str); | 1178 | printf(" multiply input: %s\n", str); |
| 1174 | 1179 | ||
| 1175 | val = strtod (str, &endptr); | 1180 | val = strtod (str, &endptr); |
| 1176 | if ((val == 0.0) && (endptr == str)) { | 1181 | if ((val == 0.0) && (endptr == str)) { |
| 1177 | if(multiplier != 1) { | 1182 | die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str); |
| 1178 | die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str); | ||
| 1179 | } | ||
| 1180 | return str; | ||
| 1181 | } | 1183 | } |
| 1182 | 1184 | ||
| 1183 | if(verbose>2) | 1185 | if(verbose>2) |
| @@ -1187,15 +1189,15 @@ multiply (char *str) | |||
| 1187 | conv = fmtstr; | 1189 | conv = fmtstr; |
| 1188 | } | 1190 | } |
| 1189 | if (val == (int)val) { | 1191 | if (val == (int)val) { |
| 1190 | sprintf(str, "%.0f", val); | 1192 | snprintf(buffer, DEFAULT_BUFFER_SIZE, "%.0f", val); |
| 1191 | } else { | 1193 | } else { |
| 1192 | if(verbose>2) | 1194 | if(verbose>2) |
| 1193 | printf(" multiply using format: %s\n", conv); | 1195 | printf(" multiply using format: %s\n", conv); |
| 1194 | sprintf(str, conv, val); | 1196 | snprintf(buffer, DEFAULT_BUFFER_SIZE, conv, val); |
| 1195 | } | 1197 | } |
| 1196 | if(verbose>2) | 1198 | if(verbose>2) |
| 1197 | printf(" multiply result: %s\n", str); | 1199 | printf(" multiply result: %s\n", buffer); |
| 1198 | return str; | 1200 | return buffer; |
| 1199 | } | 1201 | } |
| 1200 | 1202 | ||
| 1201 | 1203 | ||
| @@ -1272,7 +1274,7 @@ print_help (void) | |||
| 1272 | printf (" %s\n", "--rate-multiplier"); | 1274 | printf (" %s\n", "--rate-multiplier"); |
| 1273 | printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute")); | 1275 | printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute")); |
| 1274 | printf (" %s\n", "--offset=OFFSET"); | 1276 | printf (" %s\n", "--offset=OFFSET"); |
| 1275 | printf (" %s\n", _("Add/substract the specified OFFSET to numeric sensor data")); | 1277 | printf (" %s\n", _("Add/subtract the specified OFFSET to numeric sensor data")); |
| 1276 | 1278 | ||
| 1277 | /* Tests Against Strings */ | 1279 | /* Tests Against Strings */ |
| 1278 | printf (" %s\n", "-s, --string=STRING"); | 1280 | printf (" %s\n", "-s, --string=STRING"); |
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index a607da1e..05f19ad4 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c | |||
| @@ -34,9 +34,6 @@ const char *email = "devel@monitoring-plugins.org"; | |||
| 34 | #include "common.h" | 34 | #include "common.h" |
| 35 | #include "popen.h" | 35 | #include "popen.h" |
| 36 | #include "utils.h" | 36 | #include "utils.h" |
| 37 | #include <string.h> | ||
| 38 | #include <math.h> | ||
| 39 | #include <libintl.h> | ||
| 40 | 37 | ||
| 41 | #ifdef HAVE_DECL_SWAPCTL | 38 | #ifdef HAVE_DECL_SWAPCTL |
| 42 | # ifdef HAVE_SYS_PARAM_H | 39 | # ifdef HAVE_SYS_PARAM_H |
| @@ -555,7 +552,7 @@ validate_arguments (void) | |||
| 555 | } | 552 | } |
| 556 | else if ((warn.is_percentage == crit.is_percentage) && (warn.value < crit.value)) { | 553 | else if ((warn.is_percentage == crit.is_percentage) && (warn.value < crit.value)) { |
| 557 | /* This is NOT triggered if warn and crit are different units, e.g warn is percentage | 554 | /* This is NOT triggered if warn and crit are different units, e.g warn is percentage |
| 558 | * and crit is absolut. We cannot determine the condition at this point since we | 555 | * and crit is absolute. We cannot determine the condition at this point since we |
| 559 | * dont know the value of total swap yet | 556 | * dont know the value of total swap yet |
| 560 | */ | 557 | */ |
| 561 | usage4(_("Warning should be more than critical")); | 558 | usage4(_("Warning should be more than critical")); |
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index 1365b9cb..1d307cf3 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c | |||
| @@ -128,7 +128,7 @@ main (int argc, char **argv) | |||
| 128 | SERVICE[i] = toupper(SERVICE[i]); | 128 | SERVICE[i] = toupper(SERVICE[i]); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | /* set up a resonable buffer at first (will be realloc()'ed if | 131 | /* set up a reasonable buffer at first (will be realloc()'ed if |
| 132 | * user specifies other options) */ | 132 | * user specifies other options) */ |
| 133 | server_expect = calloc(sizeof(char *), 2); | 133 | server_expect = calloc(sizeof(char *), 2); |
| 134 | 134 | ||
diff --git a/plugins/check_ups.c b/plugins/check_ups.c index 0de37a20..12bce217 100644 --- a/plugins/check_ups.c +++ b/plugins/check_ups.c | |||
| @@ -507,7 +507,7 @@ process_arguments (int argc, char **argv) | |||
| 507 | usage2 (_("Invalid hostname/address"), optarg); | 507 | usage2 (_("Invalid hostname/address"), optarg); |
| 508 | } | 508 | } |
| 509 | break; | 509 | break; |
| 510 | case 'T': /* FIXME: to be improved (ie "-T C" for Celsius or "-T F" for Farenheit) */ | 510 | case 'T': /* FIXME: to be improved (ie "-T C" for Celsius or "-T F" for Fahrenheit) */ |
| 511 | temp_output_c = 1; | 511 | temp_output_c = 1; |
| 512 | break; | 512 | break; |
| 513 | case 'u': /* ups name */ | 513 | case 'u': /* ups name */ |
diff --git a/plugins/picohttpparser/picohttpparser.c b/plugins/picohttpparser/picohttpparser.c index d9680b79..d0bfac62 100644 --- a/plugins/picohttpparser/picohttpparser.c +++ b/plugins/picohttpparser/picohttpparser.c | |||
| @@ -400,7 +400,7 @@ int phr_parse_request(const char *buf_start, size_t len, const char **method, si | |||
| 400 | *num_headers = 0; | 400 | *num_headers = 0; |
| 401 | 401 | ||
| 402 | /* if last_len != 0, check if the request is complete (a fast countermeasure | 402 | /* if last_len != 0, check if the request is complete (a fast countermeasure |
| 403 | againt slowloris */ | 403 | against slowloris */ |
| 404 | if (last_len != 0 && is_complete(buf, buf_end, last_len, &r) == NULL) { | 404 | if (last_len != 0 && is_complete(buf, buf_end, last_len, &r) == NULL) { |
| 405 | return r; | 405 | return r; |
| 406 | } | 406 | } |
| @@ -435,7 +435,7 @@ static const char *parse_response(const char *buf, const char *buf_end, int *maj | |||
| 435 | } | 435 | } |
| 436 | PARSE_INT_3(status); | 436 | PARSE_INT_3(status); |
| 437 | 437 | ||
| 438 | /* get message includig preceding space */ | 438 | /* get message including preceding space */ |
| 439 | if ((buf = get_token_to_eol(buf, buf_end, msg, msg_len, ret)) == NULL) { | 439 | if ((buf = get_token_to_eol(buf, buf_end, msg, msg_len, ret)) == NULL) { |
| 440 | return NULL; | 440 | return NULL; |
| 441 | } | 441 | } |
diff --git a/plugins/popen.c b/plugins/popen.c index 9eb49b62..723817d5 100644 --- a/plugins/popen.c +++ b/plugins/popen.c | |||
| @@ -14,7 +14,7 @@ | |||
| 14 | * FILE * spopen(const char *); | 14 | * FILE * spopen(const char *); |
| 15 | * int spclose(FILE *); | 15 | * int spclose(FILE *); |
| 16 | * | 16 | * |
| 17 | * Code taken with liitle modification from "Advanced Programming for the Unix | 17 | * Code taken with little modification from "Advanced Programming for the Unix |
| 18 | * Environment" by W. Richard Stevens | 18 | * Environment" by W. Richard Stevens |
| 19 | * | 19 | * |
| 20 | * This is considered safe in that no shell is spawned, and the environment | 20 | * This is considered safe in that no shell is spawned, and the environment |
diff --git a/plugins/runcmd.c b/plugins/runcmd.c index a7155d27..c1d675d0 100644 --- a/plugins/runcmd.c +++ b/plugins/runcmd.c | |||
| @@ -44,6 +44,8 @@ | |||
| 44 | # include <sys/wait.h> | 44 | # include <sys/wait.h> |
| 45 | #endif | 45 | #endif |
| 46 | 46 | ||
| 47 | #include "./utils.h" | ||
| 48 | |||
| 47 | /** macros **/ | 49 | /** macros **/ |
| 48 | #ifndef WEXITSTATUS | 50 | #ifndef WEXITSTATUS |
| 49 | # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) | 51 | # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) |
| @@ -203,7 +205,7 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) | |||
| 203 | } | 205 | } |
| 204 | 206 | ||
| 205 | /* parent picks up execution here */ | 207 | /* parent picks up execution here */ |
| 206 | /* close childs descriptors in our address space */ | 208 | /* close children descriptors in our address space */ |
| 207 | close(pfd[1]); | 209 | close(pfd[1]); |
| 208 | close(pfderr[1]); | 210 | close(pfderr[1]); |
| 209 | 211 | ||
diff --git a/plugins/sslutils.c b/plugins/sslutils.c index 286273f6..666a0120 100644 --- a/plugins/sslutils.c +++ b/plugins/sslutils.c | |||
| @@ -134,7 +134,16 @@ int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int | |||
| 134 | return STATE_CRITICAL; | 134 | return STATE_CRITICAL; |
| 135 | } | 135 | } |
| 136 | if (cert && privkey) { | 136 | if (cert && privkey) { |
| 137 | SSL_CTX_use_certificate_chain_file(c, cert); | 137 | #ifdef USE_OPENSSL |
| 138 | if (!SSL_CTX_use_certificate_chain_file(c, cert)) { | ||
| 139 | #elif USE_GNUTLS | ||
| 140 | if (!SSL_CTX_use_certificate_file(c, cert, SSL_FILETYPE_PEM)) { | ||
| 141 | #else | ||
| 142 | #error Unported for unknown SSL library | ||
| 143 | #endif | ||
| 144 | printf ("%s\n", _("CRITICAL - Unable to open certificate chain file!\n")); | ||
| 145 | return STATE_CRITICAL; | ||
| 146 | } | ||
| 138 | SSL_CTX_use_PrivateKey_file(c, privkey, SSL_FILETYPE_PEM); | 147 | SSL_CTX_use_PrivateKey_file(c, privkey, SSL_FILETYPE_PEM); |
| 139 | #ifdef USE_OPENSSL | 148 | #ifdef USE_OPENSSL |
| 140 | if (!SSL_CTX_check_private_key(c)) { | 149 | if (!SSL_CTX_check_private_key(c)) { |
| @@ -191,17 +200,6 @@ int np_net_ssl_read(void *buf, int num) { | |||
| 191 | return SSL_read(s, buf, num); | 200 | return SSL_read(s, buf, num); |
| 192 | } | 201 | } |
| 193 | 202 | ||
| 194 | int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){ | ||
| 195 | # ifdef USE_OPENSSL | ||
| 196 | X509 *certificate = NULL; | ||
| 197 | certificate=SSL_get_peer_certificate(s); | ||
| 198 | return(np_net_ssl_check_certificate(certificate, days_till_exp_warn, days_till_exp_crit)); | ||
| 199 | # else /* ifndef USE_OPENSSL */ | ||
| 200 | printf("%s\n", _("WARNING - Plugin does not support checking certificates.")); | ||
| 201 | return STATE_WARNING; | ||
| 202 | # endif /* USE_OPENSSL */ | ||
| 203 | } | ||
| 204 | |||
| 205 | int np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_warn, int days_till_exp_crit){ | 203 | int np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_warn, int days_till_exp_crit){ |
| 206 | # ifdef USE_OPENSSL | 204 | # ifdef USE_OPENSSL |
| 207 | X509_NAME *subj=NULL; | 205 | X509_NAME *subj=NULL; |
| @@ -328,4 +326,16 @@ int np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_warn, int | |||
| 328 | # endif /* USE_OPENSSL */ | 326 | # endif /* USE_OPENSSL */ |
| 329 | } | 327 | } |
| 330 | 328 | ||
| 329 | int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){ | ||
| 330 | # ifdef USE_OPENSSL | ||
| 331 | X509 *certificate = NULL; | ||
| 332 | certificate=SSL_get_peer_certificate(s); | ||
| 333 | return(np_net_ssl_check_certificate(certificate, days_till_exp_warn, days_till_exp_crit)); | ||
| 334 | # else /* ifndef USE_OPENSSL */ | ||
| 335 | printf("%s\n", _("WARNING - Plugin does not support checking certificates.")); | ||
| 336 | return STATE_WARNING; | ||
| 337 | # endif /* USE_OPENSSL */ | ||
| 338 | } | ||
| 339 | |||
| 340 | |||
| 331 | #endif /* HAVE_SSL */ | 341 | #endif /* HAVE_SSL */ |
diff --git a/plugins/t/check_by_ssh.t b/plugins/t/check_by_ssh.t index 1d2939e9..b6479f1f 100644 --- a/plugins/t/check_by_ssh.t +++ b/plugins/t/check_by_ssh.t | |||
| @@ -19,19 +19,19 @@ plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_servic | |||
| 19 | plan tests => 42; | 19 | plan tests => 42; |
| 20 | 20 | ||
| 21 | # Some random check strings/response | 21 | # Some random check strings/response |
| 22 | my @responce = ('OK: Everything is fine', | 22 | my @response = ('OK: Everything is fine', |
| 23 | 'WARNING: Hey, pick me, pick me', | 23 | 'WARNING: Hey, pick me, pick me', |
| 24 | 'CRITICAL: Shit happens', | 24 | 'CRITICAL: Shit happens', |
| 25 | 'UNKNOWN: What can I do for ya', | 25 | 'UNKNOWN: What can I do for ya', |
| 26 | 'WOOPS: What did I smoke', | 26 | 'WOOPS: What did I smoke', |
| 27 | ); | 27 | ); |
| 28 | my @responce_re; | 28 | my @response_re; |
| 29 | my @check; | 29 | my @check; |
| 30 | for (@responce) { | 30 | for (@response) { |
| 31 | push(@check, "echo $_"); | 31 | push(@check, "echo $_"); |
| 32 | my $re_str = $_; | 32 | my $re_str = $_; |
| 33 | $re_str =~ s{(.)} { "\Q$1" }ge; | 33 | $re_str =~ s{(.)} { "\Q$1" }ge; |
| 34 | push(@responce_re, $re_str); | 34 | push(@response_re, $re_str); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | my $result; | 37 | my $result; |
| @@ -47,7 +47,7 @@ for (my $i=0; $i<4; $i++) { | |||
| 47 | "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[$i]; exit $i'" | 47 | "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[$i]; exit $i'" |
| 48 | ); | 48 | ); |
| 49 | cmp_ok($result->return_code, '==', $i, "Exit with return code $i"); | 49 | cmp_ok($result->return_code, '==', $i, "Exit with return code $i"); |
| 50 | is($result->output, $responce[$i], "Status text is correct for check $i"); | 50 | is($result->output, $response[$i], "Status text is correct for check $i"); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | $result = NPTest->testCmd( | 53 | $result = NPTest->testCmd( |
| @@ -84,7 +84,7 @@ $result = NPTest->testCmd( | |||
| 84 | "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[4]; exit 8'" | 84 | "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[4]; exit 8'" |
| 85 | ); | 85 | ); |
| 86 | cmp_ok($result->return_code, '==', 8, "Exit with return code 8 (out of bounds)"); | 86 | cmp_ok($result->return_code, '==', 8, "Exit with return code 8 (out of bounds)"); |
| 87 | is($result->output, $responce[4], "Return proper status text even with unknown status codes"); | 87 | is($result->output, $response[4], "Return proper status text even with unknown status codes"); |
| 88 | 88 | ||
| 89 | $result = NPTest->testCmd( | 89 | $result = NPTest->testCmd( |
| 90 | "./check_by_ssh -i $ssh_key -H $ssh_service -F $ssh_conf -C 'exit 0'" | 90 | "./check_by_ssh -i $ssh_key -H $ssh_service -F $ssh_conf -C 'exit 0'" |
| @@ -108,7 +108,7 @@ my %linemap = ( | |||
| 108 | foreach my $line (0, 2, 4, 6) { | 108 | foreach my $line (0, 2, 4, 6) { |
| 109 | my $code = $linemap{$line}; | 109 | my $code = $linemap{$line}; |
| 110 | my $statline = $line+1; | 110 | my $statline = $line+1; |
| 111 | is($lines[$line], "$responce[$code]", "multiple checks status text is correct for line $line"); | 111 | is($lines[$line], "$response[$code]", "multiple checks status text is correct for line $line"); |
| 112 | is($lines[$statline], "STATUS CODE: $code", "multiple check status code is correct for line $line"); | 112 | is($lines[$statline], "STATUS CODE: $code", "multiple check status code is correct for line $line"); |
| 113 | } | 113 | } |
| 114 | 114 | ||
| @@ -124,7 +124,7 @@ close(PASV) or die("Unable to close '/tmp/check_by_ssh.$$': $!"); | |||
| 124 | cmp_ok(scalar(@pasv), '==', 1, 'One passive result for one check performed'); | 124 | cmp_ok(scalar(@pasv), '==', 1, 'One passive result for one check performed'); |
| 125 | for (0) { | 125 | for (0) { |
| 126 | if ($pasv[$_]) { | 126 | if ($pasv[$_]) { |
| 127 | like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;serv;2;' . $responce_re[2] . '$/', 'proper result for passive check'); | 127 | like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;serv;2;' . $response_re[2] . '$/', 'proper result for passive check'); |
| 128 | } else { | 128 | } else { |
| 129 | fail('proper result for passive check'); | 129 | fail('proper result for passive check'); |
| 130 | } | 130 | } |
| @@ -144,7 +144,7 @@ for (0, 1, 2, 3, 4) { | |||
| 144 | if ($pasv[$_]) { | 144 | if ($pasv[$_]) { |
| 145 | my $ret = $_; | 145 | my $ret = $_; |
| 146 | $ret = 9 if ($_ == 4); | 146 | $ret = 9 if ($_ == 4); |
| 147 | like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;c' . $_ . ';' . $ret . ';' . $responce_re[$_] . '$/', "proper result for passive check $_"); | 147 | like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;c' . $_ . ';' . $ret . ';' . $response_re[$_] . '$/', "proper result for passive check $_"); |
| 148 | } else { | 148 | } else { |
| 149 | fail("proper result for passive check $_"); | 149 | fail("proper result for passive check $_"); |
| 150 | } | 150 | } |
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index ec527e7f..ca035ce7 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t | |||
| @@ -23,7 +23,7 @@ my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to anoth | |||
| 23 | if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { | 23 | if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { |
| 24 | plan skip_all => "Need 2 mountpoints to test"; | 24 | plan skip_all => "Need 2 mountpoints to test"; |
| 25 | } else { | 25 | } else { |
| 26 | plan tests => 78; | 26 | plan tests => 88; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | $result = NPTest->testCmd( | 29 | $result = NPTest->testCmd( |
| @@ -326,19 +326,19 @@ cmp_ok( $result->return_code, '==', 0, "grouping: exit ok if the sum of free meg | |||
| 326 | $result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all - 1) ." -c ". ($free_mb_on_all - 1) ." -p $mountpoint_valid -g group -p $mountpoint2_valid" ); | 326 | $result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all - 1) ." -c ". ($free_mb_on_all - 1) ." -p $mountpoint_valid -g group -p $mountpoint2_valid" ); |
| 327 | cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname"); | 327 | cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname"); |
| 328 | 328 | ||
| 329 | # regex: exit unknown if given regex is not compileable | 329 | # regex: exit unknown if given regex is not compilable |
| 330 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -r '('" ); | 330 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -r '('" ); |
| 331 | cmp_ok( $result->return_code, '==', 3, "Exit UNKNOWN if regex is not compileable"); | 331 | cmp_ok( $result->return_code, '==', 3, "Exit UNKNOWN if regex is not compilable"); |
| 332 | 332 | ||
| 333 | # ignore: exit unknown, if all pathes are deselected using -i | 333 | # ignore: exit unknown, if all paths are deselected using -i |
| 334 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '$mountpoint_valid' -i '$mountpoint2_valid'" ); | 334 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '$mountpoint_valid' -i '$mountpoint2_valid'" ); |
| 335 | cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored (case sensitive)"); | 335 | cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored (case sensitive)"); |
| 336 | 336 | ||
| 337 | # ignore: exit unknown, if all pathes are deselected using -I | 337 | # ignore: exit unknown, if all paths are deselected using -I |
| 338 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -I '".uc($mountpoint_valid)."' -I '".uc($mountpoint2_valid)."'" ); | 338 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -I '".uc($mountpoint_valid)."' -I '".uc($mountpoint2_valid)."'" ); |
| 339 | cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored (case insensitive)"); | 339 | cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored (case insensitive)"); |
| 340 | 340 | ||
| 341 | # ignore: exit unknown, if all pathes are deselected using -i | 341 | # ignore: exit unknown, if all paths are deselected using -i |
| 342 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '.*'" ); | 342 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '.*'" ); |
| 343 | cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored using -i '.*'"); | 343 | cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored using -i '.*'"); |
| 344 | 344 | ||
| @@ -347,7 +347,32 @@ $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mo | |||
| 347 | like( $result->output, qr/$mountpoint_valid/, "output data does have $mountpoint_valid in it"); | 347 | like( $result->output, qr/$mountpoint_valid/, "output data does have $mountpoint_valid in it"); |
| 348 | unlike( $result->output, qr/$mountpoint2_valid/, "output data does not have $mountpoint2_valid in it"); | 348 | unlike( $result->output, qr/$mountpoint2_valid/, "output data does not have $mountpoint2_valid in it"); |
| 349 | 349 | ||
| 350 | # ignore: test if all pathes are listed when ignore regex doesn't match | 350 | # ignore: test if all paths are listed when ignore regex doesn't match |
| 351 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '^barbazJodsf\$'"); | 351 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '^barbazJodsf\$'"); |
| 352 | like( $result->output, qr/$mountpoint_valid/, "ignore: output data does have $mountpoint_valid when regex doesn't match"); | 352 | like( $result->output, qr/$mountpoint_valid/, "ignore: output data does have $mountpoint_valid when regex doesn't match"); |
| 353 | like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mountpoint2_valid when regex doesn't match"); | 353 | like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mountpoint2_valid when regex doesn't match"); |
| 354 | |||
| 355 | # ignore-missing: exit okay, when fs is not accessible | ||
| 356 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob"); | ||
| 357 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob"); | ||
| 358 | like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /bob;.*$/', 'Output OK'); | ||
| 359 | |||
| 360 | # ignore-missing: exit okay, when regex does not match | ||
| 361 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob"); | ||
| 362 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | ||
| 363 | like( $result->output, '/^DISK OK - No disks were found for provided parameters;.*$/', 'Output OK'); | ||
| 364 | |||
| 365 | # ignore-missing: exit okay, when fs with exact match (-E) is not found | ||
| 366 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc"); | ||
| 367 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs"); | ||
| 368 | like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /etc;.*$/', 'Output OK'); | ||
| 369 | |||
| 370 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex) | ||
| 371 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/\$'"); | ||
| 372 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | ||
| 373 | like( $result->output, '/^DISK OK - free space: \/ .*$/', 'Output OK'); | ||
| 374 | |||
| 375 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path) | ||
| 376 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'"); | ||
| 377 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | ||
| 378 | like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK'); \ No newline at end of file | ||
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index 1ca52f61..1f2fbdfd 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t | |||
| @@ -178,13 +178,13 @@ SKIP: { | |||
| 178 | 178 | ||
| 179 | $res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -u http://$host_tcp_http -e 200,301,302"); | 179 | $res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -u http://$host_tcp_http -e 200,301,302"); |
| 180 | is( $res->return_code, 0, "Proxy HTTP works"); | 180 | is( $res->return_code, 0, "Proxy HTTP works"); |
| 181 | like($res->output, qr/OK: Status line output matched/, "Proxy HTTP Output is sufficent"); | 181 | like($res->output, qr/OK: Status line output matched/, "Proxy HTTP Output is sufficient"); |
| 182 | 182 | ||
| 183 | $res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT"); | 183 | $res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT"); |
| 184 | is( $res->return_code, 0, "Proxy HTTP CONNECT works"); | 184 | is( $res->return_code, 0, "Proxy HTTP CONNECT works"); |
| 185 | like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent"); | 185 | like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficient"); |
| 186 | 186 | ||
| 187 | $res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT:HEAD"); | 187 | $res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT:HEAD"); |
| 188 | is( $res->return_code, 0, "Proxy HTTP CONNECT works with override method"); | 188 | is( $res->return_code, 0, "Proxy HTTP CONNECT works with override method"); |
| 189 | like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent"); | 189 | like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficient"); |
| 190 | } | 190 | } |
diff --git a/plugins/t/check_mysql.t b/plugins/t/check_mysql.t index e426bf59..baf3acc6 100644 --- a/plugins/t/check_mysql.t +++ b/plugins/t/check_mysql.t | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | # | 5 | # |
| 6 | # | 6 | # |
| 7 | # These are the database permissions required for this test: | 7 | # These are the database permissions required for this test: |
| 8 | # GRANT SELECT ON $db.* TO $user@$host INDENTIFIED BY '$password'; | 8 | # GRANT SELECT ON $db.* TO $user@$host IDENTIFIED BY '$password'; |
| 9 | # GRANT SUPER, REPLICATION CLIENT ON *.* TO $user@$host; | 9 | # GRANT SUPER, REPLICATION CLIENT ON *.* TO $user@$host; |
| 10 | # Check with: | 10 | # Check with: |
| 11 | # mysql -u$user -p$password -h$host $db | 11 | # mysql -u$user -p$password -h$host $db |
| @@ -23,9 +23,9 @@ plan tests => 15; | |||
| 23 | my $bad_login_output = '/Access denied for user /'; | 23 | my $bad_login_output = '/Access denied for user /'; |
| 24 | my $mysqlserver = getTestParameter("NP_MYSQL_SERVER", "A MySQL Server hostname or IP with no slaves setup"); | 24 | my $mysqlserver = getTestParameter("NP_MYSQL_SERVER", "A MySQL Server hostname or IP with no slaves setup"); |
| 25 | my $mysqlsocket = getTestParameter("NP_MYSQL_SOCKET", "Full path to a MySQL Server socket with no slaves setup"); | 25 | my $mysqlsocket = getTestParameter("NP_MYSQL_SOCKET", "Full path to a MySQL Server socket 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"); | 26 | my $mysql_login_details = getTestParameter("NP_MYSQL_LOGIN_DETAILS", "Command line parameters to specify login access (requires REPLICATION CLIENT privileges)", "-u test -ptest"); |
| 27 | my $with_slave = getTestParameter("NP_MYSQL_WITH_SLAVE", "MySQL server with slaves setup"); | 27 | my $with_slave = getTestParameter("NP_MYSQL_WITH_SLAVE", "MySQL server with slaves setup"); |
| 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"); | 28 | my $with_slave_login = getTestParameter("NP_MYSQL_WITH_SLAVE_LOGIN", "Login details for server with slave (requires REPLICATION CLIENT privileges)", $mysql_login_details || "-u test -ptest"); |
| 29 | 29 | ||
| 30 | my $result; | 30 | my $result; |
| 31 | 31 | ||
diff --git a/plugins/t/check_mysql_query.t b/plugins/t/check_mysql_query.t index 96899ac6..c30245b2 100644 --- a/plugins/t/check_mysql_query.t +++ b/plugins/t/check_mysql_query.t | |||
| @@ -31,7 +31,7 @@ $result = NPTest->testCmd("./check_mysql_query -q 'SELECT 1+1' -H $mysqlserver $ | |||
| 31 | cmp_ok( $result->return_code, '==', 0, "Can run query"); | 31 | cmp_ok( $result->return_code, '==', 0, "Can run query"); |
| 32 | 32 | ||
| 33 | $result = NPTest->testCmd("./check_mysql_query -H $mysqlserver $mysql_login_details"); | 33 | $result = NPTest->testCmd("./check_mysql_query -H $mysqlserver $mysql_login_details"); |
| 34 | cmp_ok( $result->return_code, '==', 3, "Missing query parmeter"); | 34 | cmp_ok( $result->return_code, '==', 3, "Missing query parameter"); |
| 35 | like( $result->output, "/Must specify a SQL query to run/", "Missing query error message"); | 35 | like( $result->output, "/Must specify a SQL query to run/", "Missing query error message"); |
| 36 | 36 | ||
| 37 | $result = NPTest->testCmd("./check_mysql_query -q 'SELECT 1+1' -H $mysqlserver -u dummy -d mysql"); | 37 | $result = NPTest->testCmd("./check_mysql_query -q 'SELECT 1+1' -H $mysqlserver -u dummy -d mysql"); |
diff --git a/plugins/t/check_nagios.t b/plugins/t/check_nagios.t index 81fc24d8..f38f5e9c 100644 --- a/plugins/t/check_nagios.t +++ b/plugins/t/check_nagios.t | |||
| @@ -36,7 +36,7 @@ cmp_ok( $result->return_code, '==', 1, "Log over 5 minutes old" ); | |||
| 36 | like ( $result->output, $warningOutput, "Output for warning correct" ); | 36 | like ( $result->output, $warningOutput, "Output for warning correct" ); |
| 37 | 37 | ||
| 38 | my $now = time; | 38 | my $now = time; |
| 39 | # This substitution is dependant on the testcase | 39 | # This substitution is dependent on the testcase |
| 40 | system( "perl -pe 's/1133537544/$now/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1"; | 40 | system( "perl -pe 's/1133537544/$now/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1"; |
| 41 | 41 | ||
| 42 | $result = NPTest->testCmd( | 42 | $result = NPTest->testCmd( |
diff --git a/plugins/t/negate.t b/plugins/t/negate.t index d96a109b..5ec1c843 100644 --- a/plugins/t/negate.t +++ b/plugins/t/negate.t | |||
| @@ -84,7 +84,7 @@ foreach my $current_state (keys(%state)) { | |||
| 84 | foreach my $new_state (keys(%state)) { | 84 | foreach my $new_state (keys(%state)) { |
| 85 | $res = NPTest->testCmd( "./negate -s --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" ); | 85 | $res = NPTest->testCmd( "./negate -s --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" ); |
| 86 | is( $res->return_code, $state{$new_state}, "Got fake $new_state (with substitute)" ); | 86 | is( $res->return_code, $state{$new_state}, "Got fake $new_state (with substitute)" ); |
| 87 | is( $res->output, uc($new_state).": Fake $new_state", "Substitued fake $new_state output"); | 87 | is( $res->output, uc($new_state).": Fake $new_state", "Substituted fake $new_state output"); |
| 88 | } | 88 | } |
| 89 | } | 89 | } |
| 90 | 90 | ||
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index d766ac37..6078b274 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t | |||
| @@ -9,12 +9,14 @@ use strict; | |||
| 9 | use Test::More; | 9 | use Test::More; |
| 10 | use NPTest; | 10 | use NPTest; |
| 11 | use FindBin qw($Bin); | 11 | use FindBin qw($Bin); |
| 12 | use IO::Socket::INET; | ||
| 12 | 13 | ||
| 13 | $ENV{'LC_TIME'} = "C"; | 14 | $ENV{'LC_TIME'} = "C"; |
| 14 | 15 | ||
| 15 | my $common_tests = 71; | 16 | my $common_tests = 71; |
| 16 | my $virtual_port_tests = 8; | 17 | my $virtual_port_tests = 8; |
| 17 | my $ssl_only_tests = 12; | 18 | my $ssl_only_tests = 12; |
| 19 | my $chunked_encoding_special_tests = 1; | ||
| 18 | # Check that all dependent modules are available | 20 | # Check that all dependent modules are available |
| 19 | eval "use HTTP::Daemon 6.01;"; | 21 | eval "use HTTP::Daemon 6.01;"; |
| 20 | plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@; | 22 | plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@; |
| @@ -30,7 +32,7 @@ if ($@) { | |||
| 30 | plan skip_all => "Missing required module for test: $@"; | 32 | plan skip_all => "Missing required module for test: $@"; |
| 31 | } else { | 33 | } else { |
| 32 | if (-x "./$plugin") { | 34 | if (-x "./$plugin") { |
| 33 | plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests; | 35 | plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests + $chunked_encoding_special_tests; |
| 34 | } else { | 36 | } else { |
| 35 | plan skip_all => "No $plugin compiled"; | 37 | plan skip_all => "No $plugin compiled"; |
| 36 | } | 38 | } |
| @@ -51,6 +53,7 @@ my $port_http = 50000 + int(rand(1000)); | |||
| 51 | my $port_https = $port_http + 1; | 53 | my $port_https = $port_http + 1; |
| 52 | my $port_https_expired = $port_http + 2; | 54 | my $port_https_expired = $port_http + 2; |
| 53 | my $port_https_clientcert = $port_http + 3; | 55 | my $port_https_clientcert = $port_http + 3; |
| 56 | my $port_hacked_http = $port_http + 4; | ||
| 54 | 57 | ||
| 55 | # This array keeps sockets around for implementing timeouts | 58 | # This array keeps sockets around for implementing timeouts |
| 56 | my @persist; | 59 | my @persist; |
| @@ -72,6 +75,28 @@ if (!$pid) { | |||
| 72 | } | 75 | } |
| 73 | push @pids, $pid; | 76 | push @pids, $pid; |
| 74 | 77 | ||
| 78 | # Fork the hacked HTTP server | ||
| 79 | undef $pid; | ||
| 80 | $pid = fork; | ||
| 81 | defined $pid or die "Failed to fork"; | ||
| 82 | if (!$pid) { | ||
| 83 | # this is the fork | ||
| 84 | undef @pids; | ||
| 85 | my $socket = new IO::Socket::INET ( | ||
| 86 | LocalHost => '0.0.0.0', | ||
| 87 | LocalPort => $port_hacked_http, | ||
| 88 | Proto => 'tcp', | ||
| 89 | Listen => 5, | ||
| 90 | Reuse => 1 | ||
| 91 | ); | ||
| 92 | die "cannot create socket $!n" unless $socket; | ||
| 93 | my $local_sock = $socket->sockport(); | ||
| 94 | print "server waiting for client connection on port $local_sock\n"; | ||
| 95 | run_hacked_http_server ( $socket ); | ||
| 96 | die "hacked http server stopped"; | ||
| 97 | } | ||
| 98 | push @pids, $pid; | ||
| 99 | |||
| 75 | if (exists $servers->{https}) { | 100 | if (exists $servers->{https}) { |
| 76 | # Fork a normal HTTPS server | 101 | # Fork a normal HTTPS server |
| 77 | $pid = fork; | 102 | $pid = fork; |
| @@ -207,6 +232,37 @@ sub run_server { | |||
| 207 | } | 232 | } |
| 208 | } | 233 | } |
| 209 | 234 | ||
| 235 | sub run_hacked_http_server { | ||
| 236 | my $socket = shift; | ||
| 237 | |||
| 238 | # auto-flush on socket | ||
| 239 | $| = 1; | ||
| 240 | |||
| 241 | |||
| 242 | while(1) | ||
| 243 | { | ||
| 244 | # waiting for a new client connection | ||
| 245 | my $client_socket = $socket->accept(); | ||
| 246 | |||
| 247 | # get information about a newly connected client | ||
| 248 | my $client_address = $client_socket->peerhost(); | ||
| 249 | my $client_portn = $client_socket->peerport(); | ||
| 250 | print "connection from $client_address:$client_portn"; | ||
| 251 | |||
| 252 | # read up to 1024 characters from the connected client | ||
| 253 | my $data = ""; | ||
| 254 | $client_socket->recv($data, 1024); | ||
| 255 | print "received data: $data"; | ||
| 256 | |||
| 257 | # write response data to the connected client | ||
| 258 | $data = "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n"; | ||
| 259 | $client_socket->send($data); | ||
| 260 | |||
| 261 | # notify client that response has been sent | ||
| 262 | shutdown($client_socket, 1); | ||
| 263 | } | ||
| 264 | } | ||
| 265 | |||
| 210 | END { | 266 | END { |
| 211 | foreach my $pid (@pids) { | 267 | foreach my $pid (@pids) { |
| 212 | if ($pid) { print "Killing $pid\n"; kill "INT", $pid } | 268 | if ($pid) { print "Killing $pid\n"; kill "INT", $pid } |
| @@ -222,6 +278,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") { | |||
| 222 | my $result; | 278 | my $result; |
| 223 | my $command = "./$plugin -H 127.0.0.1"; | 279 | my $command = "./$plugin -H 127.0.0.1"; |
| 224 | 280 | ||
| 281 | run_chunked_encoding_special_test( {command => "$command -p $port_hacked_http"}); | ||
| 225 | run_common_tests( { command => "$command -p $port_http" } ); | 282 | run_common_tests( { command => "$command -p $port_http" } ); |
| 226 | SKIP: { | 283 | SKIP: { |
| 227 | skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https}; | 284 | skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https}; |
| @@ -511,3 +568,14 @@ sub run_common_tests { | |||
| 511 | }; | 568 | }; |
| 512 | is( $@, "", $cmd ); | 569 | is( $@, "", $cmd ); |
| 513 | } | 570 | } |
| 571 | |||
| 572 | sub run_chunked_encoding_special_test { | ||
| 573 | my ($opts) = @_; | ||
| 574 | my $command = $opts->{command}; | ||
| 575 | |||
| 576 | $cmd = "$command -u / -s 'ChunkedEncodingSpecialTest'"; | ||
| 577 | eval { | ||
| 578 | $result = NPTest->testCmd( $cmd, 5 ); | ||
| 579 | }; | ||
| 580 | is( $@, "", $cmd ); | ||
| 581 | } | ||
diff --git a/plugins/tests/check_procs.t b/plugins/tests/check_procs.t index 3af218f5..b3a0a301 100755 --- a/plugins/tests/check_procs.t +++ b/plugins/tests/check_procs.t | |||
| @@ -8,7 +8,7 @@ use Test::More; | |||
| 8 | use NPTest; | 8 | use NPTest; |
| 9 | 9 | ||
| 10 | if (-x "./check_procs") { | 10 | if (-x "./check_procs") { |
| 11 | plan tests => 52; | 11 | plan tests => 54; |
| 12 | } else { | 12 | } else { |
| 13 | plan skip_all => "No check_procs compiled"; | 13 | plan skip_all => "No check_procs compiled"; |
| 14 | } | 14 | } |
| @@ -34,9 +34,13 @@ is( $result->return_code, 0, "Checking no threshold breeched" ); | |||
| 34 | is( $result->output, "PROCS OK: 95 processes | procs=95;100;200;0;", "Output correct" ); | 34 | is( $result->output, "PROCS OK: 95 processes | procs=95;100;200;0;", "Output correct" ); |
| 35 | 35 | ||
| 36 | $result = NPTest->testCmd( "$command -C launchd -c 5" ); | 36 | $result = NPTest->testCmd( "$command -C launchd -c 5" ); |
| 37 | is( $result->return_code, 2, "Checking processes filtered by command name" ); | 37 | is( $result->return_code, 2, "Checking processes matched by command name" ); |
| 38 | is( $result->output, "PROCS CRITICAL: 6 processes with command name 'launchd' | procs=6;;5;0;", "Output correct" ); | 38 | is( $result->output, "PROCS CRITICAL: 6 processes with command name 'launchd' | procs=6;;5;0;", "Output correct" ); |
| 39 | 39 | ||
| 40 | $result = NPTest->testCmd( "$command -X bash -c 5" ); | ||
| 41 | is( $result->return_code, 2, "Checking processes excluded by command name" ); | ||
| 42 | is( $result->output, "PROCS CRITICAL: 95 processes with exclude progs 'bash' | procs=95;;5;0;", "Output correct" ); | ||
| 43 | |||
| 40 | SKIP: { | 44 | SKIP: { |
| 41 | skip 'user with uid 501 required', 4 unless getpwuid(501); | 45 | skip 'user with uid 501 required', 4 unless getpwuid(501); |
| 42 | 46 | ||
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index bc03ec60..bfe42e16 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t | |||
| @@ -53,7 +53,7 @@ if ($pid) { | |||
| 53 | #print "child\n"; | 53 | #print "child\n"; |
| 54 | 54 | ||
| 55 | print "Please contact SNMP at: $port_snmp\n"; | 55 | print "Please contact SNMP at: $port_snmp\n"; |
| 56 | close(STDERR); # Coment out to debug snmpd problems (most errors sent there are OK) | 56 | close(STDERR); # Comment out to debug snmpd problems (most errors sent there are OK) |
| 57 | exec("snmpd -c tests/conf/snmpd.conf -C -f -r udp:$port_snmp"); | 57 | exec("snmpd -c tests/conf/snmpd.conf -C -f -r udp:$port_snmp"); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| @@ -227,7 +227,7 @@ is($res->output, 'SNMP OK - "555\"I said\"" | ', "Check string with a double quo | |||
| 227 | 227 | ||
| 228 | $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.15 -r 'CUSTOM CHECK OK'" ); | 228 | $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.15 -r 'CUSTOM CHECK OK'" ); |
| 229 | is($res->return_code, 0, "String check should check whole string, not a parsed number" ); | 229 | is($res->return_code, 0, "String check should check whole string, not a parsed number" ); |
| 230 | is($res->output, 'SNMP OK - "CUSTOM CHECK OK: foo is 12345" | ', "String check witn numbers returns whole string"); | 230 | is($res->output, 'SNMP OK - "CUSTOM CHECK OK: foo is 12345" | ', "String check with numbers returns whole string"); |
| 231 | 231 | ||
| 232 | $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.16 -w -2: -c -3:" ); | 232 | $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.16 -w -2: -c -3:" ); |
| 233 | is($res->return_code, 0, "Negative integer check OK" ); | 233 | is($res->return_code, 0, "Negative integer check OK" ); |
diff --git a/plugins/utils.h b/plugins/utils.h index 5b54da3c..c76b3216 100644 --- a/plugins/utils.h +++ b/plugins/utils.h | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | /* The purpose of this package is to provide safer alternatives to C | 7 | /* The purpose of this package is to provide safer alternatives to C |
| 8 | functions that might otherwise be vulnerable to hacking. This | 8 | functions that might otherwise be vulnerable to hacking. This |
| 9 | currently includes a standard suite of validation routines to be sure | 9 | currently includes a standard suite of validation routines to be sure |
| 10 | that an string argument acually converts to its intended type and a | 10 | that an string argument actually converts to its intended type and a |
| 11 | suite of string handling routine that do their own memory management | 11 | suite of string handling routine that do their own memory management |
| 12 | in order to resist overflow attacks. In addition, a few functions are | 12 | in order to resist overflow attacks. In addition, a few functions are |
| 13 | provided to standardize version and error reporting across the entire | 13 | provided to standardize version and error reporting across the entire |
