From 5b12005c173584e55bf79e898ad515013d2fcf11 Mon Sep 17 00:00:00 2001 From: Karl DeBisschop Date: Mon, 21 Oct 2002 04:03:18 +0000 Subject: 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 --- plugins/check_ftp.c | 337 ----------------------------------------- plugins/check_imap.c | 340 ----------------------------------------- plugins/check_nntp.c | 418 --------------------------------------------------- plugins/check_pop.c | 364 -------------------------------------------- 4 files changed, 1459 deletions(-) delete mode 100644 plugins/check_ftp.c delete mode 100644 plugins/check_imap.c delete mode 100644 plugins/check_nntp.c delete mode 100644 plugins/check_pop.c (limited to 'plugins') 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 @@ -/****************************************************************************** - * - * CHECK_FTP.C - * - * Program: FTP plugin for Nagios - * License: GPL - * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) - * - * $Id$ - * - * Description: - * - * This plugin will attempt to open an FTP connection with the host. - * Successul connects return STATE_OK, refusals and timeouts return - * STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful - * connects, but incorrect reponse messages from the host result in - * STATE_WARNING return values. - * - * License Information: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - *****************************************************************************/ - -#include "config.h" -#include "common.h" -#include "netutils.h" -#include "utils.h" - -#define PROGNAME "check_ftp" - -#define FTP_PORT 21 -#define FTP_EXPECT "220" -#define FTP_QUIT "QUIT\n" - -int process_arguments (int, char **); -int call_getopt (int, char **); -void print_usage (void); -void print_help (void); - -time_t start_time, end_time; -int server_port = FTP_PORT; -char *server_address = NULL; -char *server_expect = NULL; -int warning_time = 0; -int check_warning_time = FALSE; -int critical_time = 0; -int check_critical_time = FALSE; -int verbose = FALSE; - - -int -main (int argc, char **argv) -{ - int sd; - int result; - char buffer[MAX_INPUT_BUFFER]; - - if (process_arguments (argc, argv) == ERROR) - usage ("Could not parse arguments\n"); - - /* initialize alarm signal handling */ - signal (SIGALRM, socket_timeout_alarm_handler); - - /* set socket timeout */ - alarm (socket_timeout); - - /* try to connect to the host at the given port number */ - time (&start_time); - result = my_tcp_connect (server_address, server_port, &sd); - - /* we connected, so close connection before exiting */ - if (result == STATE_OK) { - - /* watch for the FTP connection string */ - result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); - - /* strip the buffer of carriage returns */ - strip (buffer); - - /* return a WARNING status if we couldn't read any data */ - if (result == -1) { - printf ("recv() failed\n"); - result = STATE_WARNING; - } - - else { - - /* make sure we find the response we are looking for */ - if (!strstr (buffer, server_expect)) { - - if (server_port == FTP_PORT) - printf ("Invalid FTP response received from host\n"); - else - printf ("Invalid FTP response received from host on port %d\n", - server_port); - result = STATE_WARNING; - } - - else { - time (&end_time); - - result = STATE_OK; - - if (check_critical_time == TRUE - && (end_time - start_time) > critical_time) result = - STATE_CRITICAL; - else if (check_warning_time == TRUE - && (end_time - start_time) > warning_time) result = - STATE_WARNING; - - if (verbose == TRUE) - printf ("FTP %s - %d sec. response time, %s\n", - (result == STATE_OK) ? "ok" : "problem", - (int) (end_time - start_time), buffer); - else - printf ("FTP %s - %d second response time\n", - (result == STATE_OK) ? "ok" : "problem", - (int) (end_time - start_time)); - } - } - - /* close the connection */ - send (sd, FTP_QUIT, strlen (FTP_QUIT), 0); - close (sd); - } - - /* reset the alarm */ - alarm (0); - - return result; -} - - - - - - -/* process command-line arguments */ -int -process_arguments (int argc, char **argv) -{ - int c; - - if (argc < 2) - usage ("\n"); - - for (c = 1; c < argc; c++) { - if (strcmp ("-to", argv[c]) == 0) - strcpy (argv[c], "-t"); - else if (strcmp ("-wt", argv[c]) == 0) - strcpy (argv[c], "-w"); - else if (strcmp ("-ct", argv[c]) == 0) - strcpy (argv[c], "-c"); - } - - c = 0; - while ((c += call_getopt (argc - c, &argv[c])) < argc) { - - if (is_option (argv[c])) - continue; - - if (server_address == NULL) { - if (argc > c) { - if (is_host (argv[c]) == FALSE) - usage ("Invalid host name/address\n"); - server_address = argv[c]; - } - else { - usage ("Host name was not supplied\n"); - } - } - } - - if (server_expect == NULL) - server_expect = strscpy (NULL, FTP_EXPECT); - - return OK; -} - - - - - -int -call_getopt (int argc, char **argv) -{ - int c, i = 0; - -#ifdef HAVE_GETOPT_H - int option_index = 0; - static struct option long_options[] = { - {"hostname", required_argument, 0, 'H'}, - {"expect", required_argument, 0, 'e'}, - {"critical", required_argument, 0, 'c'}, - {"warning", required_argument, 0, 'w'}, - {"timeout", required_argument, 0, 'w'}, - {"port", required_argument, 0, 'p'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {"help", no_argument, 0, 'h'}, - {0, 0, 0, 0} - }; -#endif - - while (1) { -#ifdef HAVE_GETOPT_H - c = - getopt_long (argc, argv, "+hVvH:e:c:w:t:p:", long_options, - &option_index); -#else - c = getopt (argc, argv, "+hVvH:e:c:w:t:p:"); -#endif - - i++; - - if (c == -1 || c == EOF || c == 1) - break; - - switch (c) { - case 'H': - case 'e': - case 'c': - case 'w': - case 't': - case 'p': - i++; - } - - switch (c) { - case '?': /* print short usage statement if args not parsable */ - printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg); - print_usage (); - exit (STATE_UNKNOWN); - case 'h': /* help */ - print_help (); - exit (STATE_OK); - case 'V': /* version */ - print_revision (my_basename (argv[0]), "$Revision$"); - exit (STATE_OK); - case 'v': /* verbose mode */ - verbose = TRUE; - break; - case 'H': /* hostname */ - if (is_host (optarg) == FALSE) - usage ("Invalid host name/address\n"); - server_address = optarg; - break; - case 'e': /* expect */ - server_expect = optarg; - break; - case 'c': /* critical */ - if (!is_intnonneg (optarg)) - usage ("Critical threshold must be a nonnegative integer\n"); - critical_time = atoi (optarg); - check_critical_time = TRUE; - break; - case 'w': /* warning */ - if (!is_intnonneg (optarg)) - usage ("Warning threshold must be a nonnegative integer\n"); - warning_time = atoi (optarg); - check_warning_time = TRUE; - break; - case 't': /* timeout */ - if (!is_intnonneg (optarg)) - usage ("Timeout interval must be a nonnegative integer\n"); - socket_timeout = atoi (optarg); - break; - case 'p': /* port */ - if (!is_intnonneg (optarg)) - usage ("Serevr port must be a nonnegative integer\n"); - server_port = atoi (optarg); - break; - } - } - return i; -} - - - - - -void -print_usage (void) -{ - printf - ("Usage: %s -H [-e expect] [-p port] [-w warn_time]\n" - " [-c crit_time] [-t to_sec] [-v]\n", PROGNAME); -} - - - - - -void -print_help (void) -{ - print_revision (PROGNAME, "$Revision$"); - printf - ("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n\n" - "This plugin tests an FTP connection with the specified host.\n\n"); - print_usage (); - printf - ("Options:\n" - " -H, --hostname=ADDRESS\n" - " Host name argument for servers using host headers (use numeric\n" - " address if possible to bypass DNS lookup).\n" - " -e, --expect=STRING\n" - " String to expect in first line of server response (default: %s)\n" - " -p, --port=INTEGER\n" - " Port number (default: %d)\n" - " -w, --warning=INTEGER\n" - " Response time to result in warning status (seconds)\n" - " -c, --critical=INTEGER\n" - " Response time to result in critical status (seconds)\n" - " -t, --timeout=INTEGER\n" - " Seconds before connection times out (default: %d)\n" - " -v" - " Show details for command-line debugging (do not use with nagios server)\n" - " -h, --help\n" - " Print detailed help screen\n" - " -V, --version\n" - " Print version information\n", - FTP_EXPECT, FTP_PORT, DEFAULT_SOCKET_TIMEOUT); -} 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 @@ -/****************************************************************************** -* -* CHECK_IMAP.C -* -* Program: IMAP4 plugin for Nagios -* License: GPL -* Copyright (c) 1999 Tom Shields (tom.shields@basswood.com) -* -* $Id$ -* -* Description: -* -* This plugin will attempt to open an IMAP connection with the host. -* Successul connects return STATE_OK, refusals and timeouts return -* STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful -* connects, but incorrect reponse messages from the host result in -* STATE_WARNING return values. -* -* Modifications: -* 04-13-1999 Tom Shields -* Initial code -* 08-18-1999 Ethan Galstad -* Modified code to work with common plugin functions, added socket -* timeout, string * length checking -* 09-19-1999 Ethan Galstad -* Changed expect string from "+OK" to "* OK" and default port to 143 -*****************************************************************************/ - -#include "config.h" -#include "common.h" -#include "netutils.h" -#include "utils.h" - -#define PROGNAME "check_imap" - -#define PORT 143 -#define EXPECT "* OK" -#define QUIT "a1 LOGOUT\n" - -int process_arguments (int, char **); -int call_getopt (int, char **); -int validate_arguments (void); -int check_disk (int usp, int free_disk); -void print_help (void); -void print_usage (void); - -int server_port = PORT; -char *server_address = NULL; -char *server_expect = NULL; -int warning_time = 0; -int check_warning_time = FALSE; -int critical_time = 0; -int check_critical_time = FALSE; -int verbose = FALSE; - -int -main (int argc, char **argv) -{ - int sd; - int result; - char buffer[MAX_INPUT_BUFFER]; - - if (process_arguments (argc, argv) != OK) - usage ("Invalid command arguments supplied\n"); - - /* initialize alarm signal handling */ - signal (SIGALRM, socket_timeout_alarm_handler); - - /* set socket timeout */ - alarm (socket_timeout); - - /* try to connect to the host at the given port number */ - time (&start_time); - result = my_tcp_connect (server_address, server_port, &sd); - - /* we connected, so close connection before exiting */ - if (result == STATE_OK) { - - /* watch for the IMAP connection string */ - result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); - - /* strip carriange returns */ - strip (buffer); - - /* return a WARNING status if we couldn't read any data */ - if (result == -1) { - printf ("recv() failed\n"); - result = STATE_WARNING; - } - - else { - - /* make sure we find the response we are looking for */ - if (!strstr (buffer, server_expect)) { - if (server_port == server_port) - printf ("Invalid IMAP response received from host\n"); - else - printf ("Invalid IMAP response received from host on port %d\n", - server_port); - result = STATE_WARNING; - } - - else { - time (&end_time); - printf ("IMAP ok - %d second response time\n", - (int) (end_time - start_time)); - result = STATE_OK; - } - } - - /* close the connection */ - send (sd, QUIT, strlen (QUIT), 0); - close (sd); - } - - /* reset the alarm handler */ - alarm (0); - - return result; -} - - - - - -/* process command-line arguments */ -int -process_arguments (int argc, char **argv) -{ - int c; - - if (argc < 2) - return ERROR; - - for (c = 1; c < argc; c++) { - if (strcmp ("-to", argv[c]) == 0) - strcpy (argv[c], "-t"); - else if (strcmp ("-wt", argv[c]) == 0) - strcpy (argv[c], "-w"); - else if (strcmp ("-ct", argv[c]) == 0) - strcpy (argv[c], "-c"); - } - - - - c = 0; - while ((c += (call_getopt (argc - c, &argv[c]))) < argc) { - - if (is_option (argv[c])) - continue; - - if (server_address == NULL) { - if (is_host (argv[c])) { - server_address = argv[c]; - } - else { - usage ("Invalid host name"); - } - } - } - - if (server_address == NULL) - server_address = strscpy (NULL, "127.0.0.1"); - - if (server_expect == NULL) - server_expect = strscpy (NULL, EXPECT); - - return validate_arguments (); -} - - - - - - -int -call_getopt (int argc, char **argv) -{ - int c, i = 0; - -#ifdef HAVE_GETOPT_H - int option_index = 0; - static struct option long_options[] = { - {"hostname", required_argument, 0, 'H'}, - {"expect", required_argument, 0, 'e'}, - {"critical", required_argument, 0, 'c'}, - {"warning", required_argument, 0, 'w'}, - {"port", required_argument, 0, 'P'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {"help", no_argument, 0, 'h'}, - {0, 0, 0, 0} - }; -#endif - - while (1) { -#ifdef HAVE_GETOPT_H - c = - getopt_long (argc, argv, "+hVvt:p:e:c:w:H:", long_options, - &option_index); -#else - c = getopt (argc, argv, "+?hVvt:p:e:c:w:H:"); -#endif - - i++; - - if (c == -1 || c == EOF || c == 1) - break; - - switch (c) { - case 't': - case 'p': - case 'e': - case 'c': - case 'w': - case 'H': - i++; - } - - switch (c) { - case 'H': /* hostname */ - if (is_host (optarg)) { - server_address = optarg; - } - else { - usage ("Invalid host name\n"); - } - break; - case 'p': /* port */ - if (is_intpos (optarg)) { - server_port = atoi (optarg); - } - else { - usage ("Server port must be a positive integer\n"); - } - break; - case 'e': /* username */ - server_expect = optarg; - break; - case 'c': /* critical time threshold */ - if (is_intnonneg (optarg)) { - critical_time = atoi (optarg); - check_critical_time = TRUE; - } - else { - usage ("Critical time must be a nonnegative integer\n"); - } - break; - case 'w': /* warning time threshold */ - if (is_intnonneg (optarg)) { - warning_time = atoi (optarg); - check_warning_time = TRUE; - } - else { - usage ("Warning time must be a nonnegative integer\n"); - } - break; - case 'v': /* verbose */ - verbose = TRUE; - break; - case 't': /* timeout */ - if (is_intnonneg (optarg)) { - socket_timeout = atoi (optarg); - } - else { - usage ("Time interval must be a nonnegative integer\n"); - } - break; - case 'V': /* version */ - print_revision (PROGNAME, "$Revision$"); - exit (STATE_OK); - case 'h': /* help */ - print_help (); - exit (STATE_OK); - case '?': /* help */ - usage ("Invalid argument\n"); - } - } - return i; -} - - - - - -int -validate_arguments (void) -{ - return OK; -} - - - - - -void -print_help (void) -{ - print_revision (PROGNAME, "$Revision$"); - printf - ("Copyright (c) 2000 Tom Shields/Karl DeBisschop\n\n" - "This plugin tests the IMAP4 service on the specified host.\n\n"); - print_usage (); - printf - ("\nOptions:\n" - " -H, --hostname=STRING or IPADDRESS\n" - " Check server on the indicated host\n" - " -p, --port=INTEGER\n" - " Make connection on the indicated port (default: %d)\n" - " -e, --expect=STRING\n" - " String to expect in first line of server response (default: %s)\n" - " -w, --warning=INTEGER\n" - " Seconds necessary to result in a warning status\n" - " -c, --critical=INTEGER\n" - " Seconds necessary to result in a critical status\n" - " -t, --timeout=INTEGER\n" - " Seconds before connection attempt times out (default: %d)\n" - " -v, --verbose\n" - " Print extra information (command-line use only)\n" - " -h, --help\n" - " Print detailed help screen\n" - " -V, --version\n" - " Print version information\n\n", - PORT, EXPECT, DEFAULT_SOCKET_TIMEOUT); - support (); -} - - - - - -void -print_usage (void) -{ - printf - ("Usage: %s -H host [-e expect] [-p port] [-w warn] [-c crit]\n" - " [-t timeout] [-v]\n" - " %s --help\n" - " %s --version\n", PROGNAME, PROGNAME, PROGNAME); -} 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 @@ -/****************************************************************************** - * - * CHECK_NNTP.C - * - * Program: NNTP plugin for Nagios - * License: GPL - * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) - * - * $Id$ - * - * Description: - * - * This plugin will attempt to open an NNTP connection with the host. - * Successul connects return STATE_OK, refusals and timeouts return - * STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful - * connects, but incorrect reponse messages from the host result in - * STATE_WARNING return values. An invalid newsgroup (if the -g - * option is used) results in a STATE_WARNING value. - * - * License Information: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - *****************************************************************************/ - -#include "config.h" -#include "common.h" -#include "netutils.h" -#include "utils.h" - -#define PROGNAME "check_nntp" - -#define PORT 119 -#define EXPECT1A "200" /* posting allowed */ -#define EXPECT1B "201" /* posting not allowed */ -#define EXPECT "NNTP" -#define QUIT "QUIT\r\n" -#define MODEREADER "MODE READER\r\n" - -int process_arguments (int, char **); -int call_getopt (int, char **); -int validate_arguments (void); -int check_disk (int usp, int free_disk); -void print_help (void); -void print_usage (void); - -int server_port = PORT; -char *server_expect = NULL; -char *server_address = NULL; -char *newsgroup = NULL; -int check_newsgroup = FALSE; -int send_modereader = FALSE; -int warning_time = 0; -int check_warning_time = FALSE; -int critical_time = 0; -int check_critical_time = FALSE; -int verbose = FALSE; - - -int -main (int argc, char **argv) -{ - char buffer[MAX_INPUT_BUFFER] = ""; - int sd; - int result; - int recv_result; - - if (process_arguments (argc, argv) != OK) - usage ("Invalid command arguments supplied\n"); - - /* initialize alarm signal handling */ - signal (SIGALRM, socket_timeout_alarm_handler); - - /* set socket timeout */ - alarm (socket_timeout); - - /* try to connect to the host at the given port number */ - time (&start_time); - result = my_tcp_connect (server_address, server_port, &sd); - - /* we connected */ - if (result == STATE_OK) { - - /* watch for the NNTP connection string */ - recv_result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); - - /* return a WARNING status if we couldn't read any data */ - if (recv_result == -1) { - - printf ("recv() failed\n"); - result = STATE_WARNING; - - } - else { - - /* strip carriage returns from buffer */ - strip (buffer); - - /* make sure we find the response we are looking for */ - if (strstr (buffer, EXPECT1A) != buffer - && strstr (buffer, EXPECT1B) != buffer) { - printf ("Invalid NNTP response received from host: %s\n", buffer); - result = STATE_WARNING; - } - - /* optionally send mode reader */ - /* added 2000-09-18 by Andreas M. Kirchwitz including some other minor fixes */ - if (send_modereader == TRUE) { - send (sd, MODEREADER, strlen (MODEREADER), 0); - recv_result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); - if (recv_result == -1) - strcpy (buffer, ""); - else - buffer[recv_result] = 0; - strip (buffer); - if ((strstr (buffer, EXPECT1A) != buffer) - && (strstr (buffer, EXPECT1B) != buffer)) { - printf ("Unexpected NNTP response received from host"); - result = STATE_WARNING; - } - } - - if (server_expect && !strstr (buffer, server_expect)) { - printf ("Invalid NNTP header received from host: %s\n", buffer); - result = STATE_WARNING; - } - - if (check_newsgroup == TRUE) { - sprintf (buffer, "GROUP %s\r\n", newsgroup); - send (sd, buffer, strlen (buffer), 0); - recv_result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); - if (recv_result == -1) - strcpy (buffer, ""); - else - buffer[recv_result] = 0; - strip (buffer); - if (strstr (buffer, "211") != buffer) { - printf ("NNTP problem - newsgroup '%s' not found\n", newsgroup); - result = STATE_WARNING; - } - } - - if (result == STATE_OK) { - time (&end_time); - if (check_critical_time == TRUE - && (end_time - start_time) > critical_time) result = - STATE_CRITICAL; - else if (check_warning_time == TRUE - && (end_time - start_time) > warning_time) result = - STATE_WARNING; - if (verbose) - printf ("NNTP %s - %d sec. response time, %s\n", - (result == STATE_OK) ? "ok" : "problem", - (int) (end_time - start_time), buffer); - else - printf ("NNTP %s - %d second response time\n", - (result == STATE_OK) ? "ok" : "problem", - (int) (end_time - start_time)); - } - - } - - /* close the connection */ - send (sd, QUIT, strlen (QUIT), 0); - close (sd); - - } - - /* reset the alarm timeout */ - alarm (0); - - return result; -} - - - - - - -/* process command-line arguments */ -int -process_arguments (int argc, char **argv) -{ - int c; - - if (argc < 2) - return ERROR; - - for (c = 1; c < argc; c++) { - if (strcmp ("-to", argv[c]) == 0) - strcpy (argv[c], "-t"); - else if (strcmp ("-wt", argv[c]) == 0) - strcpy (argv[c], "-w"); - else if (strcmp ("-ct", argv[c]) == 0) - strcpy (argv[c], "-c"); - } - - - - c = 0; - while ((c += (call_getopt (argc - c, &argv[c]))) < argc) { - - if (is_option (argv[c])) - continue; - - if (server_address == NULL) { - if (is_host (argv[c])) { - server_address = argv[c]; - } - else { - usage ("Invalid host name"); - } - } - } - - if (server_address == NULL) - server_address = strscpy (NULL, "127.0.0.1"); - -/* if (server_expect==NULL) */ -/* server_expect=strscpy(NULL,EXPECT); */ - - return validate_arguments (); -} - - - - - - -int -call_getopt (int argc, char **argv) -{ - int c, i = 0; - -#ifdef HAVE_GETOPT_H - int option_index = 0; - static struct option long_options[] = { - {"hostname", required_argument, 0, 'H'}, - {"expect", required_argument, 0, 'e'}, - {"critical", required_argument, 0, 'c'}, - {"warning", required_argument, 0, 'w'}, - {"port", required_argument, 0, 'P'}, - {"modereader", required_argument, 0, 'M'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {"help", no_argument, 0, 'h'}, - {0, 0, 0, 0} - }; -#endif - - while (1) { -#ifdef HAVE_GETOPT_H - c = - getopt_long (argc, argv, "+hVMvt:p:e:c:w:H:", long_options, - &option_index); -#else - c = getopt (argc, argv, "+?hVMvt:p:e:c:w:H:"); -#endif - - i++; - - if (c == -1 || c == EOF || c == 1) - break; - - switch (c) { - case 't': - case 'p': - case 'e': - case 'c': - case 'w': - case 'H': - i++; - } - - switch (c) { - case 'H': /* hostname */ - if (is_host (optarg)) { - server_address = optarg; - } - else { - usage ("Invalid host name\n"); - } - break; - case 'p': /* port */ - if (is_intpos (optarg)) { - server_port = atoi (optarg); - } - else { - usage ("Server port must be a positive integer\n"); - } - break; - case 'M': /* mode reader */ - send_modereader = TRUE; - break; - case 'e': /* expect */ - server_expect = optarg; - break; - case 'g': /* newsgroup */ - newsgroup = optarg; - check_newsgroup = TRUE; - break; - case 'c': /* critical time threshold */ - if (is_intnonneg (optarg)) { - critical_time = atoi (optarg); - check_critical_time = TRUE; - } - else { - usage ("Critical time must be a nonnegative integer\n"); - } - break; - case 'w': /* warning time threshold */ - if (is_intnonneg (optarg)) { - warning_time = atoi (optarg); - check_warning_time = TRUE; - } - else { - usage ("Warning time must be a nonnegative integer\n"); - } - break; - case 'v': /* verbose */ - verbose = TRUE; - break; - case 't': /* timeout */ - if (is_intnonneg (optarg)) { - socket_timeout = atoi (optarg); - } - else { - usage ("Time interval must be a nonnegative integer\n"); - } - break; - case 'V': /* version */ - print_revision (PROGNAME, "$Revision$"); - exit (STATE_OK); - case 'h': /* help */ - print_help (); - exit (STATE_OK); - case '?': /* help */ - usage ("Invalid argument\n"); - } - } - return i; -} - - - - - -int -validate_arguments (void) -{ - return OK; -} - - - - - -void -print_help (void) -{ - print_revision (PROGNAME, "$Revision$"); - printf - ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" - "This plugin tests the NNTP service on the specified host.\n\n"); - print_usage (); - printf - ("\nOptions:\n" - " -H, --hostname=STRING or IPADDRESS\n" - " Check server on the indicated host\n" - " -p, --port=INTEGER\n" - " Make connection on the indicated port (default: %d)\n" - " -e, --expect=STRING\n" - " String to expect in first line of server response (default: %s)\n" - " -g, --group=STRING\n" - " Newsgroup to poll\n" - " -w, --warning=INTEGER\n" - " Seconds necessary to result in a warning status\n" - " -c, --critical=INTEGER\n" - " Seconds necessary to result in a critical status\n" - " -t, --timeout=INTEGER\n" - " Seconds before connection attempt times out (default: %d)\n" - " -M\n" - " Send \"MODE READER\" after initial connect.\n" - " -v, --verbose\n" - " Print extra information (command-line use only)\n" - " -h, --help\n" - " Print detailed help screen\n" - " -V, --version\n" - " Print version information\n\n", - PORT, EXPECT, DEFAULT_SOCKET_TIMEOUT); - support (); -} - - - - - -void -print_usage (void) -{ - printf - ("Usage: %s -H host [-e expect] [-g group] [-p port] [-w warn] [-c crit]\n" - " [-t timeout] [-v]\n" - " %s --help\n" - " %s --version\n", PROGNAME, PROGNAME, PROGNAME); -} 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 @@ -/****************************************************************************** - * - * CHECK_POP.C - * - * Program: POP3 plugin for Nagios - * License: GPL - * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) - * - * $Id$ - * - * Description: - * - * This plugin will attempt to open an POP connection with the host. - * Successul connects return STATE_OK, refusals and timeouts return - * STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful - * connects, but incorrect reponse messages from the host result in - * STATE_WARNING return values. - * - * License Information: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - *****************************************************************************/ - -#include "config.h" -#include "common.h" -#include "netutils.h" -#include "utils.h" - -#define PROGNAME "check_pop" - -#define POP_PORT 110 -#define POP_EXPECT "+OK" -#define POP_QUIT "QUIT\n" - -int process_arguments (int, char **); -int call_getopt (int, char **); -int validate_arguments (void); -int check_disk (int usp, int free_disk); -void print_help (void); -void print_usage (void); - -int server_port = POP_PORT; -char *server_address = NULL; -char *server_expect = NULL; -int warning_time = 0; -int check_warning_time = FALSE; -int critical_time = 0; -int check_critical_time = FALSE; -int verbose = FALSE; - -int -main (int argc, char **argv) -{ - int sd; - int result; - char buffer[MAX_INPUT_BUFFER]; - - if (process_arguments (argc, argv) != OK) - usage ("Invalid command arguments supplied\n"); - - /* initialize alarm signal handling */ - signal (SIGALRM, socket_timeout_alarm_handler); - - /* set socket timeout */ - alarm (socket_timeout); - - /* try to connect to the host at the given port number */ - time (&start_time); - result = my_tcp_connect (server_address, server_port, &sd); - - /* we connected, so close connection before exiting */ - if (result == STATE_OK) { - - /* watch for the SMTP connection string */ - result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); - - /* strip the buffer of carriage returns */ - strip (buffer); - - /* return a WARNING status if we couldn't read any data */ - if (result == -1) { - printf ("recv() failed\n"); - result = STATE_WARNING; - } - - else { - - /* make sure we find the response we are looking for */ - if (!strstr (buffer, server_expect)) { - if (server_port == POP_PORT) - printf ("Invalid POP response received from host\n"); - else - printf ("Invalid POP response received from host on port %d\n", - server_port); - result = STATE_WARNING; - } - - else { - time (&end_time); - - result = STATE_OK; - - if (check_critical_time == TRUE - && (end_time - start_time) > critical_time) result = - STATE_CRITICAL; - else if (check_warning_time == TRUE - && (end_time - start_time) > warning_time) result = - STATE_WARNING; - - if (verbose == TRUE) - printf ("POP %s - %d sec. response time, %s\n", - (result == STATE_OK) ? "ok" : "problem", - (int) (end_time - start_time), buffer); - else - printf ("POP %s - %d second response time\n", - (result == STATE_OK) ? "ok" : "problem", - (int) (end_time - start_time)); - } - } - - /* close the connection */ - send (sd, POP_QUIT, strlen (POP_QUIT), 0); - close (sd); - } - - /* reset the alarm */ - alarm (0); - - return result; -} - - - - - - - -/* process command-line arguments */ -int -process_arguments (int argc, char **argv) -{ - int c; - - if (argc < 2) - return ERROR; - - for (c = 1; c < argc; c++) { - if (strcmp ("-to", argv[c]) == 0) - strcpy (argv[c], "-t"); - else if (strcmp ("-wt", argv[c]) == 0) - strcpy (argv[c], "-w"); - else if (strcmp ("-ct", argv[c]) == 0) - strcpy (argv[c], "-c"); - } - - - - c = 0; - while ((c += (call_getopt (argc - c, &argv[c]))) < argc) { - - if (is_option (argv[c])) - continue; - - if (server_address == NULL) { - if (is_host (argv[c])) { - server_address = argv[c]; - } - else { - usage ("Invalid host name"); - } - } - } - - if (server_address == NULL) - server_address = strscpy (NULL, "127.0.0.1"); - - if (server_expect == NULL) - server_expect = strscpy (NULL, POP_EXPECT); - - return validate_arguments (); -} - - - - - - -int -call_getopt (int argc, char **argv) -{ - int c, i = 0; - -#ifdef HAVE_GETOPT_H - int option_index = 0; - static struct option long_options[] = { - {"hostname", required_argument, 0, 'H'}, - {"expect", required_argument, 0, 'e'}, - {"critical", required_argument, 0, 'c'}, - {"warning", required_argument, 0, 'w'}, - {"port", required_argument, 0, 'P'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {"help", no_argument, 0, 'h'}, - {0, 0, 0, 0} - }; -#endif - - while (1) { -#ifdef HAVE_GETOPT_H - c = - getopt_long (argc, argv, "+hVvt:p:e:c:w:H:", long_options, - &option_index); -#else - c = getopt (argc, argv, "+?hVvt:p:e:c:w:H:"); -#endif - - i++; - - if (c == -1 || c == EOF || c == 1) - break; - - switch (c) { - case 't': - case 'p': - case 'e': - case 'c': - case 'w': - case 'H': - i++; - } - - switch (c) { - case 'H': /* hostname */ - if (is_host (optarg)) { - server_address = optarg; - } - else { - usage ("Invalid host name\n"); - } - break; - case 'p': /* port */ - if (is_intpos (optarg)) { - server_port = atoi (optarg); - } - else { - usage ("Server port must be a positive integer\n"); - } - break; - case 'e': /* username */ - server_expect = optarg; - break; - case 'c': /* critical time threshold */ - if (is_intnonneg (optarg)) { - critical_time = atoi (optarg); - check_critical_time = TRUE; - } - else { - usage ("Critical time must be a nonnegative integer\n"); - } - break; - case 'w': /* warning time threshold */ - if (is_intnonneg (optarg)) { - warning_time = atoi (optarg); - check_warning_time = TRUE; - } - else { - usage ("Warning time must be a nonnegative integer\n"); - } - break; - case 'v': /* verbose */ - verbose = TRUE; - break; - case 't': /* timeout */ - if (is_intnonneg (optarg)) { - socket_timeout = atoi (optarg); - } - else { - usage ("Time interval must be a nonnegative integer\n"); - } - break; - case 'V': /* version */ - print_revision (PROGNAME, "$Revision$"); - exit (STATE_OK); - case 'h': /* help */ - print_help (); - exit (STATE_OK); - case '?': /* help */ - usage ("Invalid argument\n"); - } - } - return i; -} - - - - - -int -validate_arguments (void) -{ - return OK; -} - - - - - -void -print_help (void) -{ - print_revision (PROGNAME, "$Revision$"); - printf - ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" - "This plugin tests the POP service on the specified host.\n\n"); - print_usage (); - printf - ("\nOptions:\n" - " -H, --hostname=STRING or IPADDRESS\n" - " Check server on the indicated host\n" - " -p, --port=INTEGER\n" - " Make connection on the indicated port (default: %d)\n" - " -e, --expect=STRING\n" - " String to expect in first line of server response (default: %s)\n" - " -w, --warning=INTEGER\n" - " Seconds necessary to result in a warning status\n" - " -c, --critical=INTEGER\n" - " Seconds necessary to result in a critical status\n" - " -t, --timeout=INTEGER\n" - " Seconds before connection attempt times out (default: %d)\n" - " -v, --verbose\n" - " Print extra information (command-line use only)\n" - " -h, --help\n" - " Print detailed help screen\n" - " -V, --version\n" - " Print version information\n\n", - POP_PORT, POP_EXPECT, DEFAULT_SOCKET_TIMEOUT); - support (); -} - - - - - -void -print_usage (void) -{ - printf - ("Usage: %s -H host [-e expect] [-p port] [-w warn] [-c crit] [-t timeout] [-v]\n" - " %s --help\n" - " %s --version\n", PROGNAME, PROGNAME, PROGNAME); -} -- cgit v1.2.3-74-g34f1