summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d324b71)
raw | patch | inline | side by side (parent: d324b71)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 8 Dec 2008 23:33:55 +0000 (00:33 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 9 Dec 2008 11:39:40 +0000 (12:39 +0100) |
Calculation of the percentage is not limited to two values any more but an
arbitrary number may be used now. This allows a more flexible usage.
Also, the documentation has been updated.
arbitrary number may be used now. This allows a more flexible usage.
Also, the documentation has been updated.
src/collectd-nagios.c | patch | blob | history | |
src/collectd-nagios.pod | patch | blob | history |
diff --git a/src/collectd-nagios.c b/src/collectd-nagios.c
index 1d989cbd747ac9de096777d81c02760972c18db1..15252b19a1ba10fc8d3e52ec384ab9f6a2903be3 100644 (file)
--- a/src/collectd-nagios.c
+++ b/src/collectd-nagios.c
return (status_code);
} /* int do_check_con_sum */
-static int do_check_con_percentage (int values_num, double *values, char **values_names)
+static int do_check_con_percentage (size_t values_num,
+ double *values, char **values_names)
{
- int i;
+ int i;
+ double sum = 0.0;
double percentage;
- if (values_num != 2)
- return (RET_WARNING);
- if (isnan (values[0]) || isnan (values[1]))
- return (RET_WARNING);
- if ((values[0] + values[1]) == 0)
- return (RET_WARNING);
+ const char *status_str = "UNKNOWN";
+ int status_code = RET_UNKNOWN;
- percentage = 100 * values[1] / ( values[0] + values[1] );
+ if ((values_num < 1) || (isnan (values[0])))
+ {
+ printf ("WARNING: The first value is not defined\n");
+ return (RET_WARNING);
+ }
- printf ("%lf percentage |", percentage);
for (i = 0; i < values_num; i++)
- printf (" %s=%lf;;;;", values_names[i], values[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)
{
- printf ("CRITICAL: percentage = %lf\n", percentage);
- return (RET_CRITICAL);
+ status_str = "CRITICAL";
+ status_code = RET_CRITICAL;
}
else if (match_range (&range_warning_g, percentage) != 0)
{
- printf ("WARNING: percentage = %lf\n", percentage);
- return (RET_WARNING);
- }
+ status_str = "WARNING";
+ status_code = RET_WARNING;
+ }
+ else
+ {
+ status_str = "OKAY";
+ status_code = RET_OKAY;
+ }
- printf ("OKAY: percentage = %lf\n", percentage);
- return (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)
index 49800255f266053fda3e990867c40a6fec80a7ba..c6347eac9361746c8f60b6b33713983d466da241 100644 (file)
--- a/src/collectd-nagios.pod
+++ b/src/collectd-nagios.pod
The warning and critical ranges are applied to the sum of all values.
+=item B<percentage>
+
+The warning and critical ranges are applied to the ratio (in percent) of the
+first value and the sum of all values. A warning is returned if the first
+value is not defined or if all values sum up to zero.
+
=back
=item B<-c> I<range>
message to STDOUT and signals success or failure with it's return value. It
exits with a return value of B<0> for I<success>, B<1> for I<warning> and B<2>
for I<critical>. If the values are not available or some other error occurred,
-it returns B<3> for I<unknown>.
+it returns B<3> for I<unknown>.
=head1 SEE ALSO