Various plugins: Set the cURL option "CURLOPT_NOSIGNAL".
[collectd.git] / src / bind.c
index 4b3662f..6e13a8b 100644 (file)
  *   Florian Forster <octo at verplant.org>
  **/
 
-/* Set to C99 and POSIX code */
-#ifndef _ISOC99_SOURCE
-# define _ISOC99_SOURCE
-#endif
-#ifndef _POSIX_SOURCE
-# define _POSIX_SOURCE
-#endif
-#ifndef _POSIX_C_SOURCE
-# define _POSIX_C_SOURCE 200112L
-#endif
-#ifndef _REENTRANT
-# define _REENTRANT
-#endif
+#include "config.h"
+
 #ifndef _XOPEN_SOURCE
-# define _XOPEN_SOURCE 600
-#endif
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE
+# define _XOPEN_SOURCE 600 /* glibc2 needs this for strptime */
 #endif
 
 #include "collectd.h"
 #include "plugin.h"
 #include "configfile.h"
 
+/* Some versions of libcurl don't include this themselves and then don't have
+ * fd_set available. */
+#if HAVE_SYS_SELECT_H
+# include <sys/select.h>
+#endif
+
 #include <curl/curl.h>
 #include <libxml/parser.h>
 #include <libxml/xpath.h>
@@ -465,7 +457,7 @@ static int bind_xml_read_timestamp (const char *xpath_expression, /* {{{ */
     return (-1);
   }
 
-  *ret_value = timegm(&tm);
+  *ret_value = mktime(&tm);
 
   xmlXPathFreeObject (xpathObj);
   return (0);
@@ -484,7 +476,7 @@ static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ *
     list_callback_t list_callback,
     void *user_data,
     xmlDoc *doc, xmlXPathContext *xpathCtx,
-    time_t current_time)
+    time_t current_time, int ds_type)
 {
   xmlXPathObject *xpathObj = NULL;
   int num_entries;
@@ -532,7 +524,10 @@ static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ *
       value_t value;
       int status;
 
-      status = bind_xml_read_counter (doc, counter, &value.counter);
+      if (ds_type == DS_TYPE_GAUGE)
+        status = bind_xml_read_gauge (doc, counter, &value.gauge);
+      else
+        status = bind_xml_read_counter (doc, counter, &value.counter);
       if (status != 0)
         continue;
 
@@ -796,7 +791,7 @@ static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */
     list_info_ptr_t list_info =
     {
       plugin_instance,
-      /* type = */ "dns_qtype"
+      /* type = */ "dns_qtype_gauge"
     };
 
     ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-qtypes",
@@ -805,7 +800,7 @@ static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */
     bind_parse_generic_name_value (/* xpath = */ "rdtype",
         /* callback = */ bind_xml_list_callback,
         /* user_data = */ &list_info,
-        doc, path_ctx, current_time);
+        doc, path_ctx, current_time, DS_TYPE_COUNTER);
   } /* }}} */
 
   if (view->resolver_stats != 0) /* {{{ */
@@ -824,7 +819,7 @@ static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */
     bind_parse_generic_name_value ("resstat",
         /* callback = */ bind_xml_table_callback,
         /* user_data = */ &table_ptr,
-        doc, path_ctx, current_time);
+        doc, path_ctx, current_time, DS_TYPE_COUNTER);
   } /* }}} */
 
   if (view->cacherrsets != 0) /* {{{ */
@@ -833,7 +828,7 @@ static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */
     list_info_ptr_t list_info =
     {
       plugin_instance,
-      /* type = */ "dns_qtype"
+      /* type = */ "dns_qtype_gauge"
     };
 
     ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-cache_rr_sets",
@@ -842,7 +837,7 @@ static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */
     bind_parse_generic_name_value (/* xpath = */ "cache/rrset",
         /* callback = */ bind_xml_list_callback,
         /* user_data = */ &list_info,
-        doc, path_ctx, current_time);
+        doc, path_ctx, current_time, DS_TYPE_GAUGE);
   } /* }}} */
 
   if (view->zones_num > 0)
@@ -931,7 +926,7 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
     bind_parse_generic_name_value (/* xpath = */ "server/requests/opcode",
         /* callback = */ bind_xml_list_callback,
         /* user_data = */ &list_info,
-        doc, xpathCtx, current_time);
+        doc, xpathCtx, current_time, DS_TYPE_COUNTER);
   }
 
   /* XPath:     server/queries-in/rdtype
@@ -956,7 +951,7 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
     bind_parse_generic_name_value (/* xpath = */ "server/queries-in/rdtype",
         /* callback = */ bind_xml_list_callback,
         /* user_data = */ &list_info,
-        doc, xpathCtx, current_time);
+        doc, xpathCtx, current_time, DS_TYPE_COUNTER);
   }
   
   /* XPath:     server/nsstats, server/nsstat
@@ -1006,7 +1001,7 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
       bind_parse_generic_name_value ("server/nsstat",
           /* callback = */ bind_xml_table_callback,
           /* user_data = */ &table_ptr,
-          doc, xpathCtx, current_time);
+          doc, xpathCtx, current_time, DS_TYPE_COUNTER);
     }
   }
 
@@ -1052,7 +1047,7 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
       bind_parse_generic_name_value ("server/zonestat",
           /* callback = */ bind_xml_table_callback,
           /* user_data = */ &table_ptr,
-          doc, xpathCtx, current_time);
+          doc, xpathCtx, current_time, DS_TYPE_COUNTER);
     }
   }
 
@@ -1099,7 +1094,7 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
       bind_parse_generic_name_value ("server/resstat",
           /* callback = */ bind_xml_table_callback,
           /* user_data = */ &table_ptr,
-          doc, xpathCtx, current_time);
+          doc, xpathCtx, current_time, DS_TYPE_COUNTER);
     }
   }
 
@@ -1387,10 +1382,12 @@ static int bind_init (void) /* {{{ */
     return (-1);
   }
 
+  curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1);
   curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
   curl_easy_setopt (curl, CURLOPT_USERAGENT, PACKAGE_NAME"/"PACKAGE_VERSION);
   curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, bind_curl_error);
   curl_easy_setopt (curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
+  curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1);
 
   return (0);
 } /* }}} int bind_init */