diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2017-04-27 12:50:20 (GMT) |
---|---|---|
committer | Sven Nierlein <sven@nierlein.de> | 2018-10-22 14:30:31 (GMT) |
commit | 5d9104f07fd52ff3d23107fa9800c8b2a331987f (patch) | |
tree | 2cb95b1b622fcb2b8c5e2395276cf49f1d105722 /plugins/check_curl.c | |
parent | cfb7dace5405766785f31e8162c40d6bc3bc9c2a (diff) | |
download | monitoring-plugins-5d9104f07fd52ff3d23107fa9800c8b2a331987f.tar.gz |
page length is computed from header, fallback to actual body size (get_content_length)
Diffstat (limited to 'plugins/check_curl.c')
-rw-r--r-- | plugins/check_curl.c | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index cd00b0e..babbcd5 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
@@ -168,11 +168,9 @@ char *client_cert = NULL; | |||
168 | char *client_privkey = NULL; | 168 | char *client_privkey = NULL; |
169 | char *ca_cert = NULL; | 169 | char *ca_cert = NULL; |
170 | int is_openssl_callback = FALSE; | 170 | int is_openssl_callback = FALSE; |
171 | #ifdef HAVE_SSL | 171 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) |
172 | #ifdef USE_OPENSSL | ||
173 | X509 *cert = NULL; | 172 | X509 *cert = NULL; |
174 | #endif /* USE_OPENSSL */ | 173 | #endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ |
175 | #endif /* HAVE_SSL */ | ||
176 | int no_body = FALSE; | 174 | int no_body = FALSE; |
177 | int maximum_age = -1; | 175 | int maximum_age = -1; |
178 | int address_family = AF_UNSPEC; | 176 | int address_family = AF_UNSPEC; |
@@ -199,6 +197,11 @@ void curlhelp_free_statusline (curlhelp_statusline *); | |||
199 | char *perfd_time_ssl (double microsec); | 197 | char *perfd_time_ssl (double microsec); |
200 | char *get_header_value (const struct phr_header* headers, const size_t nof_headers, const char* header); | 198 | char *get_header_value (const struct phr_header* headers, const size_t nof_headers, const char* header); |
201 | int check_document_dates (const curlhelp_write_curlbuf *, char (*msg)[DEFAULT_BUFFER_SIZE]); | 199 | int check_document_dates (const curlhelp_write_curlbuf *, char (*msg)[DEFAULT_BUFFER_SIZE]); |
200 | int get_content_length (const curlhelp_write_curlbuf* header_buf, const curlhelp_write_curlbuf* body_buf); | ||
201 | |||
202 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) | ||
203 | int np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_warn, int days_till_exp_crit); | ||
204 | #endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ | ||
202 | 205 | ||
203 | void remove_newlines (char *); | 206 | void remove_newlines (char *); |
204 | void test_file (char *); | 207 | void test_file (char *); |
@@ -756,7 +759,7 @@ GOT_FIRST_CERT: | |||
756 | * - if -N (nobody) is given, use Content-Length only and hope the server set | 759 | * - if -N (nobody) is given, use Content-Length only and hope the server set |
757 | * the value correcly | 760 | * the value correcly |
758 | */ | 761 | */ |
759 | page_len = header_buf.buflen + body_buf.buflen; | 762 | page_len = get_content_length(&header_buf, &body_buf); |
760 | if ((max_page_len > 0) && (page_len > max_page_len)) { | 763 | if ((max_page_len > 0) && (page_len > max_page_len)) { |
761 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spage size %d too large, "), msg, page_len); | 764 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spage size %d too large, "), msg, page_len); |
762 | result = max_state_alt(STATE_WARNING, result); | 765 | result = max_state_alt(STATE_WARNING, result); |
@@ -1698,6 +1701,35 @@ check_document_dates (const curlhelp_write_curlbuf *header_buf, char (*msg)[DEFA | |||
1698 | return date_result; | 1701 | return date_result; |
1699 | } | 1702 | } |
1700 | 1703 | ||
1704 | int | ||
1705 | get_content_length (const curlhelp_write_curlbuf* header_buf, const curlhelp_write_curlbuf* body_buf) | ||
1706 | { | ||
1707 | const char *s; | ||
1708 | int content_length = 0; | ||
1709 | char *copy; | ||
1710 | struct phr_header headers[255]; | ||
1711 | size_t nof_headers = 255; | ||
1712 | size_t msglen; | ||
1713 | char *content_length_s = NULL; | ||
1714 | curlhelp_statusline status_line; | ||
1715 | |||
1716 | int res = phr_parse_response (header_buf->buf, header_buf->buflen, | ||
1717 | &status_line.http_minor, &status_line.http_code, &status_line.msg, &msglen, | ||
1718 | headers, &nof_headers, 0); | ||
1719 | |||
1720 | content_length_s = get_header_value (headers, nof_headers, "content-length"); | ||
1721 | if (!content_length_s) { | ||
1722 | /* TODO: or header_buf->buflen + body_buf->buflen */ | ||
1723 | return body_buf->buflen; | ||
1724 | } | ||
1725 | /* TODO: trim */ | ||
1726 | content_length = atoi (content_length_s); | ||
1727 | |||
1728 | if (content_length_s) free (content_length_s); | ||
1729 | |||
1730 | return content_length; | ||
1731 | } | ||
1732 | |||
1701 | /* TODO: is there a better way in libcurl to check for the SSL library? */ | 1733 | /* TODO: is there a better way in libcurl to check for the SSL library? */ |
1702 | curlhelp_ssl_library | 1734 | curlhelp_ssl_library |
1703 | curlhelp_get_ssl_library (CURL* curl) | 1735 | curlhelp_get_ssl_library (CURL* curl) |