diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index bd060218a8aba6504220faeca8252b17a068c357..7841c14b755746404d7e027eefd2c0573405f5bb 100644 (file)
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
*****************************************************************************/
const char *progname = "check_disk";
+const char *program_name = "check_disk"; // Required for coreutils libs
const char *revision = "$Revision$";
const char *copyright = "1999-2003";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#endif
int process_arguments (int, char **);
-void print_path (char *mypath);
+void print_path (const char *mypath);
int validate_arguments (uintmax_t, uintmax_t, double, double, char *);
int check_disk (double usp, uintmax_t free_disk);
int walk_name_list (struct name_list *list, const char *name);
char file_system[MAX_INPUT_BUFFER];
char *output;
char *details;
+ char *perf;
+ uintmax_t psize;
float free_space, free_space_pct, total_space;
struct mount_entry *me;
struct fs_usage fsp;
struct name_list *temp_list;
- output = strdup ("");
+ output = strdup (" - free space:");
details = strdup ("");
+ perf = strdup ("");
+
+ setlocale (LC_ALL, "");
+ bindtextdomain (PACKAGE, LOCALEDIR);
+ textdomain (PACKAGE);
mount_list = read_filesystem_list (0);
if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) {
usp = (double)(fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks;
- disk_result = check_disk (usp, fsp.fsu_bavail);
+ disk_result = check_disk (usp, fsp.fsu_bavail * fsp.fsu_blocksize);
result = max_state (disk_result, result);
+ psize = fsp.fsu_blocks*fsp.fsu_blocksize/mult;
+ asprintf (&perf, "%s %s", perf,
+ perfdata ((!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
+ psize-(fsp.fsu_bavail*fsp.fsu_blocksize/mult), units,
+ TRUE, min ((uintmax_t)psize-(uintmax_t)w_df, (uintmax_t)((1.0-w_dfp/100.0)*psize)),
+ TRUE, min ((uintmax_t)psize-(uintmax_t)c_df, (uintmax_t)((1.0-c_dfp/100.0)*psize)),
+ TRUE, 0,
+ TRUE, psize));
if (disk_result==STATE_OK && erronly && !verbose)
continue;
free_space_pct = (float)fsp.fsu_bavail*100/fsp.fsu_blocks;
total_space = (float)fsp.fsu_blocks*fsp.fsu_blocksize/mult;
if (disk_result!=STATE_OK || verbose>=0)
- asprintf (&output, ("%s [%.0f %s (%.0f%%) free on %s]"),
+ asprintf (&output, ("%s %s %.0f %s (%.0f%%);"),
output,
+ (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
free_space,
units,
- free_space_pct,
- (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir);
+ free_space_pct);
asprintf (&details, _("%s\n\
%.0f of %.0f %s (%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
details, free_space, total_space, units, free_space_pct,
}
+ asprintf (&output, "%s|%s", output, perf);
+
if (verbose > 2)
asprintf (&output, "%s%s", output, details);
temp_list = temp_list->name_next;
}
- die (result, "DISK %s%s\n", state_text (result), output, details);
- return STATE_UNKNOWN;
+ printf ("DISK %s%s\n", state_text (result), output);
+ return result;
}
unsigned long l;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"timeout", required_argument, 0, 't'},
{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
strcpy (argv[c], "-t");
while (1) {
- c = getopt_long (argc, argv, "+?VqhveCt:c:w:u:p:x:X:mklM", long_options, &option_index);
+ c = getopt_long (argc, argv, "+?VqhveCt:c:w:u:p:x:X:mklM", longopts, &option);
if (c == -1 || c == EOF)
break;
mult = 1024 * 1024;
if (units)
free(units);
- units = strdup ("kB");
+ units = strdup ("MB");
break;
case 'l':
show_local_fs = 1;
break;
case 'p': /* select path */
se = (struct name_list *) malloc (sizeof (struct name_list));
- se->name = strdup (optarg);
+ se->name = optarg;
se->name_next = NULL;
se->w_df = w_df;
se->c_df = c_df;
break;
case 'x': /* exclude path or partition */
se = (struct name_list *) malloc (sizeof (struct name_list));
- se->name = strdup (optarg);
+ se->name = optarg;
se->name_next = NULL;
+ se->w_df = 0;
+ se->c_df = 0;
+ se->w_dfp = -1.0;
+ se->c_dfp = -1.0;
*dptail = se;
dptail = &se->name_next;
break;
case 'X': /* exclude file system type */
se = (struct name_list *) malloc (sizeof (struct name_list));
- se->name = strdup (optarg);
+ se->name = optarg;
se->name_next = NULL;
+ se->w_df = 0;
+ se->c_df = 0;
+ se->w_dfp = -1.0;
+ se->c_dfp = -1.0;
*fstail = se;
fstail = &se->name_next;
break;
}
-void print_path (char *mypath)
+void
+print_path (const char *mypath)
{
- if (mypath)
- printf (" for %s", mypath);
- printf ("\n");
+ if (mypath == NULL)
+ printf ("\n");
+ else
+ printf (" for %s\n", mypath);
+
+ return;
}
int
@@ -473,14 +503,14 @@ validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, char *mypath
printf (_("\
INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be between zero and 100 percent, inclusive"),
cp, wp);
- print_path (path);
+ print_path (mypath);
return ERROR;
}
else if ((w > 0 || c > 0) && (w == 0 || c == 0 || c > w)) {
printf (_("\
INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greater than zero"),
(unsigned long)c, (unsigned long)w);
- print_path (path);
+ print_path (mypath);
return ERROR;
}
{
int result = STATE_UNKNOWN;
/* check the percent used space against thresholds */
- if (usp >= 0.0 && usp >= (100.0 - c_dfp))
+ if (usp >= 0.0 && c_dfp >=0.0 && usp >= (100.0 - c_dfp))
result = STATE_CRITICAL;
else if (c_df > 0 && free_disk <= c_df)
result = STATE_CRITICAL;
- else if (usp >= 0.0 && usp >= (100.0 - w_dfp))
+ else if (usp >= 0.0 && w_dfp >=0.0 && usp >= (100.0 - w_dfp))
result = STATE_WARNING;
else if (w_df > 0 && free_disk <= w_df)
result = STATE_WARNING;
{
print_revision (progname, revision);
+ printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"));
printf (_(COPYRIGHT), copyright, email);
printf (_("\
@@ -596,7 +627,7 @@ and generates an alert if free space is less than one of the threshold values.")
check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /\n\
Checks /tmp and /var at 10%,5% and / at 100MB, 50MB\n"));
- support ();
+ printf (_(UT_SUPPORT));
}