summaryrefslogtreecommitdiffstats
path: root/plugins/t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 8bdf64b..9de3fad 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -19,18 +19,49 @@
19const char *progname = "check_disk"; 19const char *progname = "check_disk";
20const char *revision = "$Revision$"; 20const char *revision = "$Revision$";
21const char *copyright = "1999-2003"; 21const char *copyright = "1999-2003";
22const char *authors = "Nagios Plugin Development Team";
23const char *email = "nagiosplug-devel@lists.sourceforge.net"; 22const char *email = "nagiosplug-devel@lists.sourceforge.net";
24 23
25const char *summary = "\ 24#include "common.h"
25#if HAVE_INTTYPES_H
26# include <inttypes.h>
27#endif
28#include <assert.h>
29#include "popen.h"
30#include "utils.h"
31#include <stdarg.h>
32#include "../lib/fsusage.h"
33#include "../lib/mountlist.h"
34#if HAVE_LIMITS_H
35# include <limits.h>
36#endif
37
38void
39print_usage (void)
40{
41 printf (_("\
42Usage: %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
49void
50print_help (void)
51{
52 print_revision (progname, revision);
53
54 printf (_(COPYRIGHT), copyright, email);
55
56 printf (_("\
26This plugin checks the amount of used disk space on a mounted file system\n\ 57This plugin checks the amount of used disk space on a mounted file system\n\
27and generates an alert if free space is less than one of the threshold values."; 58and generates an alert if free space is less than one of the threshold values."));
28 59
29const char *option_summary = "\ 60 print_usage ();
30-w limit -c limit [-p path | -x device] [-t timeout] [-m] [-e]\n\
31 [-v] [-q]";
32 61
33const char *options = "\ 62 printf (_(HELP_VRSN));
63
64 printf (_("\
34 -w, --warning=INTEGER\n\ 65 -w, --warning=INTEGER\n\
35 Exit with WARNING status if less than INTEGER kilobytes of disk are free\n\ 66 Exit with WARNING status if less than INTEGER kilobytes of disk are free\n\
36 -w, --warning=PERCENT%%\n\ 67 -w, --warning=PERCENT%%\n\
@@ -39,12 +70,18 @@ const char *options = "\
39 Exit with CRITICAL status if less than INTEGER kilobytes of disk are free\n\ 70 Exit with CRITICAL status if less than INTEGER kilobytes of disk are free\n\
40 -c, --critical=PERCENT%%\n\ 71 -c, --critical=PERCENT%%\n\
41 Exit with CRITCAL status if less than PERCENT of disk space is free\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 (_("\
42 -u, --units=STRING\n\ 77 -u, --units=STRING\n\
43 Choose bytes, kB, MB, GB, TB (default: MB)\n\ 78 Choose bytes, kB, MB, GB, TB (default: MB)\n\
44 -k, --kilobytes\n\ 79 -k, --kilobytes\n\
45 Same as '--units kB'\n\ 80 Same as '--units kB'\n\
46 -m, --megabytes\n\ 81 -m, --megabytes\n\
47 Same as '--units MB'\n\ 82 Same as '--units MB'\n"));
83
84 printf (_("\
48 -l, --local\n\ 85 -l, --local\n\
49 Only check local filesystems\n\ 86 Only check local filesystems\n\
50 -p, --path=PATH, --partition=PARTITION\n\ 87 -p, --path=PATH, --partition=PARTITION\n\
@@ -56,40 +93,22 @@ const char *options = "\
56 -M, --mountpoint\n\ 93 -M, --mountpoint\n\
57 Display the mountpoint instead of the partition\n\ 94 Display the mountpoint instead of the partition\n\
58 -e, --errors-only\n\ 95 -e, --errors-only\n\
59 Display only devices/mountpoints with errors\n\ 96 Display only devices/mountpoints with errors\n"));
60 -C, --clear\n\ 97
61 Clear thresholds\n\ 98 printf (_(TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
62 -v, --verbose\n\ 99
63 Show details for command-line debugging (do not use with nagios server)\n\ 100 printf (_(VRBS));
64 -h, --help\n\ 101
65 Print detailed help screen\n\ 102 printf ("%s", _("Examples:\n\
66 -V, --version\n\
67 Print version information\n";
68
69const char *notes = "\
70\n";
71
72const char *examples = "\
73 check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /\n\ 103 check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /\n\
74 Checks /tmp and /var at 10%,5% and / at 100MB, 50MB\n\ 104 Checks /tmp and /var at 10%,5% and / at 100MB, 50MB\n"));
75\n";
76 105
77#include "common.h" 106 support ();
78#if HAVE_INTTYPES_H 107}
79# include <inttypes.h> 108
80#endif
81#include <assert.h>
82#include "popen.h"
83#include "utils.h"
84#include <stdarg.h>
85#include "../lib/fsusage.h"
86#include "../lib/mountlist.h"
87#if HAVE_LIMITS_H
88# include <limits.h>
89#endif
90 109
91/* If nonzero, show inode information. */ 110/* If nonzero, show inode information. */
92static int inode_format; 111/* static int inode_format; */
93 112
94/* If nonzero, show even filesystems with zero size or 113/* If nonzero, show even filesystems with zero size or
95 uninteresting types. */ 114 uninteresting types. */
@@ -100,13 +119,13 @@ static int show_local_fs = 0;
100 119
101/* If positive, the units to use when printing sizes; 120/* If positive, the units to use when printing sizes;
102 if negative, the human-readable base. */ 121 if negative, the human-readable base. */
103static int output_block_size; 122/* static int output_block_size; */
104 123
105/* If nonzero, invoke the `sync' system call before getting any usage data. 124/* If nonzero, invoke the `sync' system call before getting any usage data.
106 Using this option can make df very slow, especially with many or very 125 Using this option can make df very slow, especially with many or very
107 busy disks. Note that this may make a difference on some systems -- 126 busy disks. Note that this may make a difference on some systems --
108 SunOs4.1.3, for one. It is *not* necessary on Linux. */ 127 SunOs4.1.3, for one. It is *not* necessary on Linux. */
109static int require_sync = 0; 128/* static int require_sync = 0; */
110 129
111/* A filesystem type to display. */ 130/* A filesystem type to display. */
112 131
@@ -116,8 +135,8 @@ struct name_list
116 int found; 135 int found;
117 int w_df; 136 int w_df;
118 int c_df; 137 int c_df;
119 float w_dfp; 138 double w_dfp;
120 float c_dfp; 139 double c_dfp;
121 struct name_list *name_next; 140 struct name_list *name_next;
122}; 141};
123 142
@@ -132,7 +151,7 @@ struct name_list
132 Some filesystem types: 151 Some filesystem types:
133 4.2 4.3 ufs nfs swap ignore io vm efs dbg */ 152 4.2 4.3 ufs nfs swap ignore io vm efs dbg */
134 153
135static struct name_list *fs_select_list; 154/* static struct name_list *fs_select_list; */
136 155
137/* Linked list of filesystem types to omit. 156/* Linked list of filesystem types to omit.
138 If the list is empty, don't exclude any types. */ 157 If the list is empty, don't exclude any types. */
@@ -162,16 +181,14 @@ enum
162#endif 181#endif
163 182
164int process_arguments (int, char **); 183int process_arguments (int, char **);
165int validate_arguments (int, int, float, float, char *); 184int validate_arguments (int, int, double, double, char *);
166int check_disk (int usp, int free_disk); 185int check_disk (int usp, int free_disk);
167int walk_name_list (struct name_list *list, const char *name); 186int walk_name_list (struct name_list *list, const char *name);
168void print_help (void);
169void print_usage (void);
170 187
171int w_df = -1; 188int w_df = -1;
172int c_df = -1; 189int c_df = -1;
173float w_dfp = -1.0; 190double w_dfp = -1.0;
174float c_dfp = -1.0; 191double c_dfp = -1.0;
175char *path = ""; 192char *path = "";
176char *exclude_device = ""; 193char *exclude_device = "";
177char *units = "MB"; 194char *units = "MB";
@@ -187,15 +204,9 @@ int
187main (int argc, char **argv) 204main (int argc, char **argv)
188{ 205{
189 int usp = -1; 206 int usp = -1;
190 int total_disk = -1;
191 int used_disk = -1;
192 int free_disk = -1;
193 int result = STATE_UNKNOWN; 207 int result = STATE_UNKNOWN;
194 int disk_result = STATE_UNKNOWN; 208 int disk_result = STATE_UNKNOWN;
195 char *command_line = "";
196 char input_buffer[MAX_INPUT_BUFFER];
197 char file_system[MAX_INPUT_BUFFER]; 209 char file_system[MAX_INPUT_BUFFER];
198 char mntp[MAX_INPUT_BUFFER];
199 char *output = ""; 210 char *output = "";
200 char *details = ""; 211 char *details = "";
201 float free_space, free_space_pct, total_space; 212 float free_space, free_space_pct, total_space;
@@ -203,12 +214,11 @@ main (int argc, char **argv)
203 struct mount_entry *me; 214 struct mount_entry *me;
204 struct fs_usage fsp; 215 struct fs_usage fsp;
205 struct name_list *temp_list; 216 struct name_list *temp_list;
206 char *disk;
207 217
208 mount_list = read_filesystem_list (0); 218 mount_list = read_filesystem_list (0);
209 219
210 if (process_arguments (argc, argv) != OK) 220 if (process_arguments (argc, argv) != OK)
211 usage ("Could not parse arguments\n"); 221 usage (_("Could not parse arguments\n"));
212 222
213 for (me = mount_list; me; me = me->me_next) { 223 for (me = mount_list; me; me = me->me_next) {
214 224
@@ -225,8 +235,8 @@ main (int argc, char **argv)
225 else if (fs_exclude_list && walk_name_list (fs_exclude_list, me->me_type)) 235 else if (fs_exclude_list && walk_name_list (fs_exclude_list, me->me_type))
226 continue; 236 continue;
227 else if (dp_exclude_list && 237 else if (dp_exclude_list &&
228 walk_name_list (dp_exclude_list, me->me_devname) || 238 (walk_name_list (dp_exclude_list, me->me_devname) ||
229 walk_name_list (dp_exclude_list, me->me_mountdir)) 239 walk_name_list (dp_exclude_list, me->me_mountdir)))
230 continue; 240 continue;
231 else 241 else
232 get_fs_usage (me->me_mountdir, me->me_devname, &fsp); 242 get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
@@ -242,13 +252,13 @@ main (int argc, char **argv)
242 free_space_pct = (float)fsp.fsu_bavail*100/fsp.fsu_blocks; 252 free_space_pct = (float)fsp.fsu_bavail*100/fsp.fsu_blocks;
243 total_space = (float)fsp.fsu_blocks*fsp.fsu_blocksize/mult; 253 total_space = (float)fsp.fsu_blocks*fsp.fsu_blocksize/mult;
244 if (disk_result!=STATE_OK || verbose>=0) 254 if (disk_result!=STATE_OK || verbose>=0)
245 asprintf (&output, "%s [%.0f %s (%.0f%%) free on %s]", 255 asprintf (&output, ("%s [%.0f %s (%.0f%%) free on %s]"),
246 output, 256 output,
247 free_space, 257 free_space,
248 units, 258 units,
249 free_space_pct, 259 free_space_pct,
250 (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir); 260 (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir);
251 asprintf (&details, "%s\n%.0f of %.0f %s (%.0f%%) free on %s (type %s mounted on %s) warn:%d crit:%d warn%%:%.0f%% crit%%:%.0f%%", 261 asprintf (&details, _("%s\n%.0f of %.0f %s (%.0f%%) free on %s (type %s mounted on %s) warn:%d crit:%d warn%%:%.0f%% crit%%:%.0f%%"),
252 details, 262 details,
253 free_space, 263 free_space,
254 total_space, 264 total_space,
@@ -269,13 +279,14 @@ main (int argc, char **argv)
269 temp_list = path_select_list; 279 temp_list = path_select_list;
270 while (temp_list) { 280 while (temp_list) {
271 if (temp_list->found != TRUE) { 281 if (temp_list->found != TRUE) {
272 asprintf (&output, "%s [%s not found]", output, temp_list->name); 282 asprintf (&output, _("%s [%s not found]"), output, temp_list->name);
273 result = STATE_CRITICAL; 283 result = STATE_CRITICAL;
274 } 284 }
275 temp_list = temp_list->name_next; 285 temp_list = temp_list->name_next;
276 } 286 }
277 287
278 terminate (result, "DISK %s%s\n", state_text (result), output, details); 288 terminate (result, "DISK %s%s\n", state_text (result), output, details);
289 return STATE_UNKNOWN;
279} 290}
280 291
281 292
@@ -288,7 +299,6 @@ process_arguments (int argc, char **argv)
288 int c; 299 int c;
289 struct name_list *se; 300 struct name_list *se;
290 struct name_list **pathtail = &path_select_list; 301 struct name_list **pathtail = &path_select_list;
291 struct name_list **devtail = &dev_select_list;
292 struct name_list **fstail = &fs_exclude_list; 302 struct name_list **fstail = &fs_exclude_list;
293 struct name_list **dptail = &dp_exclude_list; 303 struct name_list **dptail = &dp_exclude_list;
294 struct name_list *temp_list; 304 struct name_list *temp_list;
@@ -343,39 +353,39 @@ process_arguments (int argc, char **argv)
343 break; 353 break;
344 } 354 }
345 else { 355 else {
346 usage ("Timeout Interval must be an integer!\n"); 356 usage (_("Timeout Interval must be an integer!\n"));
347 } 357 }
348 case 'w': /* warning time threshold */ 358 case 'w': /* warning threshold */
349 if (is_intnonneg (optarg)) { 359 if (is_intnonneg (optarg)) {
350 w_df = atoi (optarg); 360 w_df = atoi (optarg);
351 break; 361 break;
352 } 362 }
353 else if (strpbrk (optarg, ",:") && 363 else if (strpbrk (optarg, ",:") &&
354 strstr (optarg, "%") && 364 strstr (optarg, "%") &&
355 sscanf (optarg, "%d%*[:,]%f%%", &w_df, &w_dfp) == 2) { 365 sscanf (optarg, "%d%*[:,]%lf%%", &w_df, &w_dfp) == 2) {
356 break; 366 break;
357 } 367 }
358 else if (strstr (optarg, "%") && sscanf (optarg, "%f%%", &w_dfp) == 1) { 368 else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_dfp) == 1) {
359 break; 369 break;
360 } 370 }
361 else { 371 else {
362 usage ("Warning threshold must be integer or percentage!\n"); 372 usage (_("Warning threshold must be integer or percentage!\n"));
363 } 373 }
364 case 'c': /* critical time threshold */ 374 case 'c': /* critical threshold */
365 if (is_intnonneg (optarg)) { 375 if (is_intnonneg (optarg)) {
366 c_df = atoi (optarg); 376 c_df = atoi (optarg);
367 break; 377 break;
368 } 378 }
369 else if (strpbrk (optarg, ",:") && 379 else if (strpbrk (optarg, ",:") &&
370 strstr (optarg, "%") && 380 strstr (optarg, "%") &&
371 sscanf (optarg, "%d%*[,:]%f%%", &c_df, &c_dfp) == 2) { 381 sscanf (optarg, "%d%*[,:]%lf%%", &c_df, &c_dfp) == 2) {
372 break; 382 break;
373 } 383 }
374 else if (strstr (optarg, "%") && sscanf (optarg, "%f%%", &c_dfp) == 1) { 384 else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_dfp) == 1) {
375 break; 385 break;
376 } 386 }
377 else { 387 else {
378 usage ("Critical threshold must be integer or percentage!\n"); 388 usage (_("Critical threshold must be integer or percentage!\n"));
379 } 389 }
380 case 'u': 390 case 'u':
381 if (! strcmp (optarg, "bytes")) { 391 if (! strcmp (optarg, "bytes")) {
@@ -394,7 +404,7 @@ process_arguments (int argc, char **argv)
394 mult = (unsigned long)1024 * 1024 * 1024 * 1024; 404 mult = (unsigned long)1024 * 1024 * 1024 * 1024;
395 units = "TB"; 405 units = "TB";
396 } else { 406 } else {
397 terminate (STATE_UNKNOWN, "unit type %s not known\n", optarg); 407 terminate (STATE_UNKNOWN, _("unit type %s not known\n"), optarg);
398 } 408 }
399 break; 409 break;
400 case 'k': /* display mountpoint */ 410 case 'k': /* display mountpoint */
@@ -458,7 +468,7 @@ process_arguments (int argc, char **argv)
458 print_help (); 468 print_help ();
459 exit (STATE_OK); 469 exit (STATE_OK);
460 case '?': /* help */ 470 case '?': /* help */
461 usage ("check_disk: unrecognized option\n"); 471 usage (_("check_disk: unrecognized option\n"));
462 break; 472 break;
463 } 473 }
464 } 474 }
@@ -485,7 +495,11 @@ process_arguments (int argc, char **argv)
485 if (path_select_list) { 495 if (path_select_list) {
486 temp_list = path_select_list; 496 temp_list = path_select_list;
487 while (temp_list) { 497 while (temp_list) {
488 if (validate_arguments (temp_list->w_df, temp_list->c_df, temp_list->w_dfp, temp_list->c_dfp, temp_list->name) == ERROR) 498 if (validate_arguments (temp_list->w_df,
499 temp_list->c_df,
500 temp_list->w_dfp,
501 temp_list->c_dfp,
502 temp_list->name) == ERROR)
489 result = ERROR; 503 result = ERROR;
490 temp_list = temp_list->name_next; 504 temp_list = temp_list->name_next;
491 } 505 }
@@ -496,34 +510,33 @@ process_arguments (int argc, char **argv)
496} 510}
497 511
498 512
499void print_path (char *path) 513void print_path (char *mypath)
500{ 514{
501 if (path) 515 if (mypath)
502 printf (" for %s", path); 516 printf (" for %s", mypath);
503 printf ("\n"); 517 printf ("\n");
504} 518}
505 519
506int 520int
507validate_arguments (int w, int c, float wp, float cp, char *path) 521validate_arguments (int w, int c, double wp, double cp, char *mypath)
508{ 522{
509 if (w < 0 && c < 0 && wp < 0 && cp < 0) { 523 if (w < 0 && c < 0 && wp < 0.0 && cp < 0.0) {
510 printf ("INPUT ERROR: No thresholds specified"); 524 printf (_("INPUT ERROR: No thresholds specified"));
511 print_path (path); 525 print_path (mypath);
512 return ERROR; 526 return ERROR;
513 } 527 }
514 else if ((wp >= 0 || cp >= 0) 528 else if ((wp >= 0.0 || cp >= 0.0) &&
515 && (wp < 0 || cp < 0 || wp > 100 || cp > 100 529 (wp < 0.0 || cp < 0.0 || wp > 100.0 || cp > 100.0 || cp > wp)) {
516 || cp > wp)) { 530 printf (_("\
517 printf 531INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be between zero and 100 percent, inclusive"),
518 ("INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be between zero and 100 percent, inclusive", 532 cp, wp);
519 cp, wp);
520 print_path (path); 533 print_path (path);
521 return ERROR; 534 return ERROR;
522 } 535 }
523 else if ((w > 0 || c > 0) && (w < 0 || c < 0 || c > w)) { 536 else if ((w > 0 || c > 0) && (w < 0 || c < 0 || c > w)) {
524 printf 537 printf (_("\
525 ("INPUT ERROR: C_DF (%d) should be less than W_DF (%d) and both should be greater than zero", 538INPUT ERROR: C_DF (%d) should be less than W_DF (%d) and both should be greater than zero"),
526 c, w); 539 c, w);
527 print_path (path); 540 print_path (path);
528 return ERROR; 541 return ERROR;
529 } 542 }
@@ -572,29 +585,3 @@ walk_name_list (struct name_list *list, const char *name)
572 } 585 }
573 return FALSE; 586 return FALSE;
574} 587}
575
576
577
578
579void
580print_help (void)
581{
582 print_revision (progname, revision);
583 printf ("Copyright (c) %s %s\n\t<%s>\n\n%s\n",
584 copyright, authors, email, summary);
585 print_usage ();
586 printf ("\nOptions:\n");
587 printf (options);
588 printf (notes);
589 printf ("Examples:\n%s", examples);
590 support ();
591}
592
593void
594print_usage (void)
595{
596 printf
597 ("Usage: %s %s\n"
598 " %s (-h|--help)\n"
599 " %s (-V|--version)\n", progname, option_summary, progname, progname);
600}
diff --git a/plugins/utils.h b/plugins/utils.h
index 8a6ffa1..d95422a 100644
--- a/plugins/utils.h
+++ b/plugins/utils.h
@@ -122,3 +122,7 @@ char *state_text (int result);
122 Response time to result in critical status (seconds)\n\ 122 Response time to result in critical status (seconds)\n\
123 -t, --timeout=INTEGER\n\ 123 -t, --timeout=INTEGER\n\
124 Seconds before connection times out (default: %d)\n" 124 Seconds before connection times out (default: %d)\n"
125
126#define TIMEOUT "\
127 -t, --timeout=INTEGER\n\
128 Seconds before connection times out (default: %d)\n"