Code

check_dns needs a space between 'time' and the hostname
[nagiosplug.git] / plugins / check_disk.c
index cb5e49e6da2daf686f4a8dfd5670121a034b4ee0..669a1cd6b1fd62d9488b887a3e748f08a9288da1 100644 (file)
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+ $Id$
 *****************************************************************************/
 
 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 *copyright = "1999-2004";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 #include "common.h"
@@ -111,7 +114,7 @@ enum
 int process_arguments (int, char **);
 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 check_disk (double usp, double free_disk);
 int walk_name_list (struct name_list *list, const char *name);
 void print_help (void);
 void print_usage (void);
@@ -132,7 +135,7 @@ int display_mntp = FALSE;
 static struct mount_entry *mount_list;
 
 
-\f
+
 int
 main (int argc, char **argv)
 {
@@ -160,8 +163,8 @@ main (int argc, char **argv)
 
        mount_list = read_filesystem_list (0);
 
-       if (process_arguments (argc, argv) != OK)
-               usage (_("Could not parse arguments\n"));
+       if (process_arguments (argc, argv) == ERROR)
+               usage4 (_("Could not parse arguments"));
 
        for (me = mount_list; me; me = me->me_next) {
 
@@ -186,12 +189,12 @@ main (int argc, char **argv)
 
                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 * fsp.fsu_blocksize);
+                       disk_result = check_disk (usp, (double)(fsp.fsu_bavail * fsp.fsu_blocksize / mult));
                        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,
-                                           fsp.fsu_bavail*fsp.fsu_blocksize/mult, units,
+                                           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,
@@ -239,7 +242,6 @@ main (int argc, char **argv)
 
 
 
-\f
 /* process command-line arguments */
 int
 process_arguments (int argc, char **argv)
@@ -303,7 +305,7 @@ process_arguments (int argc, char **argv)
                                break;
                        }
                        else {
-                               usage (_("Timeout Interval must be an integer!\n"));
+                               usage2 (_("Timeout interval must be a positive integer"), optarg);
                        }
                case 'w':                                                                       /* warning threshold */
                        if (is_intnonneg (optarg)) {
@@ -320,7 +322,7 @@ process_arguments (int argc, char **argv)
                                break;
                        }
                        else {
-                               usage (_("Warning threshold must be integer or percentage!\n"));
+                               usage4 (_("Warning threshold must be integer or percentage!"));
                        }
                case 'c':                                                                       /* critical threshold */
                        if (is_intnonneg (optarg)) {
@@ -337,7 +339,7 @@ process_arguments (int argc, char **argv)
                                break;
                        }
                        else {
-                               usage (_("Critical threshold must be integer or percentage!\n"));
+                               usage4 (_("Critical threshold must be integer or percentage!"));
                        }
                case 'u':
                        if (units)
@@ -373,7 +375,7 @@ process_arguments (int argc, char **argv)
                        mult = 1024 * 1024;
                        if (units)
                                free(units);
-                       units = strdup ("kB");
+                       units = strdup ("MB");
                        break;
                case 'l':
                        show_local_fs = 1;                      
@@ -436,8 +438,9 @@ process_arguments (int argc, char **argv)
                        print_help ();
                        exit (STATE_OK);
                case '?':                                                                       /* help */
-                       usage (_("check_disk: unrecognized option\n"));
-                       break;
+                       printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
+                       print_usage ();
+                       exit (STATE_UNKNOWN);
                }
        }
 
@@ -478,6 +481,7 @@ process_arguments (int argc, char **argv)
 }
 
 
+
 void
 print_path (const char *mypath) 
 {
@@ -489,10 +493,12 @@ print_path (const char *mypath)
        return;
 }
 
+
+
 int
 validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, char *mypath)
 {
-       if (w == 0 && c == 0 && wp < 0.0 && cp < 0.0) {
+       if (w < 0 && c < 0 && wp < 0.0 && cp < 0.0) {
                printf (_("INPUT ERROR: No thresholds specified"));
                print_path (mypath);
                return ERROR;
@@ -522,9 +528,8 @@ INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greate
 
 
 
-\f
 int
-check_disk (double usp, uintmax_t free_disk)
+check_disk (double usp, double free_disk)
 {
        int result = STATE_UNKNOWN;
        /* check the percent used space against thresholds */
@@ -563,20 +568,17 @@ walk_name_list (struct name_list *list, const char *name)
 
 
 
-
-
-\f
 void
 print_help (void)
 {
        print_revision (progname, revision);
 
-       printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"));
-       printf (_(COPYRIGHT), copyright, email);
+       printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
+       printf (COPYRIGHT, copyright, email);
 
        printf (_("\
 This plugin checks the amount of used disk space on a mounted file system\n\
-and generates an alert if free space is less than one of the threshold values."));
+and generates an alert if free space is less than one of the threshold values.\n\n"));
 
        print_usage ();
 
@@ -584,11 +586,11 @@ and generates an alert if free space is less than one of the threshold values.")
 
        printf (_("\
  -w, --warning=INTEGER\n\
-   Exit with WARNING status if less than INTEGER kilobytes of disk are free\n\
+   Exit with WARNING status if less than INTEGER --units of disk are free\n\
  -w, --warning=PERCENT%%\n\
    Exit with WARNING status if less than PERCENT of disk space is free\n\
  -c, --critical=INTEGER\n\
-   Exit with CRITICAL status if less than INTEGER kilobytes of disk are free\n\
+   Exit with CRITICAL status if less than INTEGER --units of disk are free\n\
  -c, --critical=PERCENT%%\n\
    Exit with CRITCAL status if less than PERCENT of disk space is free\n\
  -C, --clear\n\
@@ -631,14 +633,10 @@ and generates an alert if free space is less than one of the threshold values.")
 
 
 
-
 void
 print_usage (void)
 {
-       printf (_("\
+       printf ("\
 Usage: %s -w limit -c limit [-p path | -x device] [-t timeout] [-m] [-e]\n\
-        [-v] [-q]\n\
-       %s (-h|--help)\n\
-       %s (-V|--version)\n"),
-               progname,  progname, progname);
+                  [-v] [-q]\n", progname);
 }