diff options
| author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-10-21 04:03:18 +0000 |
|---|---|---|
| committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-10-21 04:03:18 +0000 |
| commit | 5b12005c173584e55bf79e898ad515013d2fcf11 (patch) | |
| tree | d2c42ce3e07062a1e9101708f5e5e4b9ff3f79ae | |
| parent | daa6209ac5b3a94cb64c5a38f2b0800474ad71e9 (diff) | |
| download | monitoring-plugins-5b12005c173584e55bf79e898ad515013d2fcf11.tar.gz | |
these are all combined into check_tcp now
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@148 f882894a-f735-0410-b71e-b25c423dba1c
| -rw-r--r-- | plugins/check_ftp.c | 337 | ||||
| -rw-r--r-- | plugins/check_imap.c | 340 | ||||
| -rw-r--r-- | plugins/check_nntp.c | 418 | ||||
| -rw-r--r-- | plugins/check_pop.c | 364 |
4 files changed, 0 insertions, 1459 deletions
diff --git a/plugins/check_ftp.c b/plugins/check_ftp.c deleted file mode 100644 index 1c65d642..00000000 --- a/plugins/check_ftp.c +++ /dev/null | |||
| @@ -1,337 +0,0 @@ | |||
| 1 | /****************************************************************************** | ||
| 2 | * | ||
| 3 | * CHECK_FTP.C | ||
| 4 | * | ||
| 5 | * Program: FTP plugin for Nagios | ||
| 6 | * License: GPL | ||
| 7 | * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) | ||
| 8 | * | ||
| 9 | * $Id$ | ||
| 10 | * | ||
| 11 | * Description: | ||
| 12 | * | ||
| 13 | * This plugin will attempt to open an FTP connection with the host. | ||
| 14 | * Successul connects return STATE_OK, refusals and timeouts return | ||
| 15 | * STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful | ||
| 16 | * connects, but incorrect reponse messages from the host result in | ||
| 17 | * STATE_WARNING return values. | ||
| 18 | * | ||
| 19 | * License Information: | ||
| 20 | * | ||
| 21 | * This program is free software; you can redistribute it and/or modify | ||
| 22 | * it under the terms of the GNU General Public License as published by | ||
| 23 | * the Free Software Foundation; either version 2 of the License, or | ||
| 24 | * (at your option) any later version. | ||
| 25 | * | ||
| 26 | * This program is distributed in the hope that it will be useful, | ||
| 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 29 | * GNU General Public License for more details. | ||
| 30 | * | ||
| 31 | * You should have received a copy of the GNU General Public License | ||
| 32 | * along with this program; if not, write to the Free Software | ||
| 33 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 34 | * | ||
| 35 | *****************************************************************************/ | ||
| 36 | |||
| 37 | #include "config.h" | ||
| 38 | #include "common.h" | ||
| 39 | #include "netutils.h" | ||
| 40 | #include "utils.h" | ||
| 41 | |||
| 42 | #define PROGNAME "check_ftp" | ||
| 43 | |||
| 44 | #define FTP_PORT 21 | ||
| 45 | #define FTP_EXPECT "220" | ||
| 46 | #define FTP_QUIT "QUIT\n" | ||
| 47 | |||
| 48 | int process_arguments (int, char **); | ||
| 49 | int call_getopt (int, char **); | ||
| 50 | void print_usage (void); | ||
| 51 | void print_help (void); | ||
| 52 | |||
| 53 | time_t start_time, end_time; | ||
| 54 | int server_port = FTP_PORT; | ||
| 55 | char *server_address = NULL; | ||
| 56 | char *server_expect = NULL; | ||
| 57 | int warning_time = 0; | ||
| 58 | int check_warning_time = FALSE; | ||
| 59 | int critical_time = 0; | ||
| 60 | int check_critical_time = FALSE; | ||
| 61 | int verbose = FALSE; | ||
| 62 | |||
| 63 | |||
| 64 | int | ||
| 65 | main (int argc, char **argv) | ||
| 66 | { | ||
| 67 | int sd; | ||
| 68 | int result; | ||
| 69 | char buffer[MAX_INPUT_BUFFER]; | ||
| 70 | |||
| 71 | if (process_arguments (argc, argv) == ERROR) | ||
| 72 | usage ("Could not parse arguments\n"); | ||
| 73 | |||
| 74 | /* initialize alarm signal handling */ | ||
| 75 | signal (SIGALRM, socket_timeout_alarm_handler); | ||
| 76 | |||
| 77 | /* set socket timeout */ | ||
| 78 | alarm (socket_timeout); | ||
| 79 | |||
| 80 | /* try to connect to the host at the given port number */ | ||
| 81 | time (&start_time); | ||
| 82 | result = my_tcp_connect (server_address, server_port, &sd); | ||
| 83 | |||
| 84 | /* we connected, so close connection before exiting */ | ||
| 85 | if (result == STATE_OK) { | ||
| 86 | |||
| 87 | /* watch for the FTP connection string */ | ||
| 88 | result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); | ||
| 89 | |||
| 90 | /* strip the buffer of carriage returns */ | ||
| 91 | strip (buffer); | ||
| 92 | |||
| 93 | /* return a WARNING status if we couldn't read any data */ | ||
| 94 | if (result == -1) { | ||
| 95 | printf ("recv() failed\n"); | ||
| 96 | result = STATE_WARNING; | ||
| 97 | } | ||
| 98 | |||
| 99 | else { | ||
| 100 | |||
| 101 | /* make sure we find the response we are looking for */ | ||
| 102 | if (!strstr (buffer, server_expect)) { | ||
| 103 | |||
| 104 | if (server_port == FTP_PORT) | ||
| 105 | printf ("Invalid FTP response received from host\n"); | ||
| 106 | else | ||
| 107 | printf ("Invalid FTP response received from host on port %d\n", | ||
| 108 | server_port); | ||
| 109 | result = STATE_WARNING; | ||
| 110 | } | ||
| 111 | |||
| 112 | else { | ||
| 113 | time (&end_time); | ||
| 114 | |||
| 115 | result = STATE_OK; | ||
| 116 | |||
| 117 | if (check_critical_time == TRUE | ||
| 118 | && (end_time - start_time) > critical_time) result = | ||
| 119 | STATE_CRITICAL; | ||
| 120 | else if (check_warning_time == TRUE | ||
| 121 | && (end_time - start_time) > warning_time) result = | ||
| 122 | STATE_WARNING; | ||
| 123 | |||
| 124 | if (verbose == TRUE) | ||
| 125 | printf ("FTP %s - %d sec. response time, %s\n", | ||
| 126 | (result == STATE_OK) ? "ok" : "problem", | ||
| 127 | (int) (end_time - start_time), buffer); | ||
| 128 | else | ||
| 129 | printf ("FTP %s - %d second response time\n", | ||
| 130 | (result == STATE_OK) ? "ok" : "problem", | ||
| 131 | (int) (end_time - start_time)); | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | /* close the connection */ | ||
| 136 | send (sd, FTP_QUIT, strlen (FTP_QUIT), 0); | ||
| 137 | close (sd); | ||
| 138 | } | ||
| 139 | |||
| 140 | /* reset the alarm */ | ||
| 141 | alarm (0); | ||
| 142 | |||
| 143 | return result; | ||
| 144 | } | ||
| 145 | |||
| 146 | |||
| 147 | |||
| 148 | |||
| 149 | |||
| 150 | |||
| 151 | /* process command-line arguments */ | ||
| 152 | int | ||
| 153 | process_arguments (int argc, char **argv) | ||
| 154 | { | ||
| 155 | int c; | ||
| 156 | |||
| 157 | if (argc < 2) | ||
| 158 | usage ("\n"); | ||
| 159 | |||
| 160 | for (c = 1; c < argc; c++) { | ||
| 161 | if (strcmp ("-to", argv[c]) == 0) | ||
| 162 | strcpy (argv[c], "-t"); | ||
| 163 | else if (strcmp ("-wt", argv[c]) == 0) | ||
| 164 | strcpy (argv[c], "-w"); | ||
| 165 | else if (strcmp ("-ct", argv[c]) == 0) | ||
| 166 | strcpy (argv[c], "-c"); | ||
| 167 | } | ||
| 168 | |||
| 169 | c = 0; | ||
| 170 | while ((c += call_getopt (argc - c, &argv[c])) < argc) { | ||
| 171 | |||
| 172 | if (is_option (argv[c])) | ||
| 173 | continue; | ||
| 174 | |||
| 175 | if (server_address == NULL) { | ||
| 176 | if (argc > c) { | ||
| 177 | if (is_host (argv[c]) == FALSE) | ||
| 178 | usage ("Invalid host name/address\n"); | ||
| 179 | server_address = argv[c]; | ||
| 180 | } | ||
| 181 | else { | ||
| 182 | usage ("Host name was not supplied\n"); | ||
| 183 | } | ||
| 184 | } | ||
| 185 | } | ||
| 186 | |||
| 187 | if (server_expect == NULL) | ||
| 188 | server_expect = strscpy (NULL, FTP_EXPECT); | ||
| 189 | |||
| 190 | return OK; | ||
| 191 | } | ||
| 192 | |||
| 193 | |||
| 194 | |||
| 195 | |||
| 196 | |||
| 197 | int | ||
| 198 | call_getopt (int argc, char **argv) | ||
| 199 | { | ||
| 200 | int c, i = 0; | ||
| 201 | |||
| 202 | #ifdef HAVE_GETOPT_H | ||
| 203 | int option_index = 0; | ||
| 204 | static struct option long_options[] = { | ||
| 205 | {"hostname", required_argument, 0, 'H'}, | ||
| 206 | {"expect", required_argument, 0, 'e'}, | ||
| 207 | {"critical", required_argument, 0, 'c'}, | ||
| 208 | {"warning", required_argument, 0, 'w'}, | ||
| 209 | {"timeout", required_argument, 0, 'w'}, | ||
| 210 | {"port", required_argument, 0, 'p'}, | ||
| 211 | {"verbose", no_argument, 0, 'v'}, | ||
| 212 | {"version", no_argument, 0, 'V'}, | ||
| 213 | {"help", no_argument, 0, 'h'}, | ||
| 214 | {0, 0, 0, 0} | ||
| 215 | }; | ||
| 216 | #endif | ||
| 217 | |||
| 218 | while (1) { | ||
| 219 | #ifdef HAVE_GETOPT_H | ||
| 220 | c = | ||
| 221 | getopt_long (argc, argv, "+hVvH:e:c:w:t:p:", long_options, | ||
| 222 | &option_index); | ||
| 223 | #else | ||
| 224 | c = getopt (argc, argv, "+hVvH:e:c:w:t:p:"); | ||
| 225 | #endif | ||
| 226 | |||
| 227 | i++; | ||
| 228 | |||
| 229 | if (c == -1 || c == EOF || c == 1) | ||
| 230 | break; | ||
| 231 | |||
| 232 | switch (c) { | ||
| 233 | case 'H': | ||
| 234 | case 'e': | ||
| 235 | case 'c': | ||
| 236 | case 'w': | ||
| 237 | case 't': | ||
| 238 | case 'p': | ||
| 239 | i++; | ||
| 240 | } | ||
| 241 | |||
| 242 | switch (c) { | ||
| 243 | case '?': /* print short usage statement if args not parsable */ | ||
| 244 | printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg); | ||
| 245 | print_usage (); | ||
| 246 | exit (STATE_UNKNOWN); | ||
| 247 | case 'h': /* help */ | ||
| 248 | print_help (); | ||
| 249 | exit (STATE_OK); | ||
| 250 | case 'V': /* version */ | ||
| 251 | print_revision (my_basename (argv[0]), "$Revision$"); | ||
| 252 | exit (STATE_OK); | ||
| 253 | case 'v': /* verbose mode */ | ||
| 254 | verbose = TRUE; | ||
| 255 | break; | ||
| 256 | case 'H': /* hostname */ | ||
| 257 | if (is_host (optarg) == FALSE) | ||
| 258 | usage ("Invalid host name/address\n"); | ||
| 259 | server_address = optarg; | ||
| 260 | break; | ||
| 261 | case 'e': /* expect */ | ||
| 262 | server_expect = optarg; | ||
| 263 | break; | ||
| 264 | case 'c': /* critical */ | ||
| 265 | if (!is_intnonneg (optarg)) | ||
| 266 | usage ("Critical threshold must be a nonnegative integer\n"); | ||
| 267 | critical_time = atoi (optarg); | ||
| 268 | check_critical_time = TRUE; | ||
| 269 | break; | ||
| 270 | case 'w': /* warning */ | ||
| 271 | if (!is_intnonneg (optarg)) | ||
| 272 | usage ("Warning threshold must be a nonnegative integer\n"); | ||
| 273 | warning_time = atoi (optarg); | ||
| 274 | check_warning_time = TRUE; | ||
| 275 | break; | ||
| 276 | case 't': /* timeout */ | ||
| 277 | if (!is_intnonneg (optarg)) | ||
| 278 | usage ("Timeout interval must be a nonnegative integer\n"); | ||
| 279 | socket_timeout = atoi (optarg); | ||
| 280 | break; | ||
| 281 | case 'p': /* port */ | ||
| 282 | if (!is_intnonneg (optarg)) | ||
| 283 | usage ("Serevr port must be a nonnegative integer\n"); | ||
| 284 | server_port = atoi (optarg); | ||
| 285 | break; | ||
| 286 | } | ||
| 287 | } | ||
| 288 | return i; | ||
| 289 | } | ||
| 290 | |||
| 291 | |||
| 292 | |||
| 293 | |||
| 294 | |||
| 295 | void | ||
| 296 | print_usage (void) | ||
| 297 | { | ||
| 298 | printf | ||
| 299 | ("Usage: %s -H <host_address> [-e expect] [-p port] [-w warn_time]\n" | ||
| 300 | " [-c crit_time] [-t to_sec] [-v]\n", PROGNAME); | ||
| 301 | } | ||
| 302 | |||
| 303 | |||
| 304 | |||
| 305 | |||
| 306 | |||
| 307 | void | ||
| 308 | print_help (void) | ||
| 309 | { | ||
| 310 | print_revision (PROGNAME, "$Revision$"); | ||
| 311 | printf | ||
| 312 | ("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n\n" | ||
| 313 | "This plugin tests an FTP connection with the specified host.\n\n"); | ||
| 314 | print_usage (); | ||
| 315 | printf | ||
| 316 | ("Options:\n" | ||
| 317 | " -H, --hostname=ADDRESS\n" | ||
| 318 | " Host name argument for servers using host headers (use numeric\n" | ||
| 319 | " address if possible to bypass DNS lookup).\n" | ||
| 320 | " -e, --expect=STRING\n" | ||
| 321 | " String to expect in first line of server response (default: %s)\n" | ||
| 322 | " -p, --port=INTEGER\n" | ||
| 323 | " Port number (default: %d)\n" | ||
| 324 | " -w, --warning=INTEGER\n" | ||
| 325 | " Response time to result in warning status (seconds)\n" | ||
| 326 | " -c, --critical=INTEGER\n" | ||
| 327 | " Response time to result in critical status (seconds)\n" | ||
| 328 | " -t, --timeout=INTEGER\n" | ||
| 329 | " Seconds before connection times out (default: %d)\n" | ||
| 330 | " -v" | ||
| 331 | " Show details for command-line debugging (do not use with nagios server)\n" | ||
| 332 | " -h, --help\n" | ||
| 333 | " Print detailed help screen\n" | ||
| 334 | " -V, --version\n" | ||
| 335 | " Print version information\n", | ||
| 336 | FTP_EXPECT, FTP_PORT, DEFAULT_SOCKET_TIMEOUT); | ||
| 337 | } | ||
diff --git a/plugins/check_imap.c b/plugins/check_imap.c deleted file mode 100644 index 5ec0439b..00000000 --- a/plugins/check_imap.c +++ /dev/null | |||
| @@ -1,340 +0,0 @@ | |||
| 1 | /****************************************************************************** | ||
| 2 | * | ||
| 3 | * CHECK_IMAP.C | ||
| 4 | * | ||
| 5 | * Program: IMAP4 plugin for Nagios | ||
| 6 | * License: GPL | ||
| 7 | * Copyright (c) 1999 Tom Shields (tom.shields@basswood.com) | ||
| 8 | * | ||
| 9 | * $Id$ | ||
| 10 | * | ||
| 11 | * Description: | ||
| 12 | * | ||
| 13 | * This plugin will attempt to open an IMAP connection with the host. | ||
| 14 | * Successul connects return STATE_OK, refusals and timeouts return | ||
| 15 | * STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful | ||
| 16 | * connects, but incorrect reponse messages from the host result in | ||
| 17 | * STATE_WARNING return values. | ||
| 18 | * | ||
| 19 | * Modifications: | ||
| 20 | * 04-13-1999 Tom Shields | ||
| 21 | * Initial code | ||
| 22 | * 08-18-1999 Ethan Galstad <nagios@nagios.org> | ||
| 23 | * Modified code to work with common plugin functions, added socket | ||
| 24 | * timeout, string * length checking | ||
| 25 | * 09-19-1999 Ethan Galstad <nagios@nagios.org> | ||
| 26 | * Changed expect string from "+OK" to "* OK" and default port to 143 | ||
| 27 | *****************************************************************************/ | ||
| 28 | |||
| 29 | #include "config.h" | ||
| 30 | #include "common.h" | ||
| 31 | #include "netutils.h" | ||
| 32 | #include "utils.h" | ||
| 33 | |||
| 34 | #define PROGNAME "check_imap" | ||
| 35 | |||
| 36 | #define PORT 143 | ||
| 37 | #define EXPECT "* OK" | ||
| 38 | #define QUIT "a1 LOGOUT\n" | ||
| 39 | |||
| 40 | int process_arguments (int, char **); | ||
| 41 | int call_getopt (int, char **); | ||
| 42 | int validate_arguments (void); | ||
| 43 | int check_disk (int usp, int free_disk); | ||
| 44 | void print_help (void); | ||
| 45 | void print_usage (void); | ||
| 46 | |||
| 47 | int server_port = PORT; | ||
| 48 | char *server_address = NULL; | ||
| 49 | char *server_expect = NULL; | ||
| 50 | int warning_time = 0; | ||
| 51 | int check_warning_time = FALSE; | ||
| 52 | int critical_time = 0; | ||
| 53 | int check_critical_time = FALSE; | ||
| 54 | int verbose = FALSE; | ||
| 55 | |||
| 56 | int | ||
| 57 | main (int argc, char **argv) | ||
| 58 | { | ||
| 59 | int sd; | ||
| 60 | int result; | ||
| 61 | char buffer[MAX_INPUT_BUFFER]; | ||
| 62 | |||
| 63 | if (process_arguments (argc, argv) != OK) | ||
| 64 | usage ("Invalid command arguments supplied\n"); | ||
| 65 | |||
| 66 | /* initialize alarm signal handling */ | ||
| 67 | signal (SIGALRM, socket_timeout_alarm_handler); | ||
| 68 | |||
| 69 | /* set socket timeout */ | ||
| 70 | alarm (socket_timeout); | ||
| 71 | |||
| 72 | /* try to connect to the host at the given port number */ | ||
| 73 | time (&start_time); | ||
| 74 | result = my_tcp_connect (server_address, server_port, &sd); | ||
| 75 | |||
| 76 | /* we connected, so close connection before exiting */ | ||
| 77 | if (result == STATE_OK) { | ||
| 78 | |||
| 79 | /* watch for the IMAP connection string */ | ||
| 80 | result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); | ||
| 81 | |||
| 82 | /* strip carriange returns */ | ||
| 83 | strip (buffer); | ||
| 84 | |||
| 85 | /* return a WARNING status if we couldn't read any data */ | ||
| 86 | if (result == -1) { | ||
| 87 | printf ("recv() failed\n"); | ||
| 88 | result = STATE_WARNING; | ||
| 89 | } | ||
| 90 | |||
| 91 | else { | ||
| 92 | |||
| 93 | /* make sure we find the response we are looking for */ | ||
| 94 | if (!strstr (buffer, server_expect)) { | ||
| 95 | if (server_port == server_port) | ||
| 96 | printf ("Invalid IMAP response received from host\n"); | ||
| 97 | else | ||
| 98 | printf ("Invalid IMAP response received from host on port %d\n", | ||
| 99 | server_port); | ||
| 100 | result = STATE_WARNING; | ||
| 101 | } | ||
| 102 | |||
| 103 | else { | ||
| 104 | time (&end_time); | ||
| 105 | printf ("IMAP ok - %d second response time\n", | ||
| 106 | (int) (end_time - start_time)); | ||
| 107 | result = STATE_OK; | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | /* close the connection */ | ||
| 112 | send (sd, QUIT, strlen (QUIT), 0); | ||
| 113 | close (sd); | ||
| 114 | } | ||
| 115 | |||
| 116 | /* reset the alarm handler */ | ||
| 117 | alarm (0); | ||
| 118 | |||
| 119 | return result; | ||
| 120 | } | ||
| 121 | |||
| 122 | |||
| 123 | |||
| 124 | |||
| 125 | |||
| 126 | /* process command-line arguments */ | ||
| 127 | int | ||
| 128 | process_arguments (int argc, char **argv) | ||
| 129 | { | ||
| 130 | int c; | ||
| 131 | |||
| 132 | if (argc < 2) | ||
| 133 | return ERROR; | ||
| 134 | |||
| 135 | for (c = 1; c < argc; c++) { | ||
| 136 | if (strcmp ("-to", argv[c]) == 0) | ||
| 137 | strcpy (argv[c], "-t"); | ||
| 138 | else if (strcmp ("-wt", argv[c]) == 0) | ||
| 139 | strcpy (argv[c], "-w"); | ||
| 140 | else if (strcmp ("-ct", argv[c]) == 0) | ||
| 141 | strcpy (argv[c], "-c"); | ||
| 142 | } | ||
| 143 | |||
| 144 | |||
| 145 | |||
| 146 | c = 0; | ||
| 147 | while ((c += (call_getopt (argc - c, &argv[c]))) < argc) { | ||
| 148 | |||
| 149 | if (is_option (argv[c])) | ||
| 150 | continue; | ||
| 151 | |||
| 152 | if (server_address == NULL) { | ||
| 153 | if (is_host (argv[c])) { | ||
| 154 | server_address = argv[c]; | ||
| 155 | } | ||
| 156 | else { | ||
| 157 | usage ("Invalid host name"); | ||
| 158 | } | ||
| 159 | } | ||
| 160 | } | ||
| 161 | |||
| 162 | if (server_address == NULL) | ||
| 163 | server_address = strscpy (NULL, "127.0.0.1"); | ||
| 164 | |||
| 165 | if (server_expect == NULL) | ||
| 166 | server_expect = strscpy (NULL, EXPECT); | ||
| 167 | |||
| 168 | return validate_arguments (); | ||
| 169 | } | ||
| 170 | |||
| 171 | |||
| 172 | |||
| 173 | |||
| 174 | |||
| 175 | |||
| 176 | int | ||
| 177 | call_getopt (int argc, char **argv) | ||
| 178 | { | ||
| 179 | int c, i = 0; | ||
| 180 | |||
| 181 | #ifdef HAVE_GETOPT_H | ||
| 182 | int option_index = 0; | ||
| 183 | static struct option long_options[] = { | ||
| 184 | {"hostname", required_argument, 0, 'H'}, | ||
| 185 | {"expect", required_argument, 0, 'e'}, | ||
| 186 | {"critical", required_argument, 0, 'c'}, | ||
| 187 | {"warning", required_argument, 0, 'w'}, | ||
| 188 | {"port", required_argument, 0, 'P'}, | ||
| 189 | {"verbose", no_argument, 0, 'v'}, | ||
| 190 | {"version", no_argument, 0, 'V'}, | ||
| 191 | {"help", no_argument, 0, 'h'}, | ||
| 192 | {0, 0, 0, 0} | ||
| 193 | }; | ||
| 194 | #endif | ||
| 195 | |||
| 196 | while (1) { | ||
| 197 | #ifdef HAVE_GETOPT_H | ||
| 198 | c = | ||
| 199 | getopt_long (argc, argv, "+hVvt:p:e:c:w:H:", long_options, | ||
| 200 | &option_index); | ||
| 201 | #else | ||
| 202 | c = getopt (argc, argv, "+?hVvt:p:e:c:w:H:"); | ||
| 203 | #endif | ||
| 204 | |||
| 205 | i++; | ||
| 206 | |||
| 207 | if (c == -1 || c == EOF || c == 1) | ||
| 208 | break; | ||
| 209 | |||
| 210 | switch (c) { | ||
| 211 | case 't': | ||
| 212 | case 'p': | ||
| 213 | case 'e': | ||
| 214 | case 'c': | ||
| 215 | case 'w': | ||
| 216 | case 'H': | ||
| 217 | i++; | ||
| 218 | } | ||
| 219 | |||
| 220 | switch (c) { | ||
| 221 | case 'H': /* hostname */ | ||
| 222 | if (is_host (optarg)) { | ||
| 223 | server_address = optarg; | ||
| 224 | } | ||
| 225 | else { | ||
| 226 | usage ("Invalid host name\n"); | ||
| 227 | } | ||
| 228 | break; | ||
| 229 | case 'p': /* port */ | ||
| 230 | if (is_intpos (optarg)) { | ||
| 231 | server_port = atoi (optarg); | ||
| 232 | } | ||
| 233 | else { | ||
| 234 | usage ("Server port must be a positive integer\n"); | ||
| 235 | } | ||
| 236 | break; | ||
| 237 | case 'e': /* username */ | ||
| 238 | server_expect = optarg; | ||
| 239 | break; | ||
| 240 | case 'c': /* critical time threshold */ | ||
| 241 | if (is_intnonneg (optarg)) { | ||
| 242 | critical_time = atoi (optarg); | ||
| 243 | check_critical_time = TRUE; | ||
| 244 | } | ||
| 245 | else { | ||
| 246 | usage ("Critical time must be a nonnegative integer\n"); | ||
| 247 | } | ||
| 248 | break; | ||
| 249 | case 'w': /* warning time threshold */ | ||
| 250 | if (is_intnonneg (optarg)) { | ||
| 251 | warning_time = atoi (optarg); | ||
| 252 | check_warning_time = TRUE; | ||
| 253 | } | ||
| 254 | else { | ||
| 255 | usage ("Warning time must be a nonnegative integer\n"); | ||
| 256 | } | ||
| 257 | break; | ||
| 258 | case 'v': /* verbose */ | ||
| 259 | verbose = TRUE; | ||
| 260 | break; | ||
| 261 | case 't': /* timeout */ | ||
| 262 | if (is_intnonneg (optarg)) { | ||
| 263 | socket_timeout = atoi (optarg); | ||
| 264 | } | ||
| 265 | else { | ||
| 266 | usage ("Time interval must be a nonnegative integer\n"); | ||
| 267 | } | ||
| 268 | break; | ||
| 269 | case 'V': /* version */ | ||
| 270 | print_revision (PROGNAME, "$Revision$"); | ||
| 271 | exit (STATE_OK); | ||
| 272 | case 'h': /* help */ | ||
| 273 | print_help (); | ||
| 274 | exit (STATE_OK); | ||
| 275 | case '?': /* help */ | ||
| 276 | usage ("Invalid argument\n"); | ||
| 277 | } | ||
| 278 | } | ||
| 279 | return i; | ||
| 280 | } | ||
| 281 | |||
| 282 | |||
| 283 | |||
| 284 | |||
| 285 | |||
| 286 | int | ||
| 287 | validate_arguments (void) | ||
| 288 | { | ||
| 289 | return OK; | ||
| 290 | } | ||
| 291 | |||
| 292 | |||
| 293 | |||
| 294 | |||
| 295 | |||
| 296 | void | ||
| 297 | print_help (void) | ||
| 298 | { | ||
| 299 | print_revision (PROGNAME, "$Revision$"); | ||
| 300 | printf | ||
| 301 | ("Copyright (c) 2000 Tom Shields/Karl DeBisschop\n\n" | ||
| 302 | "This plugin tests the IMAP4 service on the specified host.\n\n"); | ||
| 303 | print_usage (); | ||
| 304 | printf | ||
| 305 | ("\nOptions:\n" | ||
| 306 | " -H, --hostname=STRING or IPADDRESS\n" | ||
| 307 | " Check server on the indicated host\n" | ||
| 308 | " -p, --port=INTEGER\n" | ||
| 309 | " Make connection on the indicated port (default: %d)\n" | ||
| 310 | " -e, --expect=STRING\n" | ||
| 311 | " String to expect in first line of server response (default: %s)\n" | ||
| 312 | " -w, --warning=INTEGER\n" | ||
| 313 | " Seconds necessary to result in a warning status\n" | ||
| 314 | " -c, --critical=INTEGER\n" | ||
| 315 | " Seconds necessary to result in a critical status\n" | ||
| 316 | " -t, --timeout=INTEGER\n" | ||
| 317 | " Seconds before connection attempt times out (default: %d)\n" | ||
| 318 | " -v, --verbose\n" | ||
| 319 | " Print extra information (command-line use only)\n" | ||
| 320 | " -h, --help\n" | ||
| 321 | " Print detailed help screen\n" | ||
| 322 | " -V, --version\n" | ||
| 323 | " Print version information\n\n", | ||
| 324 | PORT, EXPECT, DEFAULT_SOCKET_TIMEOUT); | ||
| 325 | support (); | ||
| 326 | } | ||
| 327 | |||
| 328 | |||
| 329 | |||
| 330 | |||
| 331 | |||
| 332 | void | ||
| 333 | print_usage (void) | ||
| 334 | { | ||
| 335 | printf | ||
| 336 | ("Usage: %s -H host [-e expect] [-p port] [-w warn] [-c crit]\n" | ||
| 337 | " [-t timeout] [-v]\n" | ||
| 338 | " %s --help\n" | ||
| 339 | " %s --version\n", PROGNAME, PROGNAME, PROGNAME); | ||
| 340 | } | ||
diff --git a/plugins/check_nntp.c b/plugins/check_nntp.c deleted file mode 100644 index 4bdc83ab..00000000 --- a/plugins/check_nntp.c +++ /dev/null | |||
| @@ -1,418 +0,0 @@ | |||
| 1 | /****************************************************************************** | ||
| 2 | * | ||
| 3 | * CHECK_NNTP.C | ||
| 4 | * | ||
| 5 | * Program: NNTP plugin for Nagios | ||
| 6 | * License: GPL | ||
| 7 | * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) | ||
| 8 | * | ||
| 9 | * $Id$ | ||
| 10 | * | ||
| 11 | * Description: | ||
| 12 | * | ||
| 13 | * This plugin will attempt to open an NNTP connection with the host. | ||
| 14 | * Successul connects return STATE_OK, refusals and timeouts return | ||
| 15 | * STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful | ||
| 16 | * connects, but incorrect reponse messages from the host result in | ||
| 17 | * STATE_WARNING return values. An invalid newsgroup (if the -g | ||
| 18 | * option is used) results in a STATE_WARNING value. | ||
| 19 | * | ||
| 20 | * License Information: | ||
| 21 | * | ||
| 22 | * This program is free software; you can redistribute it and/or modify | ||
| 23 | * it under the terms of the GNU General Public License as published by | ||
| 24 | * the Free Software Foundation; either version 2 of the License, or | ||
| 25 | * (at your option) any later version. | ||
| 26 | * | ||
| 27 | * This program is distributed in the hope that it will be useful, | ||
| 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 30 | * GNU General Public License for more details. | ||
| 31 | * | ||
| 32 | * You should have received a copy of the GNU General Public License | ||
| 33 | * along with this program; if not, write to the Free Software | ||
| 34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 35 | * | ||
| 36 | *****************************************************************************/ | ||
| 37 | |||
| 38 | #include "config.h" | ||
| 39 | #include "common.h" | ||
| 40 | #include "netutils.h" | ||
| 41 | #include "utils.h" | ||
| 42 | |||
| 43 | #define PROGNAME "check_nntp" | ||
| 44 | |||
| 45 | #define PORT 119 | ||
| 46 | #define EXPECT1A "200" /* posting allowed */ | ||
| 47 | #define EXPECT1B "201" /* posting not allowed */ | ||
| 48 | #define EXPECT "NNTP" | ||
| 49 | #define QUIT "QUIT\r\n" | ||
| 50 | #define MODEREADER "MODE READER\r\n" | ||
| 51 | |||
| 52 | int process_arguments (int, char **); | ||
| 53 | int call_getopt (int, char **); | ||
| 54 | int validate_arguments (void); | ||
| 55 | int check_disk (int usp, int free_disk); | ||
| 56 | void print_help (void); | ||
| 57 | void print_usage (void); | ||
| 58 | |||
| 59 | int server_port = PORT; | ||
| 60 | char *server_expect = NULL; | ||
| 61 | char *server_address = NULL; | ||
| 62 | char *newsgroup = NULL; | ||
| 63 | int check_newsgroup = FALSE; | ||
| 64 | int send_modereader = FALSE; | ||
| 65 | int warning_time = 0; | ||
| 66 | int check_warning_time = FALSE; | ||
| 67 | int critical_time = 0; | ||
| 68 | int check_critical_time = FALSE; | ||
| 69 | int verbose = FALSE; | ||
| 70 | |||
| 71 | |||
| 72 | int | ||
| 73 | main (int argc, char **argv) | ||
| 74 | { | ||
| 75 | char buffer[MAX_INPUT_BUFFER] = ""; | ||
| 76 | int sd; | ||
| 77 | int result; | ||
| 78 | int recv_result; | ||
| 79 | |||
| 80 | if (process_arguments (argc, argv) != OK) | ||
| 81 | usage ("Invalid command arguments supplied\n"); | ||
| 82 | |||
| 83 | /* initialize alarm signal handling */ | ||
| 84 | signal (SIGALRM, socket_timeout_alarm_handler); | ||
| 85 | |||
| 86 | /* set socket timeout */ | ||
| 87 | alarm (socket_timeout); | ||
| 88 | |||
| 89 | /* try to connect to the host at the given port number */ | ||
| 90 | time (&start_time); | ||
| 91 | result = my_tcp_connect (server_address, server_port, &sd); | ||
| 92 | |||
| 93 | /* we connected */ | ||
| 94 | if (result == STATE_OK) { | ||
| 95 | |||
| 96 | /* watch for the NNTP connection string */ | ||
| 97 | recv_result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); | ||
| 98 | |||
| 99 | /* return a WARNING status if we couldn't read any data */ | ||
| 100 | if (recv_result == -1) { | ||
| 101 | |||
| 102 | printf ("recv() failed\n"); | ||
| 103 | result = STATE_WARNING; | ||
| 104 | |||
| 105 | } | ||
| 106 | else { | ||
| 107 | |||
| 108 | /* strip carriage returns from buffer */ | ||
| 109 | strip (buffer); | ||
| 110 | |||
| 111 | /* make sure we find the response we are looking for */ | ||
| 112 | if (strstr (buffer, EXPECT1A) != buffer | ||
| 113 | && strstr (buffer, EXPECT1B) != buffer) { | ||
| 114 | printf ("Invalid NNTP response received from host: %s\n", buffer); | ||
| 115 | result = STATE_WARNING; | ||
| 116 | } | ||
| 117 | |||
| 118 | /* optionally send mode reader */ | ||
| 119 | /* added 2000-09-18 by Andreas M. Kirchwitz <amk@krell.snafu.de> including some other minor fixes */ | ||
| 120 | if (send_modereader == TRUE) { | ||
| 121 | send (sd, MODEREADER, strlen (MODEREADER), 0); | ||
| 122 | recv_result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); | ||
| 123 | if (recv_result == -1) | ||
| 124 | strcpy (buffer, ""); | ||
| 125 | else | ||
| 126 | buffer[recv_result] = 0; | ||
| 127 | strip (buffer); | ||
| 128 | if ((strstr (buffer, EXPECT1A) != buffer) | ||
| 129 | && (strstr (buffer, EXPECT1B) != buffer)) { | ||
| 130 | printf ("Unexpected NNTP response received from host"); | ||
| 131 | result = STATE_WARNING; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | if (server_expect && !strstr (buffer, server_expect)) { | ||
| 136 | printf ("Invalid NNTP header received from host: %s\n", buffer); | ||
| 137 | result = STATE_WARNING; | ||
| 138 | } | ||
| 139 | |||
| 140 | if (check_newsgroup == TRUE) { | ||
| 141 | sprintf (buffer, "GROUP %s\r\n", newsgroup); | ||
| 142 | send (sd, buffer, strlen (buffer), 0); | ||
| 143 | recv_result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); | ||
| 144 | if (recv_result == -1) | ||
| 145 | strcpy (buffer, ""); | ||
| 146 | else | ||
| 147 | buffer[recv_result] = 0; | ||
| 148 | strip (buffer); | ||
| 149 | if (strstr (buffer, "211") != buffer) { | ||
| 150 | printf ("NNTP problem - newsgroup '%s' not found\n", newsgroup); | ||
| 151 | result = STATE_WARNING; | ||
| 152 | } | ||
| 153 | } | ||
| 154 | |||
| 155 | if (result == STATE_OK) { | ||
| 156 | time (&end_time); | ||
| 157 | if (check_critical_time == TRUE | ||
| 158 | && (end_time - start_time) > critical_time) result = | ||
| 159 | STATE_CRITICAL; | ||
| 160 | else if (check_warning_time == TRUE | ||
| 161 | && (end_time - start_time) > warning_time) result = | ||
| 162 | STATE_WARNING; | ||
| 163 | if (verbose) | ||
| 164 | printf ("NNTP %s - %d sec. response time, %s\n", | ||
| 165 | (result == STATE_OK) ? "ok" : "problem", | ||
| 166 | (int) (end_time - start_time), buffer); | ||
| 167 | else | ||
| 168 | printf ("NNTP %s - %d second response time\n", | ||
| 169 | (result == STATE_OK) ? "ok" : "problem", | ||
| 170 | (int) (end_time - start_time)); | ||
| 171 | } | ||
| 172 | |||
| 173 | } | ||
| 174 | |||
| 175 | /* close the connection */ | ||
| 176 | send (sd, QUIT, strlen (QUIT), 0); | ||
| 177 | close (sd); | ||
| 178 | |||
| 179 | } | ||
| 180 | |||
| 181 | /* reset the alarm timeout */ | ||
| 182 | alarm (0); | ||
| 183 | |||
| 184 | return result; | ||
| 185 | } | ||
| 186 | |||
| 187 | |||
| 188 | |||
| 189 | |||
| 190 | |||
| 191 | |||
| 192 | /* process command-line arguments */ | ||
| 193 | int | ||
| 194 | process_arguments (int argc, char **argv) | ||
| 195 | { | ||
| 196 | int c; | ||
| 197 | |||
| 198 | if (argc < 2) | ||
| 199 | return ERROR; | ||
| 200 | |||
| 201 | for (c = 1; c < argc; c++) { | ||
| 202 | if (strcmp ("-to", argv[c]) == 0) | ||
| 203 | strcpy (argv[c], "-t"); | ||
| 204 | else if (strcmp ("-wt", argv[c]) == 0) | ||
| 205 | strcpy (argv[c], "-w"); | ||
| 206 | else if (strcmp ("-ct", argv[c]) == 0) | ||
| 207 | strcpy (argv[c], "-c"); | ||
| 208 | } | ||
| 209 | |||
| 210 | |||
| 211 | |||
| 212 | c = 0; | ||
| 213 | while ((c += (call_getopt (argc - c, &argv[c]))) < argc) { | ||
| 214 | |||
| 215 | if (is_option (argv[c])) | ||
| 216 | continue; | ||
| 217 | |||
| 218 | if (server_address == NULL) { | ||
| 219 | if (is_host (argv[c])) { | ||
| 220 | server_address = argv[c]; | ||
| 221 | } | ||
| 222 | else { | ||
| 223 | usage ("Invalid host name"); | ||
| 224 | } | ||
| 225 | } | ||
| 226 | } | ||
| 227 | |||
| 228 | if (server_address == NULL) | ||
| 229 | server_address = strscpy (NULL, "127.0.0.1"); | ||
| 230 | |||
| 231 | /* if (server_expect==NULL) */ | ||
| 232 | /* server_expect=strscpy(NULL,EXPECT); */ | ||
| 233 | |||
| 234 | return validate_arguments (); | ||
| 235 | } | ||
| 236 | |||
| 237 | |||
| 238 | |||
| 239 | |||
| 240 | |||
| 241 | |||
| 242 | int | ||
| 243 | call_getopt (int argc, char **argv) | ||
| 244 | { | ||
| 245 | int c, i = 0; | ||
| 246 | |||
| 247 | #ifdef HAVE_GETOPT_H | ||
| 248 | int option_index = 0; | ||
| 249 | static struct option long_options[] = { | ||
| 250 | {"hostname", required_argument, 0, 'H'}, | ||
| 251 | {"expect", required_argument, 0, 'e'}, | ||
| 252 | {"critical", required_argument, 0, 'c'}, | ||
| 253 | {"warning", required_argument, 0, 'w'}, | ||
| 254 | {"port", required_argument, 0, 'P'}, | ||
| 255 | {"modereader", required_argument, 0, 'M'}, | ||
| 256 | {"verbose", no_argument, 0, 'v'}, | ||
| 257 | {"version", no_argument, 0, 'V'}, | ||
| 258 | {"help", no_argument, 0, 'h'}, | ||
| 259 | {0, 0, 0, 0} | ||
| 260 | }; | ||
| 261 | #endif | ||
| 262 | |||
| 263 | while (1) { | ||
| 264 | #ifdef HAVE_GETOPT_H | ||
| 265 | c = | ||
| 266 | getopt_long (argc, argv, "+hVMvt:p:e:c:w:H:", long_options, | ||
| 267 | &option_index); | ||
| 268 | #else | ||
| 269 | c = getopt (argc, argv, "+?hVMvt:p:e:c:w:H:"); | ||
| 270 | #endif | ||
| 271 | |||
| 272 | i++; | ||
| 273 | |||
| 274 | if (c == -1 || c == EOF || c == 1) | ||
| 275 | break; | ||
| 276 | |||
| 277 | switch (c) { | ||
| 278 | case 't': | ||
| 279 | case 'p': | ||
| 280 | case 'e': | ||
| 281 | case 'c': | ||
| 282 | case 'w': | ||
| 283 | case 'H': | ||
| 284 | i++; | ||
| 285 | } | ||
| 286 | |||
| 287 | switch (c) { | ||
| 288 | case 'H': /* hostname */ | ||
| 289 | if (is_host (optarg)) { | ||
| 290 | server_address = optarg; | ||
| 291 | } | ||
| 292 | else { | ||
| 293 | usage ("Invalid host name\n"); | ||
| 294 | } | ||
| 295 | break; | ||
| 296 | case 'p': /* port */ | ||
| 297 | if (is_intpos (optarg)) { | ||
| 298 | server_port = atoi (optarg); | ||
| 299 | } | ||
| 300 | else { | ||
| 301 | usage ("Server port must be a positive integer\n"); | ||
| 302 | } | ||
| 303 | break; | ||
| 304 | case 'M': /* mode reader */ | ||
| 305 | send_modereader = TRUE; | ||
| 306 | break; | ||
| 307 | case 'e': /* expect */ | ||
| 308 | server_expect = optarg; | ||
| 309 | break; | ||
| 310 | case 'g': /* newsgroup */ | ||
| 311 | newsgroup = optarg; | ||
| 312 | check_newsgroup = TRUE; | ||
| 313 | break; | ||
| 314 | case 'c': /* critical time threshold */ | ||
| 315 | if (is_intnonneg (optarg)) { | ||
| 316 | critical_time = atoi (optarg); | ||
| 317 | check_critical_time = TRUE; | ||
| 318 | } | ||
| 319 | else { | ||
| 320 | usage ("Critical time must be a nonnegative integer\n"); | ||
| 321 | } | ||
| 322 | break; | ||
| 323 | case 'w': /* warning time threshold */ | ||
| 324 | if (is_intnonneg (optarg)) { | ||
| 325 | warning_time = atoi (optarg); | ||
| 326 | check_warning_time = TRUE; | ||
| 327 | } | ||
| 328 | else { | ||
| 329 | usage ("Warning time must be a nonnegative integer\n"); | ||
| 330 | } | ||
| 331 | break; | ||
| 332 | case 'v': /* verbose */ | ||
| 333 | verbose = TRUE; | ||
| 334 | break; | ||
| 335 | case 't': /* timeout */ | ||
| 336 | if (is_intnonneg (optarg)) { | ||
| 337 | socket_timeout = atoi (optarg); | ||
| 338 | } | ||
| 339 | else { | ||
| 340 | usage ("Time interval must be a nonnegative integer\n"); | ||
| 341 | } | ||
| 342 | break; | ||
| 343 | case 'V': /* version */ | ||
| 344 | print_revision (PROGNAME, "$Revision$"); | ||
| 345 | exit (STATE_OK); | ||
| 346 | case 'h': /* help */ | ||
| 347 | print_help (); | ||
| 348 | exit (STATE_OK); | ||
| 349 | case '?': /* help */ | ||
| 350 | usage ("Invalid argument\n"); | ||
| 351 | } | ||
| 352 | } | ||
| 353 | return i; | ||
| 354 | } | ||
| 355 | |||
| 356 | |||
| 357 | |||
| 358 | |||
| 359 | |||
| 360 | int | ||
| 361 | validate_arguments (void) | ||
| 362 | { | ||
| 363 | return OK; | ||
| 364 | } | ||
| 365 | |||
| 366 | |||
| 367 | |||
| 368 | |||
| 369 | |||
| 370 | void | ||
| 371 | print_help (void) | ||
| 372 | { | ||
| 373 | print_revision (PROGNAME, "$Revision$"); | ||
| 374 | printf | ||
| 375 | ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" | ||
| 376 | "This plugin tests the NNTP service on the specified host.\n\n"); | ||
| 377 | print_usage (); | ||
| 378 | printf | ||
| 379 | ("\nOptions:\n" | ||
| 380 | " -H, --hostname=STRING or IPADDRESS\n" | ||
| 381 | " Check server on the indicated host\n" | ||
| 382 | " -p, --port=INTEGER\n" | ||
| 383 | " Make connection on the indicated port (default: %d)\n" | ||
| 384 | " -e, --expect=STRING\n" | ||
| 385 | " String to expect in first line of server response (default: %s)\n" | ||
| 386 | " -g, --group=STRING\n" | ||
| 387 | " Newsgroup to poll\n" | ||
| 388 | " -w, --warning=INTEGER\n" | ||
| 389 | " Seconds necessary to result in a warning status\n" | ||
| 390 | " -c, --critical=INTEGER\n" | ||
| 391 | " Seconds necessary to result in a critical status\n" | ||
| 392 | " -t, --timeout=INTEGER\n" | ||
| 393 | " Seconds before connection attempt times out (default: %d)\n" | ||
| 394 | " -M\n" | ||
| 395 | " Send \"MODE READER\" after initial connect.\n" | ||
| 396 | " -v, --verbose\n" | ||
| 397 | " Print extra information (command-line use only)\n" | ||
| 398 | " -h, --help\n" | ||
| 399 | " Print detailed help screen\n" | ||
| 400 | " -V, --version\n" | ||
| 401 | " Print version information\n\n", | ||
| 402 | PORT, EXPECT, DEFAULT_SOCKET_TIMEOUT); | ||
| 403 | support (); | ||
| 404 | } | ||
| 405 | |||
| 406 | |||
| 407 | |||
| 408 | |||
| 409 | |||
| 410 | void | ||
| 411 | print_usage (void) | ||
| 412 | { | ||
| 413 | printf | ||
| 414 | ("Usage: %s -H host [-e expect] [-g group] [-p port] [-w warn] [-c crit]\n" | ||
| 415 | " [-t timeout] [-v]\n" | ||
| 416 | " %s --help\n" | ||
| 417 | " %s --version\n", PROGNAME, PROGNAME, PROGNAME); | ||
| 418 | } | ||
diff --git a/plugins/check_pop.c b/plugins/check_pop.c deleted file mode 100644 index 9fcfaec6..00000000 --- a/plugins/check_pop.c +++ /dev/null | |||
| @@ -1,364 +0,0 @@ | |||
| 1 | /****************************************************************************** | ||
| 2 | * | ||
| 3 | * CHECK_POP.C | ||
| 4 | * | ||
| 5 | * Program: POP3 plugin for Nagios | ||
| 6 | * License: GPL | ||
| 7 | * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) | ||
| 8 | * | ||
| 9 | * $Id$ | ||
| 10 | * | ||
| 11 | * Description: | ||
| 12 | * | ||
| 13 | * This plugin will attempt to open an POP connection with the host. | ||
| 14 | * Successul connects return STATE_OK, refusals and timeouts return | ||
| 15 | * STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful | ||
| 16 | * connects, but incorrect reponse messages from the host result in | ||
| 17 | * STATE_WARNING return values. | ||
| 18 | * | ||
| 19 | * License Information: | ||
| 20 | * | ||
| 21 | * This program is free software; you can redistribute it and/or modify | ||
| 22 | * it under the terms of the GNU General Public License as published by | ||
| 23 | * the Free Software Foundation; either version 2 of the License, or | ||
| 24 | * (at your option) any later version. | ||
| 25 | * | ||
| 26 | * This program is distributed in the hope that it will be useful, | ||
| 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 29 | * GNU General Public License for more details. | ||
| 30 | * | ||
| 31 | * You should have received a copy of the GNU General Public License | ||
| 32 | * along with this program; if not, write to the Free Software | ||
| 33 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 34 | * | ||
| 35 | *****************************************************************************/ | ||
| 36 | |||
| 37 | #include "config.h" | ||
| 38 | #include "common.h" | ||
| 39 | #include "netutils.h" | ||
| 40 | #include "utils.h" | ||
| 41 | |||
| 42 | #define PROGNAME "check_pop" | ||
| 43 | |||
| 44 | #define POP_PORT 110 | ||
| 45 | #define POP_EXPECT "+OK" | ||
| 46 | #define POP_QUIT "QUIT\n" | ||
| 47 | |||
| 48 | int process_arguments (int, char **); | ||
| 49 | int call_getopt (int, char **); | ||
| 50 | int validate_arguments (void); | ||
| 51 | int check_disk (int usp, int free_disk); | ||
| 52 | void print_help (void); | ||
| 53 | void print_usage (void); | ||
| 54 | |||
| 55 | int server_port = POP_PORT; | ||
| 56 | char *server_address = NULL; | ||
| 57 | char *server_expect = NULL; | ||
| 58 | int warning_time = 0; | ||
| 59 | int check_warning_time = FALSE; | ||
| 60 | int critical_time = 0; | ||
| 61 | int check_critical_time = FALSE; | ||
| 62 | int verbose = FALSE; | ||
| 63 | |||
| 64 | int | ||
| 65 | main (int argc, char **argv) | ||
| 66 | { | ||
| 67 | int sd; | ||
| 68 | int result; | ||
| 69 | char buffer[MAX_INPUT_BUFFER]; | ||
| 70 | |||
| 71 | if (process_arguments (argc, argv) != OK) | ||
| 72 | usage ("Invalid command arguments supplied\n"); | ||
| 73 | |||
| 74 | /* initialize alarm signal handling */ | ||
| 75 | signal (SIGALRM, socket_timeout_alarm_handler); | ||
| 76 | |||
| 77 | /* set socket timeout */ | ||
| 78 | alarm (socket_timeout); | ||
| 79 | |||
| 80 | /* try to connect to the host at the given port number */ | ||
| 81 | time (&start_time); | ||
| 82 | result = my_tcp_connect (server_address, server_port, &sd); | ||
| 83 | |||
| 84 | /* we connected, so close connection before exiting */ | ||
| 85 | if (result == STATE_OK) { | ||
| 86 | |||
| 87 | /* watch for the SMTP connection string */ | ||
| 88 | result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); | ||
| 89 | |||
| 90 | /* strip the buffer of carriage returns */ | ||
| 91 | strip (buffer); | ||
| 92 | |||
| 93 | /* return a WARNING status if we couldn't read any data */ | ||
| 94 | if (result == -1) { | ||
| 95 | printf ("recv() failed\n"); | ||
| 96 | result = STATE_WARNING; | ||
| 97 | } | ||
| 98 | |||
| 99 | else { | ||
| 100 | |||
| 101 | /* make sure we find the response we are looking for */ | ||
| 102 | if (!strstr (buffer, server_expect)) { | ||
| 103 | if (server_port == POP_PORT) | ||
| 104 | printf ("Invalid POP response received from host\n"); | ||
| 105 | else | ||
| 106 | printf ("Invalid POP response received from host on port %d\n", | ||
| 107 | server_port); | ||
| 108 | result = STATE_WARNING; | ||
| 109 | } | ||
| 110 | |||
| 111 | else { | ||
| 112 | time (&end_time); | ||
| 113 | |||
| 114 | result = STATE_OK; | ||
| 115 | |||
| 116 | if (check_critical_time == TRUE | ||
| 117 | && (end_time - start_time) > critical_time) result = | ||
| 118 | STATE_CRITICAL; | ||
| 119 | else if (check_warning_time == TRUE | ||
| 120 | && (end_time - start_time) > warning_time) result = | ||
| 121 | STATE_WARNING; | ||
| 122 | |||
| 123 | if (verbose == TRUE) | ||
| 124 | printf ("POP %s - %d sec. response time, %s\n", | ||
| 125 | (result == STATE_OK) ? "ok" : "problem", | ||
| 126 | (int) (end_time - start_time), buffer); | ||
| 127 | else | ||
| 128 | printf ("POP %s - %d second response time\n", | ||
| 129 | (result == STATE_OK) ? "ok" : "problem", | ||
| 130 | (int) (end_time - start_time)); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | /* close the connection */ | ||
| 135 | send (sd, POP_QUIT, strlen (POP_QUIT), 0); | ||
| 136 | close (sd); | ||
| 137 | } | ||
| 138 | |||
| 139 | /* reset the alarm */ | ||
| 140 | alarm (0); | ||
| 141 | |||
| 142 | return result; | ||
| 143 | } | ||
| 144 | |||
| 145 | |||
| 146 | |||
| 147 | |||
| 148 | |||
| 149 | |||
| 150 | |||
| 151 | /* process command-line arguments */ | ||
| 152 | int | ||
| 153 | process_arguments (int argc, char **argv) | ||
| 154 | { | ||
| 155 | int c; | ||
| 156 | |||
| 157 | if (argc < 2) | ||
| 158 | return ERROR; | ||
| 159 | |||
| 160 | for (c = 1; c < argc; c++) { | ||
| 161 | if (strcmp ("-to", argv[c]) == 0) | ||
| 162 | strcpy (argv[c], "-t"); | ||
| 163 | else if (strcmp ("-wt", argv[c]) == 0) | ||
| 164 | strcpy (argv[c], "-w"); | ||
| 165 | else if (strcmp ("-ct", argv[c]) == 0) | ||
| 166 | strcpy (argv[c], "-c"); | ||
| 167 | } | ||
| 168 | |||
| 169 | |||
| 170 | |||
| 171 | c = 0; | ||
| 172 | while ((c += (call_getopt (argc - c, &argv[c]))) < argc) { | ||
| 173 | |||
| 174 | if (is_option (argv[c])) | ||
| 175 | continue; | ||
| 176 | |||
| 177 | if (server_address == NULL) { | ||
| 178 | if (is_host (argv[c])) { | ||
| 179 | server_address = argv[c]; | ||
| 180 | } | ||
| 181 | else { | ||
| 182 | usage ("Invalid host name"); | ||
| 183 | } | ||
| 184 | } | ||
| 185 | } | ||
| 186 | |||
| 187 | if (server_address == NULL) | ||
| 188 | server_address = strscpy (NULL, "127.0.0.1"); | ||
| 189 | |||
| 190 | if (server_expect == NULL) | ||
| 191 | server_expect = strscpy (NULL, POP_EXPECT); | ||
| 192 | |||
| 193 | return validate_arguments (); | ||
| 194 | } | ||
| 195 | |||
| 196 | |||
| 197 | |||
| 198 | |||
| 199 | |||
| 200 | |||
| 201 | int | ||
| 202 | call_getopt (int argc, char **argv) | ||
| 203 | { | ||
| 204 | int c, i = 0; | ||
| 205 | |||
| 206 | #ifdef HAVE_GETOPT_H | ||
| 207 | int option_index = 0; | ||
| 208 | static struct option long_options[] = { | ||
| 209 | {"hostname", required_argument, 0, 'H'}, | ||
| 210 | {"expect", required_argument, 0, 'e'}, | ||
| 211 | {"critical", required_argument, 0, 'c'}, | ||
| 212 | {"warning", required_argument, 0, 'w'}, | ||
| 213 | {"port", required_argument, 0, 'P'}, | ||
| 214 | {"verbose", no_argument, 0, 'v'}, | ||
| 215 | {"version", no_argument, 0, 'V'}, | ||
| 216 | {"help", no_argument, 0, 'h'}, | ||
| 217 | {0, 0, 0, 0} | ||
| 218 | }; | ||
| 219 | #endif | ||
| 220 | |||
| 221 | while (1) { | ||
| 222 | #ifdef HAVE_GETOPT_H | ||
| 223 | c = | ||
| 224 | getopt_long (argc, argv, "+hVvt:p:e:c:w:H:", long_options, | ||
| 225 | &option_index); | ||
| 226 | #else | ||
| 227 | c = getopt (argc, argv, "+?hVvt:p:e:c:w:H:"); | ||
| 228 | #endif | ||
| 229 | |||
| 230 | i++; | ||
| 231 | |||
| 232 | if (c == -1 || c == EOF || c == 1) | ||
| 233 | break; | ||
| 234 | |||
| 235 | switch (c) { | ||
| 236 | case 't': | ||
| 237 | case 'p': | ||
| 238 | case 'e': | ||
| 239 | case 'c': | ||
| 240 | case 'w': | ||
| 241 | case 'H': | ||
| 242 | i++; | ||
| 243 | } | ||
| 244 | |||
| 245 | switch (c) { | ||
| 246 | case 'H': /* hostname */ | ||
| 247 | if (is_host (optarg)) { | ||
| 248 | server_address = optarg; | ||
| 249 | } | ||
| 250 | else { | ||
| 251 | usage ("Invalid host name\n"); | ||
| 252 | } | ||
| 253 | break; | ||
| 254 | case 'p': /* port */ | ||
| 255 | if (is_intpos (optarg)) { | ||
| 256 | server_port = atoi (optarg); | ||
| 257 | } | ||
| 258 | else { | ||
| 259 | usage ("Server port must be a positive integer\n"); | ||
| 260 | } | ||
| 261 | break; | ||
| 262 | case 'e': /* username */ | ||
| 263 | server_expect = optarg; | ||
| 264 | break; | ||
| 265 | case 'c': /* critical time threshold */ | ||
| 266 | if (is_intnonneg (optarg)) { | ||
| 267 | critical_time = atoi (optarg); | ||
| 268 | check_critical_time = TRUE; | ||
| 269 | } | ||
| 270 | else { | ||
| 271 | usage ("Critical time must be a nonnegative integer\n"); | ||
| 272 | } | ||
| 273 | break; | ||
| 274 | case 'w': /* warning time threshold */ | ||
| 275 | if (is_intnonneg (optarg)) { | ||
| 276 | warning_time = atoi (optarg); | ||
| 277 | check_warning_time = TRUE; | ||
| 278 | } | ||
| 279 | else { | ||
| 280 | usage ("Warning time must be a nonnegative integer\n"); | ||
| 281 | } | ||
| 282 | break; | ||
| 283 | case 'v': /* verbose */ | ||
| 284 | verbose = TRUE; | ||
| 285 | break; | ||
| 286 | case 't': /* timeout */ | ||
| 287 | if (is_intnonneg (optarg)) { | ||
| 288 | socket_timeout = atoi (optarg); | ||
| 289 | } | ||
| 290 | else { | ||
| 291 | usage ("Time interval must be a nonnegative integer\n"); | ||
| 292 | } | ||
| 293 | break; | ||
| 294 | case 'V': /* version */ | ||
| 295 | print_revision (PROGNAME, "$Revision$"); | ||
| 296 | exit (STATE_OK); | ||
| 297 | case 'h': /* help */ | ||
| 298 | print_help (); | ||
| 299 | exit (STATE_OK); | ||
| 300 | case '?': /* help */ | ||
| 301 | usage ("Invalid argument\n"); | ||
| 302 | } | ||
| 303 | } | ||
| 304 | return i; | ||
| 305 | } | ||
| 306 | |||
| 307 | |||
| 308 | |||
| 309 | |||
| 310 | |||
| 311 | int | ||
| 312 | validate_arguments (void) | ||
| 313 | { | ||
| 314 | return OK; | ||
| 315 | } | ||
| 316 | |||
| 317 | |||
| 318 | |||
| 319 | |||
| 320 | |||
| 321 | void | ||
| 322 | print_help (void) | ||
| 323 | { | ||
| 324 | print_revision (PROGNAME, "$Revision$"); | ||
| 325 | printf | ||
| 326 | ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" | ||
| 327 | "This plugin tests the POP service on the specified host.\n\n"); | ||
| 328 | print_usage (); | ||
| 329 | printf | ||
| 330 | ("\nOptions:\n" | ||
| 331 | " -H, --hostname=STRING or IPADDRESS\n" | ||
| 332 | " Check server on the indicated host\n" | ||
| 333 | " -p, --port=INTEGER\n" | ||
| 334 | " Make connection on the indicated port (default: %d)\n" | ||
| 335 | " -e, --expect=STRING\n" | ||
| 336 | " String to expect in first line of server response (default: %s)\n" | ||
| 337 | " -w, --warning=INTEGER\n" | ||
| 338 | " Seconds necessary to result in a warning status\n" | ||
| 339 | " -c, --critical=INTEGER\n" | ||
| 340 | " Seconds necessary to result in a critical status\n" | ||
| 341 | " -t, --timeout=INTEGER\n" | ||
| 342 | " Seconds before connection attempt times out (default: %d)\n" | ||
| 343 | " -v, --verbose\n" | ||
| 344 | " Print extra information (command-line use only)\n" | ||
| 345 | " -h, --help\n" | ||
| 346 | " Print detailed help screen\n" | ||
| 347 | " -V, --version\n" | ||
| 348 | " Print version information\n\n", | ||
| 349 | POP_PORT, POP_EXPECT, DEFAULT_SOCKET_TIMEOUT); | ||
| 350 | support (); | ||
| 351 | } | ||
| 352 | |||
| 353 | |||
| 354 | |||
| 355 | |||
| 356 | |||
| 357 | void | ||
| 358 | print_usage (void) | ||
| 359 | { | ||
| 360 | printf | ||
| 361 | ("Usage: %s -H host [-e expect] [-p port] [-w warn] [-c crit] [-t timeout] [-v]\n" | ||
| 362 | " %s --help\n" | ||
| 363 | " %s --version\n", PROGNAME, PROGNAME, PROGNAME); | ||
| 364 | } | ||
