#define CON_NONE 0
#define CON_AVERAGE 1
#define CON_SUM 2
+#define CON_PERCENTAGE 3
struct range_s
{
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;
" -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"
" 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 */
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++)
{
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;
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";
return (status_code);
} /* int do_check_con_sum */
+static int do_check_con_percentage (size_t values_num,
+ double *values, char **values_names)
+{
+ size_t i;
+ double sum = 0.0;
+ double percentage;
+
+ const char *status_str = "UNKNOWN";
+ int status_code = RET_UNKNOWN;
+
+ if ((values_num < 1) || (isnan (values[0])))
+ {
+ printf ("WARNING: The first value is not defined\n");
+ return (RET_WARNING);
+ }
+
+ for (i = 0; i < values_num; i++)
+ if (!isnan (values[i]))
+ sum += values[i];
+
+ if (sum == 0.0)
+ {
+ printf ("WARNING: Values sum up to zero\n");
+ return (RET_WARNING);
+ }
+
+ percentage = 100.0 * values[0] / sum;
+
+ if (match_range (&range_critical_g, percentage) != 0)
+ {
+ status_str = "CRITICAL";
+ status_code = RET_CRITICAL;
+ }
+ else if (match_range (&range_warning_g, percentage) != 0)
+ {
+ status_str = "WARNING";
+ status_code = RET_WARNING;
+ }
+ else
+ {
+ status_str = "OKAY";
+ status_code = RET_OKAY;
+ }
+
+ printf ("%s: %lf percent |", status_str, percentage);
+ for (i = 0; i < values_num; i++)
+ printf (" %s=%lf;;;;", values_names[i], values[i]);
+ return (status_code);
+} /* int do_check_con_percentage */
+
static int do_check (void)
{
lcc_connection_t *connection;
status = do_check_con_average (values_num, values, values_names);
else if (consolitation_g == CON_SUM)
status = do_check_con_sum (values_num, values, values_names);
+ else if (consolitation_g == CON_PERCENTAGE)
+ status = do_check_con_percentage (values_num, values, values_names);
free (values);
if (values_names != NULL)
consolitation_g = CON_AVERAGE;
else if (strcasecmp (optarg, "sum") == 0)
consolitation_g = CON_SUM;
+ 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':
{
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 */