summaryrefslogtreecommitdiffstats
path: root/plugins/check_real.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_real.c')
-rw-r--r--plugins/check_real.c575
1 files changed, 280 insertions, 295 deletions
diff --git a/plugins/check_real.c b/plugins/check_real.c
index 15e035b6..ec0928ed 100644
--- a/plugins/check_real.c
+++ b/plugins/check_real.c
@@ -1,454 +1,439 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2 *
3* Monitoring check_real plugin 3 * Monitoring check_real plugin
4* 4 *
5* License: GPL 5 * License: GPL
6* Copyright (c) 2000-2007 Monitoring Plugins Development Team 6 * Copyright (c) 2000-2024 Monitoring Plugins Development Team
7* 7 *
8* Description: 8 * Description:
9* 9 *
10* This file contains the check_real plugin 10 * This file contains the check_real plugin
11* 11 *
12* This plugin tests the REAL service on the specified host. 12 * This plugin tests the REAL service on the specified host.
13* 13 *
14* 14 *
15* This program is free software: you can redistribute it and/or modify 15 * This program is free software: you can redistribute it and/or modify
16* it under the terms of the GNU General Public License as published by 16 * it under the terms of the GNU General Public License as published by
17* the Free Software Foundation, either version 3 of the License, or 17 * the Free Software Foundation, either version 3 of the License, or
18* (at your option) any later version. 18 * (at your option) any later version.
19* 19 *
20* This program is distributed in the hope that it will be useful, 20 * This program is distributed in the hope that it will be useful,
21* but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23* GNU General Public License for more details. 23 * GNU General Public License for more details.
24* 24 *
25* You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26* along with this program. If not, see <http://www.gnu.org/licenses/>. 26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27* 27 *
28* 28 *
29*****************************************************************************/ 29 *****************************************************************************/
30 30
31#include "states.h"
32#include <stdio.h>
31const char *progname = "check_real"; 33const char *progname = "check_real";
32const char *copyright = "2000-2007"; 34const char *copyright = "2000-2024";
33const char *email = "devel@monitoring-plugins.org"; 35const char *email = "devel@monitoring-plugins.org";
34 36
35#include "common.h" 37#include "common.h"
36#include "netutils.h" 38#include "netutils.h"
37#include "utils.h" 39#include "utils.h"
40#include "check_real.d/config.h"
38 41
39enum { 42#define EXPECT "RTSP/1."
40 PORT = 554 43#define URL ""
41};
42
43#define EXPECT "RTSP/1."
44#define URL ""
45 44
46int process_arguments (int, char **); 45typedef struct {
47int validate_arguments (void); 46 int errorcode;
48void print_help (void); 47 check_real_config config;
49void print_usage (void); 48} check_real_config_wrapper;
49static check_real_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/);
50 50
51int server_port = PORT; 51static void print_help(void);
52char *server_address; 52void print_usage(void);
53char *host_name;
54char *server_url = NULL;
55char *server_expect;
56int warning_time = 0;
57bool check_warning_time = false;
58int critical_time = 0;
59bool check_critical_time = false;
60bool verbose = false;
61 53
54static bool verbose = false;
62 55
63 56int main(int argc, char **argv) {
64int 57 setlocale(LC_ALL, "");
65main (int argc, char **argv) 58 bindtextdomain(PACKAGE, LOCALEDIR);
66{ 59 textdomain(PACKAGE);
67 int sd;
68 int result = STATE_UNKNOWN;
69 char buffer[MAX_INPUT_BUFFER];
70 char *status_line = NULL;
71
72 setlocale (LC_ALL, "");
73 bindtextdomain (PACKAGE, LOCALEDIR);
74 textdomain (PACKAGE);
75 60
76 /* Parse extra opts if any */ 61 /* Parse extra opts if any */
77 argv=np_extra_opts (&argc, argv, progname); 62 argv = np_extra_opts(&argc, argv, progname);
63
64 check_real_config_wrapper tmp_config = process_arguments(argc, argv);
65 if (tmp_config.errorcode == ERROR) {
66 usage4(_("Could not parse arguments"));
67 }
78 68
79 if (process_arguments (argc, argv) == ERROR) 69 const check_real_config config = tmp_config.config;
80 usage4 (_("Could not parse arguments"));
81 70
82 /* initialize alarm signal handling */ 71 /* initialize alarm signal handling */
83 signal (SIGALRM, socket_timeout_alarm_handler); 72 signal(SIGALRM, socket_timeout_alarm_handler);
84 73
85 /* set socket timeout */ 74 /* set socket timeout */
86 alarm (socket_timeout); 75 alarm(socket_timeout);
87 time (&start_time); 76 time(&start_time);
88 77
89 /* try to connect to the host at the given port number */ 78 /* try to connect to the host at the given port number */
90 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) 79 int socket;
91 die (STATE_CRITICAL, _("Unable to connect to %s on port %d\n"), 80 if (my_tcp_connect(config.server_address, config.server_port, &socket) != STATE_OK) {
92 server_address, server_port); 81 die(STATE_CRITICAL, _("Unable to connect to %s on port %d\n"), config.server_address, config.server_port);
82 }
93 83
94 /* Part I - Server Check */ 84 /* Part I - Server Check */
95 85
96 /* send the OPTIONS request */ 86 /* send the OPTIONS request */
97 sprintf (buffer, "OPTIONS rtsp://%s:%d RTSP/1.0\r\n", host_name, server_port); 87 char buffer[MAX_INPUT_BUFFER];
98 result = send (sd, buffer, strlen (buffer), 0); 88 sprintf(buffer, "OPTIONS rtsp://%s:%d RTSP/1.0\r\n", config.host_name, config.server_port);
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 }
99 93
100 /* send the header sync */ 94 /* send the header sync */
101 sprintf (buffer, "CSeq: 1\r\n"); 95 sprintf(buffer, "CSeq: 1\r\n");
102 result = send (sd, 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 }
103 100
104 /* 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 */
105 sprintf (buffer, "\r\n"); 102 sprintf(buffer, "\r\n");
106 result = send (sd, 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 }
107 107
108 /* watch for the REAL connection string */ 108 /* watch for the REAL connection string */
109 result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); 109 ssize_t received_bytes = recv(socket, buffer, MAX_INPUT_BUFFER - 1, 0);
110 110
111 /* return a CRITICAL status if we couldn't read any data */ 111 /* return a CRITICAL status if we couldn't read any data */
112 if (result == -1) 112 if (received_bytes == -1) {
113 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 }
114 115
116 mp_state_enum result = STATE_OK;
117 char *status_line = NULL;
115 /* make sure we find the response we are looking for */ 118 /* make sure we find the response we are looking for */
116 if (!strstr (buffer, server_expect)) { 119 if (!strstr(buffer, config.server_expect)) {
117 if (server_port == PORT) 120 if (config.server_port == PORT) {
118 printf ("%s\n", _("Invalid REAL response received from host")); 121 printf("%s\n", _("Invalid REAL response received from host"));
119 else 122 } else {
120 printf (_("Invalid REAL response received from host on port %d\n"), 123 printf(_("Invalid REAL response received from host on port %d\n"), config.server_port);
121 server_port); 124 }
122 } 125 } else {
123 else {
124 /* else we got the REAL string, so check the return code */ 126 /* else we got the REAL string, so check the return code */
125 127
126 time (&end_time); 128 time(&end_time);
127 129
128 result = STATE_OK; 130 result = STATE_OK;
129 131
130 status_line = (char *) strtok (buffer, "\n"); 132 status_line = strtok(buffer, "\n");
131 133
132 if (strstr (status_line, "200")) 134 if (strstr(status_line, "200")) {
133 result = STATE_OK; 135 result = STATE_OK;
136 }
134 137
135 /* client errors result in a warning state */ 138 /* client errors result in a warning state */
136 else if (strstr (status_line, "400")) 139 else if (strstr(status_line, "400")) {
137 result = STATE_WARNING; 140 result = STATE_WARNING;
138 else if (strstr (status_line, "401")) 141 } else if (strstr(status_line, "401")) {
139 result = STATE_WARNING; 142 result = STATE_WARNING;
140 else if (strstr (status_line, "402")) 143 } else if (strstr(status_line, "402")) {
141 result = STATE_WARNING; 144 result = STATE_WARNING;
142 else if (strstr (status_line, "403")) 145 } else if (strstr(status_line, "403")) {
143 result = STATE_WARNING; 146 result = STATE_WARNING;
144 else if (strstr (status_line, "404")) 147 } else if (strstr(status_line, "404")) {
145 result = STATE_WARNING; 148 result = STATE_WARNING;
146 149 } else if (strstr(status_line, "500")) {
147 /* server errors result in a critical state */ 150 /* server errors result in a critical state */
148 else if (strstr (status_line, "500"))
149 result = STATE_CRITICAL; 151 result = STATE_CRITICAL;
150 else if (strstr (status_line, "501")) 152 } else if (strstr(status_line, "501")) {
151 result = STATE_CRITICAL; 153 result = STATE_CRITICAL;
152 else if (strstr (status_line, "502")) 154 } else if (strstr(status_line, "502")) {
153 result = STATE_CRITICAL; 155 result = STATE_CRITICAL;
154 else if (strstr (status_line, "503")) 156 } else if (strstr(status_line, "503")) {
155 result = STATE_CRITICAL; 157 result = STATE_CRITICAL;
156 158 } else {
157 else
158 result = STATE_UNKNOWN; 159 result = STATE_UNKNOWN;
160 }
159 } 161 }
160 162
161 /* Part II - Check stream exists and is ok */ 163 /* Part II - Check stream exists and is ok */
162 if ((result == STATE_OK )&& (server_url != NULL) ) { 164 if ((result == STATE_OK) && (config.server_url != NULL)) {
163 165
164 /* Part I - Server Check */ 166 /* Part I - Server Check */
165 167
166 /* send the DESCRIBE request */ 168 /* send the DESCRIBE request */
167 sprintf (buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\r\n", host_name, 169 sprintf(buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\r\n", config.host_name, config.server_port, config.server_url);
168 server_port, server_url); 170
169 result = send (sd, buffer, strlen (buffer), 0); 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 }
170 175
171 /* send the header sync */ 176 /* send the header sync */
172 sprintf (buffer, "CSeq: 2\r\n"); 177 sprintf(buffer, "CSeq: 2\r\n");
173 result = send (sd, 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 }
174 182
175 /* 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 */
176 sprintf (buffer, "\r\n"); 184 sprintf(buffer, "\r\n");
177 result = send (sd, 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 }
178 189
179 /* watch for the REAL connection string */ 190 /* watch for the REAL connection string */
180 result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); 191 ssize_t recv_bytes = recv(socket, buffer, MAX_INPUT_BUFFER - 1, 0);
181 buffer[result] = '\0'; /* null terminate received buffer */ 192 if (recv_bytes == -1) {
182 193 /* return a CRITICAL status if we couldn't read any data */
183 /* return a CRITICAL status if we couldn't read any data */ 194 printf(_("No data received from host\n"));
184 if (result == -1) {
185 printf (_("No data received from host\n"));
186 result = STATE_CRITICAL; 195 result = STATE_CRITICAL;
187 } 196 } else {
188 else { 197 buffer[result] = '\0'; /* null terminate received buffer */
189 /* make sure we find the response we are looking for */ 198 /* make sure we find the response we are looking for */
190 if (!strstr (buffer, server_expect)) { 199 if (!strstr(buffer, config.server_expect)) {
191 if (server_port == PORT) 200 if (config.server_port == PORT) {
192 printf ("%s\n", _("Invalid REAL response received from host")); 201 printf("%s\n", _("Invalid REAL response received from host"));
193 else 202 } else {
194 printf (_("Invalid REAL response received from host on port %d\n"), 203 printf(_("Invalid REAL response received from host on port %d\n"), config.server_port);
195 server_port); 204 }
196 } 205 } else {
197 else {
198 206
199 /* else we got the REAL string, so check the return code */ 207 /* else we got the REAL string, so check the return code */
200 208
201 time (&end_time); 209 time(&end_time);
202 210
203 result = STATE_OK; 211 result = STATE_OK;
204 212
205 status_line = (char *) strtok (buffer, "\n"); 213 status_line = strtok(buffer, "\n");
206 214
207 if (strstr (status_line, "200")) 215 if (strstr(status_line, "200")) {
208 result = STATE_OK; 216 result = STATE_OK;
217 }
209 218
210 /* client errors result in a warning state */ 219 /* client errors result in a warning state */
211 else if (strstr (status_line, "400")) 220 else if (strstr(status_line, "400")) {
212 result = STATE_WARNING; 221 result = STATE_WARNING;
213 else if (strstr (status_line, "401")) 222 } else if (strstr(status_line, "401")) {
214 result = STATE_WARNING; 223 result = STATE_WARNING;
215 else if (strstr (status_line, "402")) 224 } else if (strstr(status_line, "402")) {
216 result = STATE_WARNING; 225 result = STATE_WARNING;
217 else if (strstr (status_line, "403")) 226 } else if (strstr(status_line, "403")) {
218 result = STATE_WARNING; 227 result = STATE_WARNING;
219 else if (strstr (status_line, "404")) 228 } else if (strstr(status_line, "404")) {
220 result = STATE_WARNING; 229 result = STATE_WARNING;
230 }
221 231
222 /* server errors result in a critical state */ 232 /* server errors result in a critical state */
223 else if (strstr (status_line, "500")) 233 else if (strstr(status_line, "500")) {
224 result = STATE_CRITICAL; 234 result = STATE_CRITICAL;
225 else if (strstr (status_line, "501")) 235 } else if (strstr(status_line, "501")) {
226 result = STATE_CRITICAL; 236 result = STATE_CRITICAL;
227 else if (strstr (status_line, "502")) 237 } else if (strstr(status_line, "502")) {
228 result = STATE_CRITICAL; 238 result = STATE_CRITICAL;
229 else if (strstr (status_line, "503")) 239 } else if (strstr(status_line, "503")) {
230 result = STATE_CRITICAL; 240 result = STATE_CRITICAL;
241 }
231 242
232 else 243 else {
233 result = STATE_UNKNOWN; 244 result = STATE_UNKNOWN;
245 }
234 } 246 }
235 } 247 }
236 } 248 }
237 249
238 /* Return results */ 250 /* Return results */
239 if (result == STATE_OK) { 251 if (result == STATE_OK) {
240 252 if (config.check_critical_time && (end_time - start_time) > config.critical_time) {
241 if (check_critical_time 253 result = STATE_CRITICAL;
242 && (end_time - start_time) > critical_time) result = STATE_CRITICAL; 254 } else if (config.check_warning_time && (end_time - start_time) > config.warning_time) {
243 else if (check_warning_time 255 result = STATE_WARNING;
244 && (end_time - start_time) > warning_time) result = 256 }
245 STATE_WARNING;
246 257
247 /* Put some HTML in here to create a dynamic link */ 258 /* Put some HTML in here to create a dynamic link */
248 printf (_("REAL %s - %d second response time\n"), 259 printf(_("REAL %s - %d second response time\n"), state_text(result), (int)(end_time - start_time));
249 state_text (result), 260 } else {
250 (int) (end_time - start_time)); 261 printf("%s\n", status_line);
251 } 262 }
252 else
253 printf ("%s\n", status_line);
254 263
255 /* close the connection */ 264 /* close the connection */
256 close (sd); 265 close(socket);
257 266
258 /* reset the alarm */ 267 /* reset the alarm */
259 alarm (0); 268 alarm(0);
260 269
261 return result; 270 exit(result);
262} 271}
263 272
264
265
266/* process command-line arguments */ 273/* process command-line arguments */
267int 274check_real_config_wrapper process_arguments(int argc, char **argv) {
268process_arguments (int argc, char **argv) 275 static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, {"IPaddress", required_argument, 0, 'I'},
269{ 276 {"expect", required_argument, 0, 'e'}, {"url", required_argument, 0, 'u'},
270 int c; 277 {"port", required_argument, 0, 'p'}, {"critical", required_argument, 0, 'c'},
271 278 {"warning", required_argument, 0, 'w'}, {"timeout", required_argument, 0, 't'},
272 int option = 0; 279 {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'},
273 static struct option longopts[] = { 280 {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}};
274 {"hostname", required_argument, 0, 'H'}, 281
275 {"IPaddress", required_argument, 0, 'I'}, 282 check_real_config_wrapper result = {
276 {"expect", required_argument, 0, 'e'}, 283 .errorcode = OK,
277 {"url", required_argument, 0, 'u'}, 284 .config = check_real_config_init(),
278 {"port", required_argument, 0, 'p'},
279 {"critical", required_argument, 0, 'c'},
280 {"warning", required_argument, 0, 'w'},
281 {"timeout", required_argument, 0, 't'},
282 {"verbose", no_argument, 0, 'v'},
283 {"version", no_argument, 0, 'V'},
284 {"help", no_argument, 0, 'h'},
285 {0, 0, 0, 0}
286 }; 285 };
287 286
288 if (argc < 2) 287 if (argc < 2) {
289 return ERROR; 288 result.errorcode = ERROR;
289 return result;
290 }
290 291
291 for (c = 1; c < argc; c++) { 292 for (int i = 1; i < argc; i++) {
292 if (strcmp ("-to", argv[c]) == 0) 293 if (strcmp("-to", argv[i]) == 0) {
293 strcpy (argv[c], "-t"); 294 strcpy(argv[i], "-t");
294 else if (strcmp ("-wt", argv[c]) == 0) 295 } else if (strcmp("-wt", argv[i]) == 0) {
295 strcpy (argv[c], "-w"); 296 strcpy(argv[i], "-w");
296 else if (strcmp ("-ct", argv[c]) == 0) 297 } else if (strcmp("-ct", argv[i]) == 0) {
297 strcpy (argv[c], "-c"); 298 strcpy(argv[i], "-c");
299 }
298 } 300 }
299 301
300 while (1) { 302 while (true) {
301 c = getopt_long (argc, argv, "+hvVI:H:e:u:p:w:c:t:", longopts, 303 int option = 0;
302 &option); 304 int option_char = getopt_long(argc, argv, "+hvVI:H:e:u:p:w:c:t:", longopts, &option);
303 305
304 if (c == -1 || c == EOF) 306 if (option_char == -1 || option_char == EOF) {
305 break; 307 break;
308 }
306 309
307 switch (c) { 310 switch (option_char) {
308 case 'I': /* hostname */ 311 case 'I': /* hostname */
309 case 'H': /* hostname */ 312 case 'H': /* hostname */
310 if (server_address) 313 if (result.config.server_address) {
311 break; 314 break;
312 else if (is_host (optarg)) 315 } else if (is_host(optarg)) {
313 server_address = optarg; 316 result.config.server_address = optarg;
314 else 317 } else {
315 usage2 (_("Invalid hostname/address"), optarg); 318 usage2(_("Invalid hostname/address"), optarg);
319 }
316 break; 320 break;
317 case 'e': /* string to expect in response header */ 321 case 'e': /* string to expect in response header */
318 server_expect = optarg; 322 result.config.server_expect = optarg;
319 break; 323 break;
320 case 'u': /* server URL */ 324 case 'u': /* server URL */
321 server_url = optarg; 325 result.config.server_url = optarg;
322 break; 326 break;
323 case 'p': /* port */ 327 case 'p': /* port */
324 if (is_intpos (optarg)) { 328 if (is_intpos(optarg)) {
325 server_port = atoi (optarg); 329 result.config.server_port = atoi(optarg);
326 } 330 } else {
327 else { 331 usage4(_("Port must be a positive integer"));
328 usage4 (_("Port must be a positive integer"));
329 } 332 }
330 break; 333 break;
331 case 'w': /* warning time threshold */ 334 case 'w': /* warning time threshold */
332 if (is_intnonneg (optarg)) { 335 if (is_intnonneg(optarg)) {
333 warning_time = atoi (optarg); 336 result.config.warning_time = atoi(optarg);
334 check_warning_time = true; 337 result.config.check_warning_time = true;
335 } 338 } else {
336 else { 339 usage4(_("Warning time must be a positive integer"));
337 usage4 (_("Warning time must be a positive integer"));
338 } 340 }
339 break; 341 break;
340 case 'c': /* critical time threshold */ 342 case 'c': /* critical time threshold */
341 if (is_intnonneg (optarg)) { 343 if (is_intnonneg(optarg)) {
342 critical_time = atoi (optarg); 344 result.config.critical_time = atoi(optarg);
343 check_critical_time = true; 345 result.config.check_critical_time = true;
344 } 346 } else {
345 else { 347 usage4(_("Critical time must be a positive integer"));
346 usage4 (_("Critical time must be a positive integer"));
347 } 348 }
348 break; 349 break;
349 case 'v': /* verbose */ 350 case 'v': /* verbose */
350 verbose = true; 351 verbose = true;
351 break; 352 break;
352 case 't': /* timeout */ 353 case 't': /* timeout */
353 if (is_intnonneg (optarg)) { 354 if (is_intnonneg(optarg)) {
354 socket_timeout = atoi (optarg); 355 socket_timeout = atoi(optarg);
355 } 356 } else {
356 else { 357 usage4(_("Timeout interval must be a positive integer"));
357 usage4 (_("Timeout interval must be a positive integer"));
358 } 358 }
359 break; 359 break;
360 case 'V': /* version */ 360 case 'V': /* version */
361 print_revision (progname, NP_VERSION); 361 print_revision(progname, NP_VERSION);
362 exit (STATE_UNKNOWN); 362 exit(STATE_UNKNOWN);
363 case 'h': /* help */ 363 case 'h': /* help */
364 print_help (); 364 print_help();
365 exit (STATE_UNKNOWN); 365 exit(STATE_UNKNOWN);
366 case '?': /* usage */ 366 case '?': /* usage */
367 usage5 (); 367 usage5();
368 } 368 }
369 } 369 }
370 370
371 c = optind; 371 int option_char = optind;
372 if (server_address==NULL && argc>c) { 372 if (result.config.server_address == NULL && argc > option_char) {
373 if (is_host (argv[c])) { 373 if (is_host(argv[option_char])) {
374 server_address = argv[c++]; 374 result.config.server_address = argv[option_char++];
375 } 375 } else {
376 else { 376 usage2(_("Invalid hostname/address"), argv[option_char]);
377 usage2 (_("Invalid hostname/address"), argv[c]);
378 } 377 }
379 } 378 }
380 379
381 if (server_address==NULL) 380 if (result.config.server_address == NULL) {
382 usage4 (_("You must provide a server to check")); 381 usage4(_("You must provide a server to check"));
383 382 }
384 if (host_name==NULL)
385 host_name = strdup (server_address);
386
387 if (server_expect == NULL)
388 server_expect = strdup(EXPECT);
389
390 return validate_arguments ();
391}
392 383
384 if (result.config.host_name == NULL) {
385 result.config.host_name = strdup(result.config.server_address);
386 }
393 387
388 if (result.config.server_expect == NULL) {
389 result.config.server_expect = strdup(EXPECT);
390 }
394 391
395int 392 return result;
396validate_arguments (void)
397{
398 return OK;
399} 393}
400 394
401 395void print_help(void) {
402
403void
404print_help (void)
405{
406 char *myport; 396 char *myport;
407 xasprintf (&myport, "%d", PORT); 397 xasprintf(&myport, "%d", PORT);
408 398
409 print_revision (progname, NP_VERSION); 399 print_revision(progname, NP_VERSION);
410 400
411 printf ("Copyright (c) 1999 Pedro Leite <leite@cic.ua.pt>\n"); 401 printf("Copyright (c) 1999 Pedro Leite <leite@cic.ua.pt>\n");
412 printf (COPYRIGHT, copyright, email); 402 printf(COPYRIGHT, copyright, email);
413 403
414 printf ("%s\n", _("This plugin tests the REAL service on the specified host.")); 404 printf("%s\n", _("This plugin tests the REAL service on the specified host."));
415 405
416 printf ("\n\n"); 406 printf("\n\n");
417 407
418 print_usage (); 408 print_usage();
419 409
420 printf (UT_HELP_VRSN); 410 printf(UT_HELP_VRSN);
421 printf (UT_EXTRA_OPTS); 411 printf(UT_EXTRA_OPTS);
422 412
423 printf (UT_HOST_PORT, 'p', myport); 413 printf(UT_HOST_PORT, 'p', myport);
424 414
425 printf (" %s\n", "-u, --url=STRING"); 415 printf(" %s\n", "-u, --url=STRING");
426 printf (" %s\n", _("Connect to this url")); 416 printf(" %s\n", _("Connect to this url"));
427 printf (" %s\n", "-e, --expect=STRING"); 417 printf(" %s\n", "-e, --expect=STRING");
428 printf (_("String to expect in first line of server response (default: %s)\n"), 418 printf(_("String to expect in first line of server response (default: %s)\n"), EXPECT);
429 EXPECT);
430 419
431 printf (UT_WARN_CRIT); 420 printf(UT_WARN_CRIT);
432 421
433 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 422 printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
434 423
435 printf (UT_VERBOSE); 424 printf(UT_VERBOSE);
436 425
437 printf ("\n"); 426 printf("\n");
438 printf ("%s\n", _("This plugin will attempt to open an RTSP connection with the host.")); 427 printf("%s\n", _("This plugin will attempt to open an RTSP connection with the host."));
439 printf ("%s\n", _("Successful connects return STATE_OK, refusals and timeouts return")); 428 printf("%s\n", _("Successful connects return STATE_OK, refusals and timeouts return"));
440 printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful connects,")); 429 printf("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful connects,"));
441 printf ("%s\n", _("but incorrect response messages from the host result in STATE_WARNING return")); 430 printf("%s\n", _("but incorrect response messages from the host result in STATE_WARNING return"));
442 printf ("%s\n", _("values.")); 431 printf("%s\n", _("values."));
443 432
444 printf (UT_SUPPORT); 433 printf(UT_SUPPORT);
445} 434}
446 435
447 436void print_usage(void) {
448 437 printf("%s\n", _("Usage:"));
449void 438 printf("%s -H host [-e expect] [-p port] [-w warn] [-c crit] [-t timeout] [-v]\n", progname);
450print_usage (void)
451{
452 printf ("%s\n", _("Usage:"));
453 printf ("%s -H host [-e expect] [-p port] [-w warn] [-c crit] [-t timeout] [-v]\n", progname);
454} 439}