X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcollectd-nagios.c;h=63effd5528bd706a30426d0b22cb557fd91faee9;hb=6d43c759c9495118ef3c088fd2d06fd09c4fda8f;hp=b7c3ffaf267bd019baccd92fb622909af9a3d3a9;hpb=dc80c73c20ef0e69c3850fd9679a827ad79e61a1;p=collectd.git diff --git a/src/collectd-nagios.c b/src/collectd-nagios.c index b7c3ffaf..63effd55 100644 --- a/src/collectd-nagios.c +++ b/src/collectd-nagios.c @@ -1,3 +1,5 @@ +#include "config.h" + #include #include #include @@ -9,18 +11,32 @@ #include /* - * This weird macro cascade forces the glibc to define `NAN'. I don't know - * another way to solve this, so more intelligent solutions are welcome. -octo + * This is copied directly from collectd.h. Make changes there! */ -#ifndef __USE_ISOC99 -# define DISABLE__USE_ISOC99 1 -# define __USE_ISOC99 1 -#endif -#include -#ifdef DISABLE__USE_ISOC99 -# undef DISABLE__USE_ISOC99 -# undef __USE_ISOC99 -#endif +#if NAN_STATIC_DEFAULT +# include +/* #endif NAN_STATIC_DEFAULT*/ +#elif NAN_STATIC_ISOC +# ifndef __USE_ISOC99 +# define DISABLE_ISOC99 1 +# define __USE_ISOC99 1 +# endif /* !defined(__USE_ISOC99) */ +# include +# if DISABLE_ISOC99 +# undef DISABLE_ISOC99 +# undef __USE_ISOC99 +# endif /* DISABLE_ISOC99 */ +/* #endif NAN_STATIC_ISOC */ +#elif NAN_ZERO_ZERO +# include +# ifdef NAN +# undef NAN +# endif +# define NAN (0.0 / 0.0) +# ifndef isnan +# define isnan(f) ((f) != (f)) +# endif /* !defined(isnan) */ +#endif /* NAN_ZERO_ZERO */ #define RET_OKAY 0 #define RET_WARNING 1 @@ -278,25 +294,22 @@ int do_check_con_none (int values_num, double *values, char **values_names) num_okay++; } - if ((num_critical != 0) || (values_num == 0)) + printf ("%i critical, %i warning, %i okay", + num_critical, num_warning, num_okay); + if (values_num > 0) { - printf ("CRITICAL: %i critical, %i warning, %i okay\n", - num_critical, num_warning, num_okay); - return (RET_CRITICAL); + printf (" |"); + for (i = 0; i < values_num; i++) + printf (" %s=%lf;;;;", values_names[i], values[i]); } + printf ("\n"); + + if ((num_critical != 0) || (values_num == 0)) + return (RET_CRITICAL); else if (num_warning != 0) - { - printf ("WARNING: %i warning, %i okay\n", - num_warning, num_okay); return (RET_WARNING); - } - else - { - printf ("OKAY: %i okay\n", num_okay); - return (RET_OKAY); - } - return (RET_UNKNOWN); + return (RET_OKAY); } /* int do_check_con_none */ int do_check_con_average (int values_num, double *values, char **values_names) @@ -304,6 +317,7 @@ int do_check_con_average (int values_num, double *values, char **values_names) int i; double total; int total_num; + double average; total = 0.0; total_num = 0; @@ -317,31 +331,23 @@ int do_check_con_average (int values_num, double *values, char **values_names) } if (total_num == 0) - { - printf ("WARNING: No defined values found\n"); + average = NAN; + else + average = total / total_num; + printf ("%lf average |", average); + for (i = 0; i < values_num; i++) + printf (" %s=%lf;;;;", values_names[i], values[i]); + + if (total_num == 0) return (RET_WARNING); - } - if (match_range (&range_critical_g, total / total_num) != 0) - { - printf ("CRITICAL: Average = %lf\n", - (double) (total / total_num)); + if (isnan (average) + || match_range (&range_critical_g, average)) return (RET_CRITICAL); - } - else if (match_range (&range_warning_g, total / total_num) != 0) - { - printf ("WARNING: Average = %lf\n", - (double) (total / total_num)); + else if (match_range (&range_warning_g, average) != 0) return (RET_WARNING); - } - else - { - printf ("OKAY: Average = %lf\n", - (double) (total / total_num)); - return (RET_OKAY); - } - return (RET_UNKNOWN); + return (RET_OKAY); } /* int do_check_con_average */ int do_check_con_sum (int values_num, double *values, char **values_names) @@ -406,7 +412,7 @@ int do_check (void) return (do_check_con_sum (values_num, values, values_names)); free (values); - free (values_names); + free (values_names); /* FIXME? */ return (RET_UNKNOWN); }