summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.de>2017-03-14 19:29:17 (GMT)
committerSven Nierlein <sven@nierlein.de>2018-10-22 14:28:51 (GMT)
commitc6c4890702ef7095557b38ffda1531285902af42 (patch)
tree109b42bbce6c981349b3a01d8ad0156dfdd12f65 /plugins
parentd74e9569b9b71f580760d44256b4f8140a29b058 (diff)
downloadmonitoring-plugins-c6c4890702ef7095557b38ffda1531285902af42.tar.gz
check_curl: implement optional http headers
Signed-off-by: Sven Nierlein <sven@nierlein.de>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_curl.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 209b449..c6a7ab8 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -103,6 +103,7 @@ curlhelp_curlbuf body_buf;
103curlhelp_curlbuf header_buf; 103curlhelp_curlbuf header_buf;
104curlhelp_statusline status_line; 104curlhelp_statusline status_line;
105char http_header[DEFAULT_BUFFER_SIZE]; 105char http_header[DEFAULT_BUFFER_SIZE];
106struct curl_slist *http_opt_headers = NULL;
106long code; 107long code;
107long socket_timeout = DEFAULT_SOCKET_TIMEOUT; 108long socket_timeout = DEFAULT_SOCKET_TIMEOUT;
108double total_time; 109double total_time;
@@ -219,10 +220,10 @@ check_http (void)
219 /* always close connection, be nice to servers */ 220 /* always close connection, be nice to servers */
220 snprintf (http_header, DEFAULT_BUFFER_SIZE, "Connection: close"); 221 snprintf (http_header, DEFAULT_BUFFER_SIZE, "Connection: close");
221 header_list = curl_slist_append (header_list, http_header); 222 header_list = curl_slist_append (header_list, http_header);
222 223
223 /* set HTTP headers */ 224 /* set HTTP headers */
224 curl_easy_setopt( curl, CURLOPT_HTTPHEADER, header_list ); 225 curl_easy_setopt( curl, CURLOPT_HTTPHEADER, header_list );
225 226
226 /* set SSL version, warn about unsecure or unsupported versions */ 227 /* set SSL version, warn about unsecure or unsupported versions */
227 if (use_ssl) { 228 if (use_ssl) {
228 curl_easy_setopt (curl, CURLOPT_SSLVERSION, ssl_version); 229 curl_easy_setopt (curl, CURLOPT_SSLVERSION, ssl_version);
@@ -289,11 +290,15 @@ check_http (void)
289 */ 290 */
290 } 291 }
291 292
293 /* set optional http header */
294 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_opt_headers);
295
292 /* do the request */ 296 /* do the request */
293 res = curl_easy_perform(curl); 297 res = curl_easy_perform(curl);
294 298
295 /* free header list, we don't need it anymore */ 299 /* free header list, we don't need it anymore */
296 curl_slist_free_all (header_list); 300 curl_slist_free_all(header_list);
301 curl_slist_free_all(http_opt_headers);
297 302
298 /* Curl errors, result in critical Nagios state */ 303 /* Curl errors, result in critical Nagios state */
299 if (res != CURLE_OK) { 304 if (res != CURLE_OK) {
@@ -460,6 +465,7 @@ process_arguments (int argc, char **argv)
460 {"ca-cert", required_argument, 0, CA_CERT_OPTION}, 465 {"ca-cert", required_argument, 0, CA_CERT_OPTION},
461 {"useragent", required_argument, 0, 'A'}, 466 {"useragent", required_argument, 0, 'A'},
462 {"invert-regex", no_argument, NULL, INVERT_REGEX}, 467 {"invert-regex", no_argument, NULL, INVERT_REGEX},
468 {"header", required_argument, 0, 'k'},
463 {0, 0, 0, 0} 469 {0, 0, 0, 0}
464 }; 470 };
465 471
@@ -467,7 +473,7 @@ process_arguments (int argc, char **argv)
467 return ERROR; 473 return ERROR;
468 474
469 while (1) { 475 while (1) {
470 c = getopt_long (argc, argv, "Vvht:c:w:A:H:j:I:a:p:s:r:u:f:C:J:K:S::", longopts, &option); 476 c = getopt_long (argc, argv, "Vvht:c:w:A:k:H:j:I:a:p:s:r:u:f:C:J:K:S::", longopts, &option);
471 if (c == -1 || c == EOF || c == 1) 477 if (c == -1 || c == EOF || c == 1)
472 break; 478 break;
473 479
@@ -526,6 +532,9 @@ process_arguments (int argc, char **argv)
526 case 'A': /* useragent */ 532 case 'A': /* useragent */
527 snprintf (user_agent, DEFAULT_BUFFER_SIZE, optarg); 533 snprintf (user_agent, DEFAULT_BUFFER_SIZE, optarg);
528 break; 534 break;
535 case 'k': /* Additional headers */
536 http_opt_headers = curl_slist_append(http_opt_headers, optarg);
537 break;
529 case 'C': /* Check SSL cert validity */ 538 case 'C': /* Check SSL cert validity */
530#ifdef LIBCURL_FEATURE_SSL 539#ifdef LIBCURL_FEATURE_SSL
531 /* TODO: C:, check age of certificate for backward compatible 540 /* TODO: C:, check age of certificate for backward compatible
@@ -854,20 +863,20 @@ curlhelp_freebuffer (curlhelp_curlbuf *buf)
854/* TODO: should be moved into 'gl' and should be probed, glibc has 863/* TODO: should be moved into 'gl' and should be probed, glibc has
855 * a strrstr 864 * a strrstr
856 */ 865 */
857const char* 866const char*
858strrstr2(const char *haystack, const char *needle) 867strrstr2(const char *haystack, const char *needle)
859{ 868{
860 int counter; 869 int counter;
861 size_t len; 870 size_t len;
862 const char *prev_pos; 871 const char *prev_pos;
863 const char *pos; 872 const char *pos;
864 873
865 if (haystack == NULL || needle == NULL) 874 if (haystack == NULL || needle == NULL)
866 return NULL; 875 return NULL;
867 876
868 if (haystack[0] == '\0' || needle[0] == '\0') 877 if (haystack[0] == '\0' || needle[0] == '\0')
869 return NULL; 878 return NULL;
870 879
871 counter = 0; 880 counter = 0;
872 prev_pos = NULL; 881 prev_pos = NULL;
873 pos = haystack; 882 pos = haystack;
@@ -902,7 +911,7 @@ curlhelp_parse_statusline (const char *buf, curlhelp_statusline *status_line)
902 start += 2; 911 start += 2;
903 buf = start; 912 buf = start;
904 } 913 }
905 914
906 first_line_end = strstr(buf, "\r\n"); 915 first_line_end = strstr(buf, "\r\n");
907 if (first_line_end == NULL) return -1; 916 if (first_line_end == NULL) return -1;
908 917