summaryrefslogtreecommitdiffstats
path: root/plugins/check_curl.d
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-09-11 13:44:55 +0200
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-09-11 13:44:55 +0200
commit99206dab7aa272e5c16c672dca81e6044ac7a4eb (patch)
tree4741f0d1cb261a9d13ab705f71522fbbf3db059b /plugins/check_curl.d
parent6969f5719268dec6459d9107e11a711dab3a18dd (diff)
downloadmonitoring-plugins-99206dab7aa272e5c16c672dca81e6044ac7a4eb.tar.gz
check_curl: refactoring to modularize code
Diffstat (limited to 'plugins/check_curl.d')
-rw-r--r--plugins/check_curl.d/config.h78
1 files changed, 45 insertions, 33 deletions
diff --git a/plugins/check_curl.d/config.h b/plugins/check_curl.d/config.h
index 7566b19c..be25d1bb 100644
--- a/plugins/check_curl.d/config.h
+++ b/plugins/check_curl.d/config.h
@@ -65,27 +65,32 @@ check_curl_working_state check_curl_working_state_init() {
65} 65}
66 66
67typedef struct { 67typedef struct {
68 check_curl_working_state initial_config;
69 sa_family_t sin_family;
70
71 bool automatic_decompression; 68 bool automatic_decompression;
72 bool haproxy_protocol; 69 bool haproxy_protocol;
70 long socket_timeout;
71 sa_family_t sin_family;
72 int curl_http_version;
73 char **http_opt_headers;
74 size_t http_opt_headers_count;
75 int ssl_version;
73 char *client_cert; 76 char *client_cert;
74 char *client_privkey; 77 char *client_privkey;
75 char *ca_cert; 78 char *ca_cert;
76 int ssl_version; 79 bool verify_peer_and_host;
77 char user_agent[DEFAULT_BUFFER_SIZE]; 80 char user_agent[DEFAULT_BUFFER_SIZE];
78 char **http_opt_headers;
79 size_t http_opt_headers_count;
80 int max_depth;
81 char *http_content_type;
82 long socket_timeout;
83 char user_auth[MAX_INPUT_BUFFER];
84 char proxy_auth[MAX_INPUT_BUFFER]; 81 char proxy_auth[MAX_INPUT_BUFFER];
82 char user_auth[MAX_INPUT_BUFFER];
83 char *http_content_type;
84 char *cookie_jar_file;
85} check_curl_static_curl_config;
86
87typedef struct {
88 check_curl_working_state initial_config;
89
90 check_curl_static_curl_config curl_config;
91 int max_depth;
85 int followmethod; 92 int followmethod;
86 int followsticky; 93 int followsticky;
87 int curl_http_version;
88 char *cookie_jar_file;
89 94
90 int maximum_age; 95 int maximum_age;
91 96
@@ -97,7 +102,6 @@ typedef struct {
97 102
98 mp_state_enum state_regex; 103 mp_state_enum state_regex;
99 bool invert_regex; 104 bool invert_regex;
100 bool verify_peer_and_host;
101 bool check_cert; 105 bool check_cert;
102 bool continue_after_check_cert; 106 bool continue_after_check_cert;
103 int days_till_exp_warn; 107 int days_till_exp_warn;
@@ -111,7 +115,8 @@ typedef struct {
111 } server_expect; 115 } server_expect;
112 char string_expect[MAX_INPUT_BUFFER]; 116 char string_expect[MAX_INPUT_BUFFER];
113 char header_expect[MAX_INPUT_BUFFER]; 117 char header_expect[MAX_INPUT_BUFFER];
114 mp_state_enum onredirect; 118 mp_state_enum on_redirect_result_state;
119 bool on_redirect_dependent;
115 120
116 bool show_extended_perfdata; 121 bool show_extended_perfdata;
117 bool show_body; 122 bool show_body;
@@ -122,33 +127,35 @@ check_curl_config check_curl_config_init() {
122 check_curl_config tmp = { 127 check_curl_config tmp = {
123 .initial_config = check_curl_working_state_init(), 128 .initial_config = check_curl_working_state_init(),
124 129
125 .sin_family = AF_UNSPEC, 130 .curl_config =
126 131 {
127 .automatic_decompression = false, 132 .automatic_decompression = false,
128 .haproxy_protocol = false, 133 .socket_timeout = DEFAULT_SOCKET_TIMEOUT,
129 .client_cert = NULL, 134 .haproxy_protocol = false,
130 .client_privkey = NULL, 135 .sin_family = AF_UNSPEC,
131 .ca_cert = NULL, 136 .curl_http_version = CURL_HTTP_VERSION_NONE,
132 .ssl_version = CURL_SSLVERSION_DEFAULT, 137 .http_opt_headers = NULL,
133 .user_agent = {'\0'}, 138 .http_opt_headers_count = 0,
134 .http_opt_headers = NULL, 139 .ssl_version = CURL_SSLVERSION_DEFAULT,
135 .http_opt_headers_count = 0, 140 .client_cert = NULL,
141 .client_privkey = NULL,
142 .ca_cert = NULL,
143 .verify_peer_and_host = false,
144 .user_agent = {'\0'},
145 .proxy_auth = "",
146 .user_auth = "",
147 .http_content_type = NULL,
148 .cookie_jar_file = NULL,
149 },
136 .max_depth = DEFAULT_MAX_REDIRS, 150 .max_depth = DEFAULT_MAX_REDIRS,
137 .http_content_type = NULL,
138 .socket_timeout = DEFAULT_SOCKET_TIMEOUT,
139 .user_auth = "",
140 .proxy_auth = "",
141 .followmethod = FOLLOW_HTTP_CURL, 151 .followmethod = FOLLOW_HTTP_CURL,
142 .followsticky = STICKY_NONE, 152 .followsticky = STICKY_NONE,
143 .curl_http_version = CURL_HTTP_VERSION_NONE,
144 .cookie_jar_file = NULL,
145 153
146 .maximum_age = -1, 154 .maximum_age = -1,
147 .regexp = {}, 155 .regexp = {},
148 .compiled_regex = {}, 156 .compiled_regex = {},
149 .state_regex = STATE_CRITICAL, 157 .state_regex = STATE_CRITICAL,
150 .invert_regex = false, 158 .invert_regex = false,
151 .verify_peer_and_host = false,
152 .check_cert = false, 159 .check_cert = false,
153 .continue_after_check_cert = false, 160 .continue_after_check_cert = false,
154 .days_till_exp_warn = 0, 161 .days_till_exp_warn = 0,
@@ -163,11 +170,16 @@ check_curl_config check_curl_config_init() {
163 }, 170 },
164 .string_expect = "", 171 .string_expect = "",
165 .header_expect = "", 172 .header_expect = "",
166 .onredirect = STATE_OK, 173 .on_redirect_result_state = STATE_OK,
174 .on_redirect_dependent = true,
167 175
168 .show_extended_perfdata = false, 176 .show_extended_perfdata = false,
169 .show_body = false, 177 .show_body = false,
170 .display_html = false, 178 .display_html = false,
171 }; 179 };
180
181 snprintf(tmp.curl_config.user_agent, DEFAULT_BUFFER_SIZE, "%s/v%s (monitoring-plugins %s, %s)",
182 "check_curl", NP_VERSION, VERSION, curl_version());
183
172 return tmp; 184 return tmp;
173} 185}