diff options
author | Lorenz <12514511+RincewindsHat@users.noreply.github.com> | 2023-01-09 16:55:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-09 16:55:10 +0100 |
commit | e0ada6f11a82ed6119836482b84c8ba5df491d8f (patch) | |
tree | 6ddcd5f7850169d82d88dca56a2e5c0dbda08b4e /plugins/check_curl.c | |
parent | c389aa4f918aab5cf181aa2cb9dec68b3bf34d4f (diff) | |
parent | 0899e41f5075d661153eb2c77ace1734a8f66bfa (diff) | |
download | monitoring-plugins-e0ada6f.tar.gz |
Merge branch 'master' into rename_output_to_cmd_output
Diffstat (limited to 'plugins/check_curl.c')
-rw-r--r-- | plugins/check_curl.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index a69854a8..55de22fd 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", |
@@ -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); |