diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-14 02:26:34 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-14 02:26:34 +0000 |
commit | 2a68978c564e53cddc90882ee7776a43839dfcff (patch) | |
tree | 7c8432f893e4c43f2d20d022ba8ccdc05752e4e6 /plugins | |
parent | 9e009c4b1128352c6039d25b39213fd480e9b055 (diff) | |
download | monitoring-plugins-2a68978c564e53cddc90882ee7776a43839dfcff.tar.gz |
remove call_getopt and ssprintf
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@191 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Makefile.am | 6 | ||||
-rw-r--r-- | plugins/check_dns.c | 2 | ||||
-rw-r--r-- | plugins/check_ldap.c | 59 | ||||
-rw-r--r-- | plugins/check_mrtg.c | 2 | ||||
-rw-r--r-- | plugins/check_mrtgtraf.c | 135 | ||||
-rw-r--r-- | plugins/check_nwstat.c | 4 | ||||
-rw-r--r-- | plugins/check_radius.c | 20 | ||||
-rw-r--r-- | plugins/utils.c | 4 | ||||
-rw-r--r-- | plugins/version.h.in | 1 |
9 files changed, 92 insertions, 141 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 6747fa36..23c713a4 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -2,7 +2,7 @@ VPATH = $(top_srcdir) $(top_srcdir)/plugins $(top_srcdir)/plugins/t -INCLUDES = @LDAPINCLUDE@ @PGINCLUDE@ @SSLINCLUDE@ +INCLUDES = @SSLINCLUDE@ libexec_PROGRAMS = check_disk check_dummy check_http check_load \ check_mrtg check_mrtgtraf check_nwstat check_overcr check_ping \ @@ -119,6 +119,10 @@ check_imap_DEPENDENCIES = check_tcp.c $(NETOBJS) $(DEPLIBS) check_nntp_DEPENDENCIES = check_tcp.c $(NETOBJS) $(DEPLIBS) check_pop_DEPENDENCIES = check_tcp.c $(NETOBJS) $(DEPLIBS) +check_mysql_INCLUDES = @MYSQLINCLUDE@ +check_pgsql_INCLUDES = @PGINCLUDE@ +check_ldap_INCLUDES = @LDAPINCLUDE@ + ############################################################################## # secondary dependencies diff --git a/plugins/check_dns.c b/plugins/check_dns.c index f9cf2889..714ecab0 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c @@ -88,7 +88,7 @@ main (int argc, char **argv) } /* get the command to run */ - sprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND, query_address, dns_server); + asprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND, query_address, dns_server); alarm (timeout_interval); time (&start_time); diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index d3f06158..213dc4a8 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c @@ -34,7 +34,6 @@ #define UNKNOWN -1 int process_arguments (int, char **); -int call_getopt (int, char **); int validate_arguments (void); static void print_help (void); static void print_usage (void); @@ -124,35 +123,10 @@ 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"); - } - - c = 0; - while (c += (call_getopt (argc - c, &argv[c]))) { - if (argc <= c) - break; - if (ld_host[0] == 0) { - strncpy (ld_host, argv[c], sizeof (ld_host) - 1); - ld_host[sizeof (ld_host) - 1] = 0; - } - } - - return c; -} - -int -call_getopt (int argc, char **argv) -{ - int c, i = 1; #ifdef HAVE_GETOPT_H int option_index = 0; /* initialize the long option struct */ - static struct option long_options[] = { + static struct option longopts[] = { {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, {"timeout", required_argument, 0, 't'}, @@ -168,15 +142,17 @@ call_getopt (int argc, char **argv) }; #endif - for (c = 1; c < argc; c++) + if (argc < 2) + return ERROR; + + for (c = 1; c < argc; c++) { if (strcmp ("-to", argv[c]) == 0) strcpy (argv[c], "-t"); + } while (1) { #ifdef HAVE_GETOPT_H - c = - getopt_long (argc, argv, "+hVt:c:w:H:b:p:a:D:P:", long_options, - &option_index); + c = getopt_long (argc, argv, "hVt:c:w:H:b:p:a:D:P:", longopts, &option_index); #else c = getopt (argc, argv, "+?hVt:c:w:H:b:p:a:D:P:"); #endif @@ -184,20 +160,6 @@ call_getopt (int argc, char **argv) if (c == -1 || c == EOF) break; - i++; - switch (c) { - case 't': - case 'c': - case 'w': - case 'H': - case 'b': - case 'p': - case 'a': - case 'D': - case 'P': - i++; - } - switch (c) { case 'h': /* help */ print_help (); @@ -239,7 +201,12 @@ call_getopt (int argc, char **argv) break; } } - return i; + + if (ld_host[0] == 0) { + asprintf (&ld_host, "%s", argv[c]); + } + + return validate_arguments (); } int diff --git a/plugins/check_mrtg.c b/plugins/check_mrtg.c index 4d297aaa..80c9b008 100644 --- a/plugins/check_mrtg.c +++ b/plugins/check_mrtg.c @@ -332,7 +332,7 @@ process_arguments (int argc, char **argv) value_warning_threshold = strtoul (argv[c++], NULL, 10); } - if (vargc > c && alue_critical_threshold == 0) { + if (argc > c && value_critical_threshold == 0) { value_critical_threshold = strtoul (argv[c++], NULL, 10); } diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c index 11f5146b..d33ebd9c 100644 --- a/plugins/check_mrtgtraf.c +++ b/plugins/check_mrtgtraf.c @@ -55,7 +55,6 @@ #define PROGNAME "check_mrtgtraf" int process_arguments (int, char **); -int call_getopt (int, char **); int validate_arguments (void); void print_help (void); void print_usage (void); @@ -77,7 +76,7 @@ main (int argc, char **argv) char input_buffer[MAX_INPUT_BUFFER]; char *temp_buffer; time_t current_time; - char error_message[MAX_INPUT_BUFFER]; + char *error_message; time_t timestamp = 0L; unsigned long average_incoming_rate = 0L; unsigned long average_outgoing_rate = 0L; @@ -198,7 +197,7 @@ main (int argc, char **argv) if (incoming_rate > incoming_critical_threshold || outgoing_rate > outgoing_critical_threshold) { result = STATE_CRITICAL; - sprintf (error_message, "%s. In = %0.1f %s, %s. Out = %0.1f %s", + asprintf (&error_message, "%s. In = %0.1f %s, %s. Out = %0.1f %s", (use_average == TRUE) ? "Ave" : "Max", adjusted_incoming_rate, incoming_speed_rating, (use_average == TRUE) ? "Ave" : "Max", adjusted_outgoing_rate, outgoing_speed_rating); @@ -206,7 +205,7 @@ main (int argc, char **argv) else if (incoming_rate > incoming_warning_threshold || outgoing_rate > outgoing_warning_threshold) { result = STATE_WARNING; - sprintf (error_message, "%s. In = %0.1f %s, %s. Out = %0.1f %s", + asprintf (&error_message, "%s. In = %0.1f %s, %s. Out = %0.1f %s", (use_average == TRUE) ? "Ave" : "Max", adjusted_incoming_rate, incoming_speed_rating, (use_average == TRUE) ? "Ave" : "Max", adjusted_outgoing_rate, outgoing_speed_rating); @@ -233,68 +232,9 @@ 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 (log_file == NULL) { - log_file = argv[c]; - } - else if (expire_minutes == -1) { - expire_minutes = atoi (optarg); - } - else if (strcmp (argv[c], "MAX") == 0) { - use_average = FALSE; - } - else if (strcmp (argv[c], "AVG") == 0) { - use_average = TRUE; - } - else if (incoming_warning_threshold == 0) { - incoming_warning_threshold = strtoul (argv[c], NULL, 10); - } - else if (incoming_critical_threshold == 0) { - incoming_critical_threshold = strtoul (argv[c], NULL, 10); - } - else if (outgoing_warning_threshold == 0) { - outgoing_warning_threshold = strtoul (argv[c], NULL, 10); - } - else if (outgoing_critical_threshold == 0) { - outgoing_critical_threshold = strtoul (argv[c], NULL, 10); - } - } - - 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[] = { + static struct option longopts[] = { {"logfile", required_argument, 0, 'F'}, {"expires", required_argument, 0, 'e'}, {"aggregation", required_argument, 0, 'a'}, @@ -308,29 +248,29 @@ call_getopt (int argc, char **argv) }; #endif + 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"); + } + while (1) { #ifdef HAVE_GETOPT_H - c = - getopt_long (argc, argv, "+hVF:e:a:c:w:", long_options, &option_index); + c = getopt_long (argc, argv, "hVF:e:a:c:w:", longopts, &option_index); #else - c = getopt (argc, argv, "+hVF:e:a:c:w:"); + c = getopt (argc, argv, "hVF:e:a:c:w:"); #endif - i++; - - if (c == -1 || c == EOF || c == 1) + if (c == -1 || c == EOF) break; switch (c) { - case 'F': - case 'e': - case 'a': - case 'c': - case 'w': - i++; - } - - switch (c) { case 'F': /* input file */ log_file = optarg; break; @@ -361,7 +301,42 @@ call_getopt (int argc, char **argv) usage ("Invalid argument\n"); } } - return i; + + c = optind; + if (argc > c && log_file == NULL) { + log_file = argv[c++]; + } + + if (argc > c && expire_minutes == -1) { + expire_minutes = atoi (argv[c++]); + } + + if (argc > c && strcmp (argv[c], "MAX") == 0) { + use_average = FALSE; + c++; + } + else if (argc > c && strcmp (argv[c], "AVG") == 0) { + use_average = TRUE; + c++; + } + + if (argc > c && incoming_warning_threshold == 0) { + incoming_warning_threshold = strtoul (argv[c++], NULL, 10); + } + + if (argc > c && incoming_critical_threshold == 0) { + incoming_critical_threshold = strtoul (argv[c++], NULL, 10); + } + + if (argc > c && outgoing_warning_threshold == 0) { + outgoing_warning_threshold = strtoul (argv[c++], NULL, 10); + } + + if (argc > c && outgoing_critical_threshold == 0) { + outgoing_critical_threshold = strtoul (argv[c++], NULL, 10); + } + + return validate_arguments (); } diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c index f8fca736..53deef87 100644 --- a/plugins/check_nwstat.c +++ b/plugins/check_nwstat.c @@ -296,7 +296,7 @@ int main(int argc, char **argv){ result=STATE_CRITICAL; else if(check_warning_value==TRUE && lru_time <= warning_value) result=STATE_WARNING; - sprintf(&output_message,"LRU sitting time = %lu minutes",lru_time); + asprintf(&output_message,"LRU sitting time = %lu minutes",lru_time); /* check KB free space on volume */ @@ -590,7 +590,7 @@ int main(int argc, char **argv){ max_service_processes=atoi(recv_buffer); - sprintf(&send_buffer,"S21\r\n"); + asprintf(&send_buffer,"S21\r\n"); result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); if(result!=STATE_OK) return result; diff --git a/plugins/check_radius.c b/plugins/check_radius.c index 614d467b..c346dc77 100644 --- a/plugins/check_radius.c +++ b/plugins/check_radius.c @@ -52,7 +52,7 @@ Number of times to retry a failed connection\n\ -t, --timeout=INTEGER\n\ Seconds before connection times out (default: %d)\n\ - -v\n\ + -v, --verbose\n\ Show details for command-line debugging (do not use with nagios server)\n\ -h, --help\n\ Print detailed help screen\n\ @@ -60,11 +60,17 @@ Print version information\n" #define DESCRIPTION "\ -The password option presents a substantial security issue because the -password can be determined by careful watching of the command line in -a process listing. This risk is exacerbated because nagios will -run the plugin at regular prdictable intervals. Please be sure that -the password used does not allow access to sensitive system resources, +This plugin tests a radius server to see if it is accepting connections.\n\ +\n\ +The server to test must be specified in the invocation, as well as a user\n\ +name and password. A configuration file may also be present. The format of\n\ +the configuration file is described in the radiusclient library sources.\n\ +\n\ +The password option presents a substantial security issue because the\n\ +password can be determined by careful watching of the command line in\n\ +a process listing. This risk is exacerbated because nagios will\n\ +run the plugin at regular prdictable intervals. Please be sure that\n\ +the password used does not allow access to sensitive system resources,\n\ otherwise compormise could occur.\n" #include "config.h" @@ -128,7 +134,7 @@ Please note that all tags must be lowercase to use the DocBook XML DTD. <sect2> <title>Future Enhancements</title> -<para>ToDo List</para> +<para>Todo List</para> <itemizedlist> <listitem>Add option to get password from a secured file rather than the command line</listitem> </itemizedlist> diff --git a/plugins/utils.c b/plugins/utils.c index 5dc6cfdb..bf6af885 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -48,7 +48,7 @@ double delta_time (struct timeval tv); void strip (char *); char *strscpy (char *dest, const char *src); -char *strscat (char *dest, const char *src); +char *strscat (char *dest, char *src); char *strnl (char *str); char *strpcpy (char *dest, const char *src, const char *str); char *strpcat (char *dest, const char *src, const char *str); @@ -406,7 +406,7 @@ strscpy (char *dest, const char *src) *****************************************************************************/ char * -strscat (char *dest, const char *src) +strscat (char *dest, char *src) { if (dest == NULL) diff --git a/plugins/version.h.in b/plugins/version.h.in index e41aaee0..6fd1e107 100644 --- a/plugins/version.h.in +++ b/plugins/version.h.in @@ -1,2 +1 @@ -#define PACKAGE_VERSION "1.3.0-alpha1" #define CVS_DATE "$Date$" |