summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>2003-08-09 06:01:03 +0000
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>2003-08-09 06:01:03 +0000
commita228492c4bea15a3e6e7bdbfd6631611c97fe92c (patch)
tree0d21d5c54a2ab5ec3f4171fab668d390ea09bbaa
parent024751bac56791b7ae5347404274046e8ba58ccb (diff)
downloadmonitoring-plugins-a228492c4bea15a3e6e7bdbfd6631611c97fe92c.tar.gz
more pedantic compiler warns
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@672 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--plugins/check_dig.c4
-rw-r--r--plugins/check_http.c1
-rw-r--r--plugins/check_load.c6
-rw-r--r--plugins/check_mrtg.c165
-rw-r--r--plugins/check_mrtgtraf.c119
-rw-r--r--plugins/check_nwstat.c33
-rw-r--r--plugins/check_overcr.c26
-rw-r--r--plugins/check_ping.c32
-rw-r--r--plugins/check_procs.c109
-rw-r--r--plugins/check_real.c31
-rw-r--r--plugins/utils.c6
-rw-r--r--plugins/utils.h6
12 files changed, 301 insertions, 237 deletions
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index 7c39a243..ff160591 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -97,7 +97,7 @@ main (int argc, char **argv)
97 input_buffer[strcspn (input_buffer, "\r\n")] = '\0'; 97 input_buffer[strcspn (input_buffer, "\r\n")] = '\0';
98 98
99 if (strstr (input_buffer, query_address) == input_buffer) { 99 if (strstr (input_buffer, query_address) == input_buffer) {
100 asprintf (&output, input_buffer); 100 output = strdup(input_buffer);
101 result = STATE_OK; 101 result = STATE_OK;
102 } 102 }
103 else { 103 else {
@@ -119,7 +119,7 @@ main (int argc, char **argv)
119 result = max_state (result, STATE_WARNING); 119 result = max_state (result, STATE_WARNING);
120 printf ("%s", input_buffer); 120 printf ("%s", input_buffer);
121 if (strlen (output) == 0) 121 if (strlen (output) == 0)
122 asprintf (&output, 1 + index (input_buffer, ':')); 122 output = strdup (1 + index (input_buffer, ':'));
123 } 123 }
124 124
125 (void) fclose (child_stderr); 125 (void) fclose (child_stderr);
diff --git a/plugins/check_http.c b/plugins/check_http.c
index e2047edd..3321d5ac 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -992,6 +992,7 @@ print_help (void)
992{ 992{
993 print_revision (progname, revision); 993 print_revision (progname, revision);
994 994
995 printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"));
995 printf (_(COPYRIGHT), copyright, email); 996 printf (_(COPYRIGHT), copyright, email);
996 997
997 printf (_("\ 998 printf (_("\
diff --git a/plugins/check_load.c b/plugins/check_load.c
index 4a38e6ce..bdb1e55d 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -45,7 +45,7 @@ void print_usage (void);
45float wload1 = -1, wload5 = -1, wload15 = -1; 45float wload1 = -1, wload5 = -1, wload15 = -1;
46float cload1 = -1, cload5 = -1, cload15 = -1; 46float cload1 = -1, cload5 = -1, cload15 = -1;
47 47
48char *status_line = ""; 48char *status_line;
49 49
50 50
51 51
@@ -72,7 +72,7 @@ main (int argc, char **argv)
72 float la1, la5, la15; 72 float la1, la5, la15;
73 73
74 if (process_arguments (argc, argv) == ERROR) 74 if (process_arguments (argc, argv) == ERROR)
75 usage ("\n"); 75 usage ("failed processing arguments\n");
76 76
77#if HAVE_GETLOADAVG==1 77#if HAVE_GETLOADAVG==1
78 result = getloadavg (la, 3); 78 result = getloadavg (la, 3);
@@ -122,7 +122,7 @@ main (int argc, char **argv)
122# endif 122# endif
123#endif 123#endif
124 124
125 if ((la1 == -1) || (la5 == -1) || (la15 == -1)) { 125 if ((la1 < 0.0) || (la5 < 0.0) || (la15 < 0.0)) {
126#if HAVE_GETLOADAVG==1 126#if HAVE_GETLOADAVG==1
127 printf (_("Error in getloadavg()\n")); 127 printf (_("Error in getloadavg()\n"));
128#else 128#else
diff --git a/plugins/check_mrtg.c b/plugins/check_mrtg.c
index 2a9958d0..21efac2e 100644
--- a/plugins/check_mrtg.c
+++ b/plugins/check_mrtg.c
@@ -24,80 +24,10 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
24#include "common.h" 24#include "common.h"
25#include "utils.h" 25#include "utils.h"
26 26
27/* original command line:
28 <log_file> <expire_minutes> <AVG|MAX> <variable> <vwl> <vcl> <label> [units] */
29
30void
31print_usage (void)
32{
33 printf (_("\
34Usage: %s -F log_file -a <AVG | MAX> -v variable -w warning -c critical\n\
35 [-l label] [-u units] [-e expire_minutes] [-t timeout] [-v]\n"), progname);
36 printf (_(UT_HLP_VRS), progname, progname);
37}
38
39void
40print_help (void)
41{
42 print_revision (progname, revision);
43
44 printf (_(COPYRIGHT), copyright, email);
45
46 printf(_("\
47This plugin will check either the average or maximum value of one of the\n\
48two variables recorded in an MRTG log file.\n"));
49
50 print_usage ();
51
52 printf (_(UT_HELP_VRSN));
53
54 printf (_("\
55 -F, --logfile=FILE\n\
56 The MRTG log file containing the data you want to monitor\n\
57 -e, --expires=MINUTES\n\
58 Minutes before MRTG data is considered to be too old\n\
59 -a, --aggregation=AVG|MAX\n\
60 Should we check average or maximum values?\n\
61 -v, --variable=INTEGER\n\
62 Which variable set should we inspect? (1 or 2)\n\
63 -w, --warning=INTEGER\n\
64 Threshold value for data to result in WARNING status\n\
65 -c, --critical=INTEGER\n\
66 Threshold value for data to result in CRITICAL status\n"));
67
68 printf (_("\
69 -l, --label=STRING\n\
70 Type label for data (Examples: Conns, \"Processor Load\", In, Out)\n\
71 -u, --units=STRING\n\
72 Option units label for data (Example: Packets/Sec, Errors/Sec, \n\
73 \"Bytes Per Second\", \"%% Utilization\")\n"));
74
75 printf (_("\
76If the value exceeds the <vwl> threshold, a WARNING status is returned. If\n\
77the value exceeds the <vcl> threshold, a CRITICAL status is returned. If\n\
78the data in the log file is older than <expire_minutes> old, a WARNING\n\
79status is returned and a warning message is printed.\n\n"));
80
81 printf(_("This plugin is useful for monitoring MRTG data that does not correspond to\n\
82bandwidth usage. (Use the check_mrtgtraf plugin for monitoring bandwidth).\n\
83It can be used to monitor any kind of data that MRTG is monitoring - errors,\n\
84packets/sec, etc. I use MRTG in conjuction with the Novell NLM that allows\n\
85me to track processor utilization, user connections, drive space, etc and\n\
86this plugin works well for monitoring that kind of data as well.\n\n"));
87
88 printf (_("Notes:\n\
89- This plugin only monitors one of the two variables stored in the MRTG log\n\
90 file. If you want to monitor both values you will have to define two\n\
91 commands with different values for the <variable> argument. Of course,\n\
92 you can always hack the code to make this plugin work for you...\n\
93- MRTG stands for the Multi Router Traffic Grapher. It can be downloaded from\n\
94 http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html\n"));
95
96 printf (_(UT_SUPPORT));
97}
98
99int process_arguments (int, char **); 27int process_arguments (int, char **);
100int validate_arguments (void); 28int validate_arguments (void);
29void print_help (void);
30void print_usage (void);
101 31
102char *log_file = NULL; 32char *log_file = NULL;
103int expire_minutes = 0; 33int expire_minutes = 0;
@@ -105,8 +35,8 @@ int use_average = TRUE;
105int variable_number = -1; 35int variable_number = -1;
106unsigned long value_warning_threshold = 0L; 36unsigned long value_warning_threshold = 0L;
107unsigned long value_critical_threshold = 0L; 37unsigned long value_critical_threshold = 0L;
108char *value_label = ""; 38char *value_label;
109char *units_label = ""; 39char *units_label;
110 40
111int 41int
112main (int argc, char **argv) 42main (int argc, char **argv)
@@ -351,5 +281,92 @@ validate_arguments (void)
351 if (variable_number == -1) 281 if (variable_number == -1)
352 usage (_("You must supply the variable number\n")); 282 usage (_("You must supply the variable number\n"));
353 283
284 if (value_label == NULL)
285 value_label = strdup ("");
286
287 if (units_label == NULL)
288 units_label = strdup ("");
289
354 return OK; 290 return OK;
355} 291}
292
293
294
295
296
297
298void
299print_help (void)
300{
301 print_revision (progname, revision);
302
303 printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"));
304 printf (_(COPYRIGHT), copyright, email);
305
306 printf(_("\
307This plugin will check either the average or maximum value of one of the\n\
308two variables recorded in an MRTG log file.\n"));
309
310 print_usage ();
311
312 printf (_(UT_HELP_VRSN));
313
314 printf (_("\
315 -F, --logfile=FILE\n\
316 The MRTG log file containing the data you want to monitor\n\
317 -e, --expires=MINUTES\n\
318 Minutes before MRTG data is considered to be too old\n\
319 -a, --aggregation=AVG|MAX\n\
320 Should we check average or maximum values?\n\
321 -v, --variable=INTEGER\n\
322 Which variable set should we inspect? (1 or 2)\n\
323 -w, --warning=INTEGER\n\
324 Threshold value for data to result in WARNING status\n\
325 -c, --critical=INTEGER\n\
326 Threshold value for data to result in CRITICAL status\n"));
327
328 printf (_("\
329 -l, --label=STRING\n\
330 Type label for data (Examples: Conns, \"Processor Load\", In, Out)\n\
331 -u, --units=STRING\n\
332 Option units label for data (Example: Packets/Sec, Errors/Sec, \n\
333 \"Bytes Per Second\", \"%% Utilization\")\n"));
334
335 printf (_("\
336If the value exceeds the <vwl> threshold, a WARNING status is returned. If\n\
337the value exceeds the <vcl> threshold, a CRITICAL status is returned. If\n\
338the data in the log file is older than <expire_minutes> old, a WARNING\n\
339status is returned and a warning message is printed.\n\n"));
340
341 printf(_("This plugin is useful for monitoring MRTG data that does not correspond to\n\
342bandwidth usage. (Use the check_mrtgtraf plugin for monitoring bandwidth).\n\
343It can be used to monitor any kind of data that MRTG is monitoring - errors,\n\
344packets/sec, etc. I use MRTG in conjuction with the Novell NLM that allows\n\
345me to track processor utilization, user connections, drive space, etc and\n\
346this plugin works well for monitoring that kind of data as well.\n\n"));
347
348 printf (_("Notes:\n\
349- This plugin only monitors one of the two variables stored in the MRTG log\n\
350 file. If you want to monitor both values you will have to define two\n\
351 commands with different values for the <variable> argument. Of course,\n\
352 you can always hack the code to make this plugin work for you...\n\
353- MRTG stands for the Multi Router Traffic Grapher. It can be downloaded from\n\
354 http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html\n"));
355
356 printf (_(UT_SUPPORT));
357}
358
359
360
361
362/* original command line:
363 <log_file> <expire_minutes> <AVG|MAX> <variable> <vwl> <vcl> <label> [units] */
364
365void
366print_usage (void)
367{
368 printf (_("\
369Usage: %s -F log_file -a <AVG | MAX> -v variable -w warning -c critical\n\
370 [-l label] [-u units] [-e expire_minutes] [-t timeout] [-v]\n"), progname);
371 printf (_(UT_HLP_VRS), progname, progname);
372}
diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c
index ce9ab191..be2f562e 100644
--- a/plugins/check_mrtgtraf.c
+++ b/plugins/check_mrtgtraf.c
@@ -24,60 +24,10 @@ const char *revision = "$Revision$";
24const char *copyright = "1999-2003"; 24const char *copyright = "1999-2003";
25const char *email = "nagiosplug-devel@lists.sourceforge.net"; 25const char *email = "nagiosplug-devel@lists.sourceforge.net";
26 26
27void
28print_usage (void)
29{
30 printf (_("\
31Usage: %s -F <log_file> -a <AVG | MAX> -v <variable> -w <warning_pair> -c <critical_pair>\n\
32 [-e expire_minutes] [-t timeout] [-v]\n"), progname);
33 printf (_(UT_HLP_VRS), progname, progname);
34}
35
36void
37print_help (void)
38{
39 print_revision (progname, revision);
40
41 printf (_(COPYRIGHT), copyright, email);
42
43 print_usage ();
44
45 printf (_(UT_HELP_VRSN));
46
47 printf (_("\
48 -F, --filename=STRING\n\
49 File to read log from\n\
50 -e, --expires=INTEGER\n\
51 Minutes after which log expires\n\
52 -a, --aggregation=(AVG|MAX)\n\
53 Test average or maximum\n\
54 -w, --warning\n\
55 Warning threshold pair \"<incoming>,<outgoing>\"\n\
56 -c, --critical\n\
57 Critical threshold pair \"<incoming>,<outgoing>\"\n"));
58
59 printf (_("\n\
60This plugin will check the incoming/outgoing transfer rates of a router,\n\
61switch, etc recorded in an MRTG log. If the newest log entry is older\n\
62than <expire_minutes>, a WARNING status is returned. If either the\n\
63incoming or outgoing rates exceed the <icl> or <ocl> thresholds (in\n\
64Bytes/sec), a CRITICAL status results. If either of the rates exceed\n\
65the <iwl> or <owl> thresholds (in Bytes/sec), a WARNING status results.\n\n"));
66
67 printf (_("Notes:\n\
68- MRTG stands for Multi Router Traffic Grapher. It can be downloaded from\n\
69 http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html\n\
70- While MRTG can monitor things other than traffic rates, this\n\
71 plugin probably won't work with much else without modification.\n\
72- The calculated i/o rates are a little off from what MRTG actually\n\
73 reports. I'm not sure why this is right now, but will look into it\n\
74 for future enhancements of this plugin.\n"));
75
76 printf (_(UT_SUPPORT));
77}
78
79int process_arguments (int, char **); 27int process_arguments (int, char **);
80int validate_arguments (void); 28int validate_arguments (void);
29void print_help(void);
30void print_usage(void);
81 31
82char *log_file = NULL; 32char *log_file = NULL;
83int expire_minutes = -1; 33int expire_minutes = -1;
@@ -87,6 +37,10 @@ unsigned long incoming_critical_threshold = 0L;
87unsigned long outgoing_warning_threshold = 0L; 37unsigned long outgoing_warning_threshold = 0L;
88unsigned long outgoing_critical_threshold = 0L; 38unsigned long outgoing_critical_threshold = 0L;
89 39
40
41
42
43
90int 44int
91main (int argc, char **argv) 45main (int argc, char **argv)
92{ 46{
@@ -357,3 +311,64 @@ validate_arguments (void)
357{ 311{
358 return OK; 312 return OK;
359} 313}
314
315
316
317
318
319
320void
321print_help (void)
322{
323 print_revision (progname, revision);
324
325 printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"));
326 printf (_(COPYRIGHT), copyright, email);
327
328 print_usage ();
329
330 printf (_(UT_HELP_VRSN));
331
332 printf (_("\
333 -F, --filename=STRING\n\
334 File to read log from\n\
335 -e, --expires=INTEGER\n\
336 Minutes after which log expires\n\
337 -a, --aggregation=(AVG|MAX)\n\
338 Test average or maximum\n\
339 -w, --warning\n\
340 Warning threshold pair \"<incoming>,<outgoing>\"\n\
341 -c, --critical\n\
342 Critical threshold pair \"<incoming>,<outgoing>\"\n"));
343
344 printf (_("\n\
345This plugin will check the incoming/outgoing transfer rates of a router,\n\
346switch, etc recorded in an MRTG log. If the newest log entry is older\n\
347than <expire_minutes>, a WARNING status is returned. If either the\n\
348incoming or outgoing rates exceed the <icl> or <ocl> thresholds (in\n\
349Bytes/sec), a CRITICAL status results. If either of the rates exceed\n\
350the <iwl> or <owl> thresholds (in Bytes/sec), a WARNING status results.\n\n"));
351
352 printf (_("Notes:\n\
353- MRTG stands for Multi Router Traffic Grapher. It can be downloaded from\n\
354 http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html\n\
355- While MRTG can monitor things other than traffic rates, this\n\
356 plugin probably won't work with much else without modification.\n\
357- The calculated i/o rates are a little off from what MRTG actually\n\
358 reports. I'm not sure why this is right now, but will look into it\n\
359 for future enhancements of this plugin.\n"));
360
361 printf (_(UT_SUPPORT));
362}
363
364
365
366
367void
368print_usage (void)
369{
370 printf (_("\
371Usage: %s -F <log_file> -a <AVG | MAX> -v <variable> -w <warning_pair> -c <critical_pair>\n\
372 [-e expire_minutes] [-t timeout] [-v]\n"), progname);
373 printf (_(UT_HLP_VRS), progname, progname);
374}
diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c
index de8a6200..4b227269 100644
--- a/plugins/check_nwstat.c
+++ b/plugins/check_nwstat.c
@@ -75,9 +75,14 @@ enum checkvar vars_to_check = NONE;
75int sap_number=-1; 75int sap_number=-1;
76 76
77int process_arguments(int, char **); 77int process_arguments(int, char **);
78void print_usage(void);
79void print_help(void); 78void print_help(void);
79void print_usage(void);
80
81
80 82
83
84
85
81int 86int
82main(int argc, char **argv) { 87main(int argc, char **argv) {
83 int result; 88 int result;
@@ -878,15 +883,12 @@ int process_arguments(int argc, char **argv) {
878 883
879 return OK; 884 return OK;
880} 885}
881
882void print_usage(void)
883{
884 printf (_("\
885Usage: %s -H host [-p port] [-v variable] [-w warning] [-c critical]\n\
886 [-t timeout].\n"), progname);
887 printf (_(UT_HLP_VRS), progname, progname);
888}
889 886
887
888
889
890
891
890void print_help(void) 892void print_help(void)
891{ 893{
892 char *myport; 894 char *myport;
@@ -894,7 +896,7 @@ void print_help(void)
894 896
895 print_revision (progname, revision); 897 print_revision (progname, revision);
896 898
897 printf (_("Copyright (c) 1999-2001 Ethan Galstad <nagios@nagios.org>\n")); 899 printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"));
898 printf (_(COPYRIGHT), copyright, email); 900 printf (_(COPYRIGHT), copyright, email);
899 901
900 printf (_("\ 902 printf (_("\
@@ -972,3 +974,14 @@ Notes:\n\
972 974
973 printf (_(UT_SUPPORT)); 975 printf (_(UT_SUPPORT));
974} 976}
977
978
979
980
981void print_usage(void)
982{
983 printf (_("\
984Usage: %s -H host [-p port] [-v variable] [-w warning] [-c critical]\n\
985 [-t timeout].\n"), progname);
986 printf (_(UT_HLP_VRS), progname, progname);
987}
diff --git a/plugins/check_overcr.c b/plugins/check_overcr.c
index 5f50ca7e..9958432e 100644
--- a/plugins/check_overcr.c
+++ b/plugins/check_overcr.c
@@ -106,17 +106,20 @@ main (int argc, char **argv)
106 temp_ptr = (char *) strtok (recv_buffer, "\r\n"); 106 temp_ptr = (char *) strtok (recv_buffer, "\r\n");
107 if (temp_ptr == NULL) 107 if (temp_ptr == NULL)
108 die (STATE_CRITICAL, _("Invalid response from server - no load information\n")); 108 die (STATE_CRITICAL, _("Invalid response from server - no load information\n"));
109 load_1min = strtod (temp_ptr, NULL); 109 else
110 load_1min = strtod (temp_ptr, NULL);
110 111
111 temp_ptr = (char *) strtok (NULL, "\r\n"); 112 temp_ptr = (char *) strtok (NULL, "\r\n");
112 if (temp_ptr == NULL) 113 if (temp_ptr == NULL)
113 die (STATE_CRITICAL, _("Invalid response from server after load 1\n")); 114 die (STATE_CRITICAL, _("Invalid response from server after load 1\n"));
114 load_5min = strtod (temp_ptr, NULL); 115 else
116 load_5min = strtod (temp_ptr, NULL);
115 117
116 temp_ptr = (char *) strtok (NULL, "\r\n"); 118 temp_ptr = (char *) strtok (NULL, "\r\n");
117 if (temp_ptr == NULL) 119 if (temp_ptr == NULL)
118 die (STATE_CRITICAL, _("Invalid response from server after load 5\n")); 120 die (STATE_CRITICAL, _("Invalid response from server after load 5\n"));
119 load_15min = strtod (temp_ptr, NULL); 121 else
122 load_15min = strtod (temp_ptr, NULL);
120 123
121 switch (vars_to_check) { 124 switch (vars_to_check) {
122 case LOAD1: 125 case LOAD1:
@@ -160,7 +163,8 @@ main (int argc, char **argv)
160 temp_ptr = (char *) strtok (NULL, "%"); 163 temp_ptr = (char *) strtok (NULL, "%");
161 if (temp_ptr == NULL) 164 if (temp_ptr == NULL)
162 die (STATE_CRITICAL, _("Invalid response from server\n")); 165 die (STATE_CRITICAL, _("Invalid response from server\n"));
163 percent_used_disk_space = strtoul (temp_ptr, NULL, 10); 166 else
167 percent_used_disk_space = strtoul (temp_ptr, NULL, 10);
164 break; 168 break;
165 } 169 }
166 170
@@ -186,8 +190,8 @@ main (int argc, char **argv)
186 190
187 if (result != STATE_OK) 191 if (result != STATE_OK)
188 die (result, _("Unknown error fetching network status\n")); 192 die (result, _("Unknown error fetching network status\n"));
189 193 else
190 port_connections = strtod (recv_buffer, NULL); 194 port_connections = strtod (recv_buffer, NULL);
191 195
192 if (check_critical_value == TRUE && (port_connections >= critical_value)) 196 if (check_critical_value == TRUE && (port_connections >= critical_value))
193 result = STATE_CRITICAL; 197 result = STATE_CRITICAL;
@@ -215,8 +219,8 @@ main (int argc, char **argv)
215 temp_ptr = (char *) strtok (NULL, ")"); 219 temp_ptr = (char *) strtok (NULL, ")");
216 if (temp_ptr == NULL) 220 if (temp_ptr == NULL)
217 die (STATE_CRITICAL, _("Invalid response from server\n")); 221 die (STATE_CRITICAL, _("Invalid response from server\n"));
218 222 else
219 processes = strtod (temp_ptr, NULL); 223 processes = strtod (temp_ptr, NULL);
220 224
221 if (check_critical_value == TRUE && (processes >= critical_value)) 225 if (check_critical_value == TRUE && (processes >= critical_value))
222 result = STATE_CRITICAL; 226 result = STATE_CRITICAL;
@@ -264,11 +268,11 @@ main (int argc, char **argv)
264 } 268 }
265 269
266 /* reset timeout */ 270 /* reset timeout */
267 alarm (0); 271/* alarm (0); */
268 272
269 printf (_("Reached end of program with no data returned\n")); 273/* printf (_("Reached end of program with no data returned\n")); */
270 274
271 return result; 275/* return result; */
272} 276}
273 277
274 278
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index 26c0192a..fd73b8ce 100644
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
@@ -55,7 +55,7 @@ int verbose = FALSE;
55float rta = UNKNOWN_TRIP_TIME; 55float rta = UNKNOWN_TRIP_TIME;
56int pl = UNKNOWN_PACKET_LOSS; 56int pl = UNKNOWN_PACKET_LOSS;
57 57
58char *warn_text = ""; 58char *warn_text;
59 59
60 60
61 61
@@ -69,11 +69,10 @@ main (int argc, char **argv)
69 int this_result = STATE_UNKNOWN; 69 int this_result = STATE_UNKNOWN;
70 int i; 70 int i;
71 71
72 addresses = malloc (max_addr); 72 addresses = malloc ((size_t)max_addr);
73 73
74 if (process_arguments (argc, argv) == ERROR) 74 if (process_arguments (argc, argv) == ERROR)
75 usage (_("Could not parse arguments")); 75 usage (_("Could not parse arguments"));
76 exit;
77 76
78 /* Set signal handling and alarm */ 77 /* Set signal handling and alarm */
79 if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { 78 if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) {
@@ -113,7 +112,7 @@ main (int argc, char **argv)
113 /* run the command */ 112 /* run the command */
114 this_result = run_ping (cmd, addresses[i]); 113 this_result = run_ping (cmd, addresses[i]);
115 114
116 if (pl == UNKNOWN_PACKET_LOSS || rta == UNKNOWN_TRIP_TIME) { 115 if (pl == UNKNOWN_PACKET_LOSS || rta < 0.0) {
117 printf ("%s\n", cmd); 116 printf ("%s\n", cmd);
118 die (STATE_UNKNOWN, 117 die (STATE_UNKNOWN,
119 _("Error: Could not interpret output from ping command\n")); 118 _("Error: Could not interpret output from ping command\n"));
@@ -193,12 +192,15 @@ process_arguments (int argc, char **argv)
193 switch (c) { 192 switch (c) {
194 case '?': /* usage */ 193 case '?': /* usage */
195 usage3 (_("Unknown argument"), optopt); 194 usage3 (_("Unknown argument"), optopt);
195 break;
196 case 'h': /* help */ 196 case 'h': /* help */
197 print_help (); 197 print_help ();
198 exit (STATE_OK); 198 exit (STATE_OK);
199 break;
199 case 'V': /* version */ 200 case 'V': /* version */
200 print_revision (progname, revision); 201 print_revision (progname, revision);
201 exit (STATE_OK); 202 exit (STATE_OK);
203 break;
202 case 't': /* timeout period */ 204 case 't': /* timeout period */
203 timeout_interval = atoi (optarg); 205 timeout_interval = atoi (optarg);
204 break; 206 break;
@@ -221,7 +223,7 @@ process_arguments (int argc, char **argv)
221 n_addresses++; 223 n_addresses++;
222 if (n_addresses > max_addr) { 224 if (n_addresses > max_addr) {
223 max_addr *= 2; 225 max_addr *= 2;
224 addresses = realloc (addresses, max_addr); 226 addresses = realloc (addresses, (size_t)max_addr);
225 if (addresses == NULL) 227 if (addresses == NULL)
226 die (STATE_UNKNOWN, _("Could not realloc() addresses\n")); 228 die (STATE_UNKNOWN, _("Could not realloc() addresses\n"));
227 } 229 }
@@ -292,7 +294,7 @@ process_arguments (int argc, char **argv)
292 } 294 }
293 } 295 }
294 296
295 if (wrta == UNKNOWN_TRIP_TIME) { 297 if (wrta < 0.0) {
296 if (is_negative (argv[c])) { 298 if (is_negative (argv[c])) {
297 printf (_("<wrta> (%s) must be a non-negative number\n"), argv[c]); 299 printf (_("<wrta> (%s) must be a non-negative number\n"), argv[c]);
298 return ERROR; 300 return ERROR;
@@ -303,7 +305,7 @@ process_arguments (int argc, char **argv)
303 } 305 }
304 } 306 }
305 307
306 if (crta == UNKNOWN_TRIP_TIME) { 308 if (crta < 0.0) {
307 if (is_negative (argv[c])) { 309 if (is_negative (argv[c])) {
308 printf (_("<crta> (%s) must be a non-negative number\n"), argv[c]); 310 printf (_("<crta> (%s) must be a non-negative number\n"), argv[c]);
309 return ERROR; 311 return ERROR;
@@ -346,11 +348,11 @@ validate_arguments ()
346 float max_seconds; 348 float max_seconds;
347 int i; 349 int i;
348 350
349 if (wrta == UNKNOWN_TRIP_TIME) { 351 if (wrta < 0.0) {
350 printf (_("<wrta> was not set\n")); 352 printf (_("<wrta> was not set\n"));
351 return ERROR; 353 return ERROR;
352 } 354 }
353 else if (crta == UNKNOWN_TRIP_TIME) { 355 else if (crta < 0.0) {
354 printf (_("<crta> was not set\n")); 356 printf (_("<crta> was not set\n"));
355 return ERROR; 357 return ERROR;
356 } 358 }
@@ -397,10 +399,9 @@ run_ping (char *cmd, char *server_address)
397 char buf[MAX_INPUT_BUFFER]; 399 char buf[MAX_INPUT_BUFFER];
398 int result = STATE_UNKNOWN; 400 int result = STATE_UNKNOWN;
399 401
400 if ((child_process = spopen (cmd)) == NULL) { 402 if ((child_process = spopen (cmd)) == NULL)
401 printf (_("Cannot open pipe: ")); 403 die (STATE_UNKNOWN, _("Cannot open pipe: %s"), cmd);
402 die (STATE_UNKNOWN, cmd); 404
403 }
404 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); 405 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
405 if (child_stderr == NULL) 406 if (child_stderr == NULL)
406 printf (_("Cannot open stderr for %s\n"), cmd); 407 printf (_("Cannot open stderr for %s\n"), cmd);
@@ -455,7 +456,7 @@ run_ping (char *cmd, char *server_address)
455 _("PING CRITICAL - Host not found (%s)"), 456 _("PING CRITICAL - Host not found (%s)"),
456 server_address); 457 server_address);
457 458
458 if (strlen (warn_text) == 0) 459 if (warn_text == NULL)
459 warn_text = strdup (buf); 460 warn_text = strdup (buf);
460 else if (asprintf (&warn_text, "%s %s", warn_text, buf) == -1) 461 else if (asprintf (&warn_text, "%s %s", warn_text, buf) == -1)
461 die (STATE_UNKNOWN, _("unable to realloc warn_text")); 462 die (STATE_UNKNOWN, _("unable to realloc warn_text"));
@@ -472,6 +473,9 @@ run_ping (char *cmd, char *server_address)
472 if (spclose (child_process)) 473 if (spclose (child_process))
473 result = max_state (result, STATE_WARNING); 474 result = max_state (result, STATE_WARNING);
474 475
476 if (warn_text == NULL)
477 warn_text = strdup("");
478
475 return result; 479 return result;
476} 480}
477 481
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 1b641c55..1894b281 100644
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
@@ -49,12 +49,14 @@ int options = 0; /* bitmask of filter criteria to test against */
49#define PCPU 256 49#define PCPU 256
50 50
51/* Different metrics */ 51/* Different metrics */
52int metric = 0; 52char *metric_name;
53#define METRIC_PROCS 0 53enum metric {
54#define METRIC_VSZ 1 54 METRIC_PROCS,
55#define METRIC_RSS 2 55 METRIC_VSZ,
56#define METRIC_CPU 3 56 METRIC_RSS,
57char *metric_name = ""; 57 METRIC_CPU
58};
59enum metric metric = METRIC_PROCS;
58 60
59int verbose = 0; 61int verbose = 0;
60int uid; 62int uid;
@@ -62,11 +64,11 @@ int ppid;
62int vsz; 64int vsz;
63int rss; 65int rss;
64float pcpu; 66float pcpu;
65char *statopts = ""; 67char *statopts;
66char *prog = ""; 68char *prog;
67char *args = ""; 69char *args;
68char *fmt = ""; 70char *fmt;
69char *fails = ""; 71char *fails;
70char tmp[MAX_INPUT_BUFFER]; 72char tmp[MAX_INPUT_BUFFER];
71 73
72 74
@@ -317,54 +319,35 @@ process_arguments (int argc, char **argv)
317 print_revision (progname, revision); 319 print_revision (progname, revision);
318 exit (STATE_OK); 320 exit (STATE_OK);
319 case 't': /* timeout period */ 321 case 't': /* timeout period */
320 if (!is_integer (optarg)) { 322 if (!is_integer (optarg))
321 printf (_("%s: Timeout Interval must be an integer!\n\n"), 323 usage (_("Timeout Interval must be an integer!\n\n"));
322 progname); 324 else
323 print_usage (); 325 timeout_interval = atoi (optarg);
324 exit (STATE_UNKNOWN);
325 }
326 timeout_interval = atoi (optarg);
327 break; 326 break;
328 case 'c': /* critical threshold */ 327 case 'c': /* critical threshold */
329 if (is_integer (optarg)) { 328 if (is_integer (optarg))
330 cmax = atoi (optarg); 329 cmax = atoi (optarg);
330 else if (sscanf (optarg, ":%d", &cmax) == 1)
331 break; 331 break;
332 } 332 else if (sscanf (optarg, "%d:%d", &cmin, &cmax) == 2)
333 else if (sscanf (optarg, ":%d", &cmax) == 1) {
334 break; 333 break;
335 } 334 else if (sscanf (optarg, "%d:", &cmin) == 1)
336 else if (sscanf (optarg, "%d:%d", &cmin, &cmax) == 2) {
337 break; 335 break;
338 } 336 else
339 else if (sscanf (optarg, "%d:", &cmin) == 1) { 337 usage (_("Critical Process Count must be an integer!\n\n"));
340 break; 338 break;
341 }
342 else {
343 printf (_("%s: Critical Process Count must be an integer!\n\n"),
344 progname);
345 print_usage ();
346 exit (STATE_UNKNOWN);
347 }
348 case 'w': /* warning time threshold */ 339 case 'w': /* warning time threshold */
349 if (is_integer (optarg)) { 340 if (is_integer (optarg))
350 wmax = atoi (optarg); 341 wmax = atoi (optarg);
342 else if (sscanf (optarg, ":%d", &wmax) == 1)
351 break; 343 break;
352 } 344 else if (sscanf (optarg, "%d:%d", &wmin, &wmax) == 2)
353 else if (sscanf (optarg, ":%d", &wmax) == 1) {
354 break;
355 }
356 else if (sscanf (optarg, "%d:%d", &wmin, &wmax) == 2) {
357 break; 345 break;
358 } 346 else if (sscanf (optarg, "%d:", &wmin) == 1)
359 else if (sscanf (optarg, "%d:", &wmin) == 1) {
360 break; 347 break;
361 } 348 else
362 else { 349 usage (_("%s: Warning Process Count must be an integer!\n\n"));
363 printf (_("%s: Warning Process Count must be an integer!\n\n"), 350 break;
364 progname);
365 print_usage ();
366 exit (STATE_UNKNOWN);
367 }
368 case 'p': /* process id */ 351 case 'p': /* process id */
369 if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) { 352 if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) {
370 asprintf (&fmt, "%s%sPPID = %d", fmt, (options ? ", " : ""), ppid); 353 asprintf (&fmt, "%s%sPPID = %d", fmt, (options ? ", " : ""), ppid);
@@ -376,7 +359,10 @@ process_arguments (int argc, char **argv)
376 print_usage (); 359 print_usage ();
377 exit (STATE_UNKNOWN); 360 exit (STATE_UNKNOWN);
378 case 's': /* status */ 361 case 's': /* status */
379 asprintf (&statopts, "%s", optarg); 362 if (statopts)
363 break;
364 else
365 statopts = strdup(optarg);
380 asprintf (&fmt, _("%s%sSTATE = %s"), fmt, (options ? ", " : ""), statopts); 366 asprintf (&fmt, _("%s%sSTATE = %s"), fmt, (options ? ", " : ""), statopts);
381 options |= STAT; 367 options |= STAT;
382 break; 368 break;
@@ -408,13 +394,19 @@ process_arguments (int argc, char **argv)
408 options |= USER; 394 options |= USER;
409 break; 395 break;
410 case 'C': /* command */ 396 case 'C': /* command */
411 asprintf (&prog, "%s", optarg); 397 if (prog)
398 break;
399 else
400 prog = strdup(optarg);
412 asprintf (&fmt, _("%s%scommand name '%s'"), fmt, (options ? ", " : ""), 401 asprintf (&fmt, _("%s%scommand name '%s'"), fmt, (options ? ", " : ""),
413 prog); 402 prog);
414 options |= PROG; 403 options |= PROG;
415 break; 404 break;
416 case 'a': /* args (full path name with args) */ 405 case 'a': /* args (full path name with args) */
417 asprintf (&args, "%s", optarg); 406 if (args)
407 break;
408 else
409 args = strdup(optarg);
418 asprintf (&fmt, _("%s%sargs '%s'"), fmt, (options ? ", " : ""), args); 410 asprintf (&fmt, _("%s%sargs '%s'"), fmt, (options ? ", " : ""), args);
419 options |= ARGS; 411 options |= ARGS;
420 break; 412 break;
@@ -521,6 +513,21 @@ validate_arguments ()
521 if (options == 0) 513 if (options == 0)
522 options = ALL; 514 options = ALL;
523 515
516 if (statopts==NULL)
517 statopts = strdup("");
518
519 if (prog==NULL)
520 prog = strdup("");
521
522 if (args==NULL)
523 args = strdup("");
524
525 if (fmt==NULL)
526 fmt = strdup("");
527
528 if (fails==NULL)
529 fails = strdup("");
530
524 return options; 531 return options;
525} 532}
526 533
diff --git a/plugins/check_real.c b/plugins/check_real.c
index ecdd5619..9c9c3e0b 100644
--- a/plugins/check_real.c
+++ b/plugins/check_real.c
@@ -38,10 +38,10 @@ void print_help (void);
38void print_usage (void); 38void print_usage (void);
39 39
40int server_port = PORT; 40int server_port = PORT;
41char *server_address = ""; 41char *server_address;
42char *host_name = ""; 42char *host_name;
43char *server_url = NULL; 43char *server_url = NULL;
44char *server_expect = EXPECT; 44char *server_expect;
45int warning_time = 0; 45int warning_time = 0;
46int check_warning_time = FALSE; 46int check_warning_time = FALSE;
47int critical_time = 0; 47int critical_time = 0;
@@ -294,18 +294,18 @@ process_arguments (int argc, char **argv)
294 switch (c) { 294 switch (c) {
295 case 'I': /* hostname */ 295 case 'I': /* hostname */
296 case 'H': /* hostname */ 296 case 'H': /* hostname */
297 if (is_host (optarg)) { 297 if (server_address)
298 server_address = optarg; 298 break;
299 } 299 else if (is_host (optarg))
300 else { 300 server_address = strdup(optarg);
301 else
301 usage (_("Invalid host name\n")); 302 usage (_("Invalid host name\n"));
302 }
303 break; 303 break;
304 case 'e': /* string to expect in response header */ 304 case 'e': /* string to expect in response header */
305 server_expect = optarg; 305 server_expect = strdup(optarg);
306 break; 306 break;
307 case 'u': /* server URL */ 307 case 'u': /* server URL */
308 server_url = optarg; 308 server_url = strdup(optarg);
309 break; 309 break;
310 case 'p': /* port */ 310 case 'p': /* port */
311 if (is_intpos (optarg)) { 311 if (is_intpos (optarg)) {
@@ -356,7 +356,7 @@ process_arguments (int argc, char **argv)
356 } 356 }
357 357
358 c = optind; 358 c = optind;
359 if (strlen(server_address)==0 && argc>c) { 359 if (server_address==NULL && argc>c) {
360 if (is_host (argv[c])) { 360 if (is_host (argv[c])) {
361 server_address = argv[c++]; 361 server_address = argv[c++];
362 } 362 }
@@ -365,11 +365,14 @@ process_arguments (int argc, char **argv)
365 } 365 }
366 } 366 }
367 367
368 if (strlen(server_address) == 0) 368 if (server_address==NULL)
369 usage (_("You must provide a server to check\n")); 369 usage (_("You must provide a server to check\n"));
370 370
371 if (strlen(host_name) == 0) 371 if (host_name==NULL)
372 asprintf (&host_name, "%s", server_address); 372 host_name = strdup (server_address);
373
374 if (server_expect == NULL)
375 server_expect = strdup(EXPECT);
373 376
374 return validate_arguments (); 377 return validate_arguments ();
375} 378}
diff --git a/plugins/utils.c b/plugins/utils.c
index 518caa8c..5b975729 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -52,14 +52,14 @@ max_state (int a, int b)
52 return max (a, b); 52 return max (a, b);
53} 53}
54 54
55void usage (char *msg) 55void usage (const char *msg)
56{ 56{
57 printf ("%s", msg); 57 printf ("%s", msg);
58 print_usage (); 58 print_usage ();
59 exit (STATE_UNKNOWN); 59 exit (STATE_UNKNOWN);
60} 60}
61 61
62void usage2(char *msg, char *arg) 62void usage2(const char *msg, const char *arg)
63{ 63{
64 printf ("%s: %s - %s\n",progname,msg,arg); 64 printf ("%s: %s - %s\n",progname,msg,arg);
65 print_usage (); 65 print_usage ();
@@ -67,7 +67,7 @@ void usage2(char *msg, char *arg)
67} 67}
68 68
69void 69void
70usage3 (char *msg, int arg) 70usage3 (const char *msg, int arg)
71{ 71{
72 printf ("%s: %s - %c\n", progname, msg, arg); 72 printf ("%s: %s - %c\n", progname, msg, arg);
73 print_usage(); 73 print_usage();
diff --git a/plugins/utils.h b/plugins/utils.h
index b763b1e2..efdbed41 100644
--- a/plugins/utils.h
+++ b/plugins/utils.h
@@ -71,9 +71,9 @@ char *strpcat (char *dest, const char *src, const char *str);
71 71
72int max_state (int a, int b); 72int max_state (int a, int b);
73 73
74void usage (char *msg) __attribute__((noreturn)); 74void usage (const char *msg) __attribute__((noreturn));
75void usage2(char *msg, char *arg) __attribute__((noreturn)); 75void usage2(const char *msg, const char *arg) __attribute__((noreturn));
76void usage3(char *msg, int arg) __attribute__((noreturn)); 76void usage3(const char *msg, int arg) __attribute__((noreturn));
77 77
78const char *state_text (int result); 78const char *state_text (int result);
79 79