summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-04-27 12:50:20 (GMT)
committerSven Nierlein <sven@nierlein.de>2018-10-22 14:30:31 (GMT)
commit5d9104f07fd52ff3d23107fa9800c8b2a331987f (patch)
tree2cb95b1b622fcb2b8c5e2395276cf49f1d105722 /plugins
parentcfb7dace5405766785f31e8162c40d6bc3bc9c2a (diff)
downloadmonitoring-plugins-5d9104f07fd52ff3d23107fa9800c8b2a331987f.tar.gz
page length is computed from header, fallback to actual body size (get_content_length)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_curl.c42
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;
168char *client_privkey = NULL; 168char *client_privkey = NULL;
169char *ca_cert = NULL; 169char *ca_cert = NULL;
170int is_openssl_callback = FALSE; 170int is_openssl_callback = FALSE;
171#ifdef HAVE_SSL 171#if defined(HAVE_SSL) && defined(USE_OPENSSL)
172#ifdef USE_OPENSSL
173X509 *cert = NULL; 172X509 *cert = NULL;
174#endif /* USE_OPENSSL */ 173#endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */
175#endif /* HAVE_SSL */
176int no_body = FALSE; 174int no_body = FALSE;
177int maximum_age = -1; 175int maximum_age = -1;
178int address_family = AF_UNSPEC; 176int address_family = AF_UNSPEC;
@@ -199,6 +197,11 @@ void curlhelp_free_statusline (curlhelp_statusline *);
199char *perfd_time_ssl (double microsec); 197char *perfd_time_ssl (double microsec);
200char *get_header_value (const struct phr_header* headers, const size_t nof_headers, const char* header); 198char *get_header_value (const struct phr_header* headers, const size_t nof_headers, const char* header);
201int check_document_dates (const curlhelp_write_curlbuf *, char (*msg)[DEFAULT_BUFFER_SIZE]); 199int check_document_dates (const curlhelp_write_curlbuf *, char (*msg)[DEFAULT_BUFFER_SIZE]);
200int get_content_length (const curlhelp_write_curlbuf* header_buf, const curlhelp_write_curlbuf* body_buf);
201
202#if defined(HAVE_SSL) && defined(USE_OPENSSL)
203int 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
203void remove_newlines (char *); 206void remove_newlines (char *);
204void test_file (char *); 207void 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
1704int
1705get_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? */
1702curlhelp_ssl_library 1734curlhelp_ssl_library
1703curlhelp_get_ssl_library (CURL* curl) 1735curlhelp_get_ssl_library (CURL* curl)