contrib/collectd2html.pl: Allow generation of graphs from remote hosts or in an alter...
[collectd.git] / src / collectd-nagios.c
index 160412c..fca9f18 100644 (file)
@@ -1,3 +1,5 @@
+#include "config.h"
+
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <sys/un.h>
 
 /*
- * 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 <math.h>
-#ifdef DISABLE__USE_ISOC99
-# undef DISABLE__USE_ISOC99
-# undef __USE_ISOC99
-#endif
+#if NAN_STATIC_DEFAULT
+# include <math.h>
+/* #endif NAN_STATIC_DEFAULT*/
+#elif NAN_STATIC_ISOC
+# ifndef __USE_ISOC99
+#  define DISABLE_ISOC99 1
+#  define __USE_ISOC99 1
+# endif /* !defined(__USE_ISOC99) */
+# include <math.h>
+# if DISABLE_ISOC99
+#  undef DISABLE_ISOC99
+#  undef __USE_ISOC99
+# endif /* DISABLE_ISOC99 */
+/* #endif NAN_STATIC_ISOC */
+#elif NAN_ZERO_ZERO
+# include <math.h>
+# 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
@@ -112,9 +128,9 @@ int match_range (range_t *range, double value)
 {
        int ret = 0;
 
-       if ((range->min != NAN) && (range->min > value))
+       if (!isnan (range->min) && (range->min > value))
                ret = 1;
-       if ((range->max != NAN) && (range->max < value))
+       if (!isnan (range->max) && (range->max < value))
                ret = 1;
 
        return (((ret - range->invert) == 0) ? 0 : 1);
@@ -268,7 +284,7 @@ int do_check_con_none (int values_num, double *values, char **values_names)
 
        for (i = 0; i < values_num; i++)
        {
-               if (values[i] == NAN)
+               if (isnan (values[i]))
                        num_warning++;
                else if (match_range (&range_critical_g, values[i]) != 0)
                        num_critical++;
@@ -309,7 +325,7 @@ int do_check_con_average (int values_num, double *values, char **values_names)
        total_num = 0;
        for (i = 0; i < values_num; i++)
        {
-               if (values[i] != NAN)
+               if (!isnan (values[i]))
                {
                        total += values[i];
                        total_num++;
@@ -354,7 +370,7 @@ int do_check_con_sum (int values_num, double *values, char **values_names)
        total_num = 0;
        for (i = 0; i < values_num; i++)
        {
-               if (values[i] != NAN)
+               if (!isnan (values[i]))
                {
                        total += values[i];
                        total_num++;