summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.de>2021-03-22 09:05:45 (GMT)
committerGitHub <noreply@github.com>2021-03-22 09:05:45 (GMT)
commit57b4dc0f2307cd49bedeed01ee56bc6077d428f5 (patch)
treebef6c182a4a28a2786472703ab14f08ef7a96cef
parent05d7f70d4553e19ea5eb27ec5c97098f014550df (diff)
parent0f926a3566fb6f3333f3a24e47e2ad204fd0fba4 (diff)
downloadmonitoring-plugins-57b4dc0f2307cd49bedeed01ee56bc6077d428f5.tar.gz
Merge pull request #1667 from monitoring-plugins/feature_check_curl
check curl bugfixes
-rw-r--r--plugins/check_curl.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 2d69b31..8f274c2 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -296,6 +296,28 @@ CURLcode sslctxfun(CURL *curl, SSL_CTX *sslctx, void *parm)
296#endif /* USE_OPENSSL */ 296#endif /* USE_OPENSSL */
297#endif /* HAVE_SSL */ 297#endif /* HAVE_SSL */
298 298
299/* returns a string "HTTP/1.x" or "HTTP/2" */
300static char *string_statuscode (int major, int minor)
301{
302 static char buf[10];
303
304 switch (major) {
305 case 1:
306 snprintf (buf, sizeof (buf), "HTTP/%d.%d", major, minor);
307 break;
308 case 2:
309 case 3:
310 snprintf (buf, sizeof (buf), "HTTP/%d", major);
311 break;
312 default:
313 /* assuming here HTTP/N with N>=4 */
314 snprintf (buf, sizeof (buf), "HTTP/%d", major);
315 break;
316 }
317
318 return buf;
319}
320
299/* Checks if the server 'reply' is one of the expected 'statuscodes' */ 321/* Checks if the server 'reply' is one of the expected 'statuscodes' */
300static int 322static int
301expected_statuscode (const char *reply, const char *statuscodes) 323expected_statuscode (const char *reply, const char *statuscodes)
@@ -746,7 +768,8 @@ GOT_FIRST_CERT:
746 if (curlhelp_parse_statusline (header_buf.buf, &status_line) < 0) { 768 if (curlhelp_parse_statusline (header_buf.buf, &status_line) < 0) {
747 snprintf (msg, DEFAULT_BUFFER_SIZE, "Unparsable status line in %.3g seconds response time|%s\n", 769 snprintf (msg, DEFAULT_BUFFER_SIZE, "Unparsable status line in %.3g seconds response time|%s\n",
748 total_time, perfstring); 770 total_time, perfstring);
749 die (STATE_CRITICAL, "HTTP CRITICAL HTTP/1.x %ld unknown - %s", code, msg); 771 /* we cannot know the major/minor version here for sure as we cannot parse the first line */
772 die (STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg);
750 } 773 }
751 774
752 /* get result code from cURL */ 775 /* get result code from cURL */
@@ -823,8 +846,8 @@ GOT_FIRST_CERT:
823 846
824 /* check status codes, set exit status accordingly */ 847 /* check status codes, set exit status accordingly */
825 if( status_line.http_code != code ) { 848 if( status_line.http_code != code ) {
826 die (STATE_CRITICAL, _("HTTP CRITICAL HTTP/%d.%d %d %s - different HTTP codes (cUrl has %ld)\n"), 849 die (STATE_CRITICAL, _("HTTP CRITICAL %s %d %s - different HTTP codes (cUrl has %ld)\n"),
827 status_line.http_major, status_line.http_minor, 850 string_statuscode (status_line.http_major, status_line.http_minor),
828 status_line.http_code, status_line.msg, code); 851 status_line.http_code, status_line.msg, code);
829 } 852 }
830 853
@@ -895,8 +918,8 @@ GOT_FIRST_CERT:
895 msg[strlen(msg)-3] = '\0'; 918 msg[strlen(msg)-3] = '\0';
896 919
897 /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */ 920 /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */
898 die (result, "HTTP %s: HTTP/%d.%d %d %s%s%s - %d bytes in %.3f second response time %s|%s\n", 921 die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n",
899 state_text(result), status_line.http_major, status_line.http_minor, 922 state_text(result), string_statuscode (status_line.http_major, status_line.http_minor),
900 status_line.http_code, status_line.msg, 923 status_line.http_code, status_line.msg,
901 strlen(msg) > 0 ? " - " : "", 924 strlen(msg) > 0 ? " - " : "",
902 msg, page_len, total_time, 925 msg, page_len, total_time,
@@ -1041,7 +1064,7 @@ redir (curlhelp_write_curlbuf* header_buf)
1041 const UriPathSegmentA* p = uri.pathHead; 1064 const UriPathSegmentA* p = uri.pathHead;
1042 for (; p; p = p->next) { 1065 for (; p; p = p->next) {
1043 strncat (new_url, "/", DEFAULT_BUFFER_SIZE); 1066 strncat (new_url, "/", DEFAULT_BUFFER_SIZE);
1044 strncat (new_url, uri_string (p->text, buf, DEFAULT_BUFFER_SIZE), DEFAULT_BUFFER_SIZE); 1067 strncat (new_url, uri_string (p->text, buf, DEFAULT_BUFFER_SIZE), DEFAULT_BUFFER_SIZE-1);
1045 } 1068 }
1046 } 1069 }
1047 1070
@@ -1354,7 +1377,7 @@ process_arguments (int argc, char **argv)
1354 ssl_version = CURL_SSLVERSION_DEFAULT; 1377 ssl_version = CURL_SSLVERSION_DEFAULT;
1355#endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 52, 0) */ 1378#endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 52, 0) */
1356 else 1379 else
1357 usage4 (_("Invalid option - Valid SSL/TLS versions: 2, 3, 1, 1.1, 1.2 (with optional '+' suffix)")); 1380 usage4 (_("Invalid option - Valid SSL/TLS versions: 2, 3, 1, 1.1, 1.2, 1.3 (with optional '+' suffix)"));
1358 } 1381 }
1359#if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 54, 0) 1382#if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 54, 0)
1360 if (got_plus) { 1383 if (got_plus) {
@@ -1659,7 +1682,7 @@ print_help (void)
1659 printf (" %s\n", "-S, --ssl=VERSION[+]"); 1682 printf (" %s\n", "-S, --ssl=VERSION[+]");
1660 printf (" %s\n", _("Connect via SSL. Port defaults to 443. VERSION is optional, and prevents")); 1683 printf (" %s\n", _("Connect via SSL. Port defaults to 443. VERSION is optional, and prevents"));
1661 printf (" %s\n", _("auto-negotiation (2 = SSLv2, 3 = SSLv3, 1 = TLSv1, 1.1 = TLSv1.1,")); 1684 printf (" %s\n", _("auto-negotiation (2 = SSLv2, 3 = SSLv3, 1 = TLSv1, 1.1 = TLSv1.1,"));
1662 printf (" %s\n", _("1.2 = TLSv1.2). With a '+' suffix, newer versions are also accepted.")); 1685 printf (" %s\n", _("1.2 = TLSv1.2, 1.3 = TLSv1.3). With a '+' suffix, newer versions are also accepted."));
1663 printf (" %s\n", _("Note: SSLv2 and SSLv3 are deprecated and are usually disabled in libcurl")); 1686 printf (" %s\n", _("Note: SSLv2 and SSLv3 are deprecated and are usually disabled in libcurl"));
1664 printf (" %s\n", "--sni"); 1687 printf (" %s\n", "--sni");
1665 printf (" %s\n", _("Enable SSL/TLS hostname extension support (SNI)")); 1688 printf (" %s\n", _("Enable SSL/TLS hostname extension support (SNI)"));