diff options
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/Makefile.am | 4 | ||||
| -rw-r--r-- | plugins/check_curl.c | 202 | ||||
| -rw-r--r-- | plugins/check_disk.c | 114 | ||||
| -rw-r--r-- | plugins/sslutils.c | 34 | ||||
| -rw-r--r-- | plugins/t/check_disk.t | 27 |
5 files changed, 266 insertions, 115 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..c37d45d9 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" |
| @@ -131,14 +132,14 @@ regmatch_t pmatch[REGS]; | |||
| 131 | char regexp[MAX_RE_SIZE]; | 132 | char regexp[MAX_RE_SIZE]; |
| 132 | int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; | 133 | int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; |
| 133 | int errcode; | 134 | int errcode; |
| 134 | int invert_regex = 0; | 135 | bool invert_regex = false; |
| 135 | 136 | ||
| 136 | char *server_address = NULL; | 137 | char *server_address = NULL; |
| 137 | char *host_name = NULL; | 138 | char *host_name = NULL; |
| 138 | char *server_url = 0; | 139 | char *server_url = 0; |
| 139 | char server_ip[DEFAULT_BUFFER_SIZE]; | 140 | char server_ip[DEFAULT_BUFFER_SIZE]; |
| 140 | struct curl_slist *server_ips = NULL; | 141 | struct curl_slist *server_ips = NULL; |
| 141 | int specify_port = FALSE; | 142 | bool specify_port = false; |
| 142 | unsigned short server_port = HTTP_PORT; | 143 | unsigned short server_port = HTTP_PORT; |
| 143 | unsigned short virtual_port = 0; | 144 | unsigned short virtual_port = 0; |
| 144 | int host_name_length; | 145 | int host_name_length; |
| @@ -150,8 +151,8 @@ int days_till_exp_warn, days_till_exp_crit; | |||
| 150 | thresholds *thlds; | 151 | thresholds *thlds; |
| 151 | char user_agent[DEFAULT_BUFFER_SIZE]; | 152 | char user_agent[DEFAULT_BUFFER_SIZE]; |
| 152 | int verbose = 0; | 153 | int verbose = 0; |
| 153 | int show_extended_perfdata = FALSE; | 154 | bool show_extended_perfdata = false; |
| 154 | int show_body = FALSE; | 155 | bool show_body = false; |
| 155 | int min_page_len = 0; | 156 | int min_page_len = 0; |
| 156 | int max_page_len = 0; | 157 | int max_page_len = 0; |
| 157 | int redir_depth = 0; | 158 | int redir_depth = 0; |
| @@ -160,10 +161,16 @@ char *http_method = NULL; | |||
| 160 | char *http_post_data = NULL; | 161 | char *http_post_data = NULL; |
| 161 | char *http_content_type = NULL; | 162 | char *http_content_type = NULL; |
| 162 | CURL *curl; | 163 | CURL *curl; |
| 164 | bool curl_global_initialized = false; | ||
| 165 | bool curl_easy_initialized = false; | ||
| 163 | struct curl_slist *header_list = NULL; | 166 | struct curl_slist *header_list = NULL; |
| 167 | bool body_buf_initialized = false; | ||
| 164 | curlhelp_write_curlbuf body_buf; | 168 | curlhelp_write_curlbuf body_buf; |
| 169 | bool header_buf_initialized = false; | ||
| 165 | curlhelp_write_curlbuf header_buf; | 170 | curlhelp_write_curlbuf header_buf; |
| 171 | bool status_line_initialized = false; | ||
| 166 | curlhelp_statusline status_line; | 172 | curlhelp_statusline status_line; |
| 173 | bool put_buf_initialized = false; | ||
| 167 | curlhelp_read_curlbuf put_buf; | 174 | curlhelp_read_curlbuf put_buf; |
| 168 | char http_header[DEFAULT_BUFFER_SIZE]; | 175 | char http_header[DEFAULT_BUFFER_SIZE]; |
| 169 | long code; | 176 | long code; |
| @@ -173,7 +180,7 @@ double time_connect; | |||
| 173 | double time_appconnect; | 180 | double time_appconnect; |
| 174 | double time_headers; | 181 | double time_headers; |
| 175 | double time_firstbyte; | 182 | double time_firstbyte; |
| 176 | char errbuf[CURL_ERROR_SIZE+1]; | 183 | char errbuf[MAX_INPUT_BUFFER]; |
| 177 | CURLcode res; | 184 | CURLcode res; |
| 178 | char url[DEFAULT_BUFFER_SIZE]; | 185 | char url[DEFAULT_BUFFER_SIZE]; |
| 179 | char msg[DEFAULT_BUFFER_SIZE]; | 186 | char msg[DEFAULT_BUFFER_SIZE]; |
| @@ -186,14 +193,14 @@ char user_auth[MAX_INPUT_BUFFER] = ""; | |||
| 186 | char proxy_auth[MAX_INPUT_BUFFER] = ""; | 193 | char proxy_auth[MAX_INPUT_BUFFER] = ""; |
| 187 | char **http_opt_headers; | 194 | char **http_opt_headers; |
| 188 | int http_opt_headers_count = 0; | 195 | int http_opt_headers_count = 0; |
| 189 | int display_html = FALSE; | 196 | bool display_html = false; |
| 190 | int onredirect = STATE_OK; | 197 | int onredirect = STATE_OK; |
| 191 | int followmethod = FOLLOW_HTTP_CURL; | 198 | int followmethod = FOLLOW_HTTP_CURL; |
| 192 | int followsticky = STICKY_NONE; | 199 | int followsticky = STICKY_NONE; |
| 193 | int use_ssl = FALSE; | 200 | bool use_ssl = false; |
| 194 | int use_sni = TRUE; | 201 | bool use_sni = true; |
| 195 | int check_cert = FALSE; | 202 | bool check_cert = false; |
| 196 | int continue_after_check_cert = FALSE; | 203 | bool continue_after_check_cert = false; |
| 197 | typedef union { | 204 | typedef union { |
| 198 | struct curl_slist* to_info; | 205 | struct curl_slist* to_info; |
| 199 | struct curl_certinfo* to_certinfo; | 206 | struct curl_certinfo* to_certinfo; |
| @@ -203,19 +210,20 @@ int ssl_version = CURL_SSLVERSION_DEFAULT; | |||
| 203 | char *client_cert = NULL; | 210 | char *client_cert = NULL; |
| 204 | char *client_privkey = NULL; | 211 | char *client_privkey = NULL; |
| 205 | char *ca_cert = NULL; | 212 | char *ca_cert = NULL; |
| 206 | int verify_peer_and_host = FALSE; | 213 | bool verify_peer_and_host = false; |
| 207 | int is_openssl_callback = FALSE; | 214 | bool is_openssl_callback = false; |
| 208 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) | 215 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) |
| 209 | X509 *cert = NULL; | 216 | X509 *cert = NULL; |
| 210 | #endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ | 217 | #endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ |
| 211 | int no_body = FALSE; | 218 | bool no_body = false; |
| 212 | int maximum_age = -1; | 219 | int maximum_age = -1; |
| 213 | int address_family = AF_UNSPEC; | 220 | int address_family = AF_UNSPEC; |
| 214 | curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; | 221 | curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; |
| 215 | int curl_http_version = CURL_HTTP_VERSION_NONE; | 222 | int curl_http_version = CURL_HTTP_VERSION_NONE; |
| 216 | int automatic_decompression = FALSE; | 223 | bool automatic_decompression = false; |
| 224 | char *cookie_jar_file = NULL; | ||
| 217 | 225 | ||
| 218 | int process_arguments (int, char**); | 226 | bool process_arguments (int, char**); |
| 219 | void handle_curl_option_return_code (CURLcode res, const char* option); | 227 | void handle_curl_option_return_code (CURLcode res, const char* option); |
| 220 | int check_http (void); | 228 | int check_http (void); |
| 221 | void redir (curlhelp_write_curlbuf*); | 229 | void redir (curlhelp_write_curlbuf*); |
| @@ -269,10 +277,10 @@ main (int argc, char **argv) | |||
| 269 | progname, NP_VERSION, VERSION, curl_version()); | 277 | progname, NP_VERSION, VERSION, curl_version()); |
| 270 | 278 | ||
| 271 | /* parse arguments */ | 279 | /* parse arguments */ |
| 272 | if (process_arguments (argc, argv) == ERROR) | 280 | if (process_arguments (argc, argv) == false) |
| 273 | usage4 (_("Could not parse arguments")); | 281 | usage4 (_("Could not parse arguments")); |
| 274 | 282 | ||
| 275 | if (display_html == TRUE) | 283 | if (display_html) |
| 276 | printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">", | 284 | printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">", |
| 277 | use_ssl ? "https" : "http", | 285 | use_ssl ? "https" : "http", |
| 278 | host_name ? host_name : server_address, | 286 | host_name ? host_name : server_address, |
| @@ -412,6 +420,23 @@ lookup_host (const char *host, char *buf, size_t buflen) | |||
| 412 | return 0; | 420 | return 0; |
| 413 | } | 421 | } |
| 414 | 422 | ||
| 423 | static void | ||
| 424 | cleanup (void) | ||
| 425 | { | ||
| 426 | if (status_line_initialized) curlhelp_free_statusline(&status_line); | ||
| 427 | status_line_initialized = false; | ||
| 428 | if (curl_easy_initialized) curl_easy_cleanup (curl); | ||
| 429 | curl_easy_initialized = false; | ||
| 430 | if (curl_global_initialized) curl_global_cleanup (); | ||
| 431 | curl_global_initialized = false; | ||
| 432 | if (body_buf_initialized) curlhelp_freewritebuffer (&body_buf); | ||
| 433 | body_buf_initialized = false; | ||
| 434 | if (header_buf_initialized) curlhelp_freewritebuffer (&header_buf); | ||
| 435 | header_buf_initialized = false; | ||
| 436 | if (put_buf_initialized) curlhelp_freereadbuffer (&put_buf); | ||
| 437 | put_buf_initialized = false; | ||
| 438 | } | ||
| 439 | |||
| 415 | int | 440 | int |
| 416 | check_http (void) | 441 | check_http (void) |
| 417 | { | 442 | { |
| @@ -426,12 +451,18 @@ check_http (void) | |||
| 426 | /* initialize curl */ | 451 | /* initialize curl */ |
| 427 | if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) | 452 | if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) |
| 428 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_global_init failed\n"); | 453 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_global_init failed\n"); |
| 454 | curl_global_initialized = true; | ||
| 429 | 455 | ||
| 430 | if ((curl = curl_easy_init()) == NULL) | 456 | if ((curl = curl_easy_init()) == NULL) { |
| 431 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_easy_init failed\n"); | 457 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_easy_init failed\n"); |
| 458 | } | ||
| 459 | curl_easy_initialized = true; | ||
| 432 | 460 | ||
| 461 | /* register cleanup function to shut down libcurl properly */ | ||
| 462 | atexit (cleanup); | ||
| 463 | |||
| 433 | if (verbose >= 1) | 464 | if (verbose >= 1) |
| 434 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_VERBOSE, TRUE), "CURLOPT_VERBOSE"); | 465 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_VERBOSE, 1), "CURLOPT_VERBOSE"); |
| 435 | 466 | ||
| 436 | /* print everything on stdout like check_http would do */ | 467 | /* print everything on stdout like check_http would do */ |
| 437 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_STDERR, stdout), "CURLOPT_STDERR"); | 468 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_STDERR, stdout), "CURLOPT_STDERR"); |
| @@ -446,12 +477,14 @@ check_http (void) | |||
| 446 | /* initialize buffer for body of the answer */ | 477 | /* initialize buffer for body of the answer */ |
| 447 | if (curlhelp_initwritebuffer(&body_buf) < 0) | 478 | if (curlhelp_initwritebuffer(&body_buf) < 0) |
| 448 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for body\n"); | 479 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for body\n"); |
| 480 | 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"); | 481 | 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"); | 482 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *)&body_buf), "CURLOPT_WRITEDATA"); |
| 451 | 483 | ||
| 452 | /* initialize buffer for header of the answer */ | 484 | /* initialize buffer for header of the answer */ |
| 453 | if (curlhelp_initwritebuffer( &header_buf ) < 0) | 485 | if (curlhelp_initwritebuffer( &header_buf ) < 0) |
| 454 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for header\n" ); | 486 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for header\n" ); |
| 487 | 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"); | 488 | 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"); | 489 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEHEADER, (void *)&header_buf), "CURLOPT_WRITEHEADER"); |
| 457 | 490 | ||
| @@ -512,7 +545,7 @@ check_http (void) | |||
| 512 | 545 | ||
| 513 | /* disable body for HEAD request */ | 546 | /* disable body for HEAD request */ |
| 514 | if (http_method && !strcmp (http_method, "HEAD" )) { | 547 | if (http_method && !strcmp (http_method, "HEAD" )) { |
| 515 | no_body = TRUE; | 548 | no_body = true; |
| 516 | } | 549 | } |
| 517 | 550 | ||
| 518 | /* set HTTP protocol version */ | 551 | /* set HTTP protocol version */ |
| @@ -609,7 +642,7 @@ check_http (void) | |||
| 609 | #ifdef USE_OPENSSL | 642 | #ifdef USE_OPENSSL |
| 610 | /* libcurl and monitoring plugins built with OpenSSL, good */ | 643 | /* 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"); | 644 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun), "CURLOPT_SSL_CTX_FUNCTION"); |
| 612 | is_openssl_callback = TRUE; | 645 | is_openssl_callback = true; |
| 613 | #else /* USE_OPENSSL */ | 646 | #else /* USE_OPENSSL */ |
| 614 | #endif /* USE_OPENSSL */ | 647 | #endif /* USE_OPENSSL */ |
| 615 | /* libcurl is built with OpenSSL, monitoring plugins, so falling | 648 | /* libcurl is built with OpenSSL, monitoring plugins, so falling |
| @@ -688,9 +721,11 @@ check_http (void) | |||
| 688 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_MAXREDIRS, max_depth+1), "CURLOPT_MAXREDIRS"); | 721 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_MAXREDIRS, max_depth+1), "CURLOPT_MAXREDIRS"); |
| 689 | 722 | ||
| 690 | /* for now allow only http and https (we are a http(s) check plugin in the end) */ | 723 | /* 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) | 724 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 85, 0) |
| 725 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS_STR, "http,https"), "CURLOPT_REDIR_PROTOCOLS_STR"); | ||
| 726 | #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"); | 727 | 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) */ | 728 | #endif |
| 694 | 729 | ||
| 695 | /* TODO: handle the following aspects of redirection, make them | 730 | /* TODO: handle the following aspects of redirection, make them |
| 696 | * command line options too later: | 731 | * command line options too later: |
| @@ -734,11 +769,19 @@ check_http (void) | |||
| 734 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_POSTFIELDS, http_post_data), "CURLOPT_POSTFIELDS"); | 769 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_POSTFIELDS, http_post_data), "CURLOPT_POSTFIELDS"); |
| 735 | } else if (!strcmp(http_method, "PUT")) { | 770 | } 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"); | 771 | 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)); | 772 | if (curlhelp_initreadbuffer (&put_buf, http_post_data, strlen (http_post_data)) < 0) |
| 773 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating read buffer for PUT\n"); | ||
| 774 | put_buf_initialized = true; | ||
| 738 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READDATA, (void *)&put_buf), "CURLOPT_READDATA"); | 775 | 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"); | 776 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_INFILESIZE, (curl_off_t)strlen (http_post_data)), "CURLOPT_INFILESIZE"); |
| 740 | } | 777 | } |
| 741 | } | 778 | } |
| 779 | |||
| 780 | /* cookie handling */ | ||
| 781 | if (cookie_jar_file != NULL) { | ||
| 782 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_COOKIEJAR, cookie_jar_file), "CURLOPT_COOKIEJAR"); | ||
| 783 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_COOKIEFILE, cookie_jar_file), "CURLOPT_COOKIEFILE"); | ||
| 784 | } | ||
| 742 | 785 | ||
| 743 | /* do the request */ | 786 | /* do the request */ |
| 744 | res = curl_easy_perform(curl); | 787 | res = curl_easy_perform(curl); |
| @@ -759,15 +802,15 @@ check_http (void) | |||
| 759 | 802 | ||
| 760 | /* certificate checks */ | 803 | /* certificate checks */ |
| 761 | #ifdef LIBCURL_FEATURE_SSL | 804 | #ifdef LIBCURL_FEATURE_SSL |
| 762 | if (use_ssl == TRUE) { | 805 | if (use_ssl) { |
| 763 | if (check_cert == TRUE) { | 806 | if (check_cert) { |
| 764 | if (is_openssl_callback) { | 807 | if (is_openssl_callback) { |
| 765 | #ifdef USE_OPENSSL | 808 | #ifdef USE_OPENSSL |
| 766 | /* check certificate with OpenSSL functions, curl has been built against OpenSSL | 809 | /* check certificate with OpenSSL functions, curl has been built against OpenSSL |
| 767 | * and we actually have OpenSSL in the monitoring tools | 810 | * and we actually have OpenSSL in the monitoring tools |
| 768 | */ | 811 | */ |
| 769 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); | 812 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); |
| 770 | if (continue_after_check_cert == FALSE) { | 813 | if (!continue_after_check_cert) { |
| 771 | return result; | 814 | return result; |
| 772 | } | 815 | } |
| 773 | #else /* USE_OPENSSL */ | 816 | #else /* USE_OPENSSL */ |
| @@ -809,7 +852,7 @@ GOT_FIRST_CERT: | |||
| 809 | } | 852 | } |
| 810 | BIO_free (cert_BIO); | 853 | BIO_free (cert_BIO); |
| 811 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); | 854 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); |
| 812 | if (continue_after_check_cert == FALSE) { | 855 | if (!continue_after_check_cert) { |
| 813 | return result; | 856 | return result; |
| 814 | } | 857 | } |
| 815 | #else /* USE_OPENSSL */ | 858 | #else /* USE_OPENSSL */ |
| @@ -817,7 +860,7 @@ GOT_FIRST_CERT: | |||
| 817 | * so we use the libcurl CURLINFO data | 860 | * so we use the libcurl CURLINFO data |
| 818 | */ | 861 | */ |
| 819 | result = net_noopenssl_check_certificate(&cert_ptr, days_till_exp_warn, days_till_exp_crit); | 862 | result = net_noopenssl_check_certificate(&cert_ptr, days_till_exp_warn, days_till_exp_crit); |
| 820 | if (continue_after_check_cert == FALSE) { | 863 | if (!continue_after_check_cert) { |
| 821 | return result; | 864 | return result; |
| 822 | } | 865 | } |
| 823 | #endif /* USE_OPENSSL */ | 866 | #endif /* USE_OPENSSL */ |
| @@ -845,7 +888,7 @@ GOT_FIRST_CERT: | |||
| 845 | perfd_time(total_time), | 888 | perfd_time(total_time), |
| 846 | perfd_size(page_len), | 889 | perfd_size(page_len), |
| 847 | perfd_time_connect(time_connect), | 890 | perfd_time_connect(time_connect), |
| 848 | use_ssl == TRUE ? perfd_time_ssl (time_appconnect-time_connect) : "", | 891 | use_ssl ? perfd_time_ssl (time_appconnect-time_connect) : "", |
| 849 | perfd_time_headers(time_headers - time_appconnect), | 892 | perfd_time_headers(time_headers - time_appconnect), |
| 850 | perfd_time_firstbyte(time_firstbyte - time_headers), | 893 | perfd_time_firstbyte(time_firstbyte - time_headers), |
| 851 | perfd_time_transfer(total_time-time_firstbyte) | 894 | perfd_time_transfer(total_time-time_firstbyte) |
| @@ -868,6 +911,7 @@ GOT_FIRST_CERT: | |||
| 868 | /* we cannot know the major/minor version here for sure as we cannot parse the first line */ | 911 | /* 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); | 912 | die (STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg); |
| 870 | } | 913 | } |
| 914 | status_line_initialized = true; | ||
| 871 | 915 | ||
| 872 | /* get result code from cURL */ | 916 | /* get result code from cURL */ |
| 873 | handle_curl_option_return_code (curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &code), "CURLINFO_RESPONSE_CODE"); | 917 | handle_curl_option_return_code (curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &code), "CURLINFO_RESPONSE_CODE"); |
| @@ -980,12 +1024,12 @@ GOT_FIRST_CERT: | |||
| 980 | 1024 | ||
| 981 | if (strlen (regexp)) { | 1025 | if (strlen (regexp)) { |
| 982 | errcode = regexec (&preg, body_buf.buf, REGS, pmatch, 0); | 1026 | errcode = regexec (&preg, body_buf.buf, REGS, pmatch, 0); |
| 983 | if ((errcode == 0 && invert_regex == 0) || (errcode == REG_NOMATCH && invert_regex == 1)) { | 1027 | if ((errcode == 0 && !invert_regex) || (errcode == REG_NOMATCH && invert_regex)) { |
| 984 | /* OK - No-op to avoid changing the logic around it */ | 1028 | /* OK - No-op to avoid changing the logic around it */ |
| 985 | result = max_state_alt(STATE_OK, result); | 1029 | result = max_state_alt(STATE_OK, result); |
| 986 | } | 1030 | } |
| 987 | else if ((errcode == REG_NOMATCH && invert_regex == 0) || (errcode == 0 && invert_regex == 1)) { | 1031 | else if ((errcode == REG_NOMATCH && !invert_regex) || (errcode == 0 && invert_regex)) { |
| 988 | if (invert_regex == 0) | 1032 | if (!invert_regex) |
| 989 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern not found, "), msg); | 1033 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern not found, "), msg); |
| 990 | else | 1034 | else |
| 991 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern found, "), msg); | 1035 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern found, "), msg); |
| @@ -1017,7 +1061,7 @@ GOT_FIRST_CERT: | |||
| 1017 | else | 1061 | else |
| 1018 | msg[strlen(msg)-3] = '\0'; | 1062 | msg[strlen(msg)-3] = '\0'; |
| 1019 | } | 1063 | } |
| 1020 | 1064 | ||
| 1021 | /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */ | 1065 | /* 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", | 1066 | 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), | 1067 | state_text(result), string_statuscode (status_line.http_major, status_line.http_minor), |
| @@ -1029,16 +1073,6 @@ GOT_FIRST_CERT: | |||
| 1029 | (show_body ? body_buf.buf : ""), | 1073 | (show_body ? body_buf.buf : ""), |
| 1030 | (show_body ? "\n" : "") ); | 1074 | (show_body ? "\n" : "") ); |
| 1031 | 1075 | ||
| 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; | 1076 | return result; |
| 1043 | } | 1077 | } |
| 1044 | 1078 | ||
| @@ -1134,7 +1168,10 @@ redir (curlhelp_write_curlbuf* header_buf) | |||
| 1134 | } | 1168 | } |
| 1135 | } | 1169 | } |
| 1136 | 1170 | ||
| 1137 | use_ssl = !uri_strcmp (uri.scheme, "https"); | 1171 | if (!uri_strcmp (uri.scheme, "https")) |
| 1172 | use_ssl = true; | ||
| 1173 | else | ||
| 1174 | use_ssl = false; | ||
| 1138 | 1175 | ||
| 1139 | /* we do a sloppy test here only, because uriparser would have failed | 1176 | /* 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 | 1177 | * above, if the port would be invalid, we just check for MAX_PORT |
| @@ -1209,6 +1246,7 @@ redir (curlhelp_write_curlbuf* header_buf) | |||
| 1209 | * attached to the URL in Location | 1246 | * attached to the URL in Location |
| 1210 | */ | 1247 | */ |
| 1211 | 1248 | ||
| 1249 | cleanup (); | ||
| 1212 | check_http (); | 1250 | check_http (); |
| 1213 | } | 1251 | } |
| 1214 | 1252 | ||
| @@ -1221,7 +1259,7 @@ test_file (char *path) | |||
| 1221 | usage2 (_("file does not exist or is not readable"), path); | 1259 | usage2 (_("file does not exist or is not readable"), path); |
| 1222 | } | 1260 | } |
| 1223 | 1261 | ||
| 1224 | int | 1262 | bool |
| 1225 | process_arguments (int argc, char **argv) | 1263 | process_arguments (int argc, char **argv) |
| 1226 | { | 1264 | { |
| 1227 | char *p; | 1265 | char *p; |
| @@ -1235,7 +1273,8 @@ process_arguments (int argc, char **argv) | |||
| 1235 | CONTINUE_AFTER_CHECK_CERT, | 1273 | CONTINUE_AFTER_CHECK_CERT, |
| 1236 | CA_CERT_OPTION, | 1274 | CA_CERT_OPTION, |
| 1237 | HTTP_VERSION_OPTION, | 1275 | HTTP_VERSION_OPTION, |
| 1238 | AUTOMATIC_DECOMPRESSION | 1276 | AUTOMATIC_DECOMPRESSION, |
| 1277 | COOKIE_JAR | ||
| 1239 | }; | 1278 | }; |
| 1240 | 1279 | ||
| 1241 | int option = 0; | 1280 | int option = 0; |
| @@ -1281,11 +1320,12 @@ process_arguments (int argc, char **argv) | |||
| 1281 | {"max-redirs", required_argument, 0, MAX_REDIRS_OPTION}, | 1320 | {"max-redirs", required_argument, 0, MAX_REDIRS_OPTION}, |
| 1282 | {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, | 1321 | {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, |
| 1283 | {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION}, | 1322 | {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION}, |
| 1323 | {"cookie-jar", required_argument, 0, COOKIE_JAR}, | ||
| 1284 | {0, 0, 0, 0} | 1324 | {0, 0, 0, 0} |
| 1285 | }; | 1325 | }; |
| 1286 | 1326 | ||
| 1287 | if (argc < 2) | 1327 | if (argc < 2) |
| 1288 | return ERROR; | 1328 | return false; |
| 1289 | 1329 | ||
| 1290 | /* support check_http compatible arguments */ | 1330 | /* support check_http compatible arguments */ |
| 1291 | for (c = 1; c < argc; c++) { | 1331 | for (c = 1; c < argc; c++) { |
| @@ -1365,7 +1405,7 @@ process_arguments (int argc, char **argv) | |||
| 1365 | if( strtol(optarg, NULL, 10) > MAX_PORT) | 1405 | if( strtol(optarg, NULL, 10) > MAX_PORT) |
| 1366 | usage2 (_("Invalid port number, supplied port number is too big"), optarg); | 1406 | usage2 (_("Invalid port number, supplied port number is too big"), optarg); |
| 1367 | server_port = (unsigned short)strtol(optarg, NULL, 10); | 1407 | server_port = (unsigned short)strtol(optarg, NULL, 10); |
| 1368 | specify_port = TRUE; | 1408 | specify_port = true; |
| 1369 | } | 1409 | } |
| 1370 | break; | 1410 | break; |
| 1371 | case 'a': /* authorization info */ | 1411 | case 'a': /* authorization info */ |
| @@ -1399,10 +1439,10 @@ process_arguments (int argc, char **argv) | |||
| 1399 | http_opt_headers[http_opt_headers_count - 1] = optarg; | 1439 | http_opt_headers[http_opt_headers_count - 1] = optarg; |
| 1400 | break; | 1440 | break; |
| 1401 | case 'L': /* show html link */ | 1441 | case 'L': /* show html link */ |
| 1402 | display_html = TRUE; | 1442 | display_html = true; |
| 1403 | break; | 1443 | break; |
| 1404 | case 'n': /* do not show html link */ | 1444 | case 'n': /* do not show html link */ |
| 1405 | display_html = FALSE; | 1445 | display_html = false; |
| 1406 | break; | 1446 | break; |
| 1407 | case 'C': /* Check SSL cert validity */ | 1447 | case 'C': /* Check SSL cert validity */ |
| 1408 | #ifdef LIBCURL_FEATURE_SSL | 1448 | #ifdef LIBCURL_FEATURE_SSL |
| @@ -1423,12 +1463,12 @@ process_arguments (int argc, char **argv) | |||
| 1423 | usage2 (_("Invalid certificate expiration period"), optarg); | 1463 | usage2 (_("Invalid certificate expiration period"), optarg); |
| 1424 | days_till_exp_warn = atoi (optarg); | 1464 | days_till_exp_warn = atoi (optarg); |
| 1425 | } | 1465 | } |
| 1426 | check_cert = TRUE; | 1466 | check_cert = true; |
| 1427 | goto enable_ssl; | 1467 | goto enable_ssl; |
| 1428 | #endif | 1468 | #endif |
| 1429 | case CONTINUE_AFTER_CHECK_CERT: /* don't stop after the certificate is checked */ | 1469 | case CONTINUE_AFTER_CHECK_CERT: /* don't stop after the certificate is checked */ |
| 1430 | #ifdef HAVE_SSL | 1470 | #ifdef HAVE_SSL |
| 1431 | continue_after_check_cert = TRUE; | 1471 | continue_after_check_cert = true; |
| 1432 | break; | 1472 | break; |
| 1433 | #endif | 1473 | #endif |
| 1434 | case 'J': /* use client certificate */ | 1474 | case 'J': /* use client certificate */ |
| @@ -1451,13 +1491,13 @@ process_arguments (int argc, char **argv) | |||
| 1451 | #endif | 1491 | #endif |
| 1452 | #ifdef LIBCURL_FEATURE_SSL | 1492 | #ifdef LIBCURL_FEATURE_SSL |
| 1453 | case 'D': /* verify peer certificate & host */ | 1493 | case 'D': /* verify peer certificate & host */ |
| 1454 | verify_peer_and_host = TRUE; | 1494 | verify_peer_and_host = true; |
| 1455 | break; | 1495 | break; |
| 1456 | #endif | 1496 | #endif |
| 1457 | case 'S': /* use SSL */ | 1497 | case 'S': /* use SSL */ |
| 1458 | #ifdef LIBCURL_FEATURE_SSL | 1498 | #ifdef LIBCURL_FEATURE_SSL |
| 1459 | enable_ssl: | 1499 | enable_ssl: |
| 1460 | use_ssl = TRUE; | 1500 | use_ssl = true; |
| 1461 | /* ssl_version initialized to CURL_SSLVERSION_DEFAULT as a default. | 1501 | /* ssl_version initialized to CURL_SSLVERSION_DEFAULT as a default. |
| 1462 | * Only set if it's non-zero. This helps when we include multiple | 1502 | * Only set if it's non-zero. This helps when we include multiple |
| 1463 | * parameters, like -S and -C combinations */ | 1503 | * parameters, like -S and -C combinations */ |
| @@ -1531,15 +1571,15 @@ process_arguments (int argc, char **argv) | |||
| 1531 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 54, 0) */ | 1571 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 54, 0) */ |
| 1532 | if (verbose >= 2) | 1572 | if (verbose >= 2) |
| 1533 | printf(_("* Set SSL/TLS version to %d\n"), ssl_version); | 1573 | printf(_("* Set SSL/TLS version to %d\n"), ssl_version); |
| 1534 | if (specify_port == FALSE) | 1574 | if (!specify_port) |
| 1535 | server_port = HTTPS_PORT; | 1575 | server_port = HTTPS_PORT; |
| 1536 | break; | 1576 | break; |
| 1537 | #else /* LIBCURL_FEATURE_SSL */ | 1577 | #else /* LIBCURL_FEATURE_SSL */ |
| 1538 | /* -C -J and -K fall through to here without SSL */ | 1578 | /* -C -J and -K fall through to here without SSL */ |
| 1539 | usage4 (_("Invalid option - SSL is not available")); | 1579 | usage4 (_("Invalid option - SSL is not available")); |
| 1540 | break; | 1580 | break; |
| 1541 | case SNI_OPTION: /* --sni is parsed, but ignored, the default is TRUE with libcurl */ | 1581 | case SNI_OPTION: /* --sni is parsed, but ignored, the default is true with libcurl */ |
| 1542 | use_sni = TRUE; | 1582 | use_sni = true; |
| 1543 | break; | 1583 | break; |
| 1544 | #endif /* LIBCURL_FEATURE_SSL */ | 1584 | #endif /* LIBCURL_FEATURE_SSL */ |
| 1545 | case MAX_REDIRS_OPTION: | 1585 | case MAX_REDIRS_OPTION: |
| @@ -1600,11 +1640,11 @@ process_arguments (int argc, char **argv) | |||
| 1600 | if (errcode != 0) { | 1640 | if (errcode != 0) { |
| 1601 | (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); | 1641 | (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); |
| 1602 | printf (_("Could Not Compile Regular Expression: %s"), errbuf); | 1642 | printf (_("Could Not Compile Regular Expression: %s"), errbuf); |
| 1603 | return ERROR; | 1643 | return false; |
| 1604 | } | 1644 | } |
| 1605 | break; | 1645 | break; |
| 1606 | case INVERT_REGEX: | 1646 | case INVERT_REGEX: |
| 1607 | invert_regex = 1; | 1647 | invert_regex = true; |
| 1608 | break; | 1648 | break; |
| 1609 | case '4': | 1649 | case '4': |
| 1610 | address_family = AF_INET; | 1650 | address_family = AF_INET; |
| @@ -1639,7 +1679,7 @@ process_arguments (int argc, char **argv) | |||
| 1639 | break; | 1679 | break; |
| 1640 | } | 1680 | } |
| 1641 | case 'N': /* no-body */ | 1681 | case 'N': /* no-body */ |
| 1642 | no_body = TRUE; | 1682 | no_body = true; |
| 1643 | break; | 1683 | break; |
| 1644 | case 'M': /* max-age */ | 1684 | case 'M': /* max-age */ |
| 1645 | { | 1685 | { |
| @@ -1662,10 +1702,10 @@ process_arguments (int argc, char **argv) | |||
| 1662 | } | 1702 | } |
| 1663 | break; | 1703 | break; |
| 1664 | case 'E': /* show extended perfdata */ | 1704 | case 'E': /* show extended perfdata */ |
| 1665 | show_extended_perfdata = TRUE; | 1705 | show_extended_perfdata = true; |
| 1666 | break; | 1706 | break; |
| 1667 | case 'B': /* print body content after status line */ | 1707 | case 'B': /* print body content after status line */ |
| 1668 | show_body = TRUE; | 1708 | show_body = true; |
| 1669 | break; | 1709 | break; |
| 1670 | case HTTP_VERSION_OPTION: | 1710 | case HTTP_VERSION_OPTION: |
| 1671 | curl_http_version = CURL_HTTP_VERSION_NONE; | 1711 | curl_http_version = CURL_HTTP_VERSION_NONE; |
| @@ -1685,7 +1725,10 @@ process_arguments (int argc, char **argv) | |||
| 1685 | } | 1725 | } |
| 1686 | break; | 1726 | break; |
| 1687 | case AUTOMATIC_DECOMPRESSION: | 1727 | case AUTOMATIC_DECOMPRESSION: |
| 1688 | automatic_decompression = TRUE; | 1728 | automatic_decompression = true; |
| 1729 | break; | ||
| 1730 | case COOKIE_JAR: | ||
| 1731 | cookie_jar_file = optarg; | ||
| 1689 | break; | 1732 | break; |
| 1690 | case '?': | 1733 | case '?': |
| 1691 | /* print short usage statement if args not parsable */ | 1734 | /* print short usage statement if args not parsable */ |
| @@ -1726,52 +1769,52 @@ process_arguments (int argc, char **argv) | |||
| 1726 | virtual_port = server_port; | 1769 | virtual_port = server_port; |
| 1727 | else { | 1770 | else { |
| 1728 | if ((use_ssl && server_port == HTTPS_PORT) || (!use_ssl && server_port == HTTP_PORT)) | 1771 | if ((use_ssl && server_port == HTTPS_PORT) || (!use_ssl && server_port == HTTP_PORT)) |
| 1729 | if(specify_port == FALSE) | 1772 | if(!specify_port) |
| 1730 | server_port = virtual_port; | 1773 | server_port = virtual_port; |
| 1731 | } | 1774 | } |
| 1732 | 1775 | ||
| 1733 | return TRUE; | 1776 | return true; |
| 1734 | } | 1777 | } |
| 1735 | 1778 | ||
| 1736 | char *perfd_time (double elapsed_time) | 1779 | char *perfd_time (double elapsed_time) |
| 1737 | { | 1780 | { |
| 1738 | return fperfdata ("time", elapsed_time, "s", | 1781 | return fperfdata ("time", elapsed_time, "s", |
| 1739 | thlds->warning?TRUE:FALSE, thlds->warning?thlds->warning->end:0, | 1782 | thlds->warning?true:false, thlds->warning?thlds->warning->end:0, |
| 1740 | thlds->critical?TRUE:FALSE, thlds->critical?thlds->critical->end:0, | 1783 | thlds->critical?true:false, thlds->critical?thlds->critical->end:0, |
| 1741 | TRUE, 0, TRUE, socket_timeout); | 1784 | true, 0, true, socket_timeout); |
| 1742 | } | 1785 | } |
| 1743 | 1786 | ||
| 1744 | char *perfd_time_connect (double elapsed_time_connect) | 1787 | char *perfd_time_connect (double elapsed_time_connect) |
| 1745 | { | 1788 | { |
| 1746 | return fperfdata ("time_connect", elapsed_time_connect, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | 1789 | return fperfdata ("time_connect", elapsed_time_connect, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
| 1747 | } | 1790 | } |
| 1748 | 1791 | ||
| 1749 | char *perfd_time_ssl (double elapsed_time_ssl) | 1792 | char *perfd_time_ssl (double elapsed_time_ssl) |
| 1750 | { | 1793 | { |
| 1751 | return fperfdata ("time_ssl", elapsed_time_ssl, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | 1794 | return fperfdata ("time_ssl", elapsed_time_ssl, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
| 1752 | } | 1795 | } |
| 1753 | 1796 | ||
| 1754 | char *perfd_time_headers (double elapsed_time_headers) | 1797 | char *perfd_time_headers (double elapsed_time_headers) |
| 1755 | { | 1798 | { |
| 1756 | return fperfdata ("time_headers", elapsed_time_headers, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | 1799 | return fperfdata ("time_headers", elapsed_time_headers, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
| 1757 | } | 1800 | } |
| 1758 | 1801 | ||
| 1759 | char *perfd_time_firstbyte (double elapsed_time_firstbyte) | 1802 | char *perfd_time_firstbyte (double elapsed_time_firstbyte) |
| 1760 | { | 1803 | { |
| 1761 | return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | 1804 | return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
| 1762 | } | 1805 | } |
| 1763 | 1806 | ||
| 1764 | char *perfd_time_transfer (double elapsed_time_transfer) | 1807 | char *perfd_time_transfer (double elapsed_time_transfer) |
| 1765 | { | 1808 | { |
| 1766 | return fperfdata ("time_transfer", elapsed_time_transfer, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | 1809 | return fperfdata ("time_transfer", elapsed_time_transfer, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
| 1767 | } | 1810 | } |
| 1768 | 1811 | ||
| 1769 | char *perfd_size (int page_len) | 1812 | char *perfd_size (int page_len) |
| 1770 | { | 1813 | { |
| 1771 | return perfdata ("size", page_len, "B", | 1814 | return perfdata ("size", page_len, "B", |
| 1772 | (min_page_len>0?TRUE:FALSE), min_page_len, | 1815 | (min_page_len>0?true:false), min_page_len, |
| 1773 | (min_page_len>0?TRUE:FALSE), 0, | 1816 | (min_page_len>0?true:false), 0, |
| 1774 | TRUE, 0, FALSE, 0); | 1817 | true, 0, false, 0); |
| 1775 | } | 1818 | } |
| 1776 | 1819 | ||
| 1777 | void | 1820 | void |
| @@ -1906,6 +1949,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)")); | 1949 | 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"); | 1950 | printf (" %s\n", "--enable-automatic-decompression"); |
| 1908 | printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING).")); | 1951 | printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING).")); |
| 1952 | printf (" %s\n", "---cookie-jar=FILE"); | ||
| 1953 | printf (" %s\n", _("Store cookies in the cookie jar and send them out when requested.")); | ||
| 1909 | printf ("\n"); | 1954 | printf ("\n"); |
| 1910 | 1955 | ||
| 1911 | printf (UT_WARN_CRIT); | 1956 | printf (UT_WARN_CRIT); |
| @@ -1990,7 +2035,8 @@ print_usage (void) | |||
| 1990 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); | 2035 | 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"); | 2036 | printf (" [-A string] [-k string] [-S <version>] [--sni]\n"); |
| 1992 | printf (" [-T <content-type>] [-j method]\n"); | 2037 | printf (" [-T <content-type>] [-j method]\n"); |
| 1993 | printf (" [--http-version=<version>]\n"); | 2038 | printf (" [--http-version=<version>] [--enable-automatic-decompression]\n"); |
| 2039 | printf (" [--cookie-jar=<cookie jar file>\n"); | ||
| 1994 | printf (" %s -H <vhost> | -I <IP-address> -C <warn_age>[,<crit_age>]\n",progname); | 2040 | printf (" %s -H <vhost> | -I <IP-address> -C <warn_age>[,<crit_age>]\n",progname); |
| 1995 | printf (" [-p <port>] [-t <timeout>] [-4|-6] [--sni]\n"); | 2041 | printf (" [-p <port>] [-t <timeout>] [-4|-6] [--sni]\n"); |
| 1996 | printf ("\n"); | 2042 | printf ("\n"); |
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 6de17f86..bd84c825 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'}, |
| @@ -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) |
| @@ -1056,7 +1126,7 @@ 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) { |
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_disk.t b/plugins/t/check_disk.t index ec527e7f..c8f08f51 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( |
| @@ -351,3 +351,28 @@ unlike( $result->output, qr/$mountpoint2_valid/, "output data does not have $mou | |||
| 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 | ||
