diff options
Diffstat (limited to 'plugins/check_curl.c')
| -rw-r--r-- | plugins/check_curl.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index a69854a8..c6593df1 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
| @@ -476,6 +476,18 @@ check_http (void) | |||
| 476 | printf ("* curl CURLOPT_RESOLVE: %s\n", dnscache); | 476 | printf ("* curl CURLOPT_RESOLVE: %s\n", dnscache); |
| 477 | } | 477 | } |
| 478 | 478 | ||
| 479 | // If server_address is an IPv6 address it must be surround by square brackets | ||
| 480 | struct in6_addr tmp_in_addr; | ||
| 481 | if (inet_pton(AF_INET6, server_address, &tmp_in_addr) == 1) { | ||
| 482 | char *new_server_address = malloc(strlen(server_address) + 3); | ||
| 483 | if (new_server_address == NULL) { | ||
| 484 | die(STATE_UNKNOWN, "HTTP UNKNOWN - Unable to allocate memory\n"); | ||
| 485 | } | ||
| 486 | snprintf(new_server_address, strlen(server_address)+3, "[%s]", server_address); | ||
| 487 | free(server_address); | ||
| 488 | server_address = new_server_address; | ||
| 489 | } | ||
| 490 | |||
| 479 | /* compose URL: use the address we want to connect to, set Host: header later */ | 491 | /* compose URL: use the address we want to connect to, set Host: header later */ |
| 480 | snprintf (url, DEFAULT_BUFFER_SIZE, "%s://%s:%d%s", | 492 | snprintf (url, DEFAULT_BUFFER_SIZE, "%s://%s:%d%s", |
| 481 | use_ssl ? "https" : "http", | 493 | use_ssl ? "https" : "http", |
| @@ -999,10 +1011,12 @@ GOT_FIRST_CERT: | |||
| 999 | result = max_state_alt(get_status(total_time, thlds), result); | 1011 | result = max_state_alt(get_status(total_time, thlds), result); |
| 1000 | 1012 | ||
| 1001 | /* Cut-off trailing characters */ | 1013 | /* Cut-off trailing characters */ |
| 1002 | if(msg[strlen(msg)-2] == ',') | 1014 | if (strlen(msg) >= 2) { |
| 1003 | msg[strlen(msg)-2] = '\0'; | 1015 | if(msg[strlen(msg)-2] == ',') |
| 1004 | else | 1016 | msg[strlen(msg)-2] = '\0'; |
| 1005 | msg[strlen(msg)-3] = '\0'; | 1017 | else |
| 1018 | msg[strlen(msg)-3] = '\0'; | ||
| 1019 | } | ||
| 1006 | 1020 | ||
| 1007 | /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */ | 1021 | /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */ |
| 1008 | die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n%s%s", | 1022 | die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n%s%s", |
| @@ -1666,7 +1680,7 @@ process_arguments (int argc, char **argv) | |||
| 1666 | curl_http_version = CURL_HTTP_VERSION_NONE; | 1680 | curl_http_version = CURL_HTTP_VERSION_NONE; |
| 1667 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 33, 0) */ | 1681 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 33, 0) */ |
| 1668 | } else { | 1682 | } else { |
| 1669 | fprintf (stderr, "unkown http-version parameter: %s\n", optarg); | 1683 | fprintf (stderr, "unknown http-version parameter: %s\n", optarg); |
| 1670 | exit (STATE_WARNING); | 1684 | exit (STATE_WARNING); |
| 1671 | } | 1685 | } |
| 1672 | break; | 1686 | break; |
| @@ -2010,9 +2024,12 @@ curlhelp_buffer_write_callback (void *buffer, size_t size, size_t nmemb, void *s | |||
| 2010 | curlhelp_write_curlbuf *buf = (curlhelp_write_curlbuf *)stream; | 2024 | curlhelp_write_curlbuf *buf = (curlhelp_write_curlbuf *)stream; |
| 2011 | 2025 | ||
| 2012 | while (buf->bufsize < buf->buflen + size * nmemb + 1) { | 2026 | while (buf->bufsize < buf->buflen + size * nmemb + 1) { |
| 2013 | buf->bufsize *= buf->bufsize * 2; | 2027 | buf->bufsize = buf->bufsize * 2; |
| 2014 | buf->buf = (char *)realloc (buf->buf, buf->bufsize); | 2028 | buf->buf = (char *)realloc (buf->buf, buf->bufsize); |
| 2015 | if (buf->buf == NULL) return -1; | 2029 | if (buf->buf == NULL) { |
| 2030 | fprintf(stderr, "malloc failed (%d) %s\n", errno, strerror(errno)); | ||
| 2031 | return -1; | ||
| 2032 | } | ||
| 2016 | } | 2033 | } |
| 2017 | 2034 | ||
| 2018 | memcpy (buf->buf + buf->buflen, buffer, size * nmemb); | 2035 | memcpy (buf->buf + buf->buflen, buffer, size * nmemb); |
