summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 024751b)
raw | patch | inline | side by side (parent: 024751b)
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Sat, 9 Aug 2003 06:01:03 +0000 (06:01 +0000) | ||
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Sat, 9 Aug 2003 06:01:03 +0000 (06:01 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@672 f882894a-f735-0410-b71e-b25c423dba1c
12 files changed:
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index 7c39a243c507c5adc8812255eedcf5de15b30885..ff16059158cdcf4dbd41766a0c820fefb07d9a10 100644 (file)
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
input_buffer[strcspn (input_buffer, "\r\n")] = '\0';
if (strstr (input_buffer, query_address) == input_buffer) {
- asprintf (&output, input_buffer);
+ output = strdup(input_buffer);
result = STATE_OK;
}
else {
result = max_state (result, STATE_WARNING);
printf ("%s", input_buffer);
if (strlen (output) == 0)
- asprintf (&output, 1 + index (input_buffer, ':'));
+ output = strdup (1 + index (input_buffer, ':'));
}
(void) fclose (child_stderr);
diff --git a/plugins/check_http.c b/plugins/check_http.c
index e2047edde64f06cfee10daa94f2a04fe95f00cb4..3321d5ac88ff715a5704d4b4e3fea12007b8f4f1 100644 (file)
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
{
print_revision (progname, revision);
+ printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"));
printf (_(COPYRIGHT), copyright, email);
printf (_("\
diff --git a/plugins/check_load.c b/plugins/check_load.c
index 4a38e6cead92d7e7e5ed1d07e684b9671e2b4e1e..bdb1e55d18fae7cdf2af6f6f7fc0d39dab6010ae 100644 (file)
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
float wload1 = -1, wload5 = -1, wload15 = -1;
float cload1 = -1, cload5 = -1, cload15 = -1;
-char *status_line = "";
+char *status_line;
float la1, la5, la15;
if (process_arguments (argc, argv) == ERROR)
- usage ("\n");
+ usage ("failed processing arguments\n");
#if HAVE_GETLOADAVG==1
result = getloadavg (la, 3);
# endif
#endif
- if ((la1 == -1) || (la5 == -1) || (la15 == -1)) {
+ if ((la1 < 0.0) || (la5 < 0.0) || (la15 < 0.0)) {
#if HAVE_GETLOADAVG==1
printf (_("Error in getloadavg()\n"));
#else
diff --git a/plugins/check_mrtg.c b/plugins/check_mrtg.c
index 2a9958d0be77455a8895520c88cbd87c10375980..21efac2e901f32c22e64d49c96c3dd3eb3841a87 100644 (file)
--- a/plugins/check_mrtg.c
+++ b/plugins/check_mrtg.c
#include "common.h"
#include "utils.h"
-/* original command line:
- <log_file> <expire_minutes> <AVG|MAX> <variable> <vwl> <vcl> <label> [units] */
-
-void
-print_usage (void)
-{
- printf (_("\
-Usage: %s -F log_file -a <AVG | MAX> -v variable -w warning -c critical\n\
- [-l label] [-u units] [-e expire_minutes] [-t timeout] [-v]\n"), progname);
- printf (_(UT_HLP_VRS), progname, progname);
-}
-
-void
-print_help (void)
-{
- print_revision (progname, revision);
-
- printf (_(COPYRIGHT), copyright, email);
-
- printf(_("\
-This plugin will check either the average or maximum value of one of the\n\
-two variables recorded in an MRTG log file.\n"));
-
- print_usage ();
-
- printf (_(UT_HELP_VRSN));
-
- printf (_("\
- -F, --logfile=FILE\n\
- The MRTG log file containing the data you want to monitor\n\
- -e, --expires=MINUTES\n\
- Minutes before MRTG data is considered to be too old\n\
- -a, --aggregation=AVG|MAX\n\
- Should we check average or maximum values?\n\
- -v, --variable=INTEGER\n\
- Which variable set should we inspect? (1 or 2)\n\
- -w, --warning=INTEGER\n\
- Threshold value for data to result in WARNING status\n\
- -c, --critical=INTEGER\n\
- Threshold value for data to result in CRITICAL status\n"));
-
- printf (_("\
- -l, --label=STRING\n\
- Type label for data (Examples: Conns, \"Processor Load\", In, Out)\n\
- -u, --units=STRING\n\
- Option units label for data (Example: Packets/Sec, Errors/Sec, \n\
- \"Bytes Per Second\", \"%% Utilization\")\n"));
-
- printf (_("\
-If the value exceeds the <vwl> threshold, a WARNING status is returned. If\n\
-the value exceeds the <vcl> threshold, a CRITICAL status is returned. If\n\
-the data in the log file is older than <expire_minutes> old, a WARNING\n\
-status is returned and a warning message is printed.\n\n"));
-
- printf(_("This plugin is useful for monitoring MRTG data that does not correspond to\n\
-bandwidth usage. (Use the check_mrtgtraf plugin for monitoring bandwidth).\n\
-It can be used to monitor any kind of data that MRTG is monitoring - errors,\n\
-packets/sec, etc. I use MRTG in conjuction with the Novell NLM that allows\n\
-me to track processor utilization, user connections, drive space, etc and\n\
-this plugin works well for monitoring that kind of data as well.\n\n"));
-
- printf (_("Notes:\n\
-- This plugin only monitors one of the two variables stored in the MRTG log\n\
- file. If you want to monitor both values you will have to define two\n\
- commands with different values for the <variable> argument. Of course,\n\
- you can always hack the code to make this plugin work for you...\n\
-- MRTG stands for the Multi Router Traffic Grapher. It can be downloaded from\n\
- http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html\n"));
-
- printf (_(UT_SUPPORT));
-}
-
int process_arguments (int, char **);
int validate_arguments (void);
+void print_help (void);
+void print_usage (void);
char *log_file = NULL;
int expire_minutes = 0;
int variable_number = -1;
unsigned long value_warning_threshold = 0L;
unsigned long value_critical_threshold = 0L;
-char *value_label = "";
-char *units_label = "";
+char *value_label;
+char *units_label;
int
main (int argc, char **argv)
if (variable_number == -1)
usage (_("You must supply the variable number\n"));
+ if (value_label == NULL)
+ value_label = strdup ("");
+
+ if (units_label == NULL)
+ units_label = strdup ("");
+
return OK;
}
+
+
+
+
+
+\f
+void
+print_help (void)
+{
+ print_revision (progname, revision);
+
+ printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"));
+ printf (_(COPYRIGHT), copyright, email);
+
+ printf(_("\
+This plugin will check either the average or maximum value of one of the\n\
+two variables recorded in an MRTG log file.\n"));
+
+ print_usage ();
+
+ printf (_(UT_HELP_VRSN));
+
+ printf (_("\
+ -F, --logfile=FILE\n\
+ The MRTG log file containing the data you want to monitor\n\
+ -e, --expires=MINUTES\n\
+ Minutes before MRTG data is considered to be too old\n\
+ -a, --aggregation=AVG|MAX\n\
+ Should we check average or maximum values?\n\
+ -v, --variable=INTEGER\n\
+ Which variable set should we inspect? (1 or 2)\n\
+ -w, --warning=INTEGER\n\
+ Threshold value for data to result in WARNING status\n\
+ -c, --critical=INTEGER\n\
+ Threshold value for data to result in CRITICAL status\n"));
+
+ printf (_("\
+ -l, --label=STRING\n\
+ Type label for data (Examples: Conns, \"Processor Load\", In, Out)\n\
+ -u, --units=STRING\n\
+ Option units label for data (Example: Packets/Sec, Errors/Sec, \n\
+ \"Bytes Per Second\", \"%% Utilization\")\n"));
+
+ printf (_("\
+If the value exceeds the <vwl> threshold, a WARNING status is returned. If\n\
+the value exceeds the <vcl> threshold, a CRITICAL status is returned. If\n\
+the data in the log file is older than <expire_minutes> old, a WARNING\n\
+status is returned and a warning message is printed.\n\n"));
+
+ printf(_("This plugin is useful for monitoring MRTG data that does not correspond to\n\
+bandwidth usage. (Use the check_mrtgtraf plugin for monitoring bandwidth).\n\
+It can be used to monitor any kind of data that MRTG is monitoring - errors,\n\
+packets/sec, etc. I use MRTG in conjuction with the Novell NLM that allows\n\
+me to track processor utilization, user connections, drive space, etc and\n\
+this plugin works well for monitoring that kind of data as well.\n\n"));
+
+ printf (_("Notes:\n\
+- This plugin only monitors one of the two variables stored in the MRTG log\n\
+ file. If you want to monitor both values you will have to define two\n\
+ commands with different values for the <variable> argument. Of course,\n\
+ you can always hack the code to make this plugin work for you...\n\
+- MRTG stands for the Multi Router Traffic Grapher. It can be downloaded from\n\
+ http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html\n"));
+
+ printf (_(UT_SUPPORT));
+}
+
+
+
+
+/* original command line:
+ <log_file> <expire_minutes> <AVG|MAX> <variable> <vwl> <vcl> <label> [units] */
+
+void
+print_usage (void)
+{
+ printf (_("\
+Usage: %s -F log_file -a <AVG | MAX> -v variable -w warning -c critical\n\
+ [-l label] [-u units] [-e expire_minutes] [-t timeout] [-v]\n"), progname);
+ printf (_(UT_HLP_VRS), progname, progname);
+}
index ce9ab19184b24a69f5de3998840802cab9aff09a..be2f562eab81dba4d679f312a893a1ce9e57eb9a 100644 (file)
--- a/plugins/check_mrtgtraf.c
+++ b/plugins/check_mrtgtraf.c
const char *copyright = "1999-2003";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
-void
-print_usage (void)
-{
- printf (_("\
-Usage: %s -F <log_file> -a <AVG | MAX> -v <variable> -w <warning_pair> -c <critical_pair>\n\
- [-e expire_minutes] [-t timeout] [-v]\n"), progname);
- printf (_(UT_HLP_VRS), progname, progname);
-}
-
-void
-print_help (void)
-{
- print_revision (progname, revision);
-
- printf (_(COPYRIGHT), copyright, email);
-
- print_usage ();
-
- printf (_(UT_HELP_VRSN));
-
- printf (_("\
- -F, --filename=STRING\n\
- File to read log from\n\
- -e, --expires=INTEGER\n\
- Minutes after which log expires\n\
- -a, --aggregation=(AVG|MAX)\n\
- Test average or maximum\n\
- -w, --warning\n\
- Warning threshold pair \"<incoming>,<outgoing>\"\n\
- -c, --critical\n\
- Critical threshold pair \"<incoming>,<outgoing>\"\n"));
-
- printf (_("\n\
-This plugin will check the incoming/outgoing transfer rates of a router,\n\
-switch, etc recorded in an MRTG log. If the newest log entry is older\n\
-than <expire_minutes>, a WARNING status is returned. If either the\n\
-incoming or outgoing rates exceed the <icl> or <ocl> thresholds (in\n\
-Bytes/sec), a CRITICAL status results. If either of the rates exceed\n\
-the <iwl> or <owl> thresholds (in Bytes/sec), a WARNING status results.\n\n"));
-
- printf (_("Notes:\n\
-- MRTG stands for Multi Router Traffic Grapher. It can be downloaded from\n\
- http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html\n\
-- While MRTG can monitor things other than traffic rates, this\n\
- plugin probably won't work with much else without modification.\n\
-- The calculated i/o rates are a little off from what MRTG actually\n\
- reports. I'm not sure why this is right now, but will look into it\n\
- for future enhancements of this plugin.\n"));
-
- printf (_(UT_SUPPORT));
-}
-\f
int process_arguments (int, char **);
int validate_arguments (void);
+void print_help(void);
+void print_usage(void);
char *log_file = NULL;
int expire_minutes = -1;
unsigned long outgoing_warning_threshold = 0L;
unsigned long outgoing_critical_threshold = 0L;
+
+
+
+\f
int
main (int argc, char **argv)
{
{
return OK;
}
+
+
+
+
+
+\f
+void
+print_help (void)
+{
+ print_revision (progname, revision);
+
+ printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"));
+ printf (_(COPYRIGHT), copyright, email);
+
+ print_usage ();
+
+ printf (_(UT_HELP_VRSN));
+
+ printf (_("\
+ -F, --filename=STRING\n\
+ File to read log from\n\
+ -e, --expires=INTEGER\n\
+ Minutes after which log expires\n\
+ -a, --aggregation=(AVG|MAX)\n\
+ Test average or maximum\n\
+ -w, --warning\n\
+ Warning threshold pair \"<incoming>,<outgoing>\"\n\
+ -c, --critical\n\
+ Critical threshold pair \"<incoming>,<outgoing>\"\n"));
+
+ printf (_("\n\
+This plugin will check the incoming/outgoing transfer rates of a router,\n\
+switch, etc recorded in an MRTG log. If the newest log entry is older\n\
+than <expire_minutes>, a WARNING status is returned. If either the\n\
+incoming or outgoing rates exceed the <icl> or <ocl> thresholds (in\n\
+Bytes/sec), a CRITICAL status results. If either of the rates exceed\n\
+the <iwl> or <owl> thresholds (in Bytes/sec), a WARNING status results.\n\n"));
+
+ printf (_("Notes:\n\
+- MRTG stands for Multi Router Traffic Grapher. It can be downloaded from\n\
+ http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html\n\
+- While MRTG can monitor things other than traffic rates, this\n\
+ plugin probably won't work with much else without modification.\n\
+- The calculated i/o rates are a little off from what MRTG actually\n\
+ reports. I'm not sure why this is right now, but will look into it\n\
+ for future enhancements of this plugin.\n"));
+
+ printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+ printf (_("\
+Usage: %s -F <log_file> -a <AVG | MAX> -v <variable> -w <warning_pair> -c <critical_pair>\n\
+ [-e expire_minutes] [-t timeout] [-v]\n"), progname);
+ printf (_(UT_HLP_VRS), progname, progname);
+}
diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c
index de8a620069aca2bbee411ec48449cfbbdbe66437..4b2272699e3e2b26c3266106efc8801b8dc51520 100644 (file)
--- a/plugins/check_nwstat.c
+++ b/plugins/check_nwstat.c
int sap_number=-1;
int process_arguments(int, char **);
-void print_usage(void);
void print_help(void);
+void print_usage(void);
+
+
+
+
+\f
int
main(int argc, char **argv) {
int result;
return OK;
}
-\f
-void print_usage(void)
-{
- printf (_("\
-Usage: %s -H host [-p port] [-v variable] [-w warning] [-c critical]\n\
- [-t timeout].\n"), progname);
- printf (_(UT_HLP_VRS), progname, progname);
-}
+
+
+
+
+\f
void print_help(void)
{
char *myport;
print_revision (progname, revision);
- printf (_("Copyright (c) 1999-2001 Ethan Galstad <nagios@nagios.org>\n"));
+ printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"));
printf (_(COPYRIGHT), copyright, email);
printf (_("\
printf (_(UT_SUPPORT));
}
+
+
+
+
+void print_usage(void)
+{
+ printf (_("\
+Usage: %s -H host [-p port] [-v variable] [-w warning] [-c critical]\n\
+ [-t timeout].\n"), progname);
+ printf (_(UT_HLP_VRS), progname, progname);
+}
diff --git a/plugins/check_overcr.c b/plugins/check_overcr.c
index 5f50ca7ec4c848538ddb3ac4e2cd06b1589990fe..9958432e1c8edbc213b1f6877166a15d6bfc08ba 100644 (file)
--- a/plugins/check_overcr.c
+++ b/plugins/check_overcr.c
temp_ptr = (char *) strtok (recv_buffer, "\r\n");
if (temp_ptr == NULL)
die (STATE_CRITICAL, _("Invalid response from server - no load information\n"));
- load_1min = strtod (temp_ptr, NULL);
+ else
+ load_1min = strtod (temp_ptr, NULL);
temp_ptr = (char *) strtok (NULL, "\r\n");
if (temp_ptr == NULL)
die (STATE_CRITICAL, _("Invalid response from server after load 1\n"));
- load_5min = strtod (temp_ptr, NULL);
+ else
+ load_5min = strtod (temp_ptr, NULL);
temp_ptr = (char *) strtok (NULL, "\r\n");
if (temp_ptr == NULL)
die (STATE_CRITICAL, _("Invalid response from server after load 5\n"));
- load_15min = strtod (temp_ptr, NULL);
+ else
+ load_15min = strtod (temp_ptr, NULL);
switch (vars_to_check) {
case LOAD1:
temp_ptr = (char *) strtok (NULL, "%");
if (temp_ptr == NULL)
die (STATE_CRITICAL, _("Invalid response from server\n"));
- percent_used_disk_space = strtoul (temp_ptr, NULL, 10);
+ else
+ percent_used_disk_space = strtoul (temp_ptr, NULL, 10);
break;
}
if (result != STATE_OK)
die (result, _("Unknown error fetching network status\n"));
-
- port_connections = strtod (recv_buffer, NULL);
+ else
+ port_connections = strtod (recv_buffer, NULL);
if (check_critical_value == TRUE && (port_connections >= critical_value))
result = STATE_CRITICAL;
temp_ptr = (char *) strtok (NULL, ")");
if (temp_ptr == NULL)
die (STATE_CRITICAL, _("Invalid response from server\n"));
-
- processes = strtod (temp_ptr, NULL);
+ else
+ processes = strtod (temp_ptr, NULL);
if (check_critical_value == TRUE && (processes >= critical_value))
result = STATE_CRITICAL;
}
/* reset timeout */
- alarm (0);
+/* alarm (0); */
- printf (_("Reached end of program with no data returned\n"));
+/* printf (_("Reached end of program with no data returned\n")); */
- return result;
+/* return result; */
}
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index 26c0192afa9a2acda0dbe0a4a392b6dbcdb814f1..fd73b8cef8eb8f55d7f2e9506825d6cf7291a16a 100644 (file)
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
float rta = UNKNOWN_TRIP_TIME;
int pl = UNKNOWN_PACKET_LOSS;
-char *warn_text = "";
+char *warn_text;
int this_result = STATE_UNKNOWN;
int i;
- addresses = malloc (max_addr);
+ addresses = malloc ((size_t)max_addr);
if (process_arguments (argc, argv) == ERROR)
usage (_("Could not parse arguments"));
- exit;
/* Set signal handling and alarm */
if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) {
/* run the command */
this_result = run_ping (cmd, addresses[i]);
- if (pl == UNKNOWN_PACKET_LOSS || rta == UNKNOWN_TRIP_TIME) {
+ if (pl == UNKNOWN_PACKET_LOSS || rta < 0.0) {
printf ("%s\n", cmd);
die (STATE_UNKNOWN,
_("Error: Could not interpret output from ping command\n"));
switch (c) {
case '?': /* usage */
usage3 (_("Unknown argument"), optopt);
+ break;
case 'h': /* help */
print_help ();
exit (STATE_OK);
+ break;
case 'V': /* version */
print_revision (progname, revision);
exit (STATE_OK);
+ break;
case 't': /* timeout period */
timeout_interval = atoi (optarg);
break;
n_addresses++;
if (n_addresses > max_addr) {
max_addr *= 2;
- addresses = realloc (addresses, max_addr);
+ addresses = realloc (addresses, (size_t)max_addr);
if (addresses == NULL)
die (STATE_UNKNOWN, _("Could not realloc() addresses\n"));
}
}
}
- if (wrta == UNKNOWN_TRIP_TIME) {
+ if (wrta < 0.0) {
if (is_negative (argv[c])) {
printf (_("<wrta> (%s) must be a non-negative number\n"), argv[c]);
return ERROR;
}
}
- if (crta == UNKNOWN_TRIP_TIME) {
+ if (crta < 0.0) {
if (is_negative (argv[c])) {
printf (_("<crta> (%s) must be a non-negative number\n"), argv[c]);
return ERROR;
float max_seconds;
int i;
- if (wrta == UNKNOWN_TRIP_TIME) {
+ if (wrta < 0.0) {
printf (_("<wrta> was not set\n"));
return ERROR;
}
- else if (crta == UNKNOWN_TRIP_TIME) {
+ else if (crta < 0.0) {
printf (_("<crta> was not set\n"));
return ERROR;
}
char buf[MAX_INPUT_BUFFER];
int result = STATE_UNKNOWN;
- if ((child_process = spopen (cmd)) == NULL) {
- printf (_("Cannot open pipe: "));
- die (STATE_UNKNOWN, cmd);
- }
+ if ((child_process = spopen (cmd)) == NULL)
+ die (STATE_UNKNOWN, _("Cannot open pipe: %s"), cmd);
+
child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
if (child_stderr == NULL)
printf (_("Cannot open stderr for %s\n"), cmd);
_("PING CRITICAL - Host not found (%s)"),
server_address);
- if (strlen (warn_text) == 0)
+ if (warn_text == NULL)
warn_text = strdup (buf);
else if (asprintf (&warn_text, "%s %s", warn_text, buf) == -1)
die (STATE_UNKNOWN, _("unable to realloc warn_text"));
if (spclose (child_process))
result = max_state (result, STATE_WARNING);
+ if (warn_text == NULL)
+ warn_text = strdup("");
+
return result;
}
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 1b641c55fc809d2e9aba357efe11856c3ae7bd46..1894b281595653ee0a6e37eedb8860a4893615e8 100644 (file)
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
#define PCPU 256
/* Different metrics */
-int metric = 0;
-#define METRIC_PROCS 0
-#define METRIC_VSZ 1
-#define METRIC_RSS 2
-#define METRIC_CPU 3
-char *metric_name = "";
+char *metric_name;
+enum metric {
+ METRIC_PROCS,
+ METRIC_VSZ,
+ METRIC_RSS,
+ METRIC_CPU
+};
+enum metric metric = METRIC_PROCS;
int verbose = 0;
int uid;
int vsz;
int rss;
float pcpu;
-char *statopts = "";
-char *prog = "";
-char *args = "";
-char *fmt = "";
-char *fails = "";
+char *statopts;
+char *prog;
+char *args;
+char *fmt;
+char *fails;
char tmp[MAX_INPUT_BUFFER];
print_revision (progname, revision);
exit (STATE_OK);
case 't': /* timeout period */
- if (!is_integer (optarg)) {
- printf (_("%s: Timeout Interval must be an integer!\n\n"),
- progname);
- print_usage ();
- exit (STATE_UNKNOWN);
- }
- timeout_interval = atoi (optarg);
+ if (!is_integer (optarg))
+ usage (_("Timeout Interval must be an integer!\n\n"));
+ else
+ timeout_interval = atoi (optarg);
break;
case 'c': /* critical threshold */
- if (is_integer (optarg)) {
+ if (is_integer (optarg))
cmax = atoi (optarg);
+ else if (sscanf (optarg, ":%d", &cmax) == 1)
break;
- }
- else if (sscanf (optarg, ":%d", &cmax) == 1) {
+ else if (sscanf (optarg, "%d:%d", &cmin, &cmax) == 2)
break;
- }
- else if (sscanf (optarg, "%d:%d", &cmin, &cmax) == 2) {
+ else if (sscanf (optarg, "%d:", &cmin) == 1)
break;
- }
- else if (sscanf (optarg, "%d:", &cmin) == 1) {
- break;
- }
- else {
- printf (_("%s: Critical Process Count must be an integer!\n\n"),
- progname);
- print_usage ();
- exit (STATE_UNKNOWN);
- }
+ else
+ usage (_("Critical Process Count must be an integer!\n\n"));
+ break;
case 'w': /* warning time threshold */
- if (is_integer (optarg)) {
+ if (is_integer (optarg))
wmax = atoi (optarg);
+ else if (sscanf (optarg, ":%d", &wmax) == 1)
break;
- }
- else if (sscanf (optarg, ":%d", &wmax) == 1) {
- break;
- }
- else if (sscanf (optarg, "%d:%d", &wmin, &wmax) == 2) {
+ else if (sscanf (optarg, "%d:%d", &wmin, &wmax) == 2)
break;
- }
- else if (sscanf (optarg, "%d:", &wmin) == 1) {
+ else if (sscanf (optarg, "%d:", &wmin) == 1)
break;
- }
- else {
- printf (_("%s: Warning Process Count must be an integer!\n\n"),
- progname);
- print_usage ();
- exit (STATE_UNKNOWN);
- }
+ else
+ usage (_("%s: Warning Process Count must be an integer!\n\n"));
+ break;
case 'p': /* process id */
if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) {
asprintf (&fmt, "%s%sPPID = %d", fmt, (options ? ", " : ""), ppid);
print_usage ();
exit (STATE_UNKNOWN);
case 's': /* status */
- asprintf (&statopts, "%s", optarg);
+ if (statopts)
+ break;
+ else
+ statopts = strdup(optarg);
asprintf (&fmt, _("%s%sSTATE = %s"), fmt, (options ? ", " : ""), statopts);
options |= STAT;
break;
options |= USER;
break;
case 'C': /* command */
- asprintf (&prog, "%s", optarg);
+ if (prog)
+ break;
+ else
+ prog = strdup(optarg);
asprintf (&fmt, _("%s%scommand name '%s'"), fmt, (options ? ", " : ""),
prog);
options |= PROG;
break;
case 'a': /* args (full path name with args) */
- asprintf (&args, "%s", optarg);
+ if (args)
+ break;
+ else
+ args = strdup(optarg);
asprintf (&fmt, _("%s%sargs '%s'"), fmt, (options ? ", " : ""), args);
options |= ARGS;
break;
if (options == 0)
options = ALL;
+ if (statopts==NULL)
+ statopts = strdup("");
+
+ if (prog==NULL)
+ prog = strdup("");
+
+ if (args==NULL)
+ args = strdup("");
+
+ if (fmt==NULL)
+ fmt = strdup("");
+
+ if (fails==NULL)
+ fails = strdup("");
+
return options;
}
diff --git a/plugins/check_real.c b/plugins/check_real.c
index ecdd5619ee7ff097c5ccdf7ee4ecc3ec4db3d187..9c9c3e0b93cdd2797ca7ef9ff6a4834c19a7ec4c 100644 (file)
--- a/plugins/check_real.c
+++ b/plugins/check_real.c
void print_usage (void);
int server_port = PORT;
-char *server_address = "";
-char *host_name = "";
+char *server_address;
+char *host_name;
char *server_url = NULL;
-char *server_expect = EXPECT;
+char *server_expect;
int warning_time = 0;
int check_warning_time = FALSE;
int critical_time = 0;
switch (c) {
case 'I': /* hostname */
case 'H': /* hostname */
- if (is_host (optarg)) {
- server_address = optarg;
- }
- else {
+ if (server_address)
+ break;
+ else if (is_host (optarg))
+ server_address = strdup(optarg);
+ else
usage (_("Invalid host name\n"));
- }
break;
case 'e': /* string to expect in response header */
- server_expect = optarg;
+ server_expect = strdup(optarg);
break;
case 'u': /* server URL */
- server_url = optarg;
+ server_url = strdup(optarg);
break;
case 'p': /* port */
if (is_intpos (optarg)) {
}
c = optind;
- if (strlen(server_address)==0 && argc>c) {
+ if (server_address==NULL && argc>c) {
if (is_host (argv[c])) {
server_address = argv[c++];
}
}
}
- if (strlen(server_address) == 0)
+ if (server_address==NULL)
usage (_("You must provide a server to check\n"));
- if (strlen(host_name) == 0)
- asprintf (&host_name, "%s", server_address);
+ if (host_name==NULL)
+ host_name = strdup (server_address);
+
+ if (server_expect == NULL)
+ server_expect = strdup(EXPECT);
return validate_arguments ();
}
diff --git a/plugins/utils.c b/plugins/utils.c
index 518caa8c3d627e1a94027b821a34e0b0f867a1a7..5b97572932327fc9e33956c9c8e3ee687c5d3205 100644 (file)
--- a/plugins/utils.c
+++ b/plugins/utils.c
return max (a, b);
}
-void usage (char *msg)
+void usage (const char *msg)
{
printf ("%s", msg);
print_usage ();
exit (STATE_UNKNOWN);
}
-void usage2(char *msg, char *arg)
+void usage2(const char *msg, const char *arg)
{
printf ("%s: %s - %s\n",progname,msg,arg);
print_usage ();
}
void
-usage3 (char *msg, int arg)
+usage3 (const char *msg, int arg)
{
printf ("%s: %s - %c\n", progname, msg, arg);
print_usage();
diff --git a/plugins/utils.h b/plugins/utils.h
index b763b1e25ffe348ea4d699569f7e37ff3cade57a..efdbed41d49f560c3e0c743cf31287f0b1d8ad3a 100644 (file)
--- a/plugins/utils.h
+++ b/plugins/utils.h
int max_state (int a, int b);
-void usage (char *msg) __attribute__((noreturn));
-void usage2(char *msg, char *arg) __attribute__((noreturn));
-void usage3(char *msg, int arg) __attribute__((noreturn));
+void usage (const char *msg) __attribute__((noreturn));
+void usage2(const char *msg, const char *arg) __attribute__((noreturn));
+void usage3(const char *msg, int arg) __attribute__((noreturn));
const char *state_text (int result);