From 90b45deb4138efb47efbdd98a4aede1aebb47146 Mon Sep 17 00:00:00 2001 From: Karl DeBisschop Date: Sat, 9 Aug 2003 13:36:49 +0000 Subject: more pedantic compiler warnings git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@674 f882894a-f735-0410-b71e-b25c423dba1c diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index f7c826b..c4e427a 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c @@ -41,8 +41,8 @@ int server_port = SMTP_PORT; char *server_address = NULL; char *server_expect = NULL; int smtp_use_dummycmd = 1; -char *mail_command = "MAIL "; -char *from_arg = " "; +char *mail_command; +char *from_arg; int warning_time = 0; int check_warning_time = FALSE; int critical_time = 0; @@ -60,7 +60,7 @@ main (int argc, char **argv) int sd; double elapsed_time; int result = STATE_UNKNOWN; - char buffer[MAX_INPUT_BUFFER] = ""; + char buffer[MAX_INPUT_BUFFER]; char *from_str = NULL; char *helocmd = NULL; struct timeval tv; @@ -313,7 +313,13 @@ process_arguments (int argc, char **argv) } if (server_expect == NULL) - asprintf (&server_expect, SMTP_EXPECT); + server_expect = strdup (SMTP_EXPECT); + + if (mail_command == NULL) + mail_command = strdup("MAIL "); + + if (from_arg==NULL) + from_arg = strdup(" "); return validate_arguments (); } diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c index 7fcb811..fdded58 100644 --- a/plugins/check_ssh.c +++ b/plugins/check_ssh.c @@ -32,7 +32,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #define SSH_DFL_PORT 22 #define BUFF_SZ 256 -short port = -1; +int port = -1; char *server_name = NULL; int verbose = FALSE; @@ -41,7 +41,7 @@ int validate_arguments (void); void print_help (void); void print_usage (void); -int ssh_connect (char *haddr, short hport); +int ssh_connect (char *haddr, int hport); int main (int argc, char **argv) @@ -111,7 +111,8 @@ process_arguments (int argc, char **argv) case 't': /* timeout period */ if (!is_integer (optarg)) usage (_("Timeout Interval must be an integer!\n\n")); - socket_timeout = atoi (optarg); + else + socket_timeout = atoi (optarg); break; case '4': address_family = AF_INET; @@ -178,7 +179,7 @@ validate_arguments (void) *-----------------------------------------------------------------------*/ int -ssh_connect (char *haddr, short hport) +ssh_connect (char *haddr, int hport) { int sd; int result; diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index a897d8e..fc0572c 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c @@ -1,21 +1,27 @@ /***************************************************************************** -* -* 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. -* + + 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" + +/* progname changes depending on symlink called */ +char *progname = "check_tcp"; +const char *revision = "$Revision$"; +const char *copyright = "1999-2003"; +const char *email = "nagiosplug-devel@lists.sourceforge.net"; + #include "common.h" #include "netutils.h" #include "utils.h" @@ -51,9 +57,9 @@ enum { }; int process_arguments (int, char **); -void print_usage (void); -void print_help (void); int my_recv (void); +void print_help (void); +void print_usage (void); char *SERVICE = NULL; char *SEND = NULL; @@ -67,94 +73,35 @@ char *server_address = NULL; char *server_send = NULL; char *server_quit = NULL; char **server_expect = NULL; -int server_expect_count = 0; +size_t server_expect_count = 0; int maxbytes = 0; char **warn_codes = NULL; -int warn_codes_count = 0; +size_t warn_codes_count = 0; char **crit_codes = NULL; -int crit_codes_count = 0; -int delay = 0; +size_t crit_codes_count = 0; +unsigned int delay = 0; double warning_time = 0; int check_warning_time = FALSE; double critical_time = 0; int check_critical_time = FALSE; double elapsed_time = 0; +long microsec; int verbose = FALSE; int use_ssl = FALSE; int sd = 0; -char *buffer = ""; - -/* progname changes depending on symlink called */ -char *progname = "check_tcp"; -const char *revision = "$Revision$"; -const char *copyright = "1999-2003"; -const char *email = "nagiosplug-devel@lists.sourceforge.net"; - - - - -void -print_usage (void) -{ - printf (_("\ -Usage: %s -H host -p port [-w ] [-c ]\n\ - [-s ] [-e ] [-q ]\n\ - [-m ] [-d ] [-t ]\n\ - [-r ] [-v] [-4|-6]\n"), progname); - printf (" %s (-h|--help)\n", progname); - printf (" %s (-V|--version)\n", progname); -} -void -print_help (void) -{ - print_revision (progname, revision); - - printf (_(COPYRIGHT), copyright, email); - - printf (_("This plugin tests %s connections with the specified host.\n\n"), - SERVICE); - - print_usage (); - - printf (_(UT_HELP_VRSN)); - - printf (_(UT_HOST_PORT), 'p', "none"); - - printf (_(UT_IPv46)); - - printf (_("\ - -s, --send=STRING\n\ - String to send to the server\n\ - -e, --expect=STRING\n\ - String to expect in server response\n\ - -q, --quit=STRING\n\ - String to send server to initiate a clean close of the connection\n")); +char *buffer; - printf (_("\ - -r, --refuse=ok|warn|crit\n\ - Accept tcp refusals with states ok, warn, crit (default: crit)\n\ - -m, --maxbytes=INTEGER\n\ - Close connection once more than this number of bytes are received\n\ - -d, --delay=INTEGER\n\ - Seconds to wait between sending string and polling for response\n")); - printf (_(UT_WARN_CRIT)); - printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); - printf (_(UT_VERBOSE)); - printf (_(UT_SUPPORT)); -} - - int main (int argc, char **argv) { int result; int i; - char *status = ""; + char *status; struct timeval tv; setlocale (LC_ALL, ""); @@ -296,10 +243,10 @@ main (int argc, char **argv) asprintf (&server_send, "%s\r\n", server_send); #ifdef HAVE_SSL if (use_ssl) - SSL_write(ssl, server_send, strlen (server_send)); + SSL_write(ssl, server_send, (int)strlen(server_send)); else #endif - send (sd, server_send, strlen (server_send), 0); + send (sd, server_send, strlen(server_send), 0); } if (delay > 0) { @@ -311,6 +258,7 @@ main (int argc, char **argv) buffer = malloc (MAXBUF); memset (buffer, '\0', MAXBUF); + status = strdup (""); /* watch for the expect string */ while ((i = my_recv ()) > 0) { buffer[i] = '\0'; @@ -333,8 +281,8 @@ main (int argc, char **argv) if (server_expect_count > 0) { for (i = 0;; i++) { if (verbose) - printf ("%d %d\n", i, server_expect_count); - if (i >= server_expect_count) + printf ("%d %d\n", i, (int)server_expect_count); + if (i >= (int)server_expect_count) die (STATE_WARNING, _("Invalid response from host\n")); if (strstr (status, server_expect[i])) break; @@ -345,7 +293,7 @@ main (int argc, char **argv) if (server_quit != NULL) { #ifdef HAVE_SSL if (use_ssl) { - SSL_write (ssl, server_quit, strlen (server_quit)); + SSL_write (ssl, server_quit, (int)strlen(server_quit)); SSL_shutdown (ssl); SSL_free (ssl); SSL_CTX_free (ctx); @@ -362,7 +310,8 @@ main (int argc, char **argv) if (sd) close (sd); - elapsed_time = delta_time (tv); + microsec = deltime (tv); + elapsed_time = (double)microsec / 1.0e6; if (check_critical_time == TRUE && elapsed_time > critical_time) result = STATE_CRITICAL; @@ -382,7 +331,7 @@ main (int argc, char **argv) if (status && strlen(status) > 0) printf (" [%s]", status); - printf ("|time=%.3f\n", elapsed_time); + printf ("|time=%ldus\n", microsec); return result; } @@ -479,13 +428,15 @@ process_arguments (int argc, char **argv) case 'c': /* critical */ if (!is_intnonneg (optarg)) usage (_("Critical threshold must be a nonnegative integer\n")); - critical_time = strtod (optarg, NULL); + else + critical_time = strtod (optarg, NULL); check_critical_time = TRUE; break; case 'w': /* warning */ if (!is_intnonneg (optarg)) usage (_("Warning threshold must be a nonnegative integer\n")); - warning_time = strtod (optarg, NULL); + else + warning_time = strtod (optarg, NULL); check_warning_time = TRUE; break; case 'C': @@ -499,12 +450,14 @@ process_arguments (int argc, char **argv) case 't': /* timeout */ if (!is_intpos (optarg)) usage (_("Timeout interval must be a positive integer\n")); - socket_timeout = atoi (optarg); + else + socket_timeout = atoi (optarg); break; case 'p': /* port */ if (!is_intpos (optarg)) usage (_("Server port must be a positive integer\n")); - server_port = atoi (optarg); + else + server_port = atoi (optarg); break; case 's': server_send = optarg; @@ -520,7 +473,8 @@ process_arguments (int argc, char **argv) case 'm': if (!is_intpos (optarg)) usage (_("Maxbytes must be a positive integer\n")); - maxbytes = atoi (optarg); + else + maxbytes = atoi (optarg); case 'q': server_quit = optarg; break; @@ -627,3 +581,66 @@ my_recv (void) return i; } + + + + + + +void +print_help (void) +{ + print_revision (progname, revision); + + printf (_(COPYRIGHT), copyright, email); + + printf (_("This plugin tests %s connections with the specified host.\n\n"), + SERVICE); + + print_usage (); + + printf (_(UT_HELP_VRSN)); + + printf (_(UT_HOST_PORT), 'p', "none"); + + printf (_(UT_IPv46)); + + printf (_("\ + -s, --send=STRING\n\ + String to send to the server\n\ + -e, --expect=STRING\n\ + String to expect in server response\n\ + -q, --quit=STRING\n\ + String to send server to initiate a clean close of the connection\n")); + + printf (_("\ + -r, --refuse=ok|warn|crit\n\ + Accept tcp refusals with states ok, warn, crit (default: crit)\n\ + -m, --maxbytes=INTEGER\n\ + Close connection once more than this number of bytes are received\n\ + -d, --delay=INTEGER\n\ + Seconds to wait between sending string and polling for response\n")); + + printf (_(UT_WARN_CRIT)); + + printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); + + printf (_(UT_VERBOSE)); + + printf (_(UT_SUPPORT)); +} + + + + +void +print_usage (void) +{ + printf (_("\ +Usage: %s -H host -p port [-w ] [-c ]\n\ + [-s ] [-e ] [-q ]\n\ + [-m ] [-d ] [-t ]\n\ + [-r ] [-v] [-4|-6]\n"), progname); + printf (" %s (-h|--help)\n", progname); + printf (" %s (-V|--version)\n", progname); +} diff --git a/plugins/check_time.c b/plugins/check_time.c index dde6eea..36b622f 100644 --- a/plugins/check_time.c +++ b/plugins/check_time.c @@ -29,51 +29,6 @@ enum { TIME_PORT = 37 }; -void -print_usage (void) -{ - printf (_("\ -Usage: %s -H [-p port] [-w variance] [-c variance]\n\ - [-W connect_time] [-C connect_time] [-t timeout]\n"), progname); - printf (_(UT_HLP_VRS), progname, progname); -} - -void -print_help (void) -{ - char *myport; - asprintf (&myport, "%d", TIME_PORT); - - print_revision (progname, revision); - - printf (_("Copyright (c) 1999 Ethan Galstad\n")); - printf (_(COPYRIGHT), copyright, email); - - printf (_("\ -This plugin will check the time on the specified host.\n\n")); - - print_usage (); - - printf (_(UT_HELP_VRSN)); - - printf (_(UT_HOST_PORT), 'p', myport); - - printf (_("\ - -w, --warning-variance=INTEGER\n\ - Time difference (sec.) necessary to result in a warning status\n\ - -c, --critical-variance=INTEGER\n\ - Time difference (sec.) necessary to result in a critical status\n\ - -W, --warning-connect=INTEGER\n\ - Response time (sec.) necessary to result in warning status\n\ - -C, --critical-connect=INTEGER\n\ - Response time (sec.) necessary to result in critical status\n")); - - printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); - - support (); -} - - #define UNIX_EPOCH 2208988800UL unsigned long server_time, raw_server_time; @@ -89,11 +44,9 @@ int check_critical_diff = FALSE; int server_port = TIME_PORT; char *server_address = NULL; - int process_arguments (int, char **); -void print_usage (void); void print_help (void); - +void print_usage (void); int main (int argc, char **argv) @@ -276,24 +229,28 @@ process_arguments (int argc, char **argv) case 'W': /* warning-connect */ if (!is_intnonneg (optarg)) usage (_("Warning threshold must be a nonnegative integer\n")); - warning_time = atoi (optarg); + else + warning_time = atoi (optarg); check_warning_time = TRUE; break; case 'C': /* critical-connect */ if (!is_intnonneg (optarg)) usage (_("Critical threshold must be a nonnegative integer\n")); - critical_time = atoi (optarg); + else + critical_time = atoi (optarg); check_critical_time = TRUE; break; case 'p': /* port */ if (!is_intnonneg (optarg)) usage (_("Server port must be a nonnegative integer\n")); - server_port = atoi (optarg); + else + server_port = atoi (optarg); break; case 't': /* timeout */ if (!is_intnonneg (optarg)) usage (_("Timeout interval must be a nonnegative integer\n")); - socket_timeout = atoi (optarg); + else + socket_timeout = atoi (optarg); break; } } @@ -312,3 +269,55 @@ process_arguments (int argc, char **argv) return OK; } + + + + + + +void +print_help (void) +{ + char *myport; + asprintf (&myport, "%d", TIME_PORT); + + print_revision (progname, revision); + + printf (_("Copyright (c) 1999 Ethan Galstad\n")); + printf (_(COPYRIGHT), copyright, email); + + printf (_("\ +This plugin will check the time on the specified host.\n\n")); + + print_usage (); + + printf (_(UT_HELP_VRSN)); + + printf (_(UT_HOST_PORT), 'p', myport); + + printf (_("\ + -w, --warning-variance=INTEGER\n\ + Time difference (sec.) necessary to result in a warning status\n\ + -c, --critical-variance=INTEGER\n\ + Time difference (sec.) necessary to result in a critical status\n\ + -W, --warning-connect=INTEGER\n\ + Response time (sec.) necessary to result in warning status\n\ + -C, --critical-connect=INTEGER\n\ + Response time (sec.) necessary to result in critical status\n")); + + printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); + + support (); +} + + + + +void +print_usage (void) +{ + printf (_("\ +Usage: %s -H [-p port] [-w variance] [-c variance]\n\ + [-W connect_time] [-C connect_time] [-t timeout]\n"), progname); + printf (_(UT_HLP_VRS), progname, progname); +} diff --git a/plugins/check_udp.c b/plugins/check_udp.c index 11b942a..bd5de58 100644 --- a/plugins/check_udp.c +++ b/plugins/check_udp.c @@ -25,56 +25,9 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "netutils.h" #include "utils.h" -/* Original Command line: - check_udp [-p port] [-s send] [-e expect] \ - [-wt warn_time] [-ct crit_time] [-to to_sec] */ -void -print_usage (void) -{ - printf (_("\ -Usage: %s -H [-p port] [-w warn_time] [-c crit_time]\n\ - [-e expect] [-s send] [-t to_sec] [-v]\n"), progname); - printf (_(UT_HLP_VRS), progname, progname); -} - -void -print_help (void) -{ - print_revision (progname, revision); - - printf (_("Copyright (c) 1999 Ethan Galstad\n")); - printf (_(COPYRIGHT), copyright, email); - - printf (_("\ -This plugin tests an UDP connection with the specified host.\n\n")); - - print_usage (); - - printf (_(UT_HELP_VRSN)); - - printf (_(UT_HOST_PORT), 'p', "none"); - - printf (_("\ - -e, --expect=STRING \n\ - String to expect in first line of server response\n\ - -s, --send=STRING \n\ - String to send to the server when initiating the connection\n")); - - printf (_(UT_WARN_CRIT)); - - printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); - - printf (_(UT_VERBOSE)); - - printf (_("\ -This plugin will attempt to connect to the specified port on the host.\n\ -Successful connects return STATE_OK, refusals and timeouts return\n\ -STATE_CRITICAL, other errors return STATE_UNKNOWN.\n\n")); - - printf(_(UT_SUPPORT)); -} - int process_arguments (int, char **); +void print_help (void); +void print_usage (void); int warning_time = 0; int check_warning_time = FALSE; @@ -84,7 +37,7 @@ int verbose = FALSE; int server_port = 0; char *server_address = NULL; char *server_expect = NULL; -char *server_send = ""; +char *server_send; int main (int argc, char **argv) @@ -207,24 +160,28 @@ process_arguments (int argc, char **argv) case 'c': /* critical */ if (!is_intnonneg (optarg)) usage (_("Critical threshold must be a nonnegative integer\n")); - critical_time = atoi (optarg); + else + 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); + else + 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); + else + socket_timeout = atoi (optarg); break; case 'p': /* port */ if (!is_intnonneg (optarg)) usage (_("Server port must be a nonnegative integer\n")); - server_port = atoi (optarg); + else + server_port = atoi (optarg); break; case 'e': /* expect */ server_expect = optarg; @@ -245,5 +202,65 @@ process_arguments (int argc, char **argv) if (server_address == NULL) usage (_("Host name was not supplied\n")); + if (server_send == NULL) + server_send = strdup(""); + return c; } + + + + + + +void +print_help (void) +{ + print_revision (progname, revision); + + printf (_("Copyright (c) 1999 Ethan Galstad\n")); + printf (_(COPYRIGHT), copyright, email); + + printf (_("\ +This plugin tests an UDP connection with the specified host.\n\n")); + + print_usage (); + + printf (_(UT_HELP_VRSN)); + + printf (_(UT_HOST_PORT), 'p', "none"); + + printf (_("\ + -e, --expect=STRING \n\ + String to expect in first line of server response\n\ + -s, --send=STRING \n\ + String to send to the server when initiating the connection\n")); + + printf (_(UT_WARN_CRIT)); + + printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); + + printf (_(UT_VERBOSE)); + + printf (_("\ +This plugin will attempt to connect to the specified port on the host.\n\ +Successful connects return STATE_OK, refusals and timeouts return\n\ +STATE_CRITICAL, other errors return STATE_UNKNOWN.\n\n")); + + printf(_(UT_SUPPORT)); +} + + + + +/* Original Command line: + check_udp [-p port] [-s send] [-e expect] \ + [-wt warn_time] [-ct crit_time] [-to to_sec] */ +void +print_usage (void) +{ + printf (_("\ +Usage: %s -H [-p port] [-w warn_time] [-c crit_time]\n\ + [-e expect] [-s send] [-t to_sec] [-v]\n"), progname); + printf (_(UT_HLP_VRS), progname, progname); +} diff --git a/plugins/check_ups.c b/plugins/check_ups.c index 499b922..fcee747 100644 --- a/plugins/check_ups.c +++ b/plugins/check_ups.c @@ -29,68 +29,6 @@ enum { PORT = 3493 }; -void -print_usage (void) -{ - printf (_("\ -Usage: %s -H host [-e expect] [-p port] [-w warn] [-c crit]\n\ - [-t timeout] [-v]\n"), progname); - printf (_(UT_HLP_VRS), progname, progname); -} - -void -print_help (void) -{ - char *myport; - asprintf (&myport, "%d", PORT); - - print_revision (progname, revision); - - printf (_("Copyright (c) 2000 Tom Shields")); - printf (_(COPYRIGHT), copyright, email); - - printf (_("This plugin tests the UPS service on the specified host.\n\ -Network UPS Tools from www.exploits.org must be running for this plugin to\n\ -work.\n\n")); - - print_usage (); - - printf (_(UT_HELP_VRSN)); - - printf (_(UT_HOST_PORT), 'p', myport); - - printf (_("\ - -u, --ups=STRING\n\ - Name of UPS\n")); - - printf (_(UT_WARN_CRIT)); - - printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); - - printf (_(UT_VERBOSE)); - - printf (_("\ -This plugin attempts to determine the status of a UPS (Uninterruptible Power\n\ -Supply) on a local or remote host. If the UPS is online or calibrating, the\n\ -plugin will return an OK state. If the battery is on it will return a WARNING\n\ -state. If the UPS is off or has a low battery the plugin will return a CRITICAL\n\ -state.\n\n")); - - printf (_("\ -You may also specify a variable to check [such as temperature, utility voltage,\n\ -battery load, etc.] as well as warning and critical thresholds for the value of\n\ -that variable. If the remote host has multiple UPS that are being monitored you\n\ -will have to use the [ups] option to specify which UPS to check.\n\n")); - - printf (_("Notes:\n\n\ -This plugin requires that the UPSD daemon distributed with Russel Kroll's\n\ -Smart UPS Tools be installed on the remote host. If you do not have the\n\ -package installed on your system, you can download it from\n\ -http://www.exploits.org/nut\n\n")); - - printf (_(UT_SUPPORT)); -} - #define CHECK_NONE 0 #define UPS_NONE 0 /* no supported options */ @@ -110,7 +48,7 @@ http://www.exploits.org/nut\n\n")); #define UPSSTATUS_UNKOWN 64 int server_port = PORT; -char *server_address = "127.0.0.1"; +char *server_address; char *ups_name = NULL; double warning_value = 0.0; double critical_value = 0.0; @@ -124,14 +62,16 @@ double ups_utility_voltage = 0.0; double ups_battery_percent = 0.0; double ups_load_percent = 0.0; double ups_temperature = 0.0; -char *ups_status = "N/A"; +char *ups_status; int determine_status (void); int determine_supported_vars (void); -int get_ups_variable (const char *, char *, int); +int get_ups_variable (const char *, char *, size_t); int process_arguments (int, char **); int validate_arguments (void); +void print_help (void); +void print_usage (void); int main (int argc, char **argv) @@ -141,6 +81,7 @@ main (int argc, char **argv) char temp_buffer[MAX_INPUT_BUFFER]; double ups_utility_deviation = 0.0; + ups_status = strdup ("N/A"); if (process_arguments (argc, argv) != OK) usage ("Invalid command arguments supplied\n"); @@ -160,7 +101,7 @@ main (int argc, char **argv) if (determine_status () != OK) return STATE_CRITICAL; - asprintf (&ups_status, ""); + ups_status = strdup (""); result = STATE_OK; if (status & UPSSTATUS_OFF) { @@ -395,7 +336,7 @@ determine_supported_vars (void) /* gets a variable value for a specific UPS */ int -get_ups_variable (const char *varname, char *buf, int buflen) +get_ups_variable (const char *varname, char *buf, size_t buflen) { /* char command[MAX_INPUT_BUFFER]; */ char temp_buffer[MAX_INPUT_BUFFER]; @@ -569,6 +510,9 @@ process_arguments (int argc, char **argv) usage ("Invalid host name"); } + if (server_address == NULL) + server_address = strdup("127.0.0.1"); + return validate_arguments(); } @@ -581,3 +525,73 @@ validate_arguments (void) { return OK; } + + + + + + +void +print_help (void) +{ + char *myport; + asprintf (&myport, "%d", PORT); + + print_revision (progname, revision); + + printf (_("Copyright (c) 2000 Tom Shields")); + printf (_(COPYRIGHT), copyright, email); + + printf (_("This plugin tests the UPS service on the specified host.\n\ +Network UPS Tools from www.exploits.org must be running for this plugin to\n\ +work.\n\n")); + + print_usage (); + + printf (_(UT_HELP_VRSN)); + + printf (_(UT_HOST_PORT), 'p', myport); + + printf (_("\ + -u, --ups=STRING\n\ + Name of UPS\n")); + + printf (_(UT_WARN_CRIT)); + + printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); + + printf (_(UT_VERBOSE)); + + printf (_("\ +This plugin attempts to determine the status of a UPS (Uninterruptible Power\n\ +Supply) on a local or remote host. If the UPS is online or calibrating, the\n\ +plugin will return an OK state. If the battery is on it will return a WARNING\n\ +state. If the UPS is off or has a low battery the plugin will return a CRITICAL\n\ +state.\n\n")); + + printf (_("\ +You may also specify a variable to check [such as temperature, utility voltage,\n\ +battery load, etc.] as well as warning and critical thresholds for the value of\n\ +that variable. If the remote host has multiple UPS that are being monitored you\n\ +will have to use the [ups] option to specify which UPS to check.\n\n")); + + printf (_("Notes:\n\n\ +This plugin requires that the UPSD daemon distributed with Russel Kroll's\n\ +Smart UPS Tools be installed on the remote host. If you do not have the\n\ +package installed on your system, you can download it from\n\ +http://www.exploits.org/nut\n\n")); + + printf (_(UT_SUPPORT)); +} + + + + +void +print_usage (void) +{ + printf (_("\ +Usage: %s -H host [-e expect] [-p port] [-w warn] [-c crit]\n\ + [-t timeout] [-v]\n"), progname); + printf (_(UT_HLP_VRS), progname, progname); +} diff --git a/plugins/check_users.c b/plugins/check_users.c index d4480e7..9e18201 100644 --- a/plugins/check_users.c +++ b/plugins/check_users.c @@ -25,43 +25,11 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "popen.h" #include "utils.h" -void -print_usage (void) -{ - printf ("Usage: %s -w -c \n", progname); - printf (_(UT_HLP_VRS), progname, progname); -} - -void -print_help (void) -{ - print_revision (progname, revision); - - printf (_("Copyright (c) 1999 Ethan Galstad\n")); - printf (_(COPYRIGHT), copyright, email); - - printf (_("\ -This plugin checks the number of users currently logged in on the local\n\ -system and generates an error if the number exceeds the thresholds specified.\n")); - - print_usage (); - - printf (_(UT_HELP_VRSN)); - - printf (_("\ - -w, --warning=INTEGER\n\ - Set WARNING status if more than INTEGER users are logged in\n\ - -c, --critical=INTEGER\n\ - Set CRITICAL status if more than INTEGER users are logged in\n")); - - printf (_(UT_SUPPORT)); -} - #define possibly_set(a,b) ((a) == 0 ? (b) : 0) int process_arguments (int, char **); -void print_usage (void); void print_help (void); +void print_usage (void); int wusers = -1; int cusers = -1; @@ -171,12 +139,14 @@ process_arguments (int argc, char **argv) case 'c': /* critical */ if (!is_intnonneg (optarg)) usage (_("Critical threshold must be a nonnegative integer\n")); - cusers = atoi (optarg); + else + cusers = atoi (optarg); break; case 'w': /* warning */ if (!is_intnonneg (optarg)) usage (_("Warning threshold must be a nonnegative integer\n")); - wusers = atoi (optarg); + else + wusers = atoi (optarg); break; } } @@ -185,14 +155,56 @@ process_arguments (int argc, char **argv) if (wusers == -1 && argc > c) { if (is_intnonneg (argv[c]) == FALSE) usage (_("Warning threshold must be a nonnegative integer\n")); - wusers = atoi (argv[c++]); + else + wusers = atoi (argv[c++]); } if (cusers == -1 && argc > c) { if (is_intnonneg (argv[c]) == FALSE) usage (_("Warning threshold must be a nonnegative integer\n")); - cusers = atoi (argv[c]); + else + cusers = atoi (argv[c]); } return OK; } + + + + + + +void +print_help (void) +{ + print_revision (progname, revision); + + printf (_("Copyright (c) 1999 Ethan Galstad\n")); + printf (_(COPYRIGHT), copyright, email); + + printf (_("\ +This plugin checks the number of users currently logged in on the local\n\ +system and generates an error if the number exceeds the thresholds specified.\n")); + + print_usage (); + + printf (_(UT_HELP_VRSN)); + + printf (_("\ + -w, --warning=INTEGER\n\ + Set WARNING status if more than INTEGER users are logged in\n\ + -c, --critical=INTEGER\n\ + Set CRITICAL status if more than INTEGER users are logged in\n")); + + printf (_(UT_SUPPORT)); +} + + + + +void +print_usage (void) +{ + printf ("Usage: %s -w -c \n", progname); + printf (_(UT_HLP_VRS), progname, progname); +} -- cgit v0.10-9-g596f