summaryrefslogtreecommitdiffstats
path: root/plugins/check_real.c
diff options
context:
space:
mode:
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>2002-11-12 11:26:01 (GMT)
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>2002-11-12 11:26:01 (GMT)
commit41367d9625c1d8a854bdeef4c09511ad4d93b192 (patch)
tree89f874444ede056c67cc4b5283e7b095efa9a255 /plugins/check_real.c
parentfb38088231efc4fc87308f54713ab91f33378c90 (diff)
downloadmonitoring-plugins-41367d9625c1d8a854bdeef4c09511ad4d93b192.tar.gz
remove call_getopt
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@188 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_real.c')
-rw-r--r--plugins/check_real.c105
1 files changed, 30 insertions, 75 deletions
diff --git a/plugins/check_real.c b/plugins/check_real.c
index ba746b8..c553352 100644
--- a/plugins/check_real.c
+++ b/plugins/check_real.c
@@ -55,17 +55,16 @@
55#define URL "" 55#define URL ""
56 56
57int process_arguments (int, char **); 57int process_arguments (int, char **);
58int call_getopt (int, char **);
59int validate_arguments (void); 58int validate_arguments (void);
60int check_disk (int usp, int free_disk); 59int check_disk (int usp, int free_disk);
61void print_help (void); 60void print_help (void);
62void print_usage (void); 61void print_usage (void);
63 62
64int server_port = PORT; 63int server_port = PORT;
65char *server_address = NULL; 64char *server_address = "";
66char *host_name = NULL; 65char *host_name = NULL;
67char *server_url = NULL; 66char *server_url = NULL;
68char *server_expect = NULL; 67char *server_expect = EXPECT;
69int warning_time = 0; 68int warning_time = 0;
70int check_warning_time = FALSE; 69int check_warning_time = FALSE;
71int critical_time = 0; 70int critical_time = 0;
@@ -117,7 +116,7 @@ main (int argc, char **argv)
117 terminate (STATE_CRITICAL, "No data received from %s\n", host_name); 116 terminate (STATE_CRITICAL, "No data received from %s\n", host_name);
118 117
119 /* make sure we find the response we are looking for */ 118 /* make sure we find the response we are looking for */
120 if (!strstr (buffer, EXPECT)) { 119 if (!strstr (buffer, server_expect)) {
121 if (server_port == PORT) 120 if (server_port == PORT)
122 printf ("Invalid REAL response received from host\n"); 121 printf ("Invalid REAL response received from host\n");
123 else 122 else
@@ -190,7 +189,7 @@ main (int argc, char **argv)
190 } 189 }
191 else { 190 else {
192 /* make sure we find the response we are looking for */ 191 /* make sure we find the response we are looking for */
193 if (!strstr (buffer, EXPECT)) { 192 if (!strstr (buffer, server_expect)) {
194 if (server_port == PORT) 193 if (server_port == PORT)
195 printf ("Invalid REAL response received from host\n"); 194 printf ("Invalid REAL response received from host\n");
196 else 195 else
@@ -275,52 +274,6 @@ process_arguments (int argc, char **argv)
275{ 274{
276 int c; 275 int c;
277 276
278 if (argc < 2)
279 return ERROR;
280
281 for (c = 1; c < argc; c++) {
282 if (strcmp ("-to", argv[c]) == 0)
283 strcpy (argv[c], "-t");
284 else if (strcmp ("-wt", argv[c]) == 0)
285 strcpy (argv[c], "-w");
286 else if (strcmp ("-ct", argv[c]) == 0)
287 strcpy (argv[c], "-c");
288 }
289
290
291
292 c = 0;
293 while ((c += (call_getopt (argc - c, &argv[c]))) < argc) {
294
295 if (is_option (argv[c]))
296 continue;
297
298 if (server_address == NULL) {
299 if (is_host (argv[c])) {
300 server_address = argv[c];
301 }
302 else {
303 usage ("Invalid host name");
304 }
305 }
306 }
307
308 if (server_expect == NULL)
309 server_expect = strscpy (NULL, EXPECT);
310
311 return validate_arguments ();
312}
313
314
315
316
317
318
319int
320call_getopt (int argc, char **argv)
321{
322 int c, i = 0;
323
324#ifdef HAVE_GETOPT_H 277#ifdef HAVE_GETOPT_H
325 int option_index = 0; 278 int option_index = 0;
326 static struct option long_options[] = { 279 static struct option long_options[] = {
@@ -339,6 +292,18 @@ call_getopt (int argc, char **argv)
339 }; 292 };
340#endif 293#endif
341 294
295 if (argc < 2)
296 return ERROR;
297
298 for (c = 1; c < argc; c++) {
299 if (strcmp ("-to", argv[c]) == 0)
300 strcpy (argv[c], "-t");
301 else if (strcmp ("-wt", argv[c]) == 0)
302 strcpy (argv[c], "-w");
303 else if (strcmp ("-ct", argv[c]) == 0)
304 strcpy (argv[c], "-c");
305 }
306
342 while (1) { 307 while (1) {
343#ifdef HAVE_GETOPT_H 308#ifdef HAVE_GETOPT_H
344 c = 309 c =
@@ -348,32 +313,11 @@ call_getopt (int argc, char **argv)
348 c = getopt (argc, argv, "+?hVI:H:e:u:p:w:c:t"); 313 c = getopt (argc, argv, "+?hVI:H:e:u:p:w:c:t");
349#endif 314#endif
350 315
351 i++; 316 if (c == -1 || c == EOF)
352
353 if (c == -1 || c == EOF || c == 1)
354 break; 317 break;
355 318
356 switch (c) { 319 switch (c) {
357 case 'I':
358 case 'H':
359 case 'e':
360 case 'u':
361 case 'p':
362 case 'w':
363 case 'c':
364 case 't':
365 i++;
366 }
367
368 switch (c) {
369 case 'I': /* hostname */ 320 case 'I': /* hostname */
370 if (is_host (optarg)) {
371 server_address = optarg;
372 }
373 else {
374 usage ("Invalid host name\n");
375 }
376 break;
377 case 'H': /* hostname */ 321 case 'H': /* hostname */
378 if (is_host (optarg)) { 322 if (is_host (optarg)) {
379 server_address = optarg; 323 server_address = optarg;
@@ -385,7 +329,7 @@ call_getopt (int argc, char **argv)
385 case 'e': /* string to expect in response header */ 329 case 'e': /* string to expect in response header */
386 server_expect = optarg; 330 server_expect = optarg;
387 break; 331 break;
388 case 'u': /* string to expect in response header */ 332 case 'u': /* server URL */
389 server_url = optarg; 333 server_url = optarg;
390 break; 334 break;
391 case 'p': /* port */ 335 case 'p': /* port */
@@ -435,7 +379,18 @@ call_getopt (int argc, char **argv)
435 usage ("Invalid argument\n"); 379 usage ("Invalid argument\n");
436 } 380 }
437 } 381 }
438 return i; 382
383 c = optind;
384 if (strlen(server_address) == 0 && argc > c) {
385 if (is_host (argv[c])) {
386 server_address = argv[c++];
387 }
388 else {
389 usage ("Invalid host name");
390 }
391 }
392
393 return validate_arguments ();
439} 394}
440 395
441 396