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