diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_curl.c | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index a3f63f1..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" */ | ||
300 | static 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' */ |
300 | static int | 322 | static int |
301 | expected_statuscode (const char *reply, const char *statuscodes) | 323 | expected_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, |