diff options
| author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-08-09 13:36:49 +0000 |
|---|---|---|
| committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-08-09 13:36:49 +0000 |
| commit | 90b45deb4138efb47efbdd98a4aede1aebb47146 (patch) | |
| tree | d27a0180ce89542ee546a0b1e958b68a114ea7ce /plugins/check_tcp.c | |
| parent | 4784cac1f017a67978c2f3f2af75b161d1ef33c0 (diff) | |
| download | monitoring-plugins-90b45deb4138efb47efbdd98a4aede1aebb47146.tar.gz | |
more pedantic compiler warnings
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@674 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_tcp.c')
| -rw-r--r-- | plugins/check_tcp.c | 209 |
1 files changed, 113 insertions, 96 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index a897d8e8..fc0572cc 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c | |||
| @@ -1,21 +1,27 @@ | |||
| 1 | /***************************************************************************** | 1 | /***************************************************************************** |
| 2 | * | 2 | |
| 3 | * This program is free software; you can redistribute it and/or modify | 3 | This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by | 4 | it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or | 5 | the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. | 6 | (at your option) any later version. |
| 7 | * | 7 | |
| 8 | * This program is distributed in the hope that it will be useful, | 8 | This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. | 11 | GNU General Public License for more details. |
| 12 | * | 12 | |
| 13 | * You should have received a copy of the GNU General Public License | 13 | You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software | 14 | along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 16 | * | 16 | |
| 17 | *****************************************************************************/ | 17 | *****************************************************************************/ |
| 18 | #include "config.h" | 18 | |
| 19 | /* progname changes depending on symlink called */ | ||
| 20 | char *progname = "check_tcp"; | ||
| 21 | const char *revision = "$Revision$"; | ||
| 22 | const char *copyright = "1999-2003"; | ||
| 23 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | ||
| 24 | |||
| 19 | #include "common.h" | 25 | #include "common.h" |
| 20 | #include "netutils.h" | 26 | #include "netutils.h" |
| 21 | #include "utils.h" | 27 | #include "utils.h" |
| @@ -51,9 +57,9 @@ enum { | |||
| 51 | }; | 57 | }; |
| 52 | 58 | ||
| 53 | int process_arguments (int, char **); | 59 | int process_arguments (int, char **); |
| 54 | void print_usage (void); | ||
| 55 | void print_help (void); | ||
| 56 | int my_recv (void); | 60 | int my_recv (void); |
| 61 | void print_help (void); | ||
| 62 | void print_usage (void); | ||
| 57 | 63 | ||
| 58 | char *SERVICE = NULL; | 64 | char *SERVICE = NULL; |
| 59 | char *SEND = NULL; | 65 | char *SEND = NULL; |
| @@ -67,94 +73,35 @@ char *server_address = NULL; | |||
| 67 | char *server_send = NULL; | 73 | char *server_send = NULL; |
| 68 | char *server_quit = NULL; | 74 | char *server_quit = NULL; |
| 69 | char **server_expect = NULL; | 75 | char **server_expect = NULL; |
| 70 | int server_expect_count = 0; | 76 | size_t server_expect_count = 0; |
| 71 | int maxbytes = 0; | 77 | int maxbytes = 0; |
| 72 | char **warn_codes = NULL; | 78 | char **warn_codes = NULL; |
| 73 | int warn_codes_count = 0; | 79 | size_t warn_codes_count = 0; |
| 74 | char **crit_codes = NULL; | 80 | char **crit_codes = NULL; |
| 75 | int crit_codes_count = 0; | 81 | size_t crit_codes_count = 0; |
| 76 | int delay = 0; | 82 | unsigned int delay = 0; |
| 77 | double warning_time = 0; | 83 | double warning_time = 0; |
| 78 | int check_warning_time = FALSE; | 84 | int check_warning_time = FALSE; |
| 79 | double critical_time = 0; | 85 | double critical_time = 0; |
| 80 | int check_critical_time = FALSE; | 86 | int check_critical_time = FALSE; |
| 81 | double elapsed_time = 0; | 87 | double elapsed_time = 0; |
| 88 | long microsec; | ||
| 82 | int verbose = FALSE; | 89 | int verbose = FALSE; |
| 83 | int use_ssl = FALSE; | 90 | int use_ssl = FALSE; |
| 84 | int sd = 0; | 91 | int sd = 0; |
| 85 | char *buffer = ""; | 92 | char *buffer; |
| 86 | |||
| 87 | /* progname changes depending on symlink called */ | ||
| 88 | char *progname = "check_tcp"; | ||
| 89 | const char *revision = "$Revision$"; | ||
| 90 | const char *copyright = "1999-2003"; | ||
| 91 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | ||
| 92 | |||
| 93 | |||
| 94 | |||
| 95 | |||
| 96 | void | ||
| 97 | print_usage (void) | ||
| 98 | { | ||
| 99 | printf (_("\ | ||
| 100 | Usage: %s -H host -p port [-w <warning time>] [-c <critical time>]\n\ | ||
| 101 | [-s <send string>] [-e <expect string>] [-q <quit string>]\n\ | ||
| 102 | [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\ | ||
| 103 | [-r <refuse state>] [-v] [-4|-6]\n"), progname); | ||
| 104 | printf (" %s (-h|--help)\n", progname); | ||
| 105 | printf (" %s (-V|--version)\n", progname); | ||
| 106 | } | ||
| 107 | void | ||
| 108 | print_help (void) | ||
| 109 | { | ||
| 110 | print_revision (progname, revision); | ||
| 111 | |||
| 112 | printf (_(COPYRIGHT), copyright, email); | ||
| 113 | |||
| 114 | printf (_("This plugin tests %s connections with the specified host.\n\n"), | ||
| 115 | SERVICE); | ||
| 116 | |||
| 117 | print_usage (); | ||
| 118 | |||
| 119 | printf (_(UT_HELP_VRSN)); | ||
| 120 | |||
| 121 | printf (_(UT_HOST_PORT), 'p', "none"); | ||
| 122 | |||
| 123 | printf (_(UT_IPv46)); | ||
| 124 | |||
| 125 | printf (_("\ | ||
| 126 | -s, --send=STRING\n\ | ||
| 127 | String to send to the server\n\ | ||
| 128 | -e, --expect=STRING\n\ | ||
| 129 | String to expect in server response\n\ | ||
| 130 | -q, --quit=STRING\n\ | ||
| 131 | String to send server to initiate a clean close of the connection\n")); | ||
| 132 | 93 | ||
| 133 | printf (_("\ | ||
| 134 | -r, --refuse=ok|warn|crit\n\ | ||
| 135 | Accept tcp refusals with states ok, warn, crit (default: crit)\n\ | ||
| 136 | -m, --maxbytes=INTEGER\n\ | ||
| 137 | Close connection once more than this number of bytes are received\n\ | ||
| 138 | -d, --delay=INTEGER\n\ | ||
| 139 | Seconds to wait between sending string and polling for response\n")); | ||
| 140 | 94 | ||
| 141 | printf (_(UT_WARN_CRIT)); | ||
| 142 | 95 | ||
| 143 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
| 144 | 96 | ||
| 145 | printf (_(UT_VERBOSE)); | ||
| 146 | 97 | ||
| 147 | printf (_(UT_SUPPORT)); | ||
| 148 | } | ||
| 149 | 98 | ||
| 150 | |||
| 151 | |||
| 152 | int | 99 | int |
| 153 | main (int argc, char **argv) | 100 | main (int argc, char **argv) |
| 154 | { | 101 | { |
| 155 | int result; | 102 | int result; |
| 156 | int i; | 103 | int i; |
| 157 | char *status = ""; | 104 | char *status; |
| 158 | struct timeval tv; | 105 | struct timeval tv; |
| 159 | 106 | ||
| 160 | setlocale (LC_ALL, ""); | 107 | setlocale (LC_ALL, ""); |
| @@ -296,10 +243,10 @@ main (int argc, char **argv) | |||
| 296 | asprintf (&server_send, "%s\r\n", server_send); | 243 | asprintf (&server_send, "%s\r\n", server_send); |
| 297 | #ifdef HAVE_SSL | 244 | #ifdef HAVE_SSL |
| 298 | if (use_ssl) | 245 | if (use_ssl) |
| 299 | SSL_write(ssl, server_send, strlen (server_send)); | 246 | SSL_write(ssl, server_send, (int)strlen(server_send)); |
| 300 | else | 247 | else |
| 301 | #endif | 248 | #endif |
| 302 | send (sd, server_send, strlen (server_send), 0); | 249 | send (sd, server_send, strlen(server_send), 0); |
| 303 | } | 250 | } |
| 304 | 251 | ||
| 305 | if (delay > 0) { | 252 | if (delay > 0) { |
| @@ -311,6 +258,7 @@ main (int argc, char **argv) | |||
| 311 | 258 | ||
| 312 | buffer = malloc (MAXBUF); | 259 | buffer = malloc (MAXBUF); |
| 313 | memset (buffer, '\0', MAXBUF); | 260 | memset (buffer, '\0', MAXBUF); |
| 261 | status = strdup (""); | ||
| 314 | /* watch for the expect string */ | 262 | /* watch for the expect string */ |
| 315 | while ((i = my_recv ()) > 0) { | 263 | while ((i = my_recv ()) > 0) { |
| 316 | buffer[i] = '\0'; | 264 | buffer[i] = '\0'; |
| @@ -333,8 +281,8 @@ main (int argc, char **argv) | |||
| 333 | if (server_expect_count > 0) { | 281 | if (server_expect_count > 0) { |
| 334 | for (i = 0;; i++) { | 282 | for (i = 0;; i++) { |
| 335 | if (verbose) | 283 | if (verbose) |
| 336 | printf ("%d %d\n", i, server_expect_count); | 284 | printf ("%d %d\n", i, (int)server_expect_count); |
| 337 | if (i >= server_expect_count) | 285 | if (i >= (int)server_expect_count) |
| 338 | die (STATE_WARNING, _("Invalid response from host\n")); | 286 | die (STATE_WARNING, _("Invalid response from host\n")); |
| 339 | if (strstr (status, server_expect[i])) | 287 | if (strstr (status, server_expect[i])) |
| 340 | break; | 288 | break; |
| @@ -345,7 +293,7 @@ main (int argc, char **argv) | |||
| 345 | if (server_quit != NULL) { | 293 | if (server_quit != NULL) { |
| 346 | #ifdef HAVE_SSL | 294 | #ifdef HAVE_SSL |
| 347 | if (use_ssl) { | 295 | if (use_ssl) { |
| 348 | SSL_write (ssl, server_quit, strlen (server_quit)); | 296 | SSL_write (ssl, server_quit, (int)strlen(server_quit)); |
| 349 | SSL_shutdown (ssl); | 297 | SSL_shutdown (ssl); |
| 350 | SSL_free (ssl); | 298 | SSL_free (ssl); |
| 351 | SSL_CTX_free (ctx); | 299 | SSL_CTX_free (ctx); |
| @@ -362,7 +310,8 @@ main (int argc, char **argv) | |||
| 362 | if (sd) | 310 | if (sd) |
| 363 | close (sd); | 311 | close (sd); |
| 364 | 312 | ||
| 365 | elapsed_time = delta_time (tv); | 313 | microsec = deltime (tv); |
| 314 | elapsed_time = (double)microsec / 1.0e6; | ||
| 366 | 315 | ||
| 367 | if (check_critical_time == TRUE && elapsed_time > critical_time) | 316 | if (check_critical_time == TRUE && elapsed_time > critical_time) |
| 368 | result = STATE_CRITICAL; | 317 | result = STATE_CRITICAL; |
| @@ -382,7 +331,7 @@ main (int argc, char **argv) | |||
| 382 | if (status && strlen(status) > 0) | 331 | if (status && strlen(status) > 0) |
| 383 | printf (" [%s]", status); | 332 | printf (" [%s]", status); |
| 384 | 333 | ||
| 385 | printf ("|time=%.3f\n", elapsed_time); | 334 | printf ("|time=%ldus\n", microsec); |
| 386 | 335 | ||
| 387 | return result; | 336 | return result; |
| 388 | } | 337 | } |
| @@ -479,13 +428,15 @@ process_arguments (int argc, char **argv) | |||
| 479 | case 'c': /* critical */ | 428 | case 'c': /* critical */ |
| 480 | if (!is_intnonneg (optarg)) | 429 | if (!is_intnonneg (optarg)) |
| 481 | usage (_("Critical threshold must be a nonnegative integer\n")); | 430 | usage (_("Critical threshold must be a nonnegative integer\n")); |
| 482 | critical_time = strtod (optarg, NULL); | 431 | else |
| 432 | critical_time = strtod (optarg, NULL); | ||
| 483 | check_critical_time = TRUE; | 433 | check_critical_time = TRUE; |
| 484 | break; | 434 | break; |
| 485 | case 'w': /* warning */ | 435 | case 'w': /* warning */ |
| 486 | if (!is_intnonneg (optarg)) | 436 | if (!is_intnonneg (optarg)) |
| 487 | usage (_("Warning threshold must be a nonnegative integer\n")); | 437 | usage (_("Warning threshold must be a nonnegative integer\n")); |
| 488 | warning_time = strtod (optarg, NULL); | 438 | else |
| 439 | warning_time = strtod (optarg, NULL); | ||
| 489 | check_warning_time = TRUE; | 440 | check_warning_time = TRUE; |
| 490 | break; | 441 | break; |
| 491 | case 'C': | 442 | case 'C': |
| @@ -499,12 +450,14 @@ process_arguments (int argc, char **argv) | |||
| 499 | case 't': /* timeout */ | 450 | case 't': /* timeout */ |
| 500 | if (!is_intpos (optarg)) | 451 | if (!is_intpos (optarg)) |
| 501 | usage (_("Timeout interval must be a positive integer\n")); | 452 | usage (_("Timeout interval must be a positive integer\n")); |
| 502 | socket_timeout = atoi (optarg); | 453 | else |
| 454 | socket_timeout = atoi (optarg); | ||
| 503 | break; | 455 | break; |
| 504 | case 'p': /* port */ | 456 | case 'p': /* port */ |
| 505 | if (!is_intpos (optarg)) | 457 | if (!is_intpos (optarg)) |
| 506 | usage (_("Server port must be a positive integer\n")); | 458 | usage (_("Server port must be a positive integer\n")); |
| 507 | server_port = atoi (optarg); | 459 | else |
| 460 | server_port = atoi (optarg); | ||
| 508 | break; | 461 | break; |
| 509 | case 's': | 462 | case 's': |
| 510 | server_send = optarg; | 463 | server_send = optarg; |
| @@ -520,7 +473,8 @@ process_arguments (int argc, char **argv) | |||
| 520 | case 'm': | 473 | case 'm': |
| 521 | if (!is_intpos (optarg)) | 474 | if (!is_intpos (optarg)) |
| 522 | usage (_("Maxbytes must be a positive integer\n")); | 475 | usage (_("Maxbytes must be a positive integer\n")); |
| 523 | maxbytes = atoi (optarg); | 476 | else |
| 477 | maxbytes = atoi (optarg); | ||
| 524 | case 'q': | 478 | case 'q': |
| 525 | server_quit = optarg; | 479 | server_quit = optarg; |
| 526 | break; | 480 | break; |
| @@ -627,3 +581,66 @@ my_recv (void) | |||
| 627 | 581 | ||
| 628 | return i; | 582 | return i; |
| 629 | } | 583 | } |
| 584 | |||
| 585 | |||
| 586 | |||
| 587 | |||
| 588 | |||
| 589 | |||
| 590 | void | ||
| 591 | print_help (void) | ||
| 592 | { | ||
| 593 | print_revision (progname, revision); | ||
| 594 | |||
| 595 | printf (_(COPYRIGHT), copyright, email); | ||
| 596 | |||
| 597 | printf (_("This plugin tests %s connections with the specified host.\n\n"), | ||
| 598 | SERVICE); | ||
| 599 | |||
| 600 | print_usage (); | ||
| 601 | |||
| 602 | printf (_(UT_HELP_VRSN)); | ||
| 603 | |||
| 604 | printf (_(UT_HOST_PORT), 'p', "none"); | ||
| 605 | |||
| 606 | printf (_(UT_IPv46)); | ||
| 607 | |||
| 608 | printf (_("\ | ||
| 609 | -s, --send=STRING\n\ | ||
| 610 | String to send to the server\n\ | ||
| 611 | -e, --expect=STRING\n\ | ||
| 612 | String to expect in server response\n\ | ||
| 613 | -q, --quit=STRING\n\ | ||
| 614 | String to send server to initiate a clean close of the connection\n")); | ||
| 615 | |||
| 616 | printf (_("\ | ||
| 617 | -r, --refuse=ok|warn|crit\n\ | ||
| 618 | Accept tcp refusals with states ok, warn, crit (default: crit)\n\ | ||
| 619 | -m, --maxbytes=INTEGER\n\ | ||
| 620 | Close connection once more than this number of bytes are received\n\ | ||
| 621 | -d, --delay=INTEGER\n\ | ||
| 622 | Seconds to wait between sending string and polling for response\n")); | ||
| 623 | |||
| 624 | printf (_(UT_WARN_CRIT)); | ||
| 625 | |||
| 626 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
| 627 | |||
| 628 | printf (_(UT_VERBOSE)); | ||
| 629 | |||
| 630 | printf (_(UT_SUPPORT)); | ||
| 631 | } | ||
| 632 | |||
| 633 | |||
| 634 | |||
| 635 | |||
| 636 | void | ||
| 637 | print_usage (void) | ||
| 638 | { | ||
| 639 | printf (_("\ | ||
| 640 | Usage: %s -H host -p port [-w <warning time>] [-c <critical time>]\n\ | ||
| 641 | [-s <send string>] [-e <expect string>] [-q <quit string>]\n\ | ||
| 642 | [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\ | ||
| 643 | [-r <refuse state>] [-v] [-4|-6]\n"), progname); | ||
| 644 | printf (" %s (-h|--help)\n", progname); | ||
| 645 | printf (" %s (-V|--version)\n", progname); | ||
| 646 | } | ||
