diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-07-14 23:35:52 +0200 |
---|---|---|
committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-07-14 23:35:52 +0200 |
commit | e570ce63634b57573aa84b12d84e7651d466a761 (patch) | |
tree | 6fb8bede4e3c60ef2be43c5630675c5d6275d180 | |
parent | e855107eeb882d25ce777562d16886ea9aa2633e (diff) | |
download | monitoring-plugins-e570ce63634b57573aa84b12d84e7651d466a761.tar.gz |
check_curl: various small improvements
-rw-r--r-- | plugins/check_curl.c | 134 | ||||
-rw-r--r-- | plugins/check_curl.d/config.h | 12 |
2 files changed, 74 insertions, 72 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 5b8a06be..88c5f3e7 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
@@ -53,7 +53,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
53 | #include "curl/curl.h" | 53 | #include "curl/curl.h" |
54 | #include "curl/easy.h" | 54 | #include "curl/easy.h" |
55 | 55 | ||
56 | #include "picohttpparser.h" | 56 | #include "./picohttpparser/picohttpparser.h" |
57 | 57 | ||
58 | #include "uriparser/Uri.h" | 58 | #include "uriparser/Uri.h" |
59 | 59 | ||
@@ -164,7 +164,7 @@ static char *perfd_time_ssl(double elapsed_time_ssl, long /*socket_timeout*/); | |||
164 | static char *perfd_time_firstbyte(double elapsed_time_firstbyte, long /*socket_timeout*/); | 164 | static char *perfd_time_firstbyte(double elapsed_time_firstbyte, long /*socket_timeout*/); |
165 | static char *perfd_time_headers(double elapsed_time_headers, long /*socket_timeout*/); | 165 | static char *perfd_time_headers(double elapsed_time_headers, long /*socket_timeout*/); |
166 | static char *perfd_time_transfer(double elapsed_time_transfer, long /*socket_timeout*/); | 166 | static char *perfd_time_transfer(double elapsed_time_transfer, long /*socket_timeout*/); |
167 | static char *perfd_size(int page_len, int /*min_page_len*/); | 167 | static char *perfd_size(size_t page_len, int /*min_page_len*/); |
168 | static void print_help(void); | 168 | static void print_help(void); |
169 | void print_usage(void); | 169 | void print_usage(void); |
170 | static void print_curl_version(void); | 170 | static void print_curl_version(void); |
@@ -185,10 +185,10 @@ static int curlhelp_parse_statusline(const char * /*buf*/, curlhelp_statusline * | |||
185 | static void curlhelp_free_statusline(curlhelp_statusline * /*status_line*/); | 185 | static void curlhelp_free_statusline(curlhelp_statusline * /*status_line*/); |
186 | static char *get_header_value(const struct phr_header *headers, size_t nof_headers, | 186 | static char *get_header_value(const struct phr_header *headers, size_t nof_headers, |
187 | const char *header); | 187 | const char *header); |
188 | static int check_document_dates(const curlhelp_write_curlbuf * /*header_buf*/, | 188 | static mp_state_enum check_document_dates(const curlhelp_write_curlbuf * /*header_buf*/, |
189 | char (*msg)[DEFAULT_BUFFER_SIZE], int /*maximum_age*/); | 189 | char (*msg)[DEFAULT_BUFFER_SIZE], int /*maximum_age*/); |
190 | static int get_content_length(const curlhelp_write_curlbuf *header_buf, | 190 | static size_t get_content_length(const curlhelp_write_curlbuf *header_buf, |
191 | const curlhelp_write_curlbuf *body_buf); | 191 | const curlhelp_write_curlbuf *body_buf); |
192 | 192 | ||
193 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) | 193 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) |
194 | int np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_warn, int days_till_exp_crit); | 194 | int np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_warn, int days_till_exp_crit); |
@@ -213,7 +213,7 @@ int main(int argc, char **argv) { | |||
213 | const check_curl_config config = tmp_config.config; | 213 | const check_curl_config config = tmp_config.config; |
214 | 214 | ||
215 | /* set defaults */ | 215 | /* set defaults */ |
216 | if (config.user_agent == NULL) { | 216 | if (strlen(config.user_agent) == 0) { |
217 | snprintf(config.user_agent, DEFAULT_BUFFER_SIZE, "%s/v%s (monitoring-plugins %s, %s)", | 217 | snprintf(config.user_agent, DEFAULT_BUFFER_SIZE, "%s/v%s (monitoring-plugins %s, %s)", |
218 | progname, NP_VERSION, VERSION, curl_version()); | 218 | progname, NP_VERSION, VERSION, curl_version()); |
219 | } | 219 | } |
@@ -224,7 +224,7 @@ int main(int argc, char **argv) { | |||
224 | config.virtual_port ? config.virtual_port : config.server_port, config.server_url); | 224 | config.virtual_port ? config.virtual_port : config.server_port, config.server_url); |
225 | } | 225 | } |
226 | 226 | ||
227 | exit(check_http(config)); | 227 | exit((int)check_http(config)); |
228 | } | 228 | } |
229 | 229 | ||
230 | #ifdef HAVE_SSL | 230 | #ifdef HAVE_SSL |
@@ -297,7 +297,7 @@ static char *string_statuscode(int major, int minor) { | |||
297 | } | 297 | } |
298 | 298 | ||
299 | /* Checks if the server 'reply' is one of the expected 'statuscodes' */ | 299 | /* Checks if the server 'reply' is one of the expected 'statuscodes' */ |
300 | static int expected_statuscode(const char *reply, const char *statuscodes) { | 300 | static bool expected_statuscode(const char *reply, const char *statuscodes) { |
301 | char *expected; | 301 | char *expected; |
302 | 302 | ||
303 | if ((expected = strdup(statuscodes)) == NULL) { | 303 | if ((expected = strdup(statuscodes)) == NULL) { |
@@ -305,10 +305,10 @@ static int expected_statuscode(const char *reply, const char *statuscodes) { | |||
305 | } | 305 | } |
306 | 306 | ||
307 | char *code; | 307 | char *code; |
308 | int result = 0; | 308 | bool result = false; |
309 | for (code = strtok(expected, ","); code != NULL; code = strtok(NULL, ",")) { | 309 | for (code = strtok(expected, ","); code != NULL; code = strtok(NULL, ",")) { |
310 | if (strstr(reply, code) != NULL) { | 310 | if (strstr(reply, code) != NULL) { |
311 | result = 1; | 311 | result = true; |
312 | break; | 312 | break; |
313 | } | 313 | } |
314 | } | 314 | } |
@@ -432,7 +432,7 @@ mp_state_enum check_http(check_curl_config config) { | |||
432 | handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_STDERR, stdout), | 432 | handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_STDERR, stdout), |
433 | "CURLOPT_STDERR"); | 433 | "CURLOPT_STDERR"); |
434 | 434 | ||
435 | if (config.automatic_decompression) | 435 | if (config.automatic_decompression) { |
436 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 21, 6) | 436 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 21, 6) |
437 | handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, ""), | 437 | handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, ""), |
438 | "CURLOPT_ACCEPT_ENCODING"); | 438 | "CURLOPT_ACCEPT_ENCODING"); |
@@ -440,6 +440,7 @@ mp_state_enum check_http(check_curl_config config) { | |||
440 | handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_ENCODING, ""), | 440 | handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_ENCODING, ""), |
441 | "CURLOPT_ENCODING"); | 441 | "CURLOPT_ENCODING"); |
442 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 21, 6) */ | 442 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 21, 6) */ |
443 | } | ||
443 | 444 | ||
444 | /* initialize buffer for body of the answer */ | 445 | /* initialize buffer for body of the answer */ |
445 | if (curlhelp_initwritebuffer(&body_buf) < 0) { | 446 | if (curlhelp_initwritebuffer(&body_buf) < 0) { |
@@ -448,7 +449,7 @@ mp_state_enum check_http(check_curl_config config) { | |||
448 | body_buf_initialized = true; | 449 | body_buf_initialized = true; |
449 | handle_curl_option_return_code( | 450 | handle_curl_option_return_code( |
450 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, | 451 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, |
451 | (curl_write_callback)curlhelp_buffer_write_callback), | 452 | curlhelp_buffer_write_callback), |
452 | "CURLOPT_WRITEFUNCTION"); | 453 | "CURLOPT_WRITEFUNCTION"); |
453 | handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&body_buf), | 454 | handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&body_buf), |
454 | "CURLOPT_WRITEDATA"); | 455 | "CURLOPT_WRITEDATA"); |
@@ -460,7 +461,7 @@ mp_state_enum check_http(check_curl_config config) { | |||
460 | header_buf_initialized = true; | 461 | header_buf_initialized = true; |
461 | handle_curl_option_return_code( | 462 | handle_curl_option_return_code( |
462 | curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, | 463 | curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, |
463 | (curl_write_callback)curlhelp_buffer_write_callback), | 464 | curlhelp_buffer_write_callback), |
464 | "CURLOPT_HEADERFUNCTION"); | 465 | "CURLOPT_HEADERFUNCTION"); |
465 | handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_WRITEHEADER, (void *)&header_buf), | 466 | handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_WRITEHEADER, (void *)&header_buf), |
466 | "CURLOPT_WRITEHEADER"); | 467 | "CURLOPT_WRITEHEADER"); |
@@ -488,7 +489,7 @@ mp_state_enum check_http(check_curl_config config) { | |||
488 | char dnscache[DEFAULT_BUFFER_SIZE]; | 489 | char dnscache[DEFAULT_BUFFER_SIZE]; |
489 | char addrstr[DEFAULT_BUFFER_SIZE / 2]; | 490 | char addrstr[DEFAULT_BUFFER_SIZE / 2]; |
490 | if (config.use_ssl && config.host_name != NULL) { | 491 | if (config.use_ssl && config.host_name != NULL) { |
491 | CURLcode res; | 492 | int res; |
492 | if ((res = lookup_host(config.server_address, addrstr, DEFAULT_BUFFER_SIZE / 2)) != 0) { | 493 | if ((res = lookup_host(config.server_address, addrstr, DEFAULT_BUFFER_SIZE / 2)) != 0) { |
493 | snprintf(msg, DEFAULT_BUFFER_SIZE, | 494 | snprintf(msg, DEFAULT_BUFFER_SIZE, |
494 | _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"), | 495 | _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"), |
@@ -572,14 +573,15 @@ mp_state_enum check_http(check_curl_config config) { | |||
572 | char *force_host_header = NULL; | 573 | char *force_host_header = NULL; |
573 | /* check if Host header is explicitly set in options */ | 574 | /* check if Host header is explicitly set in options */ |
574 | if (config.http_opt_headers_count) { | 575 | if (config.http_opt_headers_count) { |
575 | for (int i = 0; i < config.http_opt_headers_count; i++) { | 576 | for (size_t i = 0; i < config.http_opt_headers_count; i++) { |
576 | if (strncmp(config.http_opt_headers[i], "Host:", 5) == 0) { | 577 | if (strncmp(config.http_opt_headers[i], "Host:", 5) == 0) { |
577 | force_host_header = config.http_opt_headers[i]; | 578 | force_host_header = config.http_opt_headers[i]; |
578 | } | 579 | } |
579 | } | 580 | } |
580 | } | 581 | } |
581 | 582 | ||
582 | /* set hostname (virtual hosts), not needed if CURLOPT_CONNECT_TO is used, but left in anyway */ | 583 | /* set hostname (virtual hosts), not needed if CURLOPT_CONNECT_TO is used, but left in |
584 | * anyway */ | ||
583 | char http_header[DEFAULT_BUFFER_SIZE]; | 585 | char http_header[DEFAULT_BUFFER_SIZE]; |
584 | if (config.host_name != NULL && force_host_header == NULL) { | 586 | if (config.host_name != NULL && force_host_header == NULL) { |
585 | if ((config.virtual_port != HTTP_PORT && !config.use_ssl) || | 587 | if ((config.virtual_port != HTTP_PORT && !config.use_ssl) || |
@@ -599,7 +601,7 @@ mp_state_enum check_http(check_curl_config config) { | |||
599 | /* attach additional headers supplied by the user */ | 601 | /* attach additional headers supplied by the user */ |
600 | /* optionally send any other header tag */ | 602 | /* optionally send any other header tag */ |
601 | if (config.http_opt_headers_count) { | 603 | if (config.http_opt_headers_count) { |
602 | for (int i = 0; i < config.http_opt_headers_count; i++) { | 604 | for (size_t i = 0; i < config.http_opt_headers_count; i++) { |
603 | header_list = curl_slist_append(header_list, config.http_opt_headers[i]); | 605 | header_list = curl_slist_append(header_list, config.http_opt_headers[i]); |
604 | } | 606 | } |
605 | /* This cannot be free'd here because a redirection will then try to access this and | 607 | /* This cannot be free'd here because a redirection will then try to access this and |
@@ -794,8 +796,8 @@ mp_state_enum check_http(check_curl_config config) { | |||
794 | CURLOPT_POSTREDIR: method switch | 796 | CURLOPT_POSTREDIR: method switch |
795 | CURLINFO_REDIRECT_URL: custom redirect option | 797 | CURLINFO_REDIRECT_URL: custom redirect option |
796 | CURLOPT_REDIRECT_PROTOCOLS: allow people to step outside safe protocols | 798 | CURLOPT_REDIRECT_PROTOCOLS: allow people to step outside safe protocols |
797 | CURLINFO_REDIRECT_COUNT: get the number of redirects, print it, maybe a range option | 799 | CURLINFO_REDIRECT_COUNT: get the number of redirects, print it, maybe a range |
798 | here is nice like for expected page size? | 800 | option here is nice like for expected page size? |
799 | */ | 801 | */ |
800 | } else { | 802 | } else { |
801 | /* old style redirection is handled below */ | 803 | /* old style redirection is handled below */ |
@@ -863,8 +865,8 @@ mp_state_enum check_http(check_curl_config config) { | |||
863 | 865 | ||
864 | /* cookie handling */ | 866 | /* cookie handling */ |
865 | if (config.cookie_jar_file != NULL) { | 867 | if (config.cookie_jar_file != NULL) { |
866 | /* enable reading cookies from a file, and if the filename is an empty string, only enable | 868 | /* enable reading cookies from a file, and if the filename is an empty string, only |
867 | * the curl cookie engine */ | 869 | * enable the curl cookie engine */ |
868 | handle_curl_option_return_code( | 870 | handle_curl_option_return_code( |
869 | curl_easy_setopt(curl, CURLOPT_COOKIEFILE, config.cookie_jar_file), | 871 | curl_easy_setopt(curl, CURLOPT_COOKIEFILE, config.cookie_jar_file), |
870 | "CURLOPT_COOKIEFILE"); | 872 | "CURLOPT_COOKIEFILE"); |
@@ -902,7 +904,7 @@ mp_state_enum check_http(check_curl_config config) { | |||
902 | die(STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | 904 | die(STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); |
903 | } | 905 | } |
904 | 906 | ||
905 | int result_ssl = STATE_OK; | 907 | mp_state_enum result_ssl = STATE_OK; |
906 | /* certificate checks */ | 908 | /* certificate checks */ |
907 | #ifdef LIBCURL_FEATURE_SSL | 909 | #ifdef LIBCURL_FEATURE_SSL |
908 | if (config.use_ssl) { | 910 | if (config.use_ssl) { |
@@ -928,8 +930,9 @@ mp_state_enum check_http(check_curl_config config) { | |||
928 | res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &cert_ptr.to_info); | 930 | res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &cert_ptr.to_info); |
929 | if (!res && cert_ptr.to_info) { | 931 | if (!res && cert_ptr.to_info) { |
930 | # ifdef USE_OPENSSL | 932 | # ifdef USE_OPENSSL |
931 | /* We have no OpenSSL in libcurl, but we can use OpenSSL for X509 cert parsing | 933 | /* We have no OpenSSL in libcurl, but we can use OpenSSL for X509 cert |
932 | * We only check the first certificate and assume it's the one of the server | 934 | * parsing We only check the first certificate and assume it's the one of |
935 | * the server | ||
933 | */ | 936 | */ |
934 | const char *raw_cert = NULL; | 937 | const char *raw_cert = NULL; |
935 | for (int i = 0; i < cert_ptr.to_certinfo->num_of_certs; i++) { | 938 | for (int i = 0; i < cert_ptr.to_certinfo->num_of_certs; i++) { |
@@ -952,7 +955,7 @@ mp_state_enum check_http(check_curl_config config) { | |||
952 | die(STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | 955 | die(STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); |
953 | } | 956 | } |
954 | BIO *cert_BIO = BIO_new(BIO_s_mem()); | 957 | BIO *cert_BIO = BIO_new(BIO_s_mem()); |
955 | BIO_write(cert_BIO, raw_cert, strlen(raw_cert)); | 958 | BIO_write(cert_BIO, raw_cert, (int)strlen(raw_cert)); |
956 | cert = PEM_read_bio_X509(cert_BIO, NULL, NULL, NULL); | 959 | cert = PEM_read_bio_X509(cert_BIO, NULL, NULL, NULL); |
957 | if (!cert) { | 960 | if (!cert) { |
958 | snprintf( | 961 | snprintf( |
@@ -993,7 +996,7 @@ mp_state_enum check_http(check_curl_config config) { | |||
993 | double total_time; | 996 | double total_time; |
994 | handle_curl_option_return_code(curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time), | 997 | handle_curl_option_return_code(curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time), |
995 | "CURLINFO_TOTAL_TIME"); | 998 | "CURLINFO_TOTAL_TIME"); |
996 | int page_len = get_content_length(&header_buf, &body_buf); | 999 | size_t page_len = get_content_length(&header_buf, &body_buf); |
997 | char perfstring[DEFAULT_BUFFER_SIZE]; | 1000 | char perfstring[DEFAULT_BUFFER_SIZE]; |
998 | if (config.show_extended_perfdata) { | 1001 | if (config.show_extended_perfdata) { |
999 | double time_connect; | 1002 | double time_connect; |
@@ -1038,7 +1041,8 @@ mp_state_enum check_http(check_curl_config config) { | |||
1038 | snprintf(msg, DEFAULT_BUFFER_SIZE, | 1041 | snprintf(msg, DEFAULT_BUFFER_SIZE, |
1039 | "Unparsable status line in %.3g seconds response time|%s\n", total_time, | 1042 | "Unparsable status line in %.3g seconds response time|%s\n", total_time, |
1040 | perfstring); | 1043 | perfstring); |
1041 | /* we cannot know the major/minor version here for sure as we cannot parse the first line */ | 1044 | /* we cannot know the major/minor version here for sure as we cannot parse the first |
1045 | * line */ | ||
1042 | die(STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg); | 1046 | die(STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg); |
1043 | } | 1047 | } |
1044 | status_line_initialized = true; | 1048 | status_line_initialized = true; |
@@ -1070,7 +1074,7 @@ mp_state_enum check_http(check_curl_config config) { | |||
1070 | config.show_body ? body_buf.buf : ""); | 1074 | config.show_body ? body_buf.buf : ""); |
1071 | } | 1075 | } |
1072 | 1076 | ||
1073 | int result = STATE_OK; | 1077 | mp_state_enum result = STATE_OK; |
1074 | if (config.server_expect_yn) { | 1078 | if (config.server_expect_yn) { |
1075 | snprintf(msg, DEFAULT_BUFFER_SIZE, _("Status line output matched \"%s\" - "), | 1079 | snprintf(msg, DEFAULT_BUFFER_SIZE, _("Status line output matched \"%s\" - "), |
1076 | config.server_expect); | 1080 | config.server_expect); |
@@ -1225,7 +1229,7 @@ mp_state_enum check_http(check_curl_config config) { | |||
1225 | if ((config.max_page_len > 0) && (page_len > config.max_page_len)) { | 1229 | if ((config.max_page_len > 0) && (page_len > config.max_page_len)) { |
1226 | char tmp[DEFAULT_BUFFER_SIZE]; | 1230 | char tmp[DEFAULT_BUFFER_SIZE]; |
1227 | 1231 | ||
1228 | snprintf(tmp, DEFAULT_BUFFER_SIZE, _("%spage size %d too large, "), msg, page_len); | 1232 | snprintf(tmp, DEFAULT_BUFFER_SIZE, _("%spage size %zu too large, "), msg, page_len); |
1229 | 1233 | ||
1230 | strcpy(msg, tmp); | 1234 | strcpy(msg, tmp); |
1231 | 1235 | ||
@@ -1234,7 +1238,7 @@ mp_state_enum check_http(check_curl_config config) { | |||
1234 | } else if ((config.min_page_len > 0) && (page_len < config.min_page_len)) { | 1238 | } else if ((config.min_page_len > 0) && (page_len < config.min_page_len)) { |
1235 | char tmp[DEFAULT_BUFFER_SIZE]; | 1239 | char tmp[DEFAULT_BUFFER_SIZE]; |
1236 | 1240 | ||
1237 | snprintf(tmp, DEFAULT_BUFFER_SIZE, _("%spage size %d too small, "), msg, page_len); | 1241 | snprintf(tmp, DEFAULT_BUFFER_SIZE, _("%spage size %zu too small, "), msg, page_len); |
1238 | strcpy(msg, tmp); | 1242 | strcpy(msg, tmp); |
1239 | result = max_state_alt(STATE_WARNING, result); | 1243 | result = max_state_alt(STATE_WARNING, result); |
1240 | } | 1244 | } |
@@ -1253,8 +1257,8 @@ mp_state_enum check_http(check_curl_config config) { | |||
1253 | 1257 | ||
1254 | /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), | 1258 | /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), |
1255 | * msg); */ | 1259 | * msg); */ |
1256 | die(max_state_alt(result, result_ssl), | 1260 | die((int)max_state_alt(result, result_ssl), |
1257 | "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n%s%s", | 1261 | "HTTP %s: %s %d %s%s%s - %zu bytes in %.3f second response time %s|%s\n%s%s", |
1258 | state_text(result), string_statuscode(status_line.http_major, status_line.http_minor), | 1262 | state_text(result), string_statuscode(status_line.http_major, status_line.http_minor), |
1259 | status_line.http_code, status_line.msg, strlen(msg) > 0 ? " - " : "", msg, page_len, | 1263 | status_line.http_code, status_line.msg, strlen(msg) > 0 ? " - " : "", msg, page_len, |
1260 | total_time, (config.display_html ? "</A>" : ""), perfstring, | 1264 | total_time, (config.display_html ? "</A>" : ""), perfstring, |
@@ -1582,7 +1586,7 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) { | |||
1582 | case 'H': /* virtual host */ | 1586 | case 'H': /* virtual host */ |
1583 | result.config.host_name = strdup(optarg); | 1587 | result.config.host_name = strdup(optarg); |
1584 | char *p; | 1588 | char *p; |
1585 | int host_name_length; | 1589 | size_t host_name_length; |
1586 | if (result.config.host_name[0] == '[') { | 1590 | if (result.config.host_name[0] == '[') { |
1587 | if ((p = strstr(result.config.host_name, "]:")) != NULL) { /* [IPv6]:port */ | 1591 | if ((p = strstr(result.config.host_name, "]:")) != NULL) { /* [IPv6]:port */ |
1588 | result.config.virtual_port = atoi(p + 2); | 1592 | result.config.virtual_port = atoi(p + 2); |
@@ -1734,31 +1738,31 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) { | |||
1734 | result.config.ssl_version = CURL_SSLVERSION_SSLv2; | 1738 | result.config.ssl_version = CURL_SSLVERSION_SSLv2; |
1735 | } else if (optarg[0] == '3') { | 1739 | } else if (optarg[0] == '3') { |
1736 | result.config.ssl_version = CURL_SSLVERSION_SSLv3; | 1740 | result.config.ssl_version = CURL_SSLVERSION_SSLv3; |
1737 | } else if (!strcmp(optarg, "1") || !strcmp(optarg, "1.0")) | 1741 | } else if (!strcmp(optarg, "1") || !strcmp(optarg, "1.0")) { |
1738 | # if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) | 1742 | # if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) |
1739 | result.config.ssl_version = CURL_SSLVERSION_TLSv1_0; | 1743 | result.config.ssl_version = CURL_SSLVERSION_TLSv1_0; |
1740 | # else | 1744 | # else |
1741 | result.config.ssl_version = CURL_SSLVERSION_DEFAULT; | 1745 | result.config.ssl_version = CURL_SSLVERSION_DEFAULT; |
1742 | # endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) */ | 1746 | # endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) */ |
1743 | else if (!strcmp(optarg, "1.1")) | 1747 | } else if (!strcmp(optarg, "1.1")) { |
1744 | # if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) | 1748 | # if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) |
1745 | result.config.ssl_version = CURL_SSLVERSION_TLSv1_1; | 1749 | result.config.ssl_version = CURL_SSLVERSION_TLSv1_1; |
1746 | # else | 1750 | # else |
1747 | result.config.ssl_version = CURL_SSLVERSION_DEFAULT; | 1751 | result.config.ssl_version = CURL_SSLVERSION_DEFAULT; |
1748 | # endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) */ | 1752 | # endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) */ |
1749 | else if (!strcmp(optarg, "1.2")) | 1753 | } else if (!strcmp(optarg, "1.2")) { |
1750 | # if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) | 1754 | # if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) |
1751 | result.config.ssl_version = CURL_SSLVERSION_TLSv1_2; | 1755 | result.config.ssl_version = CURL_SSLVERSION_TLSv1_2; |
1752 | # else | 1756 | # else |
1753 | result.config.ssl_version = CURL_SSLVERSION_DEFAULT; | 1757 | result.config.ssl_version = CURL_SSLVERSION_DEFAULT; |
1754 | # endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) */ | 1758 | # endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) */ |
1755 | else if (!strcmp(optarg, "1.3")) | 1759 | } else if (!strcmp(optarg, "1.3")) { |
1756 | # if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 52, 0) | 1760 | # if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 52, 0) |
1757 | result.config.ssl_version = CURL_SSLVERSION_TLSv1_3; | 1761 | result.config.ssl_version = CURL_SSLVERSION_TLSv1_3; |
1758 | # else | 1762 | # else |
1759 | result.config.ssl_version = CURL_SSLVERSION_DEFAULT; | 1763 | result.config.ssl_version = CURL_SSLVERSION_DEFAULT; |
1760 | # endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 52, 0) */ | 1764 | # endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 52, 0) */ |
1761 | else { | 1765 | } else { |
1762 | usage4(_("Invalid option - Valid SSL/TLS versions: 2, 3, 1, 1.1, 1.2, 1.3 " | 1766 | usage4(_("Invalid option - Valid SSL/TLS versions: 2, 3, 1, 1.1, 1.2, 1.3 " |
1763 | "(with optional '+' suffix)")); | 1767 | "(with optional '+' suffix)")); |
1764 | } | 1768 | } |
@@ -1914,7 +1918,7 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) { | |||
1914 | printf("Bad format: try \"-m min:max\"\n"); | 1918 | printf("Bad format: try \"-m min:max\"\n"); |
1915 | exit(STATE_WARNING); | 1919 | exit(STATE_WARNING); |
1916 | } else { | 1920 | } else { |
1917 | result.config.min_page_len = atoi(tmp); | 1921 | result.config.min_page_len = atol(tmp); |
1918 | } | 1922 | } |
1919 | 1923 | ||
1920 | tmp = strtok(NULL, ":"); | 1924 | tmp = strtok(NULL, ":"); |
@@ -1922,10 +1926,10 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) { | |||
1922 | printf("Bad format: try \"-m min:max\"\n"); | 1926 | printf("Bad format: try \"-m min:max\"\n"); |
1923 | exit(STATE_WARNING); | 1927 | exit(STATE_WARNING); |
1924 | } else { | 1928 | } else { |
1925 | result.config.max_page_len = atoi(tmp); | 1929 | result.config.max_page_len = atol(tmp); |
1926 | } | 1930 | } |
1927 | } else { | 1931 | } else { |
1928 | result.config.min_page_len = atoi(optarg); | 1932 | result.config.min_page_len = atol(optarg); |
1929 | } | 1933 | } |
1930 | break; | 1934 | break; |
1931 | } | 1935 | } |
@@ -2042,8 +2046,8 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) { | |||
2042 | } | 2046 | } |
2043 | 2047 | ||
2044 | char *perfd_time(double elapsed_time, thresholds *thlds, long socket_timeout) { | 2048 | char *perfd_time(double elapsed_time, thresholds *thlds, long socket_timeout) { |
2045 | return fperfdata("time", elapsed_time, "s", thlds->warning, | 2049 | return fperfdata("time", elapsed_time, "s", (thlds->warning != NULL), |
2046 | thlds->warning ? thlds->warning->end : 0, thlds->critical, | 2050 | thlds->warning ? thlds->warning->end : 0, (thlds->critical != NULL), |
2047 | thlds->critical ? thlds->critical->end : 0, true, 0, true, socket_timeout); | 2051 | thlds->critical ? thlds->critical->end : 0, true, 0, true, socket_timeout); |
2048 | } | 2052 | } |
2049 | 2053 | ||
@@ -2072,7 +2076,7 @@ char *perfd_time_transfer(double elapsed_time_transfer, long socket_timeout) { | |||
2072 | true, socket_timeout); | 2076 | true, socket_timeout); |
2073 | } | 2077 | } |
2074 | 2078 | ||
2075 | char *perfd_size(int page_len, int min_page_len) { | 2079 | char *perfd_size(size_t page_len, int min_page_len) { |
2076 | return perfdata("size", page_len, "B", (min_page_len > 0), min_page_len, (min_page_len > 0), 0, | 2080 | return perfdata("size", page_len, "B", (min_page_len > 0), min_page_len, (min_page_len > 0), 0, |
2077 | true, 0, false, 0); | 2081 | true, 0, false, 0); |
2078 | } | 2082 | } |
@@ -2120,9 +2124,8 @@ void print_help(void) { | |||
2120 | printf(" %s\n", | 2124 | printf(" %s\n", |
2121 | _("Connect via SSL. Port defaults to 443. VERSION is optional, and prevents")); | 2125 | _("Connect via SSL. Port defaults to 443. VERSION is optional, and prevents")); |
2122 | printf(" %s\n", _("auto-negotiation (2 = SSLv2, 3 = SSLv3, 1 = TLSv1, 1.1 = TLSv1.1,")); | 2126 | printf(" %s\n", _("auto-negotiation (2 = SSLv2, 3 = SSLv3, 1 = TLSv1, 1.1 = TLSv1.1,")); |
2123 | printf( | 2127 | printf(" %s\n", _("1.2 = TLSv1.2, 1.3 = TLSv1.3). With a '+' suffix, newer versions are " |
2124 | " %s\n", | 2128 | "also accepted.")); |
2125 | _("1.2 = TLSv1.2, 1.3 = TLSv1.3). With a '+' suffix, newer versions are also accepted.")); | ||
2126 | printf(" %s\n", _("Note: SSLv2, SSLv3, TLSv1.0 and TLSv1.1 are deprecated and are usually " | 2129 | printf(" %s\n", _("Note: SSLv2, SSLv3, TLSv1.0 and TLSv1.1 are deprecated and are usually " |
2127 | "disabled in libcurl")); | 2130 | "disabled in libcurl")); |
2128 | printf(" %s\n", "--sni"); | 2131 | printf(" %s\n", "--sni"); |
@@ -2205,9 +2208,8 @@ void print_help(void) { | |||
2205 | printf(" %s\n", "-A, --useragent=STRING"); | 2208 | printf(" %s\n", "-A, --useragent=STRING"); |
2206 | printf(" %s\n", _("String to be sent in http header as \"User Agent\"")); | 2209 | printf(" %s\n", _("String to be sent in http header as \"User Agent\"")); |
2207 | printf(" %s\n", "-k, --header=STRING"); | 2210 | printf(" %s\n", "-k, --header=STRING"); |
2208 | printf( | 2211 | printf(" %s\n", _("Any other tags to be sent in http header. Use multiple times for " |
2209 | " %s\n", | 2212 | "additional headers")); |
2210 | _("Any other tags to be sent in http header. Use multiple times for additional headers")); | ||
2211 | printf(" %s\n", "-E, --extended-perfdata"); | 2213 | printf(" %s\n", "-E, --extended-perfdata"); |
2212 | printf(" %s\n", _("Print additional performance data")); | 2214 | printf(" %s\n", _("Print additional performance data")); |
2213 | printf(" %s\n", "-B, --show-body"); | 2215 | printf(" %s\n", "-B, --show-body"); |
@@ -2357,7 +2359,7 @@ void print_curl_version(void) { printf("%s\n", curl_version()); } | |||
2357 | int curlhelp_initwritebuffer(curlhelp_write_curlbuf *buf) { | 2359 | int curlhelp_initwritebuffer(curlhelp_write_curlbuf *buf) { |
2358 | buf->bufsize = DEFAULT_BUFFER_SIZE; | 2360 | buf->bufsize = DEFAULT_BUFFER_SIZE; |
2359 | buf->buflen = 0; | 2361 | buf->buflen = 0; |
2360 | buf->buf = (char *)malloc((size_t)buf->bufsize); | 2362 | buf->buf = (char *)malloc(buf->bufsize); |
2361 | if (buf->buf == NULL) { | 2363 | if (buf->buf == NULL) { |
2362 | return -1; | 2364 | return -1; |
2363 | } | 2365 | } |
@@ -2372,7 +2374,7 @@ size_t curlhelp_buffer_write_callback(void *buffer, size_t size, size_t nmemb, v | |||
2372 | buf->buf = (char *)realloc(buf->buf, buf->bufsize); | 2374 | buf->buf = (char *)realloc(buf->buf, buf->bufsize); |
2373 | if (buf->buf == NULL) { | 2375 | if (buf->buf == NULL) { |
2374 | fprintf(stderr, "malloc failed (%d) %s\n", errno, strerror(errno)); | 2376 | fprintf(stderr, "malloc failed (%d) %s\n", errno, strerror(errno)); |
2375 | return -1; | 2377 | return 0; |
2376 | } | 2378 | } |
2377 | } | 2379 | } |
2378 | 2380 | ||
@@ -2380,7 +2382,7 @@ size_t curlhelp_buffer_write_callback(void *buffer, size_t size, size_t nmemb, v | |||
2380 | buf->buflen += size * nmemb; | 2382 | buf->buflen += size * nmemb; |
2381 | buf->buf[buf->buflen] = '\0'; | 2383 | buf->buf[buf->buflen] = '\0'; |
2382 | 2384 | ||
2383 | return (int)(size * nmemb); | 2385 | return size * nmemb; |
2384 | } | 2386 | } |
2385 | 2387 | ||
2386 | size_t curlhelp_buffer_read_callback(void *buffer, size_t size, size_t nmemb, void *stream) { | 2388 | size_t curlhelp_buffer_read_callback(void *buffer, size_t size, size_t nmemb, void *stream) { |
@@ -2391,7 +2393,7 @@ size_t curlhelp_buffer_read_callback(void *buffer, size_t size, size_t nmemb, vo | |||
2391 | memcpy(buffer, buf->buf + buf->pos, n); | 2393 | memcpy(buffer, buf->buf + buf->pos, n); |
2392 | buf->pos += n; | 2394 | buf->pos += n; |
2393 | 2395 | ||
2394 | return (int)n; | 2396 | return n; |
2395 | } | 2397 | } |
2396 | 2398 | ||
2397 | void curlhelp_freewritebuffer(curlhelp_write_curlbuf *buf) { | 2399 | void curlhelp_freewritebuffer(curlhelp_write_curlbuf *buf) { |
@@ -2401,7 +2403,7 @@ void curlhelp_freewritebuffer(curlhelp_write_curlbuf *buf) { | |||
2401 | 2403 | ||
2402 | int curlhelp_initreadbuffer(curlhelp_read_curlbuf *buf, const char *data, size_t datalen) { | 2404 | int curlhelp_initreadbuffer(curlhelp_read_curlbuf *buf, const char *data, size_t datalen) { |
2403 | buf->buflen = datalen; | 2405 | buf->buflen = datalen; |
2404 | buf->buf = (char *)malloc((size_t)buf->buflen); | 2406 | buf->buf = (char *)malloc(buf->buflen); |
2405 | if (buf->buf == NULL) { | 2407 | if (buf->buf == NULL) { |
2406 | return -1; | 2408 | return -1; |
2407 | } | 2409 | } |
@@ -2568,8 +2570,8 @@ char *get_header_value(const struct phr_header *headers, const size_t nof_header | |||
2568 | return NULL; | 2570 | return NULL; |
2569 | } | 2571 | } |
2570 | 2572 | ||
2571 | int check_document_dates(const curlhelp_write_curlbuf *header_buf, char (*msg)[DEFAULT_BUFFER_SIZE], | 2573 | mp_state_enum check_document_dates(const curlhelp_write_curlbuf *header_buf, |
2572 | int maximum_age) { | 2574 | char (*msg)[DEFAULT_BUFFER_SIZE], int maximum_age) { |
2573 | struct phr_header headers[255]; | 2575 | struct phr_header headers[255]; |
2574 | size_t nof_headers = 255; | 2576 | size_t nof_headers = 255; |
2575 | curlhelp_statusline status_line; | 2577 | curlhelp_statusline status_line; |
@@ -2585,7 +2587,7 @@ int check_document_dates(const curlhelp_write_curlbuf *header_buf, char (*msg)[D | |||
2585 | char *server_date = get_header_value(headers, nof_headers, "date"); | 2587 | char *server_date = get_header_value(headers, nof_headers, "date"); |
2586 | char *document_date = get_header_value(headers, nof_headers, "last-modified"); | 2588 | char *document_date = get_header_value(headers, nof_headers, "last-modified"); |
2587 | 2589 | ||
2588 | int date_result = STATE_OK; | 2590 | mp_state_enum date_result = STATE_OK; |
2589 | if (!server_date || !*server_date) { | 2591 | if (!server_date || !*server_date) { |
2590 | char tmp[DEFAULT_BUFFER_SIZE]; | 2592 | char tmp[DEFAULT_BUFFER_SIZE]; |
2591 | 2593 | ||
@@ -2634,20 +2636,20 @@ int check_document_dates(const curlhelp_write_curlbuf *header_buf, char (*msg)[D | |||
2634 | 2636 | ||
2635 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 2637 | date_result = max_state_alt(STATE_CRITICAL, date_result); |
2636 | } else if (doc_data < srv_data - maximum_age) { | 2638 | } else if (doc_data < srv_data - maximum_age) { |
2637 | int n = (srv_data - doc_data); | 2639 | time_t last_modified = (srv_data - doc_data); |
2638 | if (n > (60 * 60 * 24 * 2)) { | 2640 | if (last_modified > (60 * 60 * 24 * 2)) { |
2639 | char tmp[DEFAULT_BUFFER_SIZE]; | 2641 | char tmp[DEFAULT_BUFFER_SIZE]; |
2640 | 2642 | ||
2641 | snprintf(tmp, DEFAULT_BUFFER_SIZE, _("%sLast modified %.1f days ago, "), *msg, | 2643 | snprintf(tmp, DEFAULT_BUFFER_SIZE, _("%sLast modified %.1f days ago, "), *msg, |
2642 | ((float)n) / (60 * 60 * 24)); | 2644 | ((float)last_modified) / (60 * 60 * 24)); |
2643 | strcpy(*msg, tmp); | 2645 | strcpy(*msg, tmp); |
2644 | 2646 | ||
2645 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 2647 | date_result = max_state_alt(STATE_CRITICAL, date_result); |
2646 | } else { | 2648 | } else { |
2647 | char tmp[DEFAULT_BUFFER_SIZE]; | 2649 | char tmp[DEFAULT_BUFFER_SIZE]; |
2648 | 2650 | ||
2649 | snprintf(tmp, DEFAULT_BUFFER_SIZE, _("%sLast modified %d:%02d:%02d ago, "), *msg, | 2651 | snprintf(tmp, DEFAULT_BUFFER_SIZE, _("%sLast modified %ld:%02ld:%02ld ago, "), *msg, |
2650 | n / (60 * 60), (n / 60) % 60, n % 60); | 2652 | last_modified / (60 * 60), (last_modified / 60) % 60, last_modified % 60); |
2651 | strcpy(*msg, tmp); | 2653 | strcpy(*msg, tmp); |
2652 | 2654 | ||
2653 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 2655 | date_result = max_state_alt(STATE_CRITICAL, date_result); |
@@ -2665,8 +2667,8 @@ int check_document_dates(const curlhelp_write_curlbuf *header_buf, char (*msg)[D | |||
2665 | return date_result; | 2667 | return date_result; |
2666 | } | 2668 | } |
2667 | 2669 | ||
2668 | int get_content_length(const curlhelp_write_curlbuf *header_buf, | 2670 | size_t get_content_length(const curlhelp_write_curlbuf *header_buf, |
2669 | const curlhelp_write_curlbuf *body_buf) { | 2671 | const curlhelp_write_curlbuf *body_buf) { |
2670 | struct phr_header headers[255]; | 2672 | struct phr_header headers[255]; |
2671 | size_t nof_headers = 255; | 2673 | size_t nof_headers = 255; |
2672 | size_t msglen; | 2674 | size_t msglen; |
diff --git a/plugins/check_curl.d/config.h b/plugins/check_curl.d/config.h index 9085fbbb..90ea3810 100644 --- a/plugins/check_curl.d/config.h +++ b/plugins/check_curl.d/config.h | |||
@@ -48,7 +48,7 @@ typedef struct { | |||
48 | char *http_method; | 48 | char *http_method; |
49 | char user_agent[DEFAULT_BUFFER_SIZE]; | 49 | char user_agent[DEFAULT_BUFFER_SIZE]; |
50 | char **http_opt_headers; | 50 | char **http_opt_headers; |
51 | int http_opt_headers_count; | 51 | size_t http_opt_headers_count; |
52 | char *http_post_data; | 52 | char *http_post_data; |
53 | int max_depth; | 53 | int max_depth; |
54 | char *http_content_type; | 54 | char *http_content_type; |
@@ -63,7 +63,7 @@ typedef struct { | |||
63 | 63 | ||
64 | int maximum_age; | 64 | int maximum_age; |
65 | char regexp[MAX_RE_SIZE]; | 65 | char regexp[MAX_RE_SIZE]; |
66 | int state_regex; | 66 | mp_state_enum state_regex; |
67 | bool invert_regex; | 67 | bool invert_regex; |
68 | bool verify_peer_and_host; | 68 | bool verify_peer_and_host; |
69 | bool check_cert; | 69 | bool check_cert; |
@@ -71,13 +71,13 @@ typedef struct { | |||
71 | int days_till_exp_warn; | 71 | int days_till_exp_warn; |
72 | int days_till_exp_crit; | 72 | int days_till_exp_crit; |
73 | thresholds *thlds; | 73 | thresholds *thlds; |
74 | int min_page_len; | 74 | size_t min_page_len; |
75 | int max_page_len; | 75 | size_t max_page_len; |
76 | char server_expect[MAX_INPUT_BUFFER]; | 76 | char server_expect[MAX_INPUT_BUFFER]; |
77 | bool server_expect_yn; | 77 | bool server_expect_yn; |
78 | char string_expect[MAX_INPUT_BUFFER]; | 78 | char string_expect[MAX_INPUT_BUFFER]; |
79 | char header_expect[MAX_INPUT_BUFFER]; | 79 | char header_expect[MAX_INPUT_BUFFER]; |
80 | int onredirect; | 80 | mp_state_enum onredirect; |
81 | 81 | ||
82 | bool show_extended_perfdata; | 82 | bool show_extended_perfdata; |
83 | bool show_body; | 83 | bool show_body; |
@@ -100,7 +100,7 @@ check_curl_config check_curl_config_init() { | |||
100 | .use_ssl = false, | 100 | .use_ssl = false, |
101 | .ssl_version = CURL_SSLVERSION_DEFAULT, | 101 | .ssl_version = CURL_SSLVERSION_DEFAULT, |
102 | .http_method = NULL, | 102 | .http_method = NULL, |
103 | .user_agent = {}, | 103 | .user_agent = {'\0'}, |
104 | .http_opt_headers = NULL, | 104 | .http_opt_headers = NULL, |
105 | .http_opt_headers_count = 0, | 105 | .http_opt_headers_count = 0, |
106 | .http_post_data = NULL, | 106 | .http_post_data = NULL, |