diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-03-12 17:59:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-12 17:59:41 +0100 |
commit | 399121ed0d69a83cce483ce6b762ad48937a3c70 (patch) | |
tree | 1ce600825da4f3f7ee4fdf6f182691be2a34c987 | |
parent | 9cb0a6f0637713763607ba472db63aaf9bfda671 (diff) | |
parent | 97e65dddbda048f10b58ef8d190f2c0146a164a0 (diff) | |
download | monitoring-plugins-399121ed0d69a83cce483ce6b762ad48937a3c70.tar.gz |
Merge pull request #2103 from RincewindsHat/refactor/check_real
Refactor/check real
-rw-r--r-- | plugins/Makefile.am | 1 | ||||
-rw-r--r-- | plugins/check_real.c | 245 | ||||
-rw-r--r-- | plugins/check_real.d/config.h | 37 |
3 files changed, 180 insertions, 103 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index a1a8103d..bb3f029e 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am | |||
@@ -56,6 +56,7 @@ EXTRA_DIST = t \ | |||
56 | check_radius.d \ | 56 | check_radius.d \ |
57 | check_nagios.d \ | 57 | check_nagios.d \ |
58 | check_dbi.d \ | 58 | check_dbi.d \ |
59 | check_real.d \ | ||
59 | check_ssh.d \ | 60 | check_ssh.d \ |
60 | check_nt.d \ | 61 | check_nt.d \ |
61 | check_dns.d \ | 62 | check_dns.d \ |
diff --git a/plugins/check_real.c b/plugins/check_real.c index 369a88b1..ec0928ed 100644 --- a/plugins/check_real.c +++ b/plugins/check_real.c | |||
@@ -28,6 +28,8 @@ | |||
28 | * | 28 | * |
29 | *****************************************************************************/ | 29 | *****************************************************************************/ |
30 | 30 | ||
31 | #include "states.h" | ||
32 | #include <stdio.h> | ||
31 | const char *progname = "check_real"; | 33 | const char *progname = "check_real"; |
32 | const char *copyright = "2000-2024"; | 34 | const char *copyright = "2000-2024"; |
33 | const char *email = "devel@monitoring-plugins.org"; | 35 | const char *email = "devel@monitoring-plugins.org"; |
@@ -35,27 +37,20 @@ const char *email = "devel@monitoring-plugins.org"; | |||
35 | #include "common.h" | 37 | #include "common.h" |
36 | #include "netutils.h" | 38 | #include "netutils.h" |
37 | #include "utils.h" | 39 | #include "utils.h" |
38 | 40 | #include "check_real.d/config.h" | |
39 | enum { | ||
40 | PORT = 554 | ||
41 | }; | ||
42 | 41 | ||
43 | #define EXPECT "RTSP/1." | 42 | #define EXPECT "RTSP/1." |
44 | #define URL "" | 43 | #define URL "" |
45 | 44 | ||
46 | static int process_arguments(int, char **); | 45 | typedef struct { |
46 | int errorcode; | ||
47 | check_real_config config; | ||
48 | } check_real_config_wrapper; | ||
49 | static check_real_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/); | ||
50 | |||
47 | static void print_help(void); | 51 | static void print_help(void); |
48 | void print_usage(void); | 52 | void print_usage(void); |
49 | 53 | ||
50 | static int server_port = PORT; | ||
51 | static char *server_address; | ||
52 | static char *host_name; | ||
53 | static char *server_url = NULL; | ||
54 | static char *server_expect; | ||
55 | static int warning_time = 0; | ||
56 | static bool check_warning_time = false; | ||
57 | static int critical_time = 0; | ||
58 | static bool check_critical_time = false; | ||
59 | static bool verbose = false; | 54 | static bool verbose = false; |
60 | 55 | ||
61 | int main(int argc, char **argv) { | 56 | int main(int argc, char **argv) { |
@@ -66,8 +61,12 @@ int main(int argc, char **argv) { | |||
66 | /* Parse extra opts if any */ | 61 | /* Parse extra opts if any */ |
67 | argv = np_extra_opts(&argc, argv, progname); | 62 | argv = np_extra_opts(&argc, argv, progname); |
68 | 63 | ||
69 | if (process_arguments(argc, argv) == ERROR) | 64 | check_real_config_wrapper tmp_config = process_arguments(argc, argv); |
65 | if (tmp_config.errorcode == ERROR) { | ||
70 | usage4(_("Could not parse arguments")); | 66 | usage4(_("Could not parse arguments")); |
67 | } | ||
68 | |||
69 | const check_real_config config = tmp_config.config; | ||
71 | 70 | ||
72 | /* initialize alarm signal handling */ | 71 | /* initialize alarm signal handling */ |
73 | signal(SIGALRM, socket_timeout_alarm_handler); | 72 | signal(SIGALRM, socket_timeout_alarm_handler); |
@@ -78,38 +77,51 @@ int main(int argc, char **argv) { | |||
78 | 77 | ||
79 | /* try to connect to the host at the given port number */ | 78 | /* try to connect to the host at the given port number */ |
80 | int socket; | 79 | int socket; |
81 | if (my_tcp_connect(server_address, server_port, &socket) != STATE_OK) | 80 | if (my_tcp_connect(config.server_address, config.server_port, &socket) != STATE_OK) { |
82 | die(STATE_CRITICAL, _("Unable to connect to %s on port %d\n"), server_address, server_port); | 81 | die(STATE_CRITICAL, _("Unable to connect to %s on port %d\n"), config.server_address, config.server_port); |
82 | } | ||
83 | 83 | ||
84 | /* Part I - Server Check */ | 84 | /* Part I - Server Check */ |
85 | 85 | ||
86 | /* send the OPTIONS request */ | 86 | /* send the OPTIONS request */ |
87 | char buffer[MAX_INPUT_BUFFER]; | 87 | char buffer[MAX_INPUT_BUFFER]; |
88 | sprintf(buffer, "OPTIONS rtsp://%s:%d RTSP/1.0\r\n", host_name, server_port); | 88 | sprintf(buffer, "OPTIONS rtsp://%s:%d RTSP/1.0\r\n", config.host_name, config.server_port); |
89 | int result = send(socket, buffer, strlen(buffer), 0); | 89 | ssize_t sent_bytes = send(socket, buffer, strlen(buffer), 0); |
90 | if (sent_bytes == -1) { | ||
91 | die(STATE_CRITICAL, _("Sending options to %s failed\n"), config.host_name); | ||
92 | } | ||
90 | 93 | ||
91 | /* send the header sync */ | 94 | /* send the header sync */ |
92 | sprintf(buffer, "CSeq: 1\r\n"); | 95 | sprintf(buffer, "CSeq: 1\r\n"); |
93 | result = send(socket, buffer, strlen(buffer), 0); | 96 | sent_bytes = send(socket, buffer, strlen(buffer), 0); |
97 | if (sent_bytes == -1) { | ||
98 | die(STATE_CRITICAL, _("Sending header sync to %s failed\n"), config.host_name); | ||
99 | } | ||
94 | 100 | ||
95 | /* send a newline so the server knows we're done with the request */ | 101 | /* send a newline so the server knows we're done with the request */ |
96 | sprintf(buffer, "\r\n"); | 102 | sprintf(buffer, "\r\n"); |
97 | result = send(socket, buffer, strlen(buffer), 0); | 103 | sent_bytes = send(socket, buffer, strlen(buffer), 0); |
104 | if (sent_bytes == -1) { | ||
105 | die(STATE_CRITICAL, _("Sending newline to %s failed\n"), config.host_name); | ||
106 | } | ||
98 | 107 | ||
99 | /* watch for the REAL connection string */ | 108 | /* watch for the REAL connection string */ |
100 | result = recv(socket, buffer, MAX_INPUT_BUFFER - 1, 0); | 109 | ssize_t received_bytes = recv(socket, buffer, MAX_INPUT_BUFFER - 1, 0); |
101 | 110 | ||
102 | /* return a CRITICAL status if we couldn't read any data */ | 111 | /* return a CRITICAL status if we couldn't read any data */ |
103 | if (result == -1) | 112 | if (received_bytes == -1) { |
104 | die(STATE_CRITICAL, _("No data received from %s\n"), host_name); | 113 | die(STATE_CRITICAL, _("No data received from %s\n"), config.host_name); |
114 | } | ||
105 | 115 | ||
116 | mp_state_enum result = STATE_OK; | ||
106 | char *status_line = NULL; | 117 | char *status_line = NULL; |
107 | /* make sure we find the response we are looking for */ | 118 | /* make sure we find the response we are looking for */ |
108 | if (!strstr(buffer, server_expect)) { | 119 | if (!strstr(buffer, config.server_expect)) { |
109 | if (server_port == PORT) | 120 | if (config.server_port == PORT) { |
110 | printf("%s\n", _("Invalid REAL response received from host")); | 121 | printf("%s\n", _("Invalid REAL response received from host")); |
111 | else | 122 | } else { |
112 | printf(_("Invalid REAL response received from host on port %d\n"), server_port); | 123 | printf(_("Invalid REAL response received from host on port %d\n"), config.server_port); |
124 | } | ||
113 | } else { | 125 | } else { |
114 | /* else we got the REAL string, so check the return code */ | 126 | /* else we got the REAL string, so check the return code */ |
115 | 127 | ||
@@ -117,69 +129,79 @@ int main(int argc, char **argv) { | |||
117 | 129 | ||
118 | result = STATE_OK; | 130 | result = STATE_OK; |
119 | 131 | ||
120 | status_line = (char *)strtok(buffer, "\n"); | 132 | status_line = strtok(buffer, "\n"); |
121 | 133 | ||
122 | if (strstr(status_line, "200")) | 134 | if (strstr(status_line, "200")) { |
123 | result = STATE_OK; | 135 | result = STATE_OK; |
136 | } | ||
124 | 137 | ||
125 | /* client errors result in a warning state */ | 138 | /* client errors result in a warning state */ |
126 | else if (strstr(status_line, "400")) | 139 | else if (strstr(status_line, "400")) { |
127 | result = STATE_WARNING; | 140 | result = STATE_WARNING; |
128 | else if (strstr(status_line, "401")) | 141 | } else if (strstr(status_line, "401")) { |
129 | result = STATE_WARNING; | 142 | result = STATE_WARNING; |
130 | else if (strstr(status_line, "402")) | 143 | } else if (strstr(status_line, "402")) { |
131 | result = STATE_WARNING; | 144 | result = STATE_WARNING; |
132 | else if (strstr(status_line, "403")) | 145 | } else if (strstr(status_line, "403")) { |
133 | result = STATE_WARNING; | 146 | result = STATE_WARNING; |
134 | else if (strstr(status_line, "404")) | 147 | } else if (strstr(status_line, "404")) { |
135 | result = STATE_WARNING; | 148 | result = STATE_WARNING; |
136 | 149 | } else if (strstr(status_line, "500")) { | |
137 | /* server errors result in a critical state */ | 150 | /* server errors result in a critical state */ |
138 | else if (strstr(status_line, "500")) | ||
139 | result = STATE_CRITICAL; | 151 | result = STATE_CRITICAL; |
140 | else if (strstr(status_line, "501")) | 152 | } else if (strstr(status_line, "501")) { |
141 | result = STATE_CRITICAL; | 153 | result = STATE_CRITICAL; |
142 | else if (strstr(status_line, "502")) | 154 | } else if (strstr(status_line, "502")) { |
143 | result = STATE_CRITICAL; | 155 | result = STATE_CRITICAL; |
144 | else if (strstr(status_line, "503")) | 156 | } else if (strstr(status_line, "503")) { |
145 | result = STATE_CRITICAL; | 157 | result = STATE_CRITICAL; |
146 | 158 | } else { | |
147 | else | ||
148 | result = STATE_UNKNOWN; | 159 | result = STATE_UNKNOWN; |
160 | } | ||
149 | } | 161 | } |
150 | 162 | ||
151 | /* Part II - Check stream exists and is ok */ | 163 | /* Part II - Check stream exists and is ok */ |
152 | if ((result == STATE_OK) && (server_url != NULL)) { | 164 | if ((result == STATE_OK) && (config.server_url != NULL)) { |
153 | 165 | ||
154 | /* Part I - Server Check */ | 166 | /* Part I - Server Check */ |
155 | 167 | ||
156 | /* send the DESCRIBE request */ | 168 | /* send the DESCRIBE request */ |
157 | sprintf(buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\r\n", host_name, server_port, server_url); | 169 | sprintf(buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\r\n", config.host_name, config.server_port, config.server_url); |
158 | result = send(socket, buffer, strlen(buffer), 0); | 170 | |
171 | ssize_t sent_bytes = send(socket, buffer, strlen(buffer), 0); | ||
172 | if (sent_bytes == -1) { | ||
173 | die(STATE_CRITICAL, _("Sending DESCRIBE request to %s failed\n"), config.host_name); | ||
174 | } | ||
159 | 175 | ||
160 | /* send the header sync */ | 176 | /* send the header sync */ |
161 | sprintf(buffer, "CSeq: 2\r\n"); | 177 | sprintf(buffer, "CSeq: 2\r\n"); |
162 | result = send(socket, buffer, strlen(buffer), 0); | 178 | sent_bytes = send(socket, buffer, strlen(buffer), 0); |
179 | if (sent_bytes == -1) { | ||
180 | die(STATE_CRITICAL, _("Sending DESCRIBE request to %s failed\n"), config.host_name); | ||
181 | } | ||
163 | 182 | ||
164 | /* send a newline so the server knows we're done with the request */ | 183 | /* send a newline so the server knows we're done with the request */ |
165 | sprintf(buffer, "\r\n"); | 184 | sprintf(buffer, "\r\n"); |
166 | result = send(socket, buffer, strlen(buffer), 0); | 185 | sent_bytes = send(socket, buffer, strlen(buffer), 0); |
186 | if (sent_bytes == -1) { | ||
187 | die(STATE_CRITICAL, _("Sending DESCRIBE request to %s failed\n"), config.host_name); | ||
188 | } | ||
167 | 189 | ||
168 | /* watch for the REAL connection string */ | 190 | /* watch for the REAL connection string */ |
169 | result = recv(socket, buffer, MAX_INPUT_BUFFER - 1, 0); | 191 | ssize_t recv_bytes = recv(socket, buffer, MAX_INPUT_BUFFER - 1, 0); |
170 | buffer[result] = '\0'; /* null terminate received buffer */ | 192 | if (recv_bytes == -1) { |
171 | 193 | /* return a CRITICAL status if we couldn't read any data */ | |
172 | /* return a CRITICAL status if we couldn't read any data */ | ||
173 | if (result == -1) { | ||
174 | printf(_("No data received from host\n")); | 194 | printf(_("No data received from host\n")); |
175 | result = STATE_CRITICAL; | 195 | result = STATE_CRITICAL; |
176 | } else { | 196 | } else { |
197 | buffer[result] = '\0'; /* null terminate received buffer */ | ||
177 | /* make sure we find the response we are looking for */ | 198 | /* make sure we find the response we are looking for */ |
178 | if (!strstr(buffer, server_expect)) { | 199 | if (!strstr(buffer, config.server_expect)) { |
179 | if (server_port == PORT) | 200 | if (config.server_port == PORT) { |
180 | printf("%s\n", _("Invalid REAL response received from host")); | 201 | printf("%s\n", _("Invalid REAL response received from host")); |
181 | else | 202 | } else { |
182 | printf(_("Invalid REAL response received from host on port %d\n"), server_port); | 203 | printf(_("Invalid REAL response received from host on port %d\n"), config.server_port); |
204 | } | ||
183 | } else { | 205 | } else { |
184 | 206 | ||
185 | /* else we got the REAL string, so check the return code */ | 207 | /* else we got the REAL string, so check the return code */ |
@@ -188,51 +210,56 @@ int main(int argc, char **argv) { | |||
188 | 210 | ||
189 | result = STATE_OK; | 211 | result = STATE_OK; |
190 | 212 | ||
191 | status_line = (char *)strtok(buffer, "\n"); | 213 | status_line = strtok(buffer, "\n"); |
192 | 214 | ||
193 | if (strstr(status_line, "200")) | 215 | if (strstr(status_line, "200")) { |
194 | result = STATE_OK; | 216 | result = STATE_OK; |
217 | } | ||
195 | 218 | ||
196 | /* client errors result in a warning state */ | 219 | /* client errors result in a warning state */ |
197 | else if (strstr(status_line, "400")) | 220 | else if (strstr(status_line, "400")) { |
198 | result = STATE_WARNING; | 221 | result = STATE_WARNING; |
199 | else if (strstr(status_line, "401")) | 222 | } else if (strstr(status_line, "401")) { |
200 | result = STATE_WARNING; | 223 | result = STATE_WARNING; |
201 | else if (strstr(status_line, "402")) | 224 | } else if (strstr(status_line, "402")) { |
202 | result = STATE_WARNING; | 225 | result = STATE_WARNING; |
203 | else if (strstr(status_line, "403")) | 226 | } else if (strstr(status_line, "403")) { |
204 | result = STATE_WARNING; | 227 | result = STATE_WARNING; |
205 | else if (strstr(status_line, "404")) | 228 | } else if (strstr(status_line, "404")) { |
206 | result = STATE_WARNING; | 229 | result = STATE_WARNING; |
230 | } | ||
207 | 231 | ||
208 | /* server errors result in a critical state */ | 232 | /* server errors result in a critical state */ |
209 | else if (strstr(status_line, "500")) | 233 | else if (strstr(status_line, "500")) { |
210 | result = STATE_CRITICAL; | 234 | result = STATE_CRITICAL; |
211 | else if (strstr(status_line, "501")) | 235 | } else if (strstr(status_line, "501")) { |
212 | result = STATE_CRITICAL; | 236 | result = STATE_CRITICAL; |
213 | else if (strstr(status_line, "502")) | 237 | } else if (strstr(status_line, "502")) { |
214 | result = STATE_CRITICAL; | 238 | result = STATE_CRITICAL; |
215 | else if (strstr(status_line, "503")) | 239 | } else if (strstr(status_line, "503")) { |
216 | result = STATE_CRITICAL; | 240 | result = STATE_CRITICAL; |
241 | } | ||
217 | 242 | ||
218 | else | 243 | else { |
219 | result = STATE_UNKNOWN; | 244 | result = STATE_UNKNOWN; |
245 | } | ||
220 | } | 246 | } |
221 | } | 247 | } |
222 | } | 248 | } |
223 | 249 | ||
224 | /* Return results */ | 250 | /* Return results */ |
225 | if (result == STATE_OK) { | 251 | if (result == STATE_OK) { |
226 | 252 | if (config.check_critical_time && (end_time - start_time) > config.critical_time) { | |
227 | if (check_critical_time && (end_time - start_time) > critical_time) | ||
228 | result = STATE_CRITICAL; | 253 | result = STATE_CRITICAL; |
229 | else if (check_warning_time && (end_time - start_time) > warning_time) | 254 | } else if (config.check_warning_time && (end_time - start_time) > config.warning_time) { |
230 | result = STATE_WARNING; | 255 | result = STATE_WARNING; |
256 | } | ||
231 | 257 | ||
232 | /* Put some HTML in here to create a dynamic link */ | 258 | /* Put some HTML in here to create a dynamic link */ |
233 | printf(_("REAL %s - %d second response time\n"), state_text(result), (int)(end_time - start_time)); | 259 | printf(_("REAL %s - %d second response time\n"), state_text(result), (int)(end_time - start_time)); |
234 | } else | 260 | } else { |
235 | printf("%s\n", status_line); | 261 | printf("%s\n", status_line); |
262 | } | ||
236 | 263 | ||
237 | /* close the connection */ | 264 | /* close the connection */ |
238 | close(socket); | 265 | close(socket); |
@@ -240,11 +267,11 @@ int main(int argc, char **argv) { | |||
240 | /* reset the alarm */ | 267 | /* reset the alarm */ |
241 | alarm(0); | 268 | alarm(0); |
242 | 269 | ||
243 | return result; | 270 | exit(result); |
244 | } | 271 | } |
245 | 272 | ||
246 | /* process command-line arguments */ | 273 | /* process command-line arguments */ |
247 | int process_arguments(int argc, char **argv) { | 274 | check_real_config_wrapper process_arguments(int argc, char **argv) { |
248 | static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, {"IPaddress", required_argument, 0, 'I'}, | 275 | static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, {"IPaddress", required_argument, 0, 'I'}, |
249 | {"expect", required_argument, 0, 'e'}, {"url", required_argument, 0, 'u'}, | 276 | {"expect", required_argument, 0, 'e'}, {"url", required_argument, 0, 'u'}, |
250 | {"port", required_argument, 0, 'p'}, {"critical", required_argument, 0, 'c'}, | 277 | {"port", required_argument, 0, 'p'}, {"critical", required_argument, 0, 'c'}, |
@@ -252,61 +279,70 @@ int process_arguments(int argc, char **argv) { | |||
252 | {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, | 279 | {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, |
253 | {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; | 280 | {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; |
254 | 281 | ||
255 | if (argc < 2) | 282 | check_real_config_wrapper result = { |
256 | return ERROR; | 283 | .errorcode = OK, |
284 | .config = check_real_config_init(), | ||
285 | }; | ||
286 | |||
287 | if (argc < 2) { | ||
288 | result.errorcode = ERROR; | ||
289 | return result; | ||
290 | } | ||
257 | 291 | ||
258 | for (int i = 1; i < argc; i++) { | 292 | for (int i = 1; i < argc; i++) { |
259 | if (strcmp("-to", argv[i]) == 0) | 293 | if (strcmp("-to", argv[i]) == 0) { |
260 | strcpy(argv[i], "-t"); | 294 | strcpy(argv[i], "-t"); |
261 | else if (strcmp("-wt", argv[i]) == 0) | 295 | } else if (strcmp("-wt", argv[i]) == 0) { |
262 | strcpy(argv[i], "-w"); | 296 | strcpy(argv[i], "-w"); |
263 | else if (strcmp("-ct", argv[i]) == 0) | 297 | } else if (strcmp("-ct", argv[i]) == 0) { |
264 | strcpy(argv[i], "-c"); | 298 | strcpy(argv[i], "-c"); |
299 | } | ||
265 | } | 300 | } |
266 | 301 | ||
267 | int option_char; | ||
268 | while (true) { | 302 | while (true) { |
269 | int option = 0; | 303 | int option = 0; |
270 | option_char = getopt_long(argc, argv, "+hvVI:H:e:u:p:w:c:t:", longopts, &option); | 304 | int option_char = getopt_long(argc, argv, "+hvVI:H:e:u:p:w:c:t:", longopts, &option); |
271 | 305 | ||
272 | if (option_char == -1 || option_char == EOF) | 306 | if (option_char == -1 || option_char == EOF) { |
273 | break; | 307 | break; |
308 | } | ||
274 | 309 | ||
275 | switch (option_char) { | 310 | switch (option_char) { |
276 | case 'I': /* hostname */ | 311 | case 'I': /* hostname */ |
277 | case 'H': /* hostname */ | 312 | case 'H': /* hostname */ |
278 | if (server_address) | 313 | if (result.config.server_address) { |
279 | break; | 314 | break; |
280 | else if (is_host(optarg)) | 315 | } else if (is_host(optarg)) { |
281 | server_address = optarg; | 316 | result.config.server_address = optarg; |
282 | else | 317 | } else { |
283 | usage2(_("Invalid hostname/address"), optarg); | 318 | usage2(_("Invalid hostname/address"), optarg); |
319 | } | ||
284 | break; | 320 | break; |
285 | case 'e': /* string to expect in response header */ | 321 | case 'e': /* string to expect in response header */ |
286 | server_expect = optarg; | 322 | result.config.server_expect = optarg; |
287 | break; | 323 | break; |
288 | case 'u': /* server URL */ | 324 | case 'u': /* server URL */ |
289 | server_url = optarg; | 325 | result.config.server_url = optarg; |
290 | break; | 326 | break; |
291 | case 'p': /* port */ | 327 | case 'p': /* port */ |
292 | if (is_intpos(optarg)) { | 328 | if (is_intpos(optarg)) { |
293 | server_port = atoi(optarg); | 329 | result.config.server_port = atoi(optarg); |
294 | } else { | 330 | } else { |
295 | usage4(_("Port must be a positive integer")); | 331 | usage4(_("Port must be a positive integer")); |
296 | } | 332 | } |
297 | break; | 333 | break; |
298 | case 'w': /* warning time threshold */ | 334 | case 'w': /* warning time threshold */ |
299 | if (is_intnonneg(optarg)) { | 335 | if (is_intnonneg(optarg)) { |
300 | warning_time = atoi(optarg); | 336 | result.config.warning_time = atoi(optarg); |
301 | check_warning_time = true; | 337 | result.config.check_warning_time = true; |
302 | } else { | 338 | } else { |
303 | usage4(_("Warning time must be a positive integer")); | 339 | usage4(_("Warning time must be a positive integer")); |
304 | } | 340 | } |
305 | break; | 341 | break; |
306 | case 'c': /* critical time threshold */ | 342 | case 'c': /* critical time threshold */ |
307 | if (is_intnonneg(optarg)) { | 343 | if (is_intnonneg(optarg)) { |
308 | critical_time = atoi(optarg); | 344 | result.config.critical_time = atoi(optarg); |
309 | check_critical_time = true; | 345 | result.config.check_critical_time = true; |
310 | } else { | 346 | } else { |
311 | usage4(_("Critical time must be a positive integer")); | 347 | usage4(_("Critical time must be a positive integer")); |
312 | } | 348 | } |
@@ -332,25 +368,28 @@ int process_arguments(int argc, char **argv) { | |||
332 | } | 368 | } |
333 | } | 369 | } |
334 | 370 | ||
335 | option_char = optind; | 371 | int option_char = optind; |
336 | if (server_address == NULL && argc > option_char) { | 372 | if (result.config.server_address == NULL && argc > option_char) { |
337 | if (is_host(argv[option_char])) { | 373 | if (is_host(argv[option_char])) { |
338 | server_address = argv[option_char++]; | 374 | result.config.server_address = argv[option_char++]; |
339 | } else { | 375 | } else { |
340 | usage2(_("Invalid hostname/address"), argv[option_char]); | 376 | usage2(_("Invalid hostname/address"), argv[option_char]); |
341 | } | 377 | } |
342 | } | 378 | } |
343 | 379 | ||
344 | if (server_address == NULL) | 380 | if (result.config.server_address == NULL) { |
345 | usage4(_("You must provide a server to check")); | 381 | usage4(_("You must provide a server to check")); |
382 | } | ||
346 | 383 | ||
347 | if (host_name == NULL) | 384 | if (result.config.host_name == NULL) { |
348 | host_name = strdup(server_address); | 385 | result.config.host_name = strdup(result.config.server_address); |
386 | } | ||
349 | 387 | ||
350 | if (server_expect == NULL) | 388 | if (result.config.server_expect == NULL) { |
351 | server_expect = strdup(EXPECT); | 389 | result.config.server_expect = strdup(EXPECT); |
390 | } | ||
352 | 391 | ||
353 | return OK; | 392 | return result; |
354 | } | 393 | } |
355 | 394 | ||
356 | void print_help(void) { | 395 | void print_help(void) { |
diff --git a/plugins/check_real.d/config.h b/plugins/check_real.d/config.h new file mode 100644 index 00000000..c4663cf9 --- /dev/null +++ b/plugins/check_real.d/config.h | |||
@@ -0,0 +1,37 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include "../../config.h" | ||
4 | #include <stddef.h> | ||
5 | |||
6 | enum { | ||
7 | PORT = 554 | ||
8 | }; | ||
9 | |||
10 | typedef struct { | ||
11 | char *server_address; | ||
12 | char *host_name; | ||
13 | int server_port; | ||
14 | char *server_url; | ||
15 | |||
16 | char *server_expect; | ||
17 | int warning_time; | ||
18 | bool check_warning_time; | ||
19 | int critical_time; | ||
20 | bool check_critical_time; | ||
21 | } check_real_config; | ||
22 | |||
23 | check_real_config check_real_config_init() { | ||
24 | check_real_config tmp = { | ||
25 | .server_address = NULL, | ||
26 | .host_name = NULL, | ||
27 | .server_port = PORT, | ||
28 | .server_url = NULL, | ||
29 | |||
30 | .server_expect = NULL, | ||
31 | .warning_time = 0, | ||
32 | .check_warning_time = false, | ||
33 | .critical_time = 0, | ||
34 | .check_critical_time = false, | ||
35 | }; | ||
36 | return tmp; | ||
37 | } | ||