mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-03-24 19:33:36 -04:00
check_curl: create outsourced helpers in extra files
This commit is contained in:
parent
684602ddec
commit
ab66b41d23
5 changed files with 1397 additions and 1335 deletions
|
|
@ -66,6 +66,7 @@ EXTRA_DIST = t \
|
|||
check_hpjd.d \
|
||||
check_game.d \
|
||||
check_radius.d \
|
||||
check_curl.d \
|
||||
check_disk.d \
|
||||
check_time.d \
|
||||
check_users.d \
|
||||
|
|
@ -134,6 +135,7 @@ check_cluster_LDADD = $(BASEOBJS)
|
|||
check_curl_CFLAGS = $(AM_CFLAGS) $(LIBCURLCFLAGS) $(URIPARSERCFLAGS) $(LIBCURLINCLUDE) $(URIPARSERINCLUDE) -Ipicohttpparser
|
||||
check_curl_CPPFLAGS = $(AM_CPPFLAGS) $(LIBCURLCFLAGS) $(URIPARSERCFLAGS) $(LIBCURLINCLUDE) $(URIPARSERINCLUDE) -Ipicohttpparser
|
||||
check_curl_LDADD = $(NETLIBS) $(LIBCURLLIBS) $(SSLOBJS) $(URIPARSERLIBS) picohttpparser/libpicohttpparser.a
|
||||
check_curl_SOURCES = check_curl.c check_curl.d/check_curl_helpers.c
|
||||
check_dbi_LDADD = $(NETLIBS) $(DBILIBS)
|
||||
check_dig_LDADD = $(NETLIBS)
|
||||
check_disk_LDADD = $(BASEOBJS)
|
||||
|
|
|
|||
1312
plugins/check_curl.c
1312
plugins/check_curl.c
File diff suppressed because it is too large
Load diff
1217
plugins/check_curl.d/check_curl_helpers.c
Normal file
1217
plugins/check_curl.d/check_curl_helpers.c
Normal file
File diff suppressed because it is too large
Load diff
125
plugins/check_curl.d/check_curl_helpers.h
Normal file
125
plugins/check_curl.d/check_curl_helpers.h
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
#include "./config.h"
|
||||
#include <curl/curl.h>
|
||||
#include "../picohttpparser/picohttpparser.h"
|
||||
// #include "curl/easy.h"
|
||||
|
||||
/* for buffers for header and body */
|
||||
typedef struct {
|
||||
size_t buflen;
|
||||
size_t bufsize;
|
||||
char *buf;
|
||||
} curlhelp_write_curlbuf;
|
||||
|
||||
/* for buffering the data sent in PUT */
|
||||
typedef struct {
|
||||
size_t buflen;
|
||||
off_t pos;
|
||||
char *buf;
|
||||
} curlhelp_read_curlbuf;
|
||||
|
||||
/* for parsing the HTTP status line */
|
||||
typedef struct {
|
||||
int http_major; /* major version of the protocol, always 1 (HTTP/0.9
|
||||
* never reached the big internet most likely) */
|
||||
int http_minor; /* minor version of the protocol, usually 0 or 1 */
|
||||
int http_code; /* HTTP return code as in RFC 2145 */
|
||||
int http_subcode; /* Microsoft IIS extension, HTTP subcodes, see
|
||||
* http://support.microsoft.com/kb/318380/en-us */
|
||||
const char *msg; /* the human readable message */
|
||||
char *first_line; /* a copy of the first line */
|
||||
} curlhelp_statusline;
|
||||
|
||||
typedef struct {
|
||||
bool curl_global_initialized;
|
||||
bool curl_easy_initialized;
|
||||
|
||||
bool body_buf_initialized;
|
||||
curlhelp_write_curlbuf *body_buf;
|
||||
|
||||
bool header_buf_initialized;
|
||||
curlhelp_write_curlbuf *header_buf;
|
||||
|
||||
bool status_line_initialized;
|
||||
curlhelp_statusline *status_line;
|
||||
|
||||
bool put_buf_initialized;
|
||||
curlhelp_read_curlbuf *put_buf;
|
||||
|
||||
CURL *curl;
|
||||
|
||||
struct curl_slist *header_list;
|
||||
struct curl_slist *host;
|
||||
} check_curl_global_state;
|
||||
|
||||
/* to know the underlying SSL library used by libcurl */
|
||||
typedef enum curlhelp_ssl_library {
|
||||
CURLHELP_SSL_LIBRARY_UNKNOWN,
|
||||
CURLHELP_SSL_LIBRARY_OPENSSL,
|
||||
CURLHELP_SSL_LIBRARY_LIBRESSL,
|
||||
CURLHELP_SSL_LIBRARY_GNUTLS,
|
||||
CURLHELP_SSL_LIBRARY_NSS
|
||||
} curlhelp_ssl_library;
|
||||
|
||||
#define MAKE_LIBCURL_VERSION(major, minor, patch) ((major) * 0x10000 + (minor) * 0x100 + (patch))
|
||||
|
||||
typedef struct {
|
||||
int errorcode;
|
||||
check_curl_global_state curl_state;
|
||||
check_curl_working_state working_state;
|
||||
} check_curl_configure_curl_wrapper;
|
||||
|
||||
check_curl_configure_curl_wrapper check_curl_configure_curl(check_curl_static_curl_config config,
|
||||
check_curl_working_state working_state,
|
||||
bool check_cert,
|
||||
bool on_redirect_dependent,
|
||||
int follow_method, int max_depth);
|
||||
|
||||
void handle_curl_option_return_code(CURLcode res, const char *option);
|
||||
|
||||
int curlhelp_initwritebuffer(curlhelp_write_curlbuf **buf);
|
||||
size_t curlhelp_buffer_write_callback(void * /*buffer*/, size_t /*size*/, size_t /*nmemb*/,
|
||||
void * /*stream*/);
|
||||
void curlhelp_freewritebuffer(curlhelp_write_curlbuf * /*buf*/);
|
||||
|
||||
int curlhelp_initreadbuffer(curlhelp_read_curlbuf **buf, const char * /*data*/, size_t /*datalen*/);
|
||||
size_t curlhelp_buffer_read_callback(void * /*buffer*/, size_t /*size*/, size_t /*nmemb*/,
|
||||
void * /*stream*/);
|
||||
void curlhelp_freereadbuffer(curlhelp_read_curlbuf * /*buf*/);
|
||||
|
||||
curlhelp_ssl_library curlhelp_get_ssl_library(void);
|
||||
const char *curlhelp_get_ssl_library_string(curlhelp_ssl_library /*ssl_library*/);
|
||||
|
||||
typedef union {
|
||||
struct curl_slist *to_info;
|
||||
struct curl_certinfo *to_certinfo;
|
||||
} cert_ptr_union;
|
||||
int net_noopenssl_check_certificate(cert_ptr_union *, int, int);
|
||||
|
||||
int curlhelp_parse_statusline(const char * /*buf*/, curlhelp_statusline * /*status_line*/);
|
||||
void curlhelp_free_statusline(curlhelp_statusline * /*status_line*/);
|
||||
|
||||
char *get_header_value(const struct phr_header *headers, size_t nof_headers, const char *header);
|
||||
mp_state_enum check_document_dates(const curlhelp_write_curlbuf * /*header_buf*/,
|
||||
const char msg[static DEFAULT_BUFFER_SIZE], int /*maximum_age*/);
|
||||
size_t get_content_length(const curlhelp_write_curlbuf *header_buf,
|
||||
const curlhelp_write_curlbuf *body_buf);
|
||||
int lookup_host(const char *host, char *buf, size_t buflen, sa_family_t addr_family);
|
||||
CURLcode sslctxfun(CURL *curl, SSL_CTX *sslctx, void *parm);
|
||||
|
||||
#define INET_ADDR_MAX_SIZE INET6_ADDRSTRLEN
|
||||
const char *strrstr2(const char *haystack, const char *needle);
|
||||
|
||||
void cleanup(check_curl_global_state global_state);
|
||||
|
||||
bool expected_statuscode(const char *reply, const char *statuscodes);
|
||||
char *string_statuscode(int major, int minor);
|
||||
|
||||
char *perfd_time(double elapsed_time, thresholds * /*thlds*/, long /*socket_timeout*/);
|
||||
char *perfd_time_connect(double elapsed_time_connect, long /*socket_timeout*/);
|
||||
char *perfd_time_ssl(double elapsed_time_ssl, long /*socket_timeout*/);
|
||||
char *perfd_time_firstbyte(double elapsed_time_firstbyte, long /*socket_timeout*/);
|
||||
char *perfd_time_headers(double elapsed_time_headers, long /*socket_timeout*/);
|
||||
char *perfd_time_transfer(double elapsed_time_transfer, long /*socket_timeout*/);
|
||||
char *perfd_size(size_t page_len, int /*min_page_len*/);
|
||||
|
||||
void test_file(char *path);
|
||||
|
|
@ -49,20 +49,7 @@ typedef struct {
|
|||
bool no_body;
|
||||
} check_curl_working_state;
|
||||
|
||||
check_curl_working_state check_curl_working_state_init() {
|
||||
check_curl_working_state result = {
|
||||
.server_address = NULL,
|
||||
.server_url = DEFAULT_SERVER_URL,
|
||||
.host_name = NULL,
|
||||
.http_method = NULL,
|
||||
.http_post_data = NULL,
|
||||
.virtualPort = 0,
|
||||
.serverPort = HTTP_PORT,
|
||||
.use_ssl = false,
|
||||
.no_body = false,
|
||||
};
|
||||
return result;
|
||||
}
|
||||
check_curl_working_state check_curl_working_state_init();
|
||||
|
||||
typedef struct {
|
||||
bool automatic_decompression;
|
||||
|
|
@ -123,63 +110,4 @@ typedef struct {
|
|||
bool display_html;
|
||||
} check_curl_config;
|
||||
|
||||
check_curl_config check_curl_config_init() {
|
||||
check_curl_config tmp = {
|
||||
.initial_config = check_curl_working_state_init(),
|
||||
|
||||
.curl_config =
|
||||
{
|
||||
.automatic_decompression = false,
|
||||
.socket_timeout = DEFAULT_SOCKET_TIMEOUT,
|
||||
.haproxy_protocol = false,
|
||||
.sin_family = AF_UNSPEC,
|
||||
.curl_http_version = CURL_HTTP_VERSION_NONE,
|
||||
.http_opt_headers = NULL,
|
||||
.http_opt_headers_count = 0,
|
||||
.ssl_version = CURL_SSLVERSION_DEFAULT,
|
||||
.client_cert = NULL,
|
||||
.client_privkey = NULL,
|
||||
.ca_cert = NULL,
|
||||
.verify_peer_and_host = false,
|
||||
.user_agent = {'\0'},
|
||||
.proxy_auth = "",
|
||||
.user_auth = "",
|
||||
.http_content_type = NULL,
|
||||
.cookie_jar_file = NULL,
|
||||
},
|
||||
.max_depth = DEFAULT_MAX_REDIRS,
|
||||
.followmethod = FOLLOW_HTTP_CURL,
|
||||
.followsticky = STICKY_NONE,
|
||||
|
||||
.maximum_age = -1,
|
||||
.regexp = {},
|
||||
.compiled_regex = {},
|
||||
.state_regex = STATE_CRITICAL,
|
||||
.invert_regex = false,
|
||||
.check_cert = false,
|
||||
.continue_after_check_cert = false,
|
||||
.days_till_exp_warn = 0,
|
||||
.days_till_exp_crit = 0,
|
||||
.thlds = NULL,
|
||||
.min_page_len = 0,
|
||||
.max_page_len = 0,
|
||||
.server_expect =
|
||||
{
|
||||
.string = HTTP_EXPECT,
|
||||
.is_present = false,
|
||||
},
|
||||
.string_expect = "",
|
||||
.header_expect = "",
|
||||
.on_redirect_result_state = STATE_OK,
|
||||
.on_redirect_dependent = true,
|
||||
|
||||
.show_extended_perfdata = false,
|
||||
.show_body = false,
|
||||
.display_html = false,
|
||||
};
|
||||
|
||||
snprintf(tmp.curl_config.user_agent, DEFAULT_BUFFER_SIZE, "%s/v%s (monitoring-plugins %s, %s)",
|
||||
"check_curl", NP_VERSION, VERSION, curl_version());
|
||||
|
||||
return tmp;
|
||||
}
|
||||
check_curl_config check_curl_config_init();
|
||||
|
|
|
|||
Loading…
Reference in a new issue