Code

Updated help file to remove swap -s reference (Sivakumar Nellurandi)
[nagiosplug.git] / plugins / check_swap.c
index fe9254d299112094db4d7833c613a6058dae8b5a..a3f4df4482c012b74f23ced67be7845d4cc43cd5 100644 (file)
@@ -42,8 +42,8 @@ void print_help (void);
 
 int warn_percent = 0;
 int crit_percent = 0;
-float warn_size = 0;
-float crit_size = 0;
+double warn_size = 0;
+double crit_size = 0;
 int verbose;
 int allswaps;
 
@@ -310,7 +310,13 @@ main (int argc, char **argv)
 # endif /* HAVE_SWAP */
 #endif /* HAVE_PROC_MEMINFO */
 
-       percent_used = 100 * ((double) used_swap) / ((double) total_swap);
+       /* if total_swap == 0, let's not divide by 0 */
+       if(total_swap) {
+               percent_used = 100 * ((double) used_swap) / ((double) total_swap);
+       } else {
+               percent_used = 0;
+       }
+
        result = max_state (result, check_swap (percent_used, free_swap));
        printf (_("SWAP %s - %d%% free (%.0f MB out of %.0f MB) %s|"),
                        state_text (result),
@@ -376,12 +382,13 @@ process_arguments (int argc, char **argv)
                switch (c) {
                case 'w':                                                                       /* warning size threshold */
                        if (is_intnonneg (optarg)) {
-                               warn_size = (float) atoi (optarg);
+                               warn_size = (double) atoi (optarg);
                                break;
                        }
                        else if (strstr (optarg, ",") &&
                                                         strstr (optarg, "%") &&
-                                                        sscanf (optarg, "%.0f,%d%%", &warn_size, &warn_percent) == 2) {
+                                                        sscanf (optarg, "%g,%d%%", &warn_size, &warn_percent) == 2) {
+                               warn_size = floor(warn_size);
                                break;
                        }
                        else if (strstr (optarg, "%") &&
@@ -393,12 +400,13 @@ process_arguments (int argc, char **argv)
                        }
                case 'c':                                                                       /* critical size threshold */
                        if (is_intnonneg (optarg)) {
-                               crit_size = (float) atoi (optarg);
+                               crit_size = (double) atoi (optarg);
                                break;
                        }
                        else if (strstr (optarg, ",") &&
                                                         strstr (optarg, "%") &&
-                                                        sscanf (optarg, "%.0f,%d%%", &crit_size, &crit_percent) == 2) {
+                                                        sscanf (optarg, "%g,%d%%", &crit_size, &crit_percent) == 2) {
+                               crit_size = floor(crit_size);
                                break;
                        }
                        else if (strstr (optarg, "%") &&
@@ -439,12 +447,12 @@ process_arguments (int argc, char **argv)
        if (c == argc)
                return validate_arguments ();
        if (warn_size == 0 && is_intnonneg (argv[c]))
-               warn_size = (float) atoi (argv[c++]);
+               warn_size = (double) atoi (argv[c++]);
 
        if (c == argc)
                return validate_arguments ();
        if (crit_size == 0 && is_intnonneg (argv[c]))
-               crit_size = atoi (argv[c++]);
+               crit_size = (double) atoi (argv[c++]);
 
        return validate_arguments ();
 }
@@ -498,10 +506,6 @@ print_help (void)
  -v, --verbose\n\
     Verbose output. Up to 3 levels\n"));
 
-       printf (_("\n\
-On Solaris, if -a specified, uses swap -l, otherwise uses swap -s.\n\
-Will be discrepencies because swap -s counts allocated swap and includes\n\
-real memory\n"));
        printf (_("\n\
 On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.\n"));