summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9728dca)
raw | patch | inline | side by side (parent: 9728dca)
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Wed, 13 Nov 2002 11:50:54 +0000 (11:50 +0000) | ||
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Wed, 13 Nov 2002 11:50:54 +0000 (11:50 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@190 f882894a-f735-0410-b71e-b25c423dba1c
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 9ce4a3248ee72329d78cc4ae5d181d41dc218f47..bde9563197bed419041a8f126a4dfe0c03450e9f 100644 (file)
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
#include <stdarg.h>
#define PROGNAME "check_disk"
+#define REVISION "$Revision$"
+#define COPYRIGHT "2000-2002"
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);
int c_df = -1;
float w_dfp = -1.0;
float c_dfp = -1.0;
-char *path = NULL;
+char *path = "";
int verbose = FALSE;
int display_mntp = FALSE;
if (process_arguments (argc, argv) != OK)
usage ("Could not parse arguments\n");
- command_line = ssprintf (command_line, "%s %s", DF_COMMAND, path);
+ asprintf (&command_line, "%s %s", DF_COMMAND, path);
if (verbose)
printf ("%s ==> ", command_line);
{
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]))) < argc) {
-
- if (w_dfp == -1 && is_intnonneg (argv[c]))
- w_dfp = (100.0 - atof (argv[c]));
- else if (c_dfp == -1 && is_intnonneg (argv[c]))
- c_dfp = (100.0 - atof (argv[c]));
- else if (path == NULL || path[0] == 0)
- path = strscpy (path, argv[c]);
- }
-
- if (path == NULL) {
- path = malloc (1);
- if (path == NULL)
- terminate (STATE_UNKNOWN, "Could not malloc empty path\n");
- path[0] = 0;
- }
-
- 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[] = {
};
#endif
+ 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, "+?Vhvt:c:w:p:m", long_options, &option_index);
+ getopt_long (argc, argv, "Vhvt:c:w:p:m", long_options, &option_index);
#else
- c = getopt (argc, argv, "+?Vhvt:c:w:p:m");
+ c = getopt (argc, argv, "Vhvt:c:w:p:m");
#endif
- i++;
-
- if (c == -1 || c == EOF || c == 1)
+ if (c == -1 || c == EOF)
break;
- switch (c) {
- case 't':
- case 'c':
- case 'w':
- case 'p':
- i++;
- }
-
switch (c) {
case 'w': /* warning time threshold */
if (is_intnonneg (optarg)) {
display_mntp = TRUE;
break;
case 'V': /* version */
- print_revision (my_basename (argv[0]), "$Revision$");
+ print_revision (PROGNAME, REVISION);
exit (STATE_OK);
case 'h': /* help */
print_help ();
break;
}
}
- return i;
+
+ c = optind;
+ if (w_dfp == -1 && argc > c && is_intnonneg (argv[c]))
+ w_dfp = (100.0 - atof (argv[c++]));
+
+ if (c_dfp == -1 && argc > c && is_intnonneg (argv[c]))
+ c_dfp = (100.0 - atof (argv[c++]));
+
+ if (argc > c && strlen (path) == 0)
+ path = argv[c++];
+
+ return validate_arguments ();
}
int
void
print_help (void)
{
- print_revision (PROGNAME, "$Revision$");
+ print_revision (PROGNAME, REVISION);
printf
("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n"
"This plugin will check the percent of used disk space on a mounted\n"
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index bc0400f86195562524614d17b51899c53ee7289a..f9cf28890ed2855548cac095371f1438953e2cc4 100644 (file)
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
#include "popen.h"
#include "utils.h"
+#define PROGNAME "check_dns"
+#define REVISION "$Revision$"
+#define COPYRIGHT "2000-2002"
+
int process_arguments (int, char **);
-int call_getopt (int, char **);
int validate_arguments (void);
-void print_usage (char *);
-void print_help (char *);
+void print_usage (void);
+void print_help (void);
int error_scan (char *);
#define ADDRESS_LENGTH 256
}
if (process_arguments (argc, argv) != OK) {
- print_usage (my_basename (argv[0]));
+ print_usage ();
return STATE_UNKNOWN;
}
/* get the command to run */
- command_line = ssprintf (command_line, "%s %s %s", NSLOOKUP_COMMAND,
- query_address, dns_server);
+ sprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND, query_address, dns_server);
alarm (timeout_interval);
time (&start_time);
/* compare to expected address */
if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) {
result = STATE_CRITICAL;
- output = ssprintf(output, "expected %s but got %s", expected_address, address);
+ asprintf(&output, "expected %s but got %s", expected_address, address);
}
(void) time (&end_time);
{
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 (query_address[0] == 0) {
- if (is_host (argv[c]) == FALSE) {
- printf ("Invalid name/address: %s\n\n", argv[c]);
- return ERROR;
- }
- if (strlen (argv[c]) >= ADDRESS_LENGTH)
- terminate (STATE_UNKNOWN, "Input buffer overflow\n");
- strcpy (query_address, argv[c]);
- }
- else if (dns_server[0] == 0) {
- if (is_host (argv[c]) == FALSE) {
- printf ("Invalid name/address: %s\n\n", argv[c]);
- return ERROR;
- }
- if (strlen (argv[c]) >= ADDRESS_LENGTH)
- terminate (STATE_UNKNOWN, "Input buffer overflow\n");
- strcpy (dns_server, argv[c]);
- }
- }
-
- return validate_arguments ();
-
-}
-
-int
-call_getopt (int argc, char **argv)
-{
- int c, i = 1;
-
#ifdef HAVE_GETOPT_H
int opt_index = 0;
static struct option long_opts[] = {
};
#endif
+ 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, "+?hVvt:H:s:r:a:", long_opts, &opt_index);
+ c = getopt_long (argc, argv, "hVvt:H:s:r:a:", long_opts, &opt_index);
#else
- c = getopt (argc, argv, "+?hVvt:H:s:r:a:");
+ c = getopt (argc, argv, "hVvt:H:s:r:a:");
#endif
if (c == -1 || c == EOF)
break;
- i++;
- switch (c) {
- case 't':
- case 'H':
- case 's':
- case 'r':
- case 'a':
- i++;
- }
-
switch (c) {
case '?': /* args not parsable */
- printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg);
- print_usage (my_basename (argv[0]));
+ printf ("%s: Unknown argument: %s\n\n", PROGNAME, optarg);
+ print_usage ();
exit (STATE_UNKNOWN);
case 'h': /* help */
- print_help (my_basename (argv[0]));
+ print_help ();
exit (STATE_OK);
case 'V': /* version */
- print_revision (my_basename (argv[0]), "$Revision$");
+ print_revision (PROGNAME, REVISION);
exit (STATE_OK);
case 'v': /* version */
verbose = TRUE;
case 'H': /* hostname */
if (is_host (optarg) == FALSE) {
printf ("Invalid host name/address\n\n");
- print_usage (my_basename (argv[0]));
+ print_usage ();
exit (STATE_UNKNOWN);
}
if (strlen (optarg) >= ADDRESS_LENGTH)
case 's': /* server name */
if (is_host (optarg) == FALSE) {
printf ("Invalid server name/address\n\n");
- print_usage (my_basename (argv[0]));
+ print_usage ();
exit (STATE_UNKNOWN);
}
if (strlen (optarg) >= ADDRESS_LENGTH)
case 'r': /* reverse server name */
if (is_host (optarg) == FALSE) {
printf ("Invalid host name/address\n\n");
- print_usage (my_basename (argv[0]));
+ print_usage ();
exit (STATE_UNKNOWN);
}
if (strlen (optarg) >= ADDRESS_LENGTH)
case 'a': /* expected address */
if (is_dotted_quad (optarg) == FALSE) {
printf ("Invalid expected address\n\n");
- print_usage (my_basename (argv[0]));
+ print_usage ();
exit (STATE_UNKNOWN);
}
if (strlen (optarg) >= ADDRESS_LENGTH)
break;
}
}
- return i;
+
+ c = optind;
+ if (query_address[0] == 0) {
+ if (is_host (argv[c]) == FALSE) {
+ printf ("Invalid name/address: %s\n\n", argv[c]);
+ return ERROR;
+ }
+ if (strlen (argv[c]) >= ADDRESS_LENGTH)
+ terminate (STATE_UNKNOWN, "Input buffer overflow\n");
+ strcpy (query_address, argv[c++]);
+ }
+
+ if (dns_server[0] == 0) {
+ if (is_host (argv[c]) == FALSE) {
+ printf ("Invalid name/address: %s\n\n", argv[c]);
+ return ERROR;
+ }
+ if (strlen (argv[c]) >= ADDRESS_LENGTH)
+ terminate (STATE_UNKNOWN, "Input buffer overflow\n");
+ strcpy (dns_server, argv[c++]);
+ }
+
+ return validate_arguments ();
}
int
}
void
-print_usage (char *cmd)
+print_usage (void)
{
printf ("Usage: %s -H host [-s server] [-a expected-address] [-t timeout]\n" " %s --help\n"
- " %s --version\n", cmd, cmd, cmd);
+ " %s --version\n", PROGNAME, PROGNAME, PROGNAME);
}
void
-print_help (char *cmd)
+print_help (void)
{
- print_revision (cmd, "$Revision$");
+ print_revision (PROGNAME, REVISION);
printf ("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n\n");
- print_usage (cmd);
- printf ("\n");
+ print_usage ();
printf
- ("-H, --hostname=HOST\n"
+ ("\nOptions:\n"
+ "-H, --hostname=HOST\n"
" The name or address you want to query\n"
"-s, --server=HOST\n"
" Optional DNS server you want to use for the lookup\n"
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index 9a2dd5570ba2b3b73f41fc5ec6ac775c6b341c05..da11e678091d36d319f10bd2ee25bf33d7597f94 100644 (file)
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
server = strscpy (server, server_name);
/* compose the command */
- command_line = ssprintf
- (command_line, "%s -b %d -c %d %s",
- PATH_TO_FPING, packet_size, packet_count, server);
+ asprintf (&command_line, "%s -b %d -c %d %s", PATH_TO_FPING,
+ packet_size, packet_count, server);
if (verbose)
printf ("%s\n", command_line);
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c
index 6d42cd3866091f048d6601d9464fd3fb9f7f0ec0..42b4bb544d3e75b05637cc044159af57721c61e2 100644 (file)
--- a/plugins/check_hpjd.c
+++ b/plugins/check_hpjd.c
#include "utils.h"
#define PROGNAME "check_hpjd"
+#define REVISION "$Revision$"
+#define COPYRIGHT "2000-2002"
#define HPJD_LINE_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.1"
#define HPJD_PAPER_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.2"
#define OFFLINE 1
int process_arguments (int, char **);
-int call_getopt (int, char **);
int validate_arguments (void);
void print_help (void);
void print_usage (void);
char *community = NULL;
-char *address = NULL;
+char *address = "127.0.0.1";
+
int
main (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 (address == NULL) {
- if (is_host (argv[c])) {
- address = argv[c];
- }
- else {
- usage ("Invalid host name");
- }
- }
- else if (community == NULL) {
- community = argv[c];
- }
- }
-
- if (address == NULL)
- address = strscpy (NULL, "127.0.0.1");
-
- 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[] = {
};
#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, "+hVH:C:", long_options, &option_index);
c = getopt (argc, argv, "+?hVH:C:");
#endif
- i++;
-
if (c == -1 || c == EOF || c == 1)
break;
- switch (c) {
- case 'H':
- case 'C':
- i++;
- }
-
switch (c) {
case 'H': /* hostname */
if (is_host (optarg)) {
community = optarg;
break;
case 'V': /* version */
- print_revision (PROGNAME, "$Revision$");
+ print_revision (PROGNAME, REVISION);
exit (STATE_OK);
case 'h': /* help */
print_help ();
usage ("Invalid argument\n");
}
}
- return i;
+
+ c = optind;
+ if (address == NULL) {
+ if (is_host (argv[c])) {
+ address = argv[c++];
+ }
+ else {
+ usage ("Invalid host name");
+ }
+ }
+
+ if (community == NULL) {
+ community = argv[c++];
+ }
+
+ return validate_arguments ();
}
void
print_help (void)
{
- print_revision (PROGNAME, "$Revision$");
+ print_revision (PROGNAME, REVISION);
printf
("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n"
"This plugin tests the STATUS of an HP printer with a JetDirect card.\n"
diff --git a/plugins/check_mrtg.c b/plugins/check_mrtg.c
index b86686d728116c4375f89612bac787fa0f7e3af2..4d297aaa1f70f20293c1bff3da26e3b6fd912e65 100644 (file)
--- a/plugins/check_mrtg.c
+++ b/plugins/check_mrtg.c
#include "utils.h"
int process_arguments (int, char **);
-int call_getopt (int, char **);
int validate_arguments (void);
void print_help (void);
void print_usage (void);
int variable_number = -1;
unsigned long value_warning_threshold = 0L;
unsigned long value_critical_threshold = 0L;
-char *value_label = NULL;
-char *units_label = NULL;
+char *value_label = "";
+char *units_label = "";
int
main (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 <= 0) {
- if (is_intpos (argv[c]))
- expire_minutes = atoi (argv[c]);
- else
- terminate (STATE_UNKNOWN,
- "%s is not a valid expiration time\nUse '%s -h' for additional help\n",
- argv[c], PROGNAME);
- }
- else if (strcmp (argv[c], "MAX") == 0) {
- use_average = FALSE;
- }
- else if (strcmp (argv[c], "AVG") == 0) {
- use_average = TRUE;
- }
- else if (variable_number == -1) {
- variable_number = atoi (argv[c]);
- if (variable_number < 1 || variable_number > 2) {
- printf ("%s :", argv[c]);
- usage ("Invalid variable number\n");
- }
- }
- else if (value_warning_threshold == 0) {
- value_warning_threshold = strtoul (argv[c], NULL, 10);
- }
- else if (value_critical_threshold == 0) {
- value_critical_threshold = strtoul (argv[c], NULL, 10);
- }
- else if (value_label == NULL) {
- value_label = argv[c];
- }
- else if (units_label == NULL) {
- units_label = argv[c];
- }
- }
-
- if (value_label == NULL)
- value_label = strscpy (NULL, "");
-
- if (units_label == NULL)
- units_label = strscpy (NULL, "");
-
- 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[] = {
};
#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:v:c:w:l:u:", long_options,
+ getopt_long (argc, argv, "hVF:e:a:v:c:w:l:u:", long_options,
&option_index);
#else
- c = getopt (argc, argv, "+?hVF:e:a:v:c:w:l:u:");
+ c = getopt (argc, argv, "hVF:e:a:v:c:w:l:u:");
#endif
- i++;
-
- if (c == -1 || c == EOF || c == 1)
+ if (c == -1 || c == EOF)
break;
- switch (c) {
- case 'F':
- case 'e':
- case 'a':
- case 'v':
- case 'c':
- case 'w':
- case 'l':
- case 'u':
- i++;
- }
-
switch (c) {
case 'F': /* input file */
log_file = optarg;
units_label = optarg;
break;
case 'V': /* version */
- print_revision (PROGNAME, "$Revision$");
+ print_revision (PROGNAME, REVISION);
exit (STATE_OK);
case 'h': /* help */
print_help ();
usage ("Invalid argument\n");
}
}
- return i;
+
+ c = optind;
+ if (log_file == NULL && argc > c) {
+ log_file = argv[c++];
+ }
+
+ if (expire_minutes <= 0 && argc > c) {
+ if (is_intpos (argv[c]))
+ expire_minutes = atoi (argv[c++]);
+ else
+ terminate (STATE_UNKNOWN,
+ "%s is not a valid expiration time\nUse '%s -h' for additional help\n",
+ argv[c], PROGNAME);
+ }
+
+ 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 && variable_number == -1) {
+ variable_number = atoi (argv[c++]);
+ if (variable_number < 1 || variable_number > 2) {
+ printf ("%s :", argv[c]);
+ usage ("Invalid variable number\n");
+ }
+ }
+
+ if (argc > c && value_warning_threshold == 0) {
+ value_warning_threshold = strtoul (argv[c++], NULL, 10);
+ }
+
+ if (vargc > c && alue_critical_threshold == 0) {
+ value_critical_threshold = strtoul (argv[c++], NULL, 10);
+ }
+
+ if (argc > c && strlen (value_label) == 0) {
+ value_label = argv[c++];
+ }
+
+ if (argc > c && strlen (units_label) == 0) {
+ units_label = argv[c++];
+ }
+
+ return validate_arguments ();
}
int
diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c
index e1426702c5f0a7710d78ddbcef3533519c25b4f7..f8fca736d179207fecc57dacd614773674232ac2 100644 (file)
--- a/plugins/check_nwstat.c
+++ b/plugins/check_nwstat.c
if(result!=STATE_OK)
return result;
if(!strcmp(recv_buffer,"-1\n"))
- netware_version = ssprintf(netware_version,"");
+ asprintf(&netware_version,"");
else {
recv_buffer[strlen(recv_buffer)-1]=0;
- netware_version = ssprintf(netware_version,"NetWare %s: ",recv_buffer);
+ asprintf(&netware_version,"NetWare %s: ",recv_buffer);
}
} else
- netware_version = ssprintf(netware_version,"");
+ asprintf(&netware_version,"");
/* check CPU load */
break;
}
- send_buffer = ssprintf(send_buffer,"UTIL%s\r\n",temp_buffer);
+ asprintf(&send_buffer,"UTIL%s\r\n",temp_buffer);
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
if(result!=STATE_OK)
return result;
else if(check_warning_value==TRUE && utilization >= warning_value)
result=STATE_WARNING;
- output_message = ssprintf(output_message,"Load %s - %s %s-min load average = %lu%%",(result==STATE_OK)?"ok":"problem",uptime,temp_buffer,utilization);
+ asprintf(&output_message,"Load %s - %s %s-min load average = %lu%%",(result==STATE_OK)?"ok":"problem",uptime,temp_buffer,utilization);
/* check number of user connections */
} else if (vars_to_check==CHECK_CONNS) {
result=STATE_CRITICAL;
else if(check_warning_value==TRUE && current_connections >= warning_value)
result=STATE_WARNING;
- output_message = ssprintf(output_message,"Conns %s - %lu current connections",(result==STATE_OK)?"ok":"problem",current_connections);
+ asprintf(&output_message,"Conns %s - %lu current connections",(result==STATE_OK)?"ok":"problem",current_connections);
/* check % long term cache hits */
} else if (vars_to_check==CHECK_LTCH) {
result=STATE_CRITICAL;
else if(check_warning_value==TRUE && cache_hits <= warning_value)
result=STATE_WARNING;
- output_message = ssprintf(output_message,"Long term cache hits = %d%%",cache_hits);
+ asprintf(&output_message,"Long term cache hits = %d%%",cache_hits);
/* check cache buffers */
} else if (vars_to_check==CHECK_CBUFF) {
result=STATE_CRITICAL;
else if(check_warning_value==TRUE && cache_buffers <= warning_value)
result=STATE_WARNING;
- output_message = ssprintf(output_message,"Total cache buffers = %lu",cache_buffers);
+ asprintf(&output_message,"Total cache buffers = %lu",cache_buffers);
/* check dirty cache buffers */
} else if (vars_to_check==CHECK_CDBUFF) {
result=STATE_CRITICAL;
else if(check_warning_value==TRUE && cache_buffers >= warning_value)
result=STATE_WARNING;
- output_message = ssprintf(output_message,"Dirty cache buffers = %lu",cache_buffers);
+ asprintf(&output_message,"Dirty cache buffers = %lu",cache_buffers);
/* check LRU sitting time in minutes */
} else if (vars_to_check==CHECK_LRUM) {
result=STATE_CRITICAL;
else if(check_warning_value==TRUE && lru_time <= warning_value)
result=STATE_WARNING;
- output_message = ssprintf(output_message,"LRU sitting time = %lu minutes",lru_time);
+ sprintf(&output_message,"LRU sitting time = %lu minutes",lru_time);
/* check KB free space on volume */
} else if (vars_to_check==CHECK_VKF) {
- send_buffer = ssprintf(send_buffer,"VKF%s\r\n",volume_name);
+ asprintf(&send_buffer,"VKF%s\r\n",volume_name);
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
if(result!=STATE_OK)
return result;
if (!strcmp(recv_buffer,"-1\n")) {
- output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
+ asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name);
result=STATE_CRITICAL;
} else {
free_disk_space=strtoul(recv_buffer,NULL,10);
result=STATE_CRITICAL;
else if(check_warning_value==TRUE && free_disk_space <= warning_value)
result=STATE_WARNING;
- output_message = ssprintf(output_message,"%s%lu KB free on volume %s",(result==STATE_OK)?"":"Only ",free_disk_space,volume_name);
+ asprintf(&output_message,"%s%lu KB free on volume %s",(result==STATE_OK)?"":"Only ",free_disk_space,volume_name);
}
/* check % free space on volume */
} else if (vars_to_check==CHECK_VPF) {
- send_buffer = ssprintf(send_buffer,"VKF%s\r\n",volume_name);
+ asprintf(&send_buffer,"VKF%s\r\n",volume_name);
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
if(result!=STATE_OK)
return result;
if(!strcmp(recv_buffer,"-1\n")){
- output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
+ asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name);
result=STATE_CRITICAL;
} else {
free_disk_space=strtoul(recv_buffer,NULL,10);
- send_buffer = ssprintf(send_buffer,"VKS%s\r\n",volume_name);
+ asprintf(&send_buffer,"VKS%s\r\n",volume_name);
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
if(result!=STATE_OK)
return result;
else if(check_warning_value==TRUE && percent_free_space <= warning_value)
result=STATE_WARNING;
free_disk_space/=1024;
- output_message = ssprintf(output_message,"%lu MB (%d%%) free on volume %s",free_disk_space,percent_free_space,volume_name);
+ asprintf(&output_message,"%lu MB (%d%%) free on volume %s",free_disk_space,percent_free_space,volume_name);
}
/* check to see if DS Database is open or closed */
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
temp_buffer=strtok(recv_buffer,"\r\n");
- output_message = ssprintf(output_message,"Directory Services Database is %s (DS version %s)",(result==STATE_OK)?"open":"closed",temp_buffer);
+ asprintf(&output_message,"Directory Services Database is %s (DS version %s)",(result==STATE_OK)?"open":"closed",temp_buffer);
/* check to see if logins are enabled */
} else if (vars_to_check==CHECK_LOGINS) {
else
result=STATE_WARNING;
- output_message = ssprintf(output_message,"Logins are %s",(result==STATE_OK)?"enabled":"disabled");
+ asprintf(&output_message,"Logins are %s",(result==STATE_OK)?"enabled":"disabled");
/* check packet receive buffers */
} else if (vars_to_check==CHECK_UPRB || vars_to_check==CHECK_PUPRB) {
- send_buffer = ssprintf(send_buffer,"S15\r\n",volume_name);
+ asprintf(&send_buffer,"S15\r\n",volume_name);
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
if(result!=STATE_OK)
return result;
used_packet_receive_buffers=atoi(recv_buffer);
- send_buffer = ssprintf(send_buffer,"S16\r\n",volume_name);
+ asprintf(&send_buffer,"S16\r\n",volume_name);
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
if(result!=STATE_OK)
return result;
result=STATE_WARNING;
}
- output_message = ssprintf(output_message,"%d of %d (%lu%%) packet receive buffers used",used_packet_receive_buffers,max_packet_receive_buffers,percent_used_packet_receive_buffers);
+ asprintf(&output_message,"%d of %d (%lu%%) packet receive buffers used",used_packet_receive_buffers,max_packet_receive_buffers,percent_used_packet_receive_buffers);
/* check SAP table entries */
} else if (vars_to_check==CHECK_SAPENTRIES) {
if(sap_number==-1)
- send_buffer = ssprintf(send_buffer,"S9\r\n");
+ asprintf(&send_buffer,"S9\r\n");
else
- send_buffer = ssprintf(send_buffer,"S9.%d\r\n",sap_number);
+ asprintf(&send_buffer,"S9.%d\r\n",sap_number);
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
if(result!=STATE_OK)
return result;
result=STATE_WARNING;
if(sap_number==-1)
- output_message = ssprintf(output_message,"%d entries in SAP table",sap_entries);
+ asprintf(&output_message,"%d entries in SAP table",sap_entries);
else
- output_message = ssprintf(output_message,"%d entries in SAP table for SAP type %d",sap_entries,sap_number);
+ asprintf(&output_message,"%d entries in SAP table for SAP type %d",sap_entries,sap_number);
/* check KB purgeable space on volume */
} else if (vars_to_check==CHECK_VKP) {
- send_buffer = ssprintf(send_buffer,"VKP%s\r\n",volume_name);
+ asprintf(&send_buffer,"VKP%s\r\n",volume_name);
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
if(result!=STATE_OK)
return result;
if (!strcmp(recv_buffer,"-1\n")) {
- output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
+ asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name);
result=STATE_CRITICAL;
} else {
purgeable_disk_space=strtoul(recv_buffer,NULL,10);
result=STATE_CRITICAL;
else if(check_warning_value==TRUE && purgeable_disk_space >= warning_value)
result=STATE_WARNING;
- output_message = ssprintf(output_message,"%s%lu KB purgeable on volume %s",(result==STATE_OK)?"":"Only ",purgeable_disk_space,volume_name);
+ asprintf(&output_message,"%s%lu KB purgeable on volume %s",(result==STATE_OK)?"":"Only ",purgeable_disk_space,volume_name);
}
/* check % purgeable space on volume */
} else if (vars_to_check==CHECK_VPP) {
- send_buffer = ssprintf(send_buffer,"VKP%s\r\n",volume_name);
+ asprintf(&send_buffer,"VKP%s\r\n",volume_name);
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
if(result!=STATE_OK)
return result;
if(!strcmp(recv_buffer,"-1\n")){
- output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
+ asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name);
result=STATE_CRITICAL;
} else {
purgeable_disk_space=strtoul(recv_buffer,NULL,10);
- send_buffer = ssprintf(send_buffer,"VKS%s\r\n",volume_name);
+ asprintf(&send_buffer,"VKS%s\r\n",volume_name);
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
if(result!=STATE_OK)
return result;
else if(check_warning_value==TRUE && percent_purgeable_space >= warning_value)
result=STATE_WARNING;
purgeable_disk_space/=1024;
- output_message = ssprintf(output_message,"%lu MB (%d%%) purgeable on volume %s",purgeable_disk_space,percent_purgeable_space,volume_name);
+ asprintf(&output_message,"%lu MB (%d%%) purgeable on volume %s",purgeable_disk_space,percent_purgeable_space,volume_name);
}
/* check KB not yet purgeable space on volume */
} else if (vars_to_check==CHECK_VKNP) {
- send_buffer = ssprintf(send_buffer,"VKNP%s\r\n",volume_name);
+ asprintf(&send_buffer,"VKNP%s\r\n",volume_name);
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
if(result!=STATE_OK)
return result;
if (!strcmp(recv_buffer,"-1\n")) {
- output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
+ asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name);
result=STATE_CRITICAL;
} else {
non_purgeable_disk_space=strtoul(recv_buffer,NULL,10);
result=STATE_CRITICAL;
else if(check_warning_value==TRUE && non_purgeable_disk_space >= warning_value)
result=STATE_WARNING;
- output_message = ssprintf(output_message,"%s%lu KB not yet purgeable on volume %s",(result==STATE_OK)?"":"Only ",non_purgeable_disk_space,volume_name);
+ asprintf(&output_message,"%s%lu KB not yet purgeable on volume %s",(result==STATE_OK)?"":"Only ",non_purgeable_disk_space,volume_name);
}
/* check % not yet purgeable space on volume */
} else if (vars_to_check==CHECK_VPNP) {
- send_buffer = ssprintf(send_buffer,"VKNP%s\r\n",volume_name);
+ asprintf(&send_buffer,"VKNP%s\r\n",volume_name);
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
if(result!=STATE_OK)
return result;
if(!strcmp(recv_buffer,"-1\n")){
- output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
+ asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name);
result=STATE_CRITICAL;
} else {
non_purgeable_disk_space=strtoul(recv_buffer,NULL,10);
- send_buffer = ssprintf(send_buffer,"VKS%s\r\n",volume_name);
+ asprintf(&send_buffer,"VKS%s\r\n",volume_name);
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
if(result!=STATE_OK)
return result;
else if(check_warning_value==TRUE && percent_non_purgeable_space >= warning_value)
result=STATE_WARNING;
purgeable_disk_space/=1024;
- output_message = ssprintf(output_message,"%lu MB (%d%%) not yet purgeable on volume %s",non_purgeable_disk_space,percent_non_purgeable_space,volume_name);
+ asprintf(&output_message,"%lu MB (%d%%) not yet purgeable on volume %s",non_purgeable_disk_space,percent_non_purgeable_space,volume_name);
}
/* check # of open files */
} else if (vars_to_check==CHECK_OFILES) {
- send_buffer = ssprintf(send_buffer,"S18\r\n");
+ asprintf(&send_buffer,"S18\r\n");
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
if(result!=STATE_OK)
return result;
else if(check_warning_value==TRUE && open_files >= warning_value)
result=STATE_WARNING;
- output_message = ssprintf(output_message,"%d open files",open_files);
+ asprintf(&output_message,"%d open files",open_files);
/* check # of abended threads (Netware 5.x only) */
} else if (vars_to_check==CHECK_ABENDS) {
- send_buffer = ssprintf(send_buffer,"S17\r\n");
+ asprintf(&send_buffer,"S17\r\n");
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
if(result!=STATE_OK)
return result;
else if(check_warning_value==TRUE && abended_threads >= warning_value)
result=STATE_WARNING;
- output_message = ssprintf(output_message,"%d abended threads",abended_threads);
+ asprintf(&output_message,"%d abended threads",abended_threads);
/* check # of current service processes (Netware 5.x only) */
} else if (vars_to_check==CHECK_CSPROCS) {
- send_buffer = ssprintf(send_buffer,"S20\r\n");
+ asprintf(&send_buffer,"S20\r\n");
result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
if(result!=STATE_OK)
return result;
max_service_processes=atoi(recv_buffer);
- send_buffer = ssprintf(send_buffer,"S21\r\n");
+ sprintf(&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;
else if(check_warning_value==TRUE && current_service_processes >= warning_value)
result=STATE_WARNING;
- output_message = ssprintf(output_message,"%d current service processes (%d max)",current_service_processes,max_service_processes);
+ asprintf(&output_message,"%d current service processes (%d max)",current_service_processes,max_service_processes);
} else {
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index df1d9eb2025c4ec4750538cafce3add20491bd65..3602122c28abd4a6288e266bc4f5f79b8c21380b 100644 (file)
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
/* does the host address of number of packets argument come first? */
#ifdef PING_PACKETS_FIRST
- command_line =
- ssprintf (command_line, PING_COMMAND, max_packets, server_address);
+ asprintf (&command_line, PING_COMMAND, max_packets, server_address);
#else
- command_line =
- ssprintf (command_line, PING_COMMAND, server_address, max_packets);
+ asprintf (&command_line, PING_COMMAND, server_address, max_packets);
#endif
/* Set signal handling and alarm */
diff --git a/plugins/check_vsz.c b/plugins/check_vsz.c
index 2ec8775b574638791ec880fcfac0fbb6e905b430..7eeab22cc9d48af2e2ef50598b3e6ad0811c0088 100644 (file)
--- a/plugins/check_vsz.c
+++ b/plugins/check_vsz.c
int proc_size = -1;
char input_buffer[MAX_INPUT_BUFFER];
char proc_name[MAX_INPUT_BUFFER];
- char *message = NULL;
+ char *message = "";
if (!process_arguments (argc, argv)) {
printf ("%s: failure parsing arguments\n", my_basename (argv[0]));
if (child_stderr == NULL)
printf ("Could not open stderr for %s\n", VSZ_COMMAND);
- message = malloc ((size_t) 1);
- message[0] = 0;
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
line++;
if (sscanf (input_buffer, VSZ_FORMAT, &proc_size, proc_name) == 2) {
if (proc == NULL) {
if (proc_size > warn) {
- len = strlen (message) + strlen (proc_name) + 23;
- message = realloc (message, len);
- if (message == NULL)
- terminate (STATE_UNKNOWN,
- "check_vsz: could not malloc message (1)");
- sprintf (message, "%s %s(%d)", message, proc_name, proc_size);
+ asprintf (&message, "%s %s(%d)", message, proc_name, proc_size);
result = max_state (result, STATE_WARNING);
}
if (proc_size > crit) {
}
}
else if (strstr (proc_name, proc)) {
- len = strlen (message) + 21;
- message = realloc (message, len);
- if (message == NULL)
- terminate (STATE_UNKNOWN,
- "check_vsz: could not malloc message (2)");
- sprintf (message, "%s %d", message, proc_size);
+ asprintf (&message, "%s %d", message, proc_size);
if (proc_size > warn) {
result = max_state (result, STATE_WARNING);
}
warn = atoi (optarg);
break;
case 'C': /* command name */
- proc = malloc (strlen (optarg) + 1);
- if (proc == NULL)
- terminate (STATE_UNKNOWN,
- "check_vsz: failed malloc of proc in process_arguments");
- strcpy (proc, optarg);
+ proc = optarg;
break;
}
}
crit = atoi (argv[c++]);
}
- if (proc == NULL) {
- proc = malloc (strlen (argv[c]) + 1);
- if (proc == NULL)
- terminate (STATE_UNKNOWN,
- "check_vsz: failed malloc of proc in process_arguments");
- strcpy (proc, argv[c]);
- }
+ if (proc == NULL)
+ proc = argv[c];
return c;
}
diff --git a/plugins/urlize.c b/plugins/urlize.c
index 9e02cb5d140340527605946dc9c889a937612d11..9835c824d4c1fbf38d2dc0e1f4324b7d9ab20d47 100644 (file)
--- a/plugins/urlize.c
+++ b/plugins/urlize.c
exit (STATE_UNKNOWN);
}
- cmd = ssprintf (cmd, "%s", argv[2]);
+ asprintf (&cmd, "%s", argv[2]);
for (i = 3; i < argc; i++) {
- cmd = ssprintf (cmd, "%s %s", cmd, argv[i]);
+ asprintf (&cmd, "%s %s", cmd, argv[i]);
}
child_process = spopen (cmd);
diff --git a/plugins/utils.c b/plugins/utils.c
index bf1d20479d034c3ee979d5ad386ec2877de11e17..5dc6cfdbc5502dc4a6e8f31bb0e0feea20e4f51b 100644 (file)
--- a/plugins/utils.c
+++ b/plugins/utils.c
char *strscpy (char *dest, const char *src);
char *strscat (char *dest, const char *src);
char *strnl (char *str);
-char *ssprintf (char *str, const char *fmt, ...);
char *strpcpy (char *dest, const char *src, const char *str);
char *strpcat (char *dest, const char *src, const char *str);
-/******************************************************************************
- *
- * Does a formatted print to a string variable
- *
- * Given a pointer destination string, which may or may not already
- * hold some text, and a source string with additional text (possibly
- * NULL or empty), returns a pointer to a string that cntains the
- * results of the specified formatted print
- *
- * Example:
- *
- * char *str=NULL;
- * str = ssprintf(str,"%d %s",1,"string");
- *
- *****************************************************************************/
-
-char *
-ssprintf (char *ptr, const char *fmt, ...)
-{
- va_list ap;
- int nchars;
- size_t size;
- char *str = NULL;
-
- if (str == NULL) {
- str = malloc (TXTBLK);
- if (str == NULL)
- terminate (STATE_UNKNOWN, "malloc failed in ssprintf");
- size = TXTBLK;
- }
- else
- size = max (strlen (str), TXTBLK);
-
- va_start (ap, fmt);
-
- while (1) {
-
- nchars = vsnprintf (str, size, fmt, ap);
-
- if (nchars > -1)
- if (nchars < (int) size) {
- va_end (ap);
- str[nchars] = '\0';
- if (ptr)
- free (ptr);
- return str;
- }
- else {
- size = (size_t) (nchars + 1);
- }
-
- else
- size *= 2;
-
- str = realloc (str, size);
-
- if (str == NULL)
- terminate (STATE_UNKNOWN, "realloc failed in ssprintf");
- }
-
-}
-
-
-
-
-
/******************************************************************************
*
* Like strscpy, except only the portion of the source string up to