summaryrefslogtreecommitdiffstats
path: root/plugins/check_curl.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_curl.c')
-rw-r--r--plugins/check_curl.c247
1 files changed, 118 insertions, 129 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 8277f5e..06fc6d6 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -128,141 +128,138 @@ enum {
128 MAX_RE_SIZE = 1024 128 MAX_RE_SIZE = 1024
129}; 129};
130#include "regex.h" 130#include "regex.h"
131regex_t preg; 131static regex_t preg;
132regmatch_t pmatch[REGS]; 132static regmatch_t pmatch[REGS];
133char regexp[MAX_RE_SIZE]; 133static char regexp[MAX_RE_SIZE];
134int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; 134static int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE;
135int errcode; 135static int errcode;
136bool invert_regex = false; 136static bool invert_regex = false;
137int state_regex = STATE_CRITICAL; 137static int state_regex = STATE_CRITICAL;
138 138
139char *server_address = NULL; 139static char *server_address = NULL;
140char *host_name = NULL; 140static char *host_name = NULL;
141char *server_url = 0; 141static char *server_url = 0;
142char server_ip[DEFAULT_BUFFER_SIZE]; 142static struct curl_slist *server_ips = NULL;
143struct curl_slist *server_ips = NULL; 143static bool specify_port = false;
144bool specify_port = false; 144static unsigned short server_port = HTTP_PORT;
145unsigned short server_port = HTTP_PORT; 145static unsigned short virtual_port = 0;
146unsigned short virtual_port = 0; 146static int host_name_length;
147int host_name_length; 147static char output_header_search[30] = "";
148char output_header_search[30] = ""; 148static char output_string_search[30] = "";
149char output_string_search[30] = ""; 149static char *warning_thresholds = NULL;
150char *warning_thresholds = NULL; 150static char *critical_thresholds = NULL;
151char *critical_thresholds = NULL; 151static int days_till_exp_warn, days_till_exp_crit;
152int days_till_exp_warn, days_till_exp_crit; 152static thresholds *thlds;
153thresholds *thlds; 153static char user_agent[DEFAULT_BUFFER_SIZE];
154char user_agent[DEFAULT_BUFFER_SIZE]; 154static int verbose = 0;
155int verbose = 0; 155static bool show_extended_perfdata = false;
156bool show_extended_perfdata = false; 156static bool show_body = false;
157bool show_body = false; 157static int min_page_len = 0;
158int min_page_len = 0; 158static int max_page_len = 0;
159int max_page_len = 0; 159static int redir_depth = 0;
160int redir_depth = 0; 160static int max_depth = DEFAULT_MAX_REDIRS;
161int max_depth = DEFAULT_MAX_REDIRS; 161static char *http_method = NULL;
162char *http_method = NULL; 162static char *http_post_data = NULL;
163char *http_post_data = NULL; 163static char *http_content_type = NULL;
164char *http_content_type = NULL; 164static CURL *curl;
165CURL *curl; 165static bool curl_global_initialized = false;
166bool curl_global_initialized = false; 166static bool curl_easy_initialized = false;
167bool curl_easy_initialized = false; 167static struct curl_slist *header_list = NULL;
168struct curl_slist *header_list = NULL; 168static bool body_buf_initialized = false;
169bool body_buf_initialized = false; 169static curlhelp_write_curlbuf body_buf;
170curlhelp_write_curlbuf body_buf; 170static bool header_buf_initialized = false;
171bool header_buf_initialized = false; 171static curlhelp_write_curlbuf header_buf;
172curlhelp_write_curlbuf header_buf; 172static bool status_line_initialized = false;
173bool status_line_initialized = false; 173static curlhelp_statusline status_line;
174curlhelp_statusline status_line; 174static bool put_buf_initialized = false;
175bool put_buf_initialized = false; 175static curlhelp_read_curlbuf put_buf;
176curlhelp_read_curlbuf put_buf; 176static char http_header[DEFAULT_BUFFER_SIZE];
177char http_header[DEFAULT_BUFFER_SIZE]; 177static long code;
178long code; 178static long socket_timeout = DEFAULT_SOCKET_TIMEOUT;
179long socket_timeout = DEFAULT_SOCKET_TIMEOUT; 179static double total_time;
180double total_time; 180static double time_connect;
181double time_connect; 181static double time_appconnect;
182double time_appconnect; 182static double time_headers;
183double time_headers; 183static double time_firstbyte;
184double time_firstbyte; 184static char errbuf[MAX_INPUT_BUFFER];
185char errbuf[MAX_INPUT_BUFFER]; 185static CURLcode res;
186CURLcode res; 186static char url[DEFAULT_BUFFER_SIZE];
187char url[DEFAULT_BUFFER_SIZE]; 187static char msg[DEFAULT_BUFFER_SIZE];
188char msg[DEFAULT_BUFFER_SIZE]; 188static char perfstring[DEFAULT_BUFFER_SIZE];
189char perfstring[DEFAULT_BUFFER_SIZE]; 189static char header_expect[MAX_INPUT_BUFFER] = "";
190char header_expect[MAX_INPUT_BUFFER] = ""; 190static char string_expect[MAX_INPUT_BUFFER] = "";
191char string_expect[MAX_INPUT_BUFFER] = ""; 191static char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT;
192char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT; 192static int server_expect_yn = 0;
193int server_expect_yn = 0; 193static char user_auth[MAX_INPUT_BUFFER] = "";
194char user_auth[MAX_INPUT_BUFFER] = ""; 194static char proxy_auth[MAX_INPUT_BUFFER] = "";
195char proxy_auth[MAX_INPUT_BUFFER] = ""; 195static char **http_opt_headers;
196char **http_opt_headers; 196static int http_opt_headers_count = 0;
197int http_opt_headers_count = 0; 197static bool display_html = false;
198bool display_html = false; 198static int onredirect = STATE_OK;
199int onredirect = STATE_OK; 199static int followmethod = FOLLOW_HTTP_CURL;
200int followmethod = FOLLOW_HTTP_CURL; 200static int followsticky = STICKY_NONE;
201int followsticky = STICKY_NONE; 201static bool use_ssl = false;
202bool use_ssl = false; 202static bool check_cert = false;
203bool use_sni = true; 203static bool continue_after_check_cert = false;
204bool check_cert = false;
205bool continue_after_check_cert = false;
206typedef union { 204typedef union {
207 struct curl_slist *to_info; 205 struct curl_slist *to_info;
208 struct curl_certinfo *to_certinfo; 206 struct curl_certinfo *to_certinfo;
209} cert_ptr_union; 207} cert_ptr_union;
210cert_ptr_union cert_ptr; 208static cert_ptr_union cert_ptr;
211int ssl_version = CURL_SSLVERSION_DEFAULT; 209static int ssl_version = CURL_SSLVERSION_DEFAULT;
212char *client_cert = NULL; 210static char *client_cert = NULL;
213char *client_privkey = NULL; 211static char *client_privkey = NULL;
214char *ca_cert = NULL; 212static char *ca_cert = NULL;
215bool verify_peer_and_host = false; 213static bool verify_peer_and_host = false;
216bool is_openssl_callback = false; 214static bool is_openssl_callback = false;
217bool add_sslctx_verify_fun = false; 215static bool add_sslctx_verify_fun = false;
218#if defined(HAVE_SSL) && defined(USE_OPENSSL) 216#if defined(HAVE_SSL) && defined(USE_OPENSSL)
219X509 *cert = NULL; 217static X509 *cert = NULL;
220#endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ 218#endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */
221bool no_body = false; 219static bool no_body = false;
222int maximum_age = -1; 220static int maximum_age = -1;
223int address_family = AF_UNSPEC; 221static int address_family = AF_UNSPEC;
224curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; 222static curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN;
225int curl_http_version = CURL_HTTP_VERSION_NONE; 223static int curl_http_version = CURL_HTTP_VERSION_NONE;
226bool automatic_decompression = false; 224static bool automatic_decompression = false;
227char *cookie_jar_file = NULL; 225static char *cookie_jar_file = NULL;
228bool haproxy_protocol = false; 226static bool haproxy_protocol = false;
229 227
230bool process_arguments(int, char **); 228static bool process_arguments(int, char **);
231void handle_curl_option_return_code(CURLcode res, const char *option); 229static void handle_curl_option_return_code(CURLcode res, const char *option);
232int check_http(void); 230static int check_http(void);
233void redir(curlhelp_write_curlbuf *); 231static void redir(curlhelp_write_curlbuf *);
234char *perfd_time(double microsec); 232static char *perfd_time(double microsec);
235char *perfd_time_connect(double microsec); 233static char *perfd_time_connect(double microsec);
236char *perfd_time_ssl(double microsec); 234static char *perfd_time_ssl(double microsec);
237char *perfd_time_firstbyte(double microsec); 235static char *perfd_time_firstbyte(double microsec);
238char *perfd_time_headers(double microsec); 236static char *perfd_time_headers(double microsec);
239char *perfd_time_transfer(double microsec); 237static char *perfd_time_transfer(double microsec);
240char *perfd_size(int page_len); 238static char *perfd_size(int page_len);
241void print_help(void); 239static void print_help(void);
242void print_usage(void); 240void print_usage(void);
243void print_curl_version(void); 241static void print_curl_version(void);
244int curlhelp_initwritebuffer(curlhelp_write_curlbuf *); 242static int curlhelp_initwritebuffer(curlhelp_write_curlbuf *);
245size_t curlhelp_buffer_write_callback(void *, size_t, size_t, void *); 243static size_t curlhelp_buffer_write_callback(void *, size_t, size_t, void *);
246void curlhelp_freewritebuffer(curlhelp_write_curlbuf *); 244static void curlhelp_freewritebuffer(curlhelp_write_curlbuf *);
247int curlhelp_initreadbuffer(curlhelp_read_curlbuf *, const char *, size_t); 245static int curlhelp_initreadbuffer(curlhelp_read_curlbuf *, const char *, size_t);
248size_t curlhelp_buffer_read_callback(void *, size_t, size_t, void *); 246static size_t curlhelp_buffer_read_callback(void *, size_t, size_t, void *);
249void curlhelp_freereadbuffer(curlhelp_read_curlbuf *); 247static void curlhelp_freereadbuffer(curlhelp_read_curlbuf *);
250curlhelp_ssl_library curlhelp_get_ssl_library(); 248static curlhelp_ssl_library curlhelp_get_ssl_library();
251const char *curlhelp_get_ssl_library_string(curlhelp_ssl_library); 249static const char *curlhelp_get_ssl_library_string(curlhelp_ssl_library);
252int net_noopenssl_check_certificate(cert_ptr_union *, int, int); 250int net_noopenssl_check_certificate(cert_ptr_union *, int, int);
253 251
254int curlhelp_parse_statusline(const char *, curlhelp_statusline *); 252static int curlhelp_parse_statusline(const char *, curlhelp_statusline *);
255void curlhelp_free_statusline(curlhelp_statusline *); 253static void curlhelp_free_statusline(curlhelp_statusline *);
256char *get_header_value(const struct phr_header *headers, const size_t nof_headers, const char *header); 254static char *get_header_value(const struct phr_header *headers, const size_t nof_headers, const char *header);
257int check_document_dates(const curlhelp_write_curlbuf *, char (*msg)[DEFAULT_BUFFER_SIZE]); 255static int check_document_dates(const curlhelp_write_curlbuf *, char (*msg)[DEFAULT_BUFFER_SIZE]);
258int get_content_length(const curlhelp_write_curlbuf *header_buf, const curlhelp_write_curlbuf *body_buf); 256static int get_content_length(const curlhelp_write_curlbuf *header_buf, const curlhelp_write_curlbuf *body_buf);
259 257
260#if defined(HAVE_SSL) && defined(USE_OPENSSL) 258#if defined(HAVE_SSL) && defined(USE_OPENSSL)
261int np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_warn, int days_till_exp_crit); 259int np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_warn, int days_till_exp_crit);
262#endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ 260#endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */
263 261
264void remove_newlines(char *); 262static void test_file(char *);
265void test_file(char *);
266 263
267int main(int argc, char **argv) { 264int main(int argc, char **argv) {
268 int result = STATE_UNKNOWN; 265 int result = STATE_UNKNOWN;
@@ -2311,14 +2308,6 @@ int curlhelp_parse_statusline(const char *buf, curlhelp_statusline *status_line)
2311 2308
2312void curlhelp_free_statusline(curlhelp_statusline *status_line) { free(status_line->first_line); } 2309void curlhelp_free_statusline(curlhelp_statusline *status_line) { free(status_line->first_line); }
2313 2310
2314void remove_newlines(char *s) {
2315 char *p;
2316
2317 for (p = s; *p != '\0'; p++)
2318 if (*p == '\r' || *p == '\n')
2319 *p = ' ';
2320}
2321
2322char *get_header_value(const struct phr_header *headers, const size_t nof_headers, const char *header) { 2311char *get_header_value(const struct phr_header *headers, const size_t nof_headers, const char *header) {
2323 for (size_t i = 0; i < nof_headers; i++) { 2312 for (size_t i = 0; i < nof_headers; i++) {
2324 if (headers[i].name != NULL && strncasecmp(header, headers[i].name, max(headers[i].name_len, 4)) == 0) { 2313 if (headers[i].name != NULL && strncasecmp(header, headers[i].name, max(headers[i].name_len, 4)) == 0) {