diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-08-08 04:33:21 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-08-08 04:33:21 +0000 |
commit | 65ca899d2c98b6342783922a5709c4b61e6b2b1f (patch) | |
tree | 81bff537f3ba725e1d214d548199868572baf76b /plugins | |
parent | 92cd137176830bcdfbd477f151ba22d456b2e31c (diff) | |
download | monitoring-plugins-65ca899d2c98b6342783922a5709c4b61e6b2b1f.tar.gz |
fix a variety of compiler warnings about qualifier discards and other pedantic stuff
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@662 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_by_ssh.c | 203 | ||||
-rw-r--r-- | plugins/check_disk.c | 226 | ||||
-rw-r--r-- | plugins/check_nt.c | 6 | ||||
-rw-r--r-- | plugins/netutils.c | 6 | ||||
-rw-r--r-- | plugins/netutils.h | 4 | ||||
-rw-r--r-- | plugins/popen.h | 2 | ||||
-rw-r--r-- | plugins/utils.h | 16 |
7 files changed, 240 insertions, 223 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index 1211daa3..8527b727 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c | |||
@@ -1,25 +1,19 @@ | |||
1 | /****************************************************************************** | 1 | /****************************************************************************** |
2 | * | 2 | |
3 | * This file is part of the Nagios Plugins. | 3 | The Nagios Plugins are free software; you can redistribute them |
4 | * | 4 | and/or modify them under the terms of the GNU General Public |
5 | * Copyright (c) 1999, 2000, 2001 Karl DeBisschop <karl@debisschop.net> | 5 | License as published by the Free Software Foundation; either |
6 | * | 6 | version 2 of the License, or (at your option) any later version. |
7 | * The Nagios Plugins are free software; you can redistribute them | 7 | |
8 | * and/or modify them under the terms of the GNU General Public | 8 | This program is distributed in the hope that it will be useful, but |
9 | * License as published by the Free Software Foundation; either | 9 | WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * version 2 of the License, or (at your option) any later version. | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 | * | 11 | General Public License for more details. |
12 | * This program is distributed in the hope that it will be useful, but | 12 | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | You should have received a copy of the GNU General Public License |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | along with this program; if not, write to the Free Software |
15 | * General Public License for more details. | 15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
16 | * | 16 | |
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | * | ||
21 | * $Id$ | ||
22 | * | ||
23 | *****************************************************************************/ | 17 | *****************************************************************************/ |
24 | 18 | ||
25 | const char *progname = "check_by_ssh"; | 19 | const char *progname = "check_by_ssh"; |
@@ -27,7 +21,6 @@ const char *revision = "$Revision$"; | |||
27 | const char *copyright = "2000-2003"; | 21 | const char *copyright = "2000-2003"; |
28 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 22 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; |
29 | 23 | ||
30 | #include "config.h" | ||
31 | #include "common.h" | 24 | #include "common.h" |
32 | #include "netutils.h" | 25 | #include "netutils.h" |
33 | #include "utils.h" | 26 | #include "utils.h" |
@@ -38,83 +31,10 @@ int validate_arguments (void); | |||
38 | void print_help (void); | 31 | void print_help (void); |
39 | void print_usage (void); | 32 | void print_usage (void); |
40 | 33 | ||
41 | void | ||
42 | print_help (void) | ||
43 | { | ||
44 | print_revision (progname, revision); | ||
45 | |||
46 | printf (_(COPYRIGHT), copyright, email); | ||
47 | |||
48 | printf (_("This plugin uses SSH to execute commands on a remote host\n\n")); | ||
49 | |||
50 | print_usage (); | ||
51 | |||
52 | printf (_(UT_HELP_VRSN)); | ||
53 | |||
54 | printf (_(UT_HOST_PORT), 'p', "none"); | ||
55 | |||
56 | printf (_(UT_IPv46)); | ||
57 | |||
58 | printf (_("\ | ||
59 | -1, --proto1\n\ | ||
60 | tell ssh to use Protocol 1\n\ | ||
61 | -2, --proto2\n\ | ||
62 | tell ssh to use Protocol 2\n\ | ||
63 | -f\n\ | ||
64 | tells ssh to fork rather than create a tty\n")); | ||
65 | |||
66 | printf (_("\ | ||
67 | -C, --command='COMMAND STRING'\n\ | ||
68 | command to execute on the remote machine\n\ | ||
69 | -l, --logname=USERNAME\n\ | ||
70 | SSH user name on remote host [optional]\n\ | ||
71 | -i, --identity=KEYFILE\n\ | ||
72 | identity of an authorized key [optional]\n\ | ||
73 | -O, --output=FILE\n\ | ||
74 | external command file for nagios [optional]\n\ | ||
75 | -s, --services=LIST\n\ | ||
76 | list of nagios service names, separated by ':' [optional]\n\ | ||
77 | -n, --name=NAME\n\ | ||
78 | short name of host in nagios configuration [optional]\n")); | ||
79 | |||
80 | printf (_(UT_WARN_CRIT)); | ||
81 | |||
82 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
83 | |||
84 | printf (_("\n\ | ||
85 | The most common mode of use is to refer to a local identity file with\n\ | ||
86 | the '-i' option. In this mode, the identity pair should have a null\n\ | ||
87 | passphrase and the public key should be listed in the authorized_keys\n\ | ||
88 | file of the remote host. Usually the key will be restricted to running\n\ | ||
89 | only one command on the remote server. If the remote SSH server tracks\n\ | ||
90 | invocation agruments, the one remote program may be an agent that can\n\ | ||
91 | execute additional commands as proxy\n")); | ||
92 | |||
93 | printf (_("\n\ | ||
94 | To use passive mode, provide multiple '-C' options, and provide\n\ | ||
95 | all of -O, -s, and -n options (servicelist order must match '-C'\n\ | ||
96 | options)\n")); | ||
97 | } | ||
98 | |||
99 | |||
100 | |||
101 | |||
102 | |||
103 | void | ||
104 | print_usage (void) | ||
105 | { | ||
106 | printf (_("Usage:\n\ | ||
107 | check_by_ssh [-f46] [-t timeout] [-i identity] [-l user] -H <host> -C <command>\n\ | ||
108 | [-n name] [-s servicelist] [-O outputfile] [-p port]\n\ | ||
109 | check_by_ssh -V prints version info\n\ | ||
110 | check_by_ssh -h prints more detailed help\n")); | ||
111 | } | ||
112 | |||
113 | |||
114 | int commands = 0; | 34 | int commands = 0; |
115 | int services = 0; | 35 | int services = 0; |
116 | char *remotecmd = ""; | 36 | char *remotecmd = NULL; |
117 | char *comm = SSH_COMMAND; | 37 | char *comm = NULL; |
118 | char *hostname = NULL; | 38 | char *hostname = NULL; |
119 | char *outputfile = NULL; | 39 | char *outputfile = NULL; |
120 | char *host_shortname = NULL; | 40 | char *host_shortname = NULL; |
@@ -123,20 +43,26 @@ int passive = FALSE; | |||
123 | int verbose = FALSE; | 43 | int verbose = FALSE; |
124 | 44 | ||
125 | 45 | ||
46 | |||
47 | |||
48 | |||
49 | |||
126 | int | 50 | int |
127 | main (int argc, char **argv) | 51 | main (int argc, char **argv) |
128 | { | 52 | { |
129 | 53 | ||
130 | char input_buffer[MAX_INPUT_BUFFER]; | 54 | char input_buffer[MAX_INPUT_BUFFER]; |
131 | char *result_text = ""; | 55 | char *result_text; |
132 | char *status_text; | 56 | char *status_text; |
133 | char *output = ""; | 57 | char *output; |
134 | char *eol = NULL; | 58 | char *eol = NULL; |
135 | int cresult; | 59 | int cresult; |
136 | int result = STATE_UNKNOWN; | 60 | int result = STATE_UNKNOWN; |
137 | time_t local_time; | 61 | time_t local_time; |
138 | FILE *fp = NULL; | 62 | FILE *fp = NULL; |
139 | 63 | ||
64 | asprintf (&remotecmd, "%s", ""); | ||
65 | asprintf (&comm, "%s", SSH_COMMAND); | ||
140 | 66 | ||
141 | /* process arguments */ | 67 | /* process arguments */ |
142 | if (process_arguments (argc, argv) == ERROR) | 68 | if (process_arguments (argc, argv) == ERROR) |
@@ -235,6 +161,7 @@ main (int argc, char **argv) | |||
235 | 161 | ||
236 | 162 | ||
237 | 163 | ||
164 | |||
238 | /* process command-line arguments */ | 165 | /* process command-line arguments */ |
239 | int | 166 | int |
240 | process_arguments (int argc, char **argv) | 167 | process_arguments (int argc, char **argv) |
@@ -392,3 +319,81 @@ validate_arguments (void) | |||
392 | 319 | ||
393 | return OK; | 320 | return OK; |
394 | } | 321 | } |
322 | |||
323 | |||
324 | |||
325 | |||
326 | |||
327 | |||
328 | void | ||
329 | print_help (void) | ||
330 | { | ||
331 | print_revision (progname, revision); | ||
332 | |||
333 | printf (_("Copyright (c) 1999 Karl DeBisschop <kdebisschop@users.sourceforge.net>\n")); | ||
334 | printf (_(COPYRIGHT), copyright, email); | ||
335 | |||
336 | printf (_("This plugin uses SSH to execute commands on a remote host\n\n")); | ||
337 | |||
338 | print_usage (); | ||
339 | |||
340 | printf (_(UT_HELP_VRSN)); | ||
341 | |||
342 | printf (_(UT_HOST_PORT), 'p', "none"); | ||
343 | |||
344 | printf (_(UT_IPv46)); | ||
345 | |||
346 | printf (_("\ | ||
347 | -1, --proto1\n\ | ||
348 | tell ssh to use Protocol 1\n\ | ||
349 | -2, --proto2\n\ | ||
350 | tell ssh to use Protocol 2\n\ | ||
351 | -f\n\ | ||
352 | tells ssh to fork rather than create a tty\n")); | ||
353 | |||
354 | printf (_("\ | ||
355 | -C, --command='COMMAND STRING'\n\ | ||
356 | command to execute on the remote machine\n\ | ||
357 | -l, --logname=USERNAME\n\ | ||
358 | SSH user name on remote host [optional]\n\ | ||
359 | -i, --identity=KEYFILE\n\ | ||
360 | identity of an authorized key [optional]\n\ | ||
361 | -O, --output=FILE\n\ | ||
362 | external command file for nagios [optional]\n\ | ||
363 | -s, --services=LIST\n\ | ||
364 | list of nagios service names, separated by ':' [optional]\n\ | ||
365 | -n, --name=NAME\n\ | ||
366 | short name of host in nagios configuration [optional]\n")); | ||
367 | |||
368 | printf (_(UT_WARN_CRIT)); | ||
369 | |||
370 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
371 | |||
372 | printf (_("\n\ | ||
373 | The most common mode of use is to refer to a local identity file with\n\ | ||
374 | the '-i' option. In this mode, the identity pair should have a null\n\ | ||
375 | passphrase and the public key should be listed in the authorized_keys\n\ | ||
376 | file of the remote host. Usually the key will be restricted to running\n\ | ||
377 | only one command on the remote server. If the remote SSH server tracks\n\ | ||
378 | invocation agruments, the one remote program may be an agent that can\n\ | ||
379 | execute additional commands as proxy\n")); | ||
380 | |||
381 | printf (_("\n\ | ||
382 | To use passive mode, provide multiple '-C' options, and provide\n\ | ||
383 | all of -O, -s, and -n options (servicelist order must match '-C'\n\ | ||
384 | options)\n")); | ||
385 | } | ||
386 | |||
387 | |||
388 | |||
389 | |||
390 | |||
391 | void | ||
392 | print_usage (void) | ||
393 | { | ||
394 | printf (_("\n\ | ||
395 | Usage: %s [-f46] [-t timeout] [-i identity] [-l user] -H <host> \n\ | ||
396 | -C <command> [-n name] [-s servicelist] [-O outputfile] [-p port]\n"), | ||
397 | progname); | ||
398 | printf (_(UT_HLP_VRS), progname, progname); | ||
399 | } | ||
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index b0b0d2a5..7feb5a57 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -35,80 +35,6 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
35 | # include <limits.h> | 35 | # include <limits.h> |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | void | ||
39 | print_usage (void) | ||
40 | { | ||
41 | printf (_("\ | ||
42 | Usage: %s -w limit -c limit [-p path | -x device] [-t timeout] [-m] [-e]\n\ | ||
43 | [-v] [-q]\n\ | ||
44 | %s (-h|--help)\n\ | ||
45 | %s (-V|--version)\n"), | ||
46 | progname, progname, progname); | ||
47 | } | ||
48 | |||
49 | void | ||
50 | print_help (void) | ||
51 | { | ||
52 | print_revision (progname, revision); | ||
53 | |||
54 | printf (_(COPYRIGHT), copyright, email); | ||
55 | |||
56 | printf (_("\ | ||
57 | This plugin checks the amount of used disk space on a mounted file system\n\ | ||
58 | and generates an alert if free space is less than one of the threshold values.")); | ||
59 | |||
60 | print_usage (); | ||
61 | |||
62 | printf (_(UT_HELP_VRSN)); | ||
63 | |||
64 | printf (_("\ | ||
65 | -w, --warning=INTEGER\n\ | ||
66 | Exit with WARNING status if less than INTEGER kilobytes of disk are free\n\ | ||
67 | -w, --warning=PERCENT%%\n\ | ||
68 | Exit with WARNING status if less than PERCENT of disk space is free\n\ | ||
69 | -c, --critical=INTEGER\n\ | ||
70 | Exit with CRITICAL status if less than INTEGER kilobytes of disk are free\n\ | ||
71 | -c, --critical=PERCENT%%\n\ | ||
72 | Exit with CRITCAL status if less than PERCENT of disk space is free\n\ | ||
73 | -C, --clear\n\ | ||
74 | Clear thresholds\n")); | ||
75 | |||
76 | printf (_("\ | ||
77 | -u, --units=STRING\n\ | ||
78 | Choose bytes, kB, MB, GB, TB (default: MB)\n\ | ||
79 | -k, --kilobytes\n\ | ||
80 | Same as '--units kB'\n\ | ||
81 | -m, --megabytes\n\ | ||
82 | Same as '--units MB'\n")); | ||
83 | |||
84 | printf (_("\ | ||
85 | -l, --local\n\ | ||
86 | Only check local filesystems\n\ | ||
87 | -p, --path=PATH, --partition=PARTITION\n\ | ||
88 | Path or partition (may be repeated)\n\ | ||
89 | -x, --exclude_device=PATH <STRING>\n\ | ||
90 | Ignore device (only works if -p unspecified)\n\ | ||
91 | -X, --exclude-type=TYPE <STRING>\n\ | ||
92 | Ignore all filesystems of indicated type (may be repeated)\n\ | ||
93 | -M, --mountpoint\n\ | ||
94 | Display the mountpoint instead of the partition\n\ | ||
95 | -e, --errors-only\n\ | ||
96 | Display only devices/mountpoints with errors\n")); | ||
97 | |||
98 | printf (_(UT_WARN_CRIT)); | ||
99 | |||
100 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
101 | |||
102 | printf (_(UT_VERBOSE)); | ||
103 | |||
104 | printf ("%s", _("Examples:\n\ | ||
105 | check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /\n\ | ||
106 | Checks /tmp and /var at 10%,5% and / at 100MB, 50MB\n")); | ||
107 | |||
108 | support (); | ||
109 | } | ||
110 | |||
111 | |||
112 | /* If nonzero, show inode information. */ | 38 | /* If nonzero, show inode information. */ |
113 | /* static int inode_format; */ | 39 | /* static int inode_format; */ |
114 | 40 | ||
@@ -135,8 +61,8 @@ struct name_list | |||
135 | { | 61 | { |
136 | char *name; | 62 | char *name; |
137 | int found; | 63 | int found; |
138 | int w_df; | 64 | uintmax_t w_df; |
139 | int c_df; | 65 | uintmax_t c_df; |
140 | double w_dfp; | 66 | double w_dfp; |
141 | double c_dfp; | 67 | double c_dfp; |
142 | struct name_list *name_next; | 68 | struct name_list *name_next; |
@@ -183,18 +109,21 @@ enum | |||
183 | #endif | 109 | #endif |
184 | 110 | ||
185 | int process_arguments (int, char **); | 111 | int process_arguments (int, char **); |
186 | int validate_arguments (int, int, double, double, char *); | 112 | void print_path (char *mypath); |
187 | int check_disk (int usp, int free_disk); | 113 | int validate_arguments (uintmax_t, uintmax_t, double, double, char *); |
114 | int check_disk (int usp, uintmax_t free_disk); | ||
188 | int walk_name_list (struct name_list *list, const char *name); | 115 | int walk_name_list (struct name_list *list, const char *name); |
116 | void print_help (void); | ||
117 | void print_usage (void); | ||
189 | 118 | ||
190 | int w_df = -1; | 119 | uintmax_t w_df = 0; |
191 | int c_df = -1; | 120 | uintmax_t c_df = 0; |
192 | double w_dfp = -1.0; | 121 | double w_dfp = -1.0; |
193 | double c_dfp = -1.0; | 122 | double c_dfp = -1.0; |
194 | char *path = ""; | 123 | char *path = ""; |
195 | char *exclude_device = ""; | 124 | char *exclude_device = ""; |
196 | char *units = "MB"; | 125 | char *units = NULL; |
197 | unsigned long mult = 1024 * 1024; | 126 | uintmax_t mult = 1024 * 1024; |
198 | int verbose = 0; | 127 | int verbose = 0; |
199 | int erronly = FALSE; | 128 | int erronly = FALSE; |
200 | int display_mntp = FALSE; | 129 | int display_mntp = FALSE; |
@@ -202,10 +131,12 @@ int display_mntp = FALSE; | |||
202 | /* Linked list of mounted filesystems. */ | 131 | /* Linked list of mounted filesystems. */ |
203 | static struct mount_entry *mount_list; | 132 | static struct mount_entry *mount_list; |
204 | 133 | ||
134 | |||
135 | |||
205 | int | 136 | int |
206 | main (int argc, char **argv) | 137 | main (int argc, char **argv) |
207 | { | 138 | { |
208 | int usp = -1; | 139 | double usp = -1.0; |
209 | int result = STATE_UNKNOWN; | 140 | int result = STATE_UNKNOWN; |
210 | int disk_result = STATE_UNKNOWN; | 141 | int disk_result = STATE_UNKNOWN; |
211 | char file_system[MAX_INPUT_BUFFER]; | 142 | char file_system[MAX_INPUT_BUFFER]; |
@@ -244,7 +175,7 @@ main (int argc, char **argv) | |||
244 | get_fs_usage (me->me_mountdir, me->me_devname, &fsp); | 175 | get_fs_usage (me->me_mountdir, me->me_devname, &fsp); |
245 | 176 | ||
246 | if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) { | 177 | if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) { |
247 | usp = (fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks; | 178 | usp = (double)(fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks; |
248 | disk_result = check_disk (usp, fsp.fsu_bavail); | 179 | disk_result = check_disk (usp, fsp.fsu_bavail); |
249 | result = max_state (disk_result, result); | 180 | result = max_state (disk_result, result); |
250 | if (disk_result==STATE_OK && erronly && !verbose) | 181 | if (disk_result==STATE_OK && erronly && !verbose) |
@@ -364,7 +295,7 @@ process_arguments (int argc, char **argv) | |||
364 | } | 295 | } |
365 | else if (strpbrk (optarg, ",:") && | 296 | else if (strpbrk (optarg, ",:") && |
366 | strstr (optarg, "%") && | 297 | strstr (optarg, "%") && |
367 | sscanf (optarg, "%d%*[:,]%lf%%", &w_df, &w_dfp) == 2) { | 298 | sscanf (optarg, "%ul%*[:,]%lf%%", &w_df, &w_dfp) == 2) { |
368 | break; | 299 | break; |
369 | } | 300 | } |
370 | else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_dfp) == 1) { | 301 | else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_dfp) == 1) { |
@@ -380,7 +311,7 @@ process_arguments (int argc, char **argv) | |||
380 | } | 311 | } |
381 | else if (strpbrk (optarg, ",:") && | 312 | else if (strpbrk (optarg, ",:") && |
382 | strstr (optarg, "%") && | 313 | strstr (optarg, "%") && |
383 | sscanf (optarg, "%d%*[,:]%lf%%", &c_df, &c_dfp) == 2) { | 314 | sscanf (optarg, "%ul%*[,:]%lf%%", &c_df, &c_dfp) == 2) { |
384 | break; | 315 | break; |
385 | } | 316 | } |
386 | else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_dfp) == 1) { | 317 | else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_dfp) == 1) { |
@@ -391,19 +322,19 @@ process_arguments (int argc, char **argv) | |||
391 | } | 322 | } |
392 | case 'u': | 323 | case 'u': |
393 | if (! strcmp (optarg, "bytes")) { | 324 | if (! strcmp (optarg, "bytes")) { |
394 | mult = 1; | 325 | mult = (uintmax_t)1; |
395 | units = "B"; | 326 | units = "B"; |
396 | } else if (! strcmp (optarg, "kB")) { | 327 | } else if (! strcmp (optarg, "kB")) { |
397 | mult = 1024; | 328 | mult = (uintmax_t)1024; |
398 | units = "kB"; | 329 | units = "kB"; |
399 | } else if (! strcmp (optarg, "MB")) { | 330 | } else if (! strcmp (optarg, "MB")) { |
400 | mult = 1024 * 1024; | 331 | mult = (uintmax_t)1024 * 1024; |
401 | units = "MB"; | 332 | units = "MB"; |
402 | } else if (! strcmp (optarg, "GB")) { | 333 | } else if (! strcmp (optarg, "GB")) { |
403 | mult = 1024 * 1024 * 1024; | 334 | mult = (uintmax_t)1024 * 1024 * 1024; |
404 | units = "GB"; | 335 | units = "GB"; |
405 | } else if (! strcmp (optarg, "TB")) { | 336 | } else if (! strcmp (optarg, "TB")) { |
406 | mult = (unsigned long)1024 * 1024 * 1024 * 1024; | 337 | mult = (uintmax_t)1024 * 1024 * 1024 * 1024; |
407 | units = "TB"; | 338 | units = "TB"; |
408 | } else { | 339 | } else { |
409 | die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); | 340 | die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); |
@@ -458,8 +389,8 @@ process_arguments (int argc, char **argv) | |||
458 | display_mntp = TRUE; | 389 | display_mntp = TRUE; |
459 | break; | 390 | break; |
460 | case 'C': | 391 | case 'C': |
461 | w_df = -1; | 392 | w_df = 0; |
462 | c_df = -1; | 393 | c_df = 0; |
463 | w_dfp = -1.0; | 394 | w_dfp = -1.0; |
464 | c_dfp = -1.0; | 395 | c_dfp = -1.0; |
465 | break; | 396 | break; |
@@ -477,10 +408,10 @@ process_arguments (int argc, char **argv) | |||
477 | 408 | ||
478 | /* Support for "check_disk warn crit [fs]" with thresholds at used level */ | 409 | /* Support for "check_disk warn crit [fs]" with thresholds at used level */ |
479 | c = optind; | 410 | c = optind; |
480 | if (w_dfp == -1 && argc > c && is_intnonneg (argv[c])) | 411 | if (w_dfp < 0 && argc > c && is_intnonneg (argv[c])) |
481 | w_dfp = (100.0 - atof (argv[c++])); | 412 | w_dfp = (100.0 - atof (argv[c++])); |
482 | 413 | ||
483 | if (c_dfp == -1 && argc > c && is_intnonneg (argv[c])) | 414 | if (c_dfp < 0 && argc > c && is_intnonneg (argv[c])) |
484 | c_dfp = (100.0 - atof (argv[c++])); | 415 | c_dfp = (100.0 - atof (argv[c++])); |
485 | 416 | ||
486 | if (argc > c && strlen (path) == 0) { | 417 | if (argc > c && strlen (path) == 0) { |
@@ -520,9 +451,9 @@ void print_path (char *mypath) | |||
520 | } | 451 | } |
521 | 452 | ||
522 | int | 453 | int |
523 | validate_arguments (int w, int c, double wp, double cp, char *mypath) | 454 | validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, char *mypath) |
524 | { | 455 | { |
525 | if (w < 0 && c < 0 && wp < 0.0 && cp < 0.0) { | 456 | if (w == 0 && c == 0 && wp < 0.0 && cp < 0.0) { |
526 | printf (_("INPUT ERROR: No thresholds specified")); | 457 | printf (_("INPUT ERROR: No thresholds specified")); |
527 | print_path (mypath); | 458 | print_path (mypath); |
528 | return ERROR; | 459 | return ERROR; |
@@ -535,10 +466,10 @@ INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be betw | |||
535 | print_path (path); | 466 | print_path (path); |
536 | return ERROR; | 467 | return ERROR; |
537 | } | 468 | } |
538 | else if ((w > 0 || c > 0) && (w < 0 || c < 0 || c > w)) { | 469 | else if ((w > 0 || c > 0) && (w == 0 || c == 0 || c > w)) { |
539 | printf (_("\ | 470 | printf (_("\ |
540 | INPUT ERROR: C_DF (%d) should be less than W_DF (%d) and both should be greater than zero"), | 471 | INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greater than zero"), |
541 | c, w); | 472 | (unsigned long)c, (unsigned long)w); |
542 | print_path (path); | 473 | print_path (path); |
543 | return ERROR; | 474 | return ERROR; |
544 | } | 475 | } |
@@ -551,17 +482,17 @@ INPUT ERROR: C_DF (%d) should be less than W_DF (%d) and both should be greater | |||
551 | 482 | ||
552 | 483 | ||
553 | int | 484 | int |
554 | check_disk (int usp, int free_disk) | 485 | check_disk (int usp, uintmax_t free_disk) |
555 | { | 486 | { |
556 | int result = STATE_UNKNOWN; | 487 | int result = STATE_UNKNOWN; |
557 | /* check the percent used space against thresholds */ | 488 | /* check the percent used space against thresholds */ |
558 | if (usp >= 0 && usp >= (100.0 - c_dfp)) | 489 | if (usp >= 0.0 && usp >= (100.0 - c_dfp)) |
559 | result = STATE_CRITICAL; | 490 | result = STATE_CRITICAL; |
560 | else if (c_df >= 0 && free_disk <= c_df) | 491 | else if (c_df > 0 && free_disk <= c_df) |
561 | result = STATE_CRITICAL; | 492 | result = STATE_CRITICAL; |
562 | else if (usp >= 0 && usp >= (100.0 - w_dfp)) | 493 | else if (usp >= 0.0 && usp >= (100.0 - w_dfp)) |
563 | result = STATE_WARNING; | 494 | result = STATE_WARNING; |
564 | else if (w_df >= 0 && free_disk <= w_df) | 495 | else if (w_df > 0 && free_disk <= w_df) |
565 | result = STATE_WARNING; | 496 | result = STATE_WARNING; |
566 | else if (usp >= 0.0) | 497 | else if (usp >= 0.0) |
567 | result = STATE_OK; | 498 | result = STATE_OK; |
@@ -579,11 +510,92 @@ walk_name_list (struct name_list *list, const char *name) | |||
579 | /* if required for name_lists that have not saved w_df, etc (eg exclude lists) */ | 510 | /* if required for name_lists that have not saved w_df, etc (eg exclude lists) */ |
580 | if (list->w_df) w_df = list->w_df; | 511 | if (list->w_df) w_df = list->w_df; |
581 | if (list->c_df) c_df = list->c_df; | 512 | if (list->c_df) c_df = list->c_df; |
582 | if (list->w_dfp) w_dfp = list->w_dfp; | 513 | if (list->w_dfp>=0.0) w_dfp = list->w_dfp; |
583 | if (list->c_dfp) c_dfp = list->c_dfp; | 514 | if (list->c_dfp>=0.0) c_dfp = list->c_dfp; |
584 | return TRUE; | 515 | return TRUE; |
585 | } | 516 | } |
586 | list = list->name_next; | 517 | list = list->name_next; |
587 | } | 518 | } |
588 | return FALSE; | 519 | return FALSE; |
589 | } | 520 | } |
521 | |||
522 | |||
523 | |||
524 | |||
525 | |||
526 | |||
527 | void | ||
528 | print_help (void) | ||
529 | { | ||
530 | print_revision (progname, revision); | ||
531 | |||
532 | printf (_(COPYRIGHT), copyright, email); | ||
533 | |||
534 | printf (_("\ | ||
535 | This plugin checks the amount of used disk space on a mounted file system\n\ | ||
536 | and generates an alert if free space is less than one of the threshold values.")); | ||
537 | |||
538 | print_usage (); | ||
539 | |||
540 | printf (_(UT_HELP_VRSN)); | ||
541 | |||
542 | printf (_("\ | ||
543 | -w, --warning=INTEGER\n\ | ||
544 | Exit with WARNING status if less than INTEGER kilobytes of disk are free\n\ | ||
545 | -w, --warning=PERCENT%%\n\ | ||
546 | Exit with WARNING status if less than PERCENT of disk space is free\n\ | ||
547 | -c, --critical=INTEGER\n\ | ||
548 | Exit with CRITICAL status if less than INTEGER kilobytes of disk are free\n\ | ||
549 | -c, --critical=PERCENT%%\n\ | ||
550 | Exit with CRITCAL status if less than PERCENT of disk space is free\n\ | ||
551 | -C, --clear\n\ | ||
552 | Clear thresholds\n")); | ||
553 | |||
554 | printf (_("\ | ||
555 | -u, --units=STRING\n\ | ||
556 | Choose bytes, kB, MB, GB, TB (default: MB)\n\ | ||
557 | -k, --kilobytes\n\ | ||
558 | Same as '--units kB'\n\ | ||
559 | -m, --megabytes\n\ | ||
560 | Same as '--units MB'\n")); | ||
561 | |||
562 | printf (_("\ | ||
563 | -l, --local\n\ | ||
564 | Only check local filesystems\n\ | ||
565 | -p, --path=PATH, --partition=PARTITION\n\ | ||
566 | Path or partition (may be repeated)\n\ | ||
567 | -x, --exclude_device=PATH <STRING>\n\ | ||
568 | Ignore device (only works if -p unspecified)\n\ | ||
569 | -X, --exclude-type=TYPE <STRING>\n\ | ||
570 | Ignore all filesystems of indicated type (may be repeated)\n\ | ||
571 | -M, --mountpoint\n\ | ||
572 | Display the mountpoint instead of the partition\n\ | ||
573 | -e, --errors-only\n\ | ||
574 | Display only devices/mountpoints with errors\n")); | ||
575 | |||
576 | printf (_(UT_WARN_CRIT)); | ||
577 | |||
578 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
579 | |||
580 | printf (_(UT_VERBOSE)); | ||
581 | |||
582 | printf ("%s", _("Examples:\n\ | ||
583 | check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /\n\ | ||
584 | Checks /tmp and /var at 10%,5% and / at 100MB, 50MB\n")); | ||
585 | |||
586 | support (); | ||
587 | } | ||
588 | |||
589 | |||
590 | |||
591 | |||
592 | void | ||
593 | print_usage (void) | ||
594 | { | ||
595 | printf (_("\ | ||
596 | Usage: %s -w limit -c limit [-p path | -x device] [-t timeout] [-m] [-e]\n\ | ||
597 | [-v] [-q]\n\ | ||
598 | %s (-h|--help)\n\ | ||
599 | %s (-V|--version)\n"), | ||
600 | progname, progname, progname); | ||
601 | } | ||
diff --git a/plugins/check_nt.c b/plugins/check_nt.c index 91022bac..22e7757d 100644 --- a/plugins/check_nt.c +++ b/plugins/check_nt.c | |||
@@ -65,7 +65,7 @@ const char *progname = "check_nt"; | |||
65 | 65 | ||
66 | int process_arguments(int, char **); | 66 | int process_arguments(int, char **); |
67 | void preparelist(char *string); | 67 | void preparelist(char *string); |
68 | int strtoularray(unsigned long *array, char *string, char *delim); | 68 | int strtoularray(unsigned long *array, char *string, const char *delim); |
69 | void print_help(void); | 69 | void print_help(void); |
70 | void print_usage(void); | 70 | void print_usage(void); |
71 | 71 | ||
@@ -117,7 +117,7 @@ int main(int argc, char **argv){ | |||
117 | else if(vars_to_check==CHECK_CPULOAD){ | 117 | else if(vars_to_check==CHECK_CPULOAD){ |
118 | 118 | ||
119 | if (check_value_list==TRUE) { | 119 | if (check_value_list==TRUE) { |
120 | if (strtoularray(&lvalue_list,value_list,",")==TRUE) { | 120 | if (strtoularray(lvalue_list,value_list,",")==TRUE) { |
121 | /* -l parameters is present with only integers */ | 121 | /* -l parameters is present with only integers */ |
122 | return_code=STATE_OK; | 122 | return_code=STATE_OK; |
123 | asprintf(&temp_string,_("CPU Load")); | 123 | asprintf(&temp_string,_("CPU Load")); |
@@ -514,7 +514,7 @@ int process_arguments(int argc, char **argv){ | |||
514 | 514 | ||
515 | 515 | ||
516 | 516 | ||
517 | int strtoularray(unsigned long *array, char *string, char *delim) { | 517 | int strtoularray(unsigned long *array, char *string, const char *delim) { |
518 | /* split a <delim> delimited string into a long array */ | 518 | /* split a <delim> delimited string into a long array */ |
519 | int idx=0; | 519 | int idx=0; |
520 | char *t1; | 520 | char *t1; |
diff --git a/plugins/netutils.c b/plugins/netutils.c index 4ca3168d..92fd1420 100644 --- a/plugins/netutils.c +++ b/plugins/netutils.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include "common.h" | 32 | #include "common.h" |
33 | #include "netutils.h" | 33 | #include "netutils.h" |
34 | 34 | ||
35 | int socket_timeout = DEFAULT_SOCKET_TIMEOUT; | 35 | unsigned int socket_timeout = DEFAULT_SOCKET_TIMEOUT; |
36 | int econn_refuse_state = STATE_CRITICAL; | 36 | int econn_refuse_state = STATE_CRITICAL; |
37 | int was_refused = FALSE; | 37 | int was_refused = FALSE; |
38 | int address_family = AF_UNSPEC; | 38 | int address_family = AF_UNSPEC; |
@@ -131,7 +131,7 @@ process_tcp_request2 (char *server_address, int server_port, | |||
131 | else { /* it has */ | 131 | else { /* it has */ |
132 | recv_result = | 132 | recv_result = |
133 | recv (sd, recv_buffer + recv_length, | 133 | recv (sd, recv_buffer + recv_length, |
134 | recv_size - recv_length - 1, 0); | 134 | (size_t)recv_size - recv_length - 1, 0); |
135 | if (recv_result == -1) { | 135 | if (recv_result == -1) { |
136 | /* recv failed, bail out */ | 136 | /* recv failed, bail out */ |
137 | strcpy (recv_buffer + recv_length, ""); | 137 | strcpy (recv_buffer + recv_length, ""); |
@@ -201,7 +201,7 @@ process_request (char *server_address, int server_port, int proto, | |||
201 | } | 201 | } |
202 | 202 | ||
203 | else { | 203 | else { |
204 | recv_result = recv (sd, recv_buffer, recv_size - 1, 0); | 204 | recv_result = recv (sd, recv_buffer, (size_t)recv_size - 1, 0); |
205 | if (recv_result == -1) { | 205 | if (recv_result == -1) { |
206 | strcpy (recv_buffer, ""); | 206 | strcpy (recv_buffer, ""); |
207 | if (proto != IPPROTO_TCP) | 207 | if (proto != IPPROTO_TCP) |
diff --git a/plugins/netutils.h b/plugins/netutils.h index 8f534976..f5df7af6 100644 --- a/plugins/netutils.h +++ b/plugins/netutils.h | |||
@@ -34,7 +34,7 @@ | |||
34 | #include <netinet/in.h> | 34 | #include <netinet/in.h> |
35 | #include <arpa/inet.h> | 35 | #include <arpa/inet.h> |
36 | 36 | ||
37 | RETSIGTYPE socket_timeout_alarm_handler (int); | 37 | RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn)); |
38 | 38 | ||
39 | int process_tcp_request2 (char *address, int port, char *sbuffer, | 39 | int process_tcp_request2 (char *address, int port, char *sbuffer, |
40 | char *rbuffer, int rsize); | 40 | char *rbuffer, int rsize); |
@@ -58,7 +58,7 @@ int is_inet6_addr (char *); | |||
58 | #endif | 58 | #endif |
59 | int is_hostname (char *); | 59 | int is_hostname (char *); |
60 | 60 | ||
61 | extern int socket_timeout; | 61 | extern unsigned int socket_timeout; |
62 | extern int econn_refuse_state; | 62 | extern int econn_refuse_state; |
63 | extern int was_refused; | 63 | extern int was_refused; |
64 | extern int address_family; | 64 | extern int address_family; |
diff --git a/plugins/popen.h b/plugins/popen.h index a1af4be0..b7585792 100644 --- a/plugins/popen.h +++ b/plugins/popen.h | |||
@@ -2,7 +2,7 @@ FILE *spopen (const char *); | |||
2 | int spclose (FILE *); | 2 | int spclose (FILE *); |
3 | RETSIGTYPE popen_timeout_alarm_handler (int); | 3 | RETSIGTYPE popen_timeout_alarm_handler (int); |
4 | 4 | ||
5 | extern int timeout_interval; | 5 | extern unsigned int timeout_interval; |
6 | pid_t *childpid; | 6 | pid_t *childpid; |
7 | int *child_stderr_array; | 7 | int *child_stderr_array; |
8 | FILE *child_process; | 8 | FILE *child_process; |
diff --git a/plugins/utils.h b/plugins/utils.h index f36834f9..9dc2654c 100644 --- a/plugins/utils.h +++ b/plugins/utils.h | |||
@@ -16,16 +16,16 @@ suite of plugins. */ | |||
16 | void support (void); | 16 | void support (void); |
17 | char *clean_revstring (const char *revstring); | 17 | char *clean_revstring (const char *revstring); |
18 | void print_revision (const char *, const char *); | 18 | void print_revision (const char *, const char *); |
19 | void die (int result, const char *fmt, ...); | 19 | void die (int result, const char *fmt, ...) __attribute__((noreturn)); |
20 | 20 | ||
21 | /* Handle timeouts */ | 21 | /* Handle timeouts */ |
22 | 22 | ||
23 | #ifdef LOCAL_TIMEOUT_ALARM_HANDLER | 23 | #ifdef LOCAL_TIMEOUT_ALARM_HANDLER |
24 | extern int timeout_interval; | 24 | extern unsigned int timeout_interval; |
25 | RETSIGTYPE timeout_alarm_handler (int); | 25 | RETSIGTYPE timeout_alarm_handler (int) __attribute__((noreturn)); |
26 | #else | 26 | #else |
27 | int timeout_interval = DEFAULT_SOCKET_TIMEOUT; | 27 | unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT; |
28 | extern RETSIGTYPE timeout_alarm_handler (int); | 28 | extern RETSIGTYPE timeout_alarm_handler (int) __attribute__((noreturn)); |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | time_t start_time, end_time; | 31 | time_t start_time, end_time; |
@@ -72,9 +72,9 @@ char *strpcat (char *dest, const char *src, const char *str); | |||
72 | 72 | ||
73 | int max_state (int a, int b); | 73 | int max_state (int a, int b); |
74 | 74 | ||
75 | void usage (char *msg); | 75 | void usage (char *msg) __attribute__((noreturn)); |
76 | void usage2(char *msg, char *arg); | 76 | void usage2(char *msg, char *arg) __attribute__((noreturn)); |
77 | void usage3(char *msg, char arg); | 77 | void usage3(char *msg, char arg) __attribute__((noreturn)); |
78 | 78 | ||
79 | char *state_text (int result); | 79 | char *state_text (int result); |
80 | 80 | ||