Merge branch 'collectd-4.5' into collectd-4.6
[collectd.git] / src / collectd-nagios.c
index 15252b1..8f4a410 100644 (file)
@@ -165,7 +165,7 @@ static int filter_ds (size_t *values_num,
                return (RET_UNKNOWN);
        }
 
-       for (i = 0; i < match_ds_num_g; i++)
+       for (i = 0; i < (size_t) match_ds_num_g; i++)
        {
                size_t j;
 
@@ -273,7 +273,7 @@ static void usage (const char *name)
                        "  -d <ds>        Select the DS to examine. May be repeated to examine multiple\n"
                        "                 DSes. By default all DSes are used.\n"
                        "  -g <consol>    Method to use to consolidate several DSes.\n"
-                       "                 Valid arguments are `none', `average' and `sum'\n"
+                       "                 See below for a list of valid arguments.\n"
                        "  -H <host>      Hostname to query the values for.\n"
                        "  -c <range>     Critical range\n"
                        "  -w <range>     Warning range\n"
@@ -284,6 +284,8 @@ static void usage (const char *name)
                        "  average:       Calculate the average of all matching DSes and apply the\n"
                        "                 warning- and critical-ranges to the calculated average.\n"
                        "  sum:           Apply the ranges to the sum of all DSes.\n"
+                       "  percentage:    Apply the ranges to the ratio (in percent) of the first value\n"
+                       "                 and the sum of all values."
                        "\n", name);
        exit (1);
 } /* void usage */
@@ -296,7 +298,7 @@ static int do_check_con_none (size_t values_num,
        int num_okay = 0;
        const char *status_str = "UNKNOWN";
        int status_code = RET_UNKNOWN;
-       int i;
+       size_t i;
 
        for (i = 0; i < values_num; i++)
        {
@@ -347,7 +349,7 @@ static int do_check_con_none (size_t values_num,
 static int do_check_con_average (size_t values_num,
                double *values, char **values_names)
 {
-       int i;
+       size_t i;
        double total;
        int total_num;
        double average;
@@ -400,7 +402,7 @@ static int do_check_con_average (size_t values_num,
 static int do_check_con_sum (size_t values_num,
                double *values, char **values_names)
 {
-       int i;
+       size_t i;
        double total;
        int total_num;
        const char *status_str = "UNKNOWN";
@@ -450,7 +452,7 @@ static int do_check_con_sum (size_t values_num,
 static int do_check_con_percentage (size_t values_num,
                double *values, char **values_names)
 {
-       int i;
+       size_t i;
        double sum = 0.0;
        double percentage;
 
@@ -615,7 +617,11 @@ int main (int argc, char **argv)
                                else if (strcasecmp (optarg, "percentage") == 0)
                                        consolitation_g = CON_PERCENTAGE;
                                else
+                               {
+                                       fprintf (stderr, "Unknown consolidation function `%s'.\n",
+                                                       optarg);
                                        usage (argv[0]);
+                               }
                                break;
                        case 'd':
                        {
@@ -647,7 +653,10 @@ int main (int argc, char **argv)
 
        if ((socket_file_g == NULL) || (value_string_g == NULL)
                        || (hostname_g == NULL))
+       {
+               fprintf (stderr, "Missing required arguments.\n");
                usage (argv[0]);
+       }
 
        return (do_check ());
 } /* int main */