2 * collectd - src/bind.c
3 * Copyright (C) 2009 Bruno Prémont
4 * Copyright (C) 2009,2010 Florian Forster
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; only version 2 of the License is applicable.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Bruno Prémont <bonbons at linux-vserver.org>
21 * Florian Forster <octo at collectd.org>
26 #if STRPTIME_NEEDS_STANDARDS
27 # ifndef _ISOC99_SOURCE
28 # define _ISOC99_SOURCE 1
30 # ifndef _POSIX_C_SOURCE
31 # define _POSIX_C_SOURCE 200112L
33 # ifndef _XOPEN_SOURCE
34 # define _XOPEN_SOURCE 500
36 #endif /* STRPTIME_NEEDS_STANDARDS */
41 #include "configfile.h"
43 /* Some versions of libcurl don't include this themselves and then don't have
44 * fd_set available. */
46 # include <sys/select.h>
49 #include <curl/curl.h>
50 #include <libxml/parser.h>
51 #include <libxml/xpath.h>
53 #ifndef BIND_DEFAULT_URL
54 # define BIND_DEFAULT_URL "http://localhost:8053/"
58 * Some types used for the callback functions. `translation_table_ptr_t' and
59 * `list_info_ptr_t' are passed to the callbacks in the `void *user_data'
62 typedef int (*list_callback_t) (const char *name, value_t value,
63 time_t current_time, void *user_data);
76 typedef struct cb_view_s cb_view_t;
78 struct translation_info_s
82 const char *type_instance;
84 typedef struct translation_info_s translation_info_t;
86 struct translation_table_ptr_s
88 const translation_info_t *table;
90 const char *plugin_instance;
92 typedef struct translation_table_ptr_s translation_table_ptr_t;
94 struct list_info_ptr_s
96 const char *plugin_instance;
99 typedef struct list_info_ptr_s list_info_ptr_t;
101 /* FIXME: Enabled by default for backwards compatibility. */
102 /* TODO: Remove time parsing code. */
103 static _Bool config_parse_time = 1;
105 static char *url = NULL;
106 static int global_opcodes = 1;
107 static int global_qtypes = 1;
108 static int global_server_stats = 1;
109 static int global_zone_maint_stats = 1;
110 static int global_resolver_stats = 0;
111 static int global_memory_stats = 1;
112 static int timeout = -1;
114 static cb_view_t *views = NULL;
115 static size_t views_num = 0;
117 static CURL *curl = NULL;
119 static char *bind_buffer = NULL;
120 static size_t bind_buffer_size = 0;
121 static size_t bind_buffer_fill = 0;
122 static char bind_curl_error[CURL_ERROR_SIZE];
124 /* Translation table for the `nsstats' values. */
125 static const translation_info_t nsstats_translation_table[] = /* {{{ */
128 { "Requestv4", "dns_request", "IPv4" },
129 { "Requestv6", "dns_request", "IPv6" },
130 { "ReqEdns0", "dns_request", "EDNS0" },
131 { "ReqBadEDNSVer", "dns_request", "BadEDNSVer" },
132 { "ReqTSIG", "dns_request", "TSIG" },
133 { "ReqSIG0", "dns_request", "SIG0" },
134 { "ReqBadSIG", "dns_request", "BadSIG" },
135 { "ReqTCP", "dns_request", "TCP" },
137 { "AuthQryRej", "dns_reject", "authorative" },
138 { "RecQryRej", "dns_reject", "recursive" },
139 { "XfrRej", "dns_reject", "transfer" },
140 { "UpdateRej", "dns_reject", "update" },
142 { "Response", "dns_response", "normal" },
143 { "TruncatedResp", "dns_response", "truncated" },
144 { "RespEDNS0", "dns_response", "EDNS0" },
145 { "RespTSIG", "dns_response", "TSIG" },
146 { "RespSIG0", "dns_response", "SIG0" },
148 { "QryAuthAns", "dns_query", "authorative" },
149 { "QryNoauthAns", "dns_query", "nonauth" },
150 { "QryReferral", "dns_query", "referral" },
151 { "QryRecursion", "dns_query", "recursion" },
152 { "QryDuplicate", "dns_query", "dupliate" },
153 { "QryDropped", "dns_query", "dropped" },
154 { "QryFailure", "dns_query", "failure" },
156 { "QrySuccess", "dns_rcode", "tx-NOERROR" },
157 { "QryNxrrset", "dns_rcode", "tx-NXRRSET" },
158 { "QrySERVFAIL", "dns_rcode", "tx-SERVFAIL" },
159 { "QryFORMERR", "dns_rcode", "tx-FORMERR" },
160 { "QryNXDOMAIN", "dns_rcode", "tx-NXDOMAIN" }
162 { "XfrReqDone", "type", "type_instance" },
163 { "UpdateReqFwd", "type", "type_instance" },
164 { "UpdateRespFwd", "type", "type_instance" },
165 { "UpdateFwdFail", "type", "type_instance" },
166 { "UpdateDone", "type", "type_instance" },
167 { "UpdateFail", "type", "type_instance" },
168 { "UpdateBadPrereq", "type", "type_instance" },
171 static int nsstats_translation_table_length =
172 STATIC_ARRAY_SIZE (nsstats_translation_table);
175 /* Translation table for the `zonestats' values. */
176 static const translation_info_t zonestats_translation_table[] = /* {{{ */
179 { "NotifyOutv4", "dns_notify", "tx-IPv4" },
180 { "NotifyOutv6", "dns_notify", "tx-IPv6" },
181 { "NotifyInv4", "dns_notify", "rx-IPv4" },
182 { "NotifyInv6", "dns_notify", "rx-IPv6" },
183 { "NotifyRej", "dns_notify", "rejected" },
184 /* SOA/AXFS/IXFS requests */
185 { "SOAOutv4", "dns_opcode", "SOA-IPv4" },
186 { "SOAOutv6", "dns_opcode", "SOA-IPv6" },
187 { "AXFRReqv4", "dns_opcode", "AXFR-IPv4" },
188 { "AXFRReqv6", "dns_opcode", "AXFR-IPv6" },
189 { "IXFRReqv4", "dns_opcode", "IXFR-IPv4" },
190 { "IXFRReqv6", "dns_opcode", "IXFR-IPv6" },
191 /* Domain transfers */
192 { "XfrSuccess", "dns_transfer", "success" },
193 { "XfrFail", "dns_transfer", "failure" }
195 static int zonestats_translation_table_length =
196 STATIC_ARRAY_SIZE (zonestats_translation_table);
199 /* Translation table for the `resstats' values. */
200 static const translation_info_t resstats_translation_table[] = /* {{{ */
202 /* Generic resolver information */
203 { "Queryv4", "dns_query", "IPv4" },
204 { "Queryv6", "dns_query", "IPv6" },
205 { "Responsev4", "dns_response", "IPv4" },
206 { "Responsev6", "dns_response", "IPv6" },
207 /* Received response codes */
208 { "NXDOMAIN", "dns_rcode", "rx-NXDOMAIN" },
209 { "SERVFAIL", "dns_rcode", "rx-SERVFAIL" },
210 { "FORMERR", "dns_rcode", "rx-FORMERR" },
211 { "OtherError", "dns_rcode", "rx-OTHER" },
212 { "EDNS0Fail", "dns_rcode", "rx-EDNS0Fail"},
213 /* Received responses */
214 { "Mismatch", "dns_response", "mismatch" },
215 { "Truncated", "dns_response", "truncated" },
216 { "Lame", "dns_response", "lame" },
217 { "Retry", "dns_query", "retry" },
219 { "GlueFetchv4", "type", "type_instance" },
220 { "GlueFetchv6", "type", "type_instance" },
221 { "GlueFetchv4Fail", "type", "type_instance" },
222 { "GlueFetchv6Fail", "type", "type_instance" },
224 /* DNSSEC information */
225 { "ValAttempt", "dns_resolver", "DNSSEC-attempt" },
226 { "ValOk", "dns_resolver", "DNSSEC-okay" },
227 { "ValNegOk", "dns_resolver", "DNSSEC-negokay" },
228 { "ValFail", "dns_resolver", "DNSSEC-fail" }
230 static int resstats_translation_table_length =
231 STATIC_ARRAY_SIZE (resstats_translation_table);
234 /* Translation table for the `memory/summary' values. */
235 static const translation_info_t memsummary_translation_table[] = /* {{{ */
237 { "TotalUse", "memory", "TotalUse" },
238 { "InUse", "memory", "InUse" },
239 { "BlockSize", "memory", "BlockSize" },
240 { "ContextSize", "memory", "ContextSize" },
241 { "Lost", "memory", "Lost" }
243 static int memsummary_translation_table_length =
244 STATIC_ARRAY_SIZE (memsummary_translation_table);
247 static void submit (time_t ts, const char *plugin_instance, /* {{{ */
248 const char *type, const char *type_instance, value_t value)
251 value_list_t vl = VALUE_LIST_INIT;
257 if (config_parse_time)
258 vl.time = TIME_T_TO_CDTIME_T (ts);
259 sstrncpy(vl.host, hostname_g, sizeof(vl.host));
260 sstrncpy(vl.plugin, "bind", sizeof(vl.plugin));
261 if (plugin_instance) {
262 sstrncpy(vl.plugin_instance, plugin_instance,
263 sizeof(vl.plugin_instance));
264 replace_special (vl.plugin_instance, sizeof (vl.plugin_instance));
266 sstrncpy(vl.type, type, sizeof(vl.type));
268 sstrncpy(vl.type_instance, type_instance,
269 sizeof(vl.type_instance));
270 replace_special (vl.plugin_instance, sizeof (vl.plugin_instance));
272 plugin_dispatch_values(&vl);
273 } /* }}} void submit */
275 static size_t bind_curl_callback (void *buf, size_t size, /* {{{ */
276 size_t nmemb, void __attribute__((unused)) *stream)
278 size_t len = size * nmemb;
283 if ((bind_buffer_fill + len) >= bind_buffer_size)
287 temp = realloc(bind_buffer, bind_buffer_fill + len + 1);
290 ERROR ("bind plugin: realloc failed.");
294 bind_buffer_size = bind_buffer_fill + len + 1;
297 memcpy (bind_buffer + bind_buffer_fill, (char *) buf, len);
298 bind_buffer_fill += len;
299 bind_buffer[bind_buffer_fill] = 0;
302 } /* }}} size_t bind_curl_callback */
305 * Callback, that's called with a translation table.
306 * (Plugin instance is fixed, type and type instance come from lookup table.)
308 static int bind_xml_table_callback (const char *name, value_t value, /* {{{ */
309 time_t current_time, void *user_data)
311 translation_table_ptr_t *table = (translation_table_ptr_t *) user_data;
317 for (i = 0; i < table->table_length; i++)
319 if (strcmp (table->table[i].xml_name, name) != 0)
322 submit (current_time,
323 table->plugin_instance,
324 table->table[i].type,
325 table->table[i].type_instance,
331 } /* }}} int bind_xml_table_callback */
334 * Callback, that's used for lists.
335 * (Plugin instance and type are fixed, xml name is used as type instance.)
337 static int bind_xml_list_callback (const char *name, /* {{{ */
338 value_t value, time_t current_time, void *user_data)
340 list_info_ptr_t *list_info = (list_info_ptr_t *) user_data;
342 if (list_info == NULL)
345 submit (current_time,
346 list_info->plugin_instance,
348 /* type instance = */ name,
352 } /* }}} int bind_xml_list_callback */
354 static int bind_xml_read_derive (xmlDoc *doc, xmlNode *node, /* {{{ */
361 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
364 ERROR ("bind plugin: bind_xml_read_derive: xmlNodeListGetString failed.");
368 status = parse_value (str_ptr, &value, DS_TYPE_DERIVE);
371 ERROR ("bind plugin: Parsing string \"%s\" to derive value failed.",
376 *ret_value = value.derive;
378 } /* }}} int bind_xml_read_derive */
380 static int bind_xml_read_gauge (xmlDoc *doc, xmlNode *node, /* {{{ */
383 char *str_ptr, *end_ptr;
386 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
389 ERROR ("bind plugin: bind_xml_read_gauge: xmlNodeListGetString failed.");
394 value = strtod (str_ptr, &end_ptr);
396 if (str_ptr == end_ptr || errno)
398 if (errno && (value < 0))
399 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed with underflow.");
400 else if (errno && (value > 0))
401 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed with overflow.");
403 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed.");
407 *ret_value = (gauge_t) value;
409 } /* }}} int bind_xml_read_gauge */
411 static int bind_xml_read_timestamp (const char *xpath_expression, /* {{{ */
412 xmlDoc *doc, xmlXPathContext *xpathCtx, time_t *ret_value)
414 xmlXPathObject *xpathObj = NULL;
420 xpathObj = xmlXPathEvalExpression (BAD_CAST xpath_expression, xpathCtx);
421 if (xpathObj == NULL)
423 ERROR ("bind plugin: Unable to evaluate XPath expression `%s'.",
428 if ((xpathObj->nodesetval == NULL) || (xpathObj->nodesetval->nodeNr < 1))
430 xmlXPathFreeObject (xpathObj);
434 if (xpathObj->nodesetval->nodeNr != 1)
436 NOTICE ("bind plugin: Evaluating the XPath expression `%s' returned "
437 "%i nodes. Only handling the first one.",
438 xpath_expression, xpathObj->nodesetval->nodeNr);
441 node = xpathObj->nodesetval->nodeTab[0];
443 if (node->xmlChildrenNode == NULL)
445 ERROR ("bind plugin: bind_xml_read_timestamp: "
446 "node->xmlChildrenNode == NULL");
447 xmlXPathFreeObject (xpathObj);
451 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
454 ERROR ("bind plugin: bind_xml_read_timestamp: xmlNodeListGetString failed.");
455 xmlXPathFreeObject (xpathObj);
459 memset (&tm, 0, sizeof(tm));
460 tmp = strptime (str_ptr, "%Y-%m-%dT%T", &tm);
464 ERROR ("bind plugin: bind_xml_read_timestamp: strptime failed.");
465 xmlXPathFreeObject (xpathObj);
469 *ret_value = mktime(&tm);
471 xmlXPathFreeObject (xpathObj);
473 } /* }}} int bind_xml_read_timestamp */
476 * bind_parse_generic_name_value
478 * Reads statistics in the form:
481 * <counter>123</counter>
484 static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ */
485 list_callback_t list_callback,
487 xmlDoc *doc, xmlXPathContext *xpathCtx,
488 time_t current_time, int ds_type)
490 xmlXPathObject *xpathObj = NULL;
494 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
495 if (xpathObj == NULL)
497 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
503 /* Iterate over all matching nodes. */
504 for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
506 xmlNode *name_node = NULL;
507 xmlNode *counter = NULL;
511 parent = xpathObj->nodesetval->nodeTab[i];
512 DEBUG ("bind plugin: bind_parse_generic_name_value: parent->name = %s;",
513 (char *) parent->name);
515 /* Iterate over all child nodes. */
516 for (child = parent->xmlChildrenNode;
520 if (child->type != XML_ELEMENT_NODE)
523 if (xmlStrcmp (BAD_CAST "name", child->name) == 0)
525 else if (xmlStrcmp (BAD_CAST "counter", child->name) == 0)
529 if ((name_node != NULL) && (counter != NULL))
531 char *name = (char *) xmlNodeListGetString (doc,
532 name_node->xmlChildrenNode, 1);
536 if (ds_type == DS_TYPE_GAUGE)
537 status = bind_xml_read_gauge (doc, counter, &value.gauge);
539 status = bind_xml_read_derive (doc, counter, &value.derive);
543 status = (*list_callback) (name, value, current_time, user_data);
551 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
552 num_entries, (num_entries == 1) ? "entry" : "entries",
555 xmlXPathFreeObject(xpathObj);
558 } /* }}} int bind_parse_generic_name_value */
561 * bind_parse_generic_value_list
563 * Reads statistics in the form:
571 static int bind_parse_generic_value_list (const char *xpath_expression, /* {{{ */
572 list_callback_t list_callback,
574 xmlDoc *doc, xmlXPathContext *xpathCtx,
575 time_t current_time, int ds_type)
577 xmlXPathObject *xpathObj = NULL;
581 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
582 if (xpathObj == NULL)
584 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
590 /* Iterate over all matching nodes. */
591 for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
595 /* Iterate over all child nodes. */
596 for (child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
604 if (child->type != XML_ELEMENT_NODE)
607 node_name = (char *) child->name;
609 if (ds_type == DS_TYPE_GAUGE)
610 status = bind_xml_read_gauge (doc, child, &value.gauge);
612 status = bind_xml_read_derive (doc, child, &value.derive);
616 status = (*list_callback) (node_name, value, current_time, user_data);
622 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
623 num_entries, (num_entries == 1) ? "entry" : "entries",
626 xmlXPathFreeObject(xpathObj);
629 } /* }}} int bind_parse_generic_value_list */
632 * bind_parse_generic_name_attr_value_list
634 * Reads statistics in the form:
636 * <counter name="name0">123</counter>
637 * <counter name="name1">234</counter>
638 * <counter name="name2">345</counter>
642 static int bind_parse_generic_name_attr_value_list (const char *xpath_expression, /* {{{ */
643 list_callback_t list_callback,
645 xmlDoc *doc, xmlXPathContext *xpathCtx,
646 time_t current_time, int ds_type)
648 xmlXPathObject *xpathObj = NULL;
652 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
653 if (xpathObj == NULL)
655 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
661 /* Iterate over all matching nodes. */
662 for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
666 /* Iterate over all child nodes. */
667 for (child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
671 if (child->type != XML_ELEMENT_NODE)
674 if (strncmp ("counter", (char *) child->name, strlen ("counter")) != 0)
681 attr_name = (char *) xmlGetProp (child, BAD_CAST "name");
682 if (attr_name == NULL)
684 DEBUG ("bind plugin: found <counter> without name.");
687 if (ds_type == DS_TYPE_GAUGE)
688 status = bind_xml_read_gauge (doc, child, &value.gauge);
690 status = bind_xml_read_derive (doc, child, &value.derive);
694 status = (*list_callback) (attr_name, value, current_time, user_data);
700 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
701 num_entries, (num_entries == 1) ? "entry" : "entries",
704 xmlXPathFreeObject(xpathObj);
707 } /* }}} int bind_parse_generic_name_attr_value_list */
709 static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */
710 xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view,
713 xmlXPathObject *path_obj;
714 char *zone_name = NULL;
718 path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
719 if (path_obj == NULL)
721 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
725 for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
727 zone_name = (char *) xmlNodeListGetString (doc,
728 path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
729 if (zone_name != NULL)
733 if (zone_name == NULL)
735 ERROR ("bind plugin: Could not determine zone name.");
736 xmlXPathFreeObject (path_obj);
740 for (j = 0; j < view->zones_num; j++)
742 if (strcasecmp (zone_name, view->zones[j]) == 0)
749 if (j >= views->zones_num)
751 xmlXPathFreeObject (path_obj);
755 zone_name = view->zones[j];
757 DEBUG ("bind plugin: bind_xml_stats_handle_zone: Found zone `%s'.",
760 { /* Parse the <counters> tag {{{ */
761 char plugin_instance[DATA_MAX_NAME_LEN];
762 translation_table_ptr_t table_ptr =
764 nsstats_translation_table,
765 nsstats_translation_table_length,
769 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-zone-%s",
770 view->name, zone_name);
772 bind_parse_generic_value_list (/* xpath = */ "counters",
773 /* callback = */ bind_xml_table_callback,
774 /* user_data = */ &table_ptr,
775 doc, path_ctx, current_time, DS_TYPE_COUNTER);
778 xmlXPathFreeObject (path_obj);
781 } /* }}} int bind_xml_stats_handle_zone */
783 static int bind_xml_stats_search_zones (int version, xmlDoc *doc, /* {{{ */
784 xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view,
787 xmlXPathObject *zone_nodes = NULL;
788 xmlXPathContext *zone_path_context;
791 zone_path_context = xmlXPathNewContext (doc);
792 if (zone_path_context == NULL)
794 ERROR ("bind plugin: xmlXPathNewContext failed.");
798 zone_nodes = xmlXPathEvalExpression (BAD_CAST "zones/zone", path_ctx);
799 if (zone_nodes == NULL)
801 ERROR ("bind plugin: Cannot find any <view> tags.");
802 xmlXPathFreeContext (zone_path_context);
806 for (i = 0; i < zone_nodes->nodesetval->nodeNr; i++)
810 node = zone_nodes->nodesetval->nodeTab[i];
811 assert (node != NULL);
813 zone_path_context->node = node;
815 bind_xml_stats_handle_zone (version, doc, zone_path_context, node, view,
819 xmlXPathFreeObject (zone_nodes);
820 xmlXPathFreeContext (zone_path_context);
822 } /* }}} int bind_xml_stats_search_zones */
824 static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */
825 xmlXPathContext *path_ctx, xmlNode *node, time_t current_time)
827 char *view_name = NULL;
834 view_name = (char*) xmlGetProp(node, BAD_CAST "name");
836 if (view_name == NULL)
838 ERROR ("bind plugin: Could not determine view name.");
842 for (j = 0; j < views_num; j++)
844 if (strcasecmp (view_name, views[j].name) == 0)
853 xmlXPathObject *path_obj;
854 path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
855 if (path_obj == NULL)
857 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
861 for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
863 view_name = (char *) xmlNodeListGetString (doc,
864 path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
865 if (view_name != NULL)
869 if (view_name == NULL)
871 ERROR ("bind plugin: Could not determine view name.");
872 xmlXPathFreeObject (path_obj);
876 for (j = 0; j < views_num; j++)
878 if (strcasecmp (view_name, views[j].name) == 0)
883 xmlXPathFreeObject (path_obj);
895 DEBUG ("bind plugin: bind_xml_stats_handle_view: Found view `%s'.",
898 if (view->qtypes != 0) /* {{{ */
900 char plugin_instance[DATA_MAX_NAME_LEN];
901 list_info_ptr_t list_info =
904 /* type = */ "dns_qtype"
907 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-qtypes",
911 bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='resqtype']",
912 /* callback = */ bind_xml_list_callback,
913 /* user_data = */ &list_info,
914 doc, path_ctx, current_time, DS_TYPE_COUNTER);
918 bind_parse_generic_name_value (/* xpath = */ "rdtype",
919 /* callback = */ bind_xml_list_callback,
920 /* user_data = */ &list_info,
921 doc, path_ctx, current_time, DS_TYPE_COUNTER);
925 if (view->resolver_stats != 0) /* {{{ */
927 char plugin_instance[DATA_MAX_NAME_LEN];
928 translation_table_ptr_t table_ptr =
930 resstats_translation_table,
931 resstats_translation_table_length,
935 ssnprintf (plugin_instance, sizeof (plugin_instance),
936 "%s-resolver_stats", view->name);
939 bind_parse_generic_name_attr_value_list ("counters[@type='resstats']",
940 /* callback = */ bind_xml_table_callback,
941 /* user_data = */ &table_ptr,
942 doc, path_ctx, current_time, DS_TYPE_COUNTER);
946 bind_parse_generic_name_value ("resstat",
947 /* callback = */ bind_xml_table_callback,
948 /* user_data = */ &table_ptr,
949 doc, path_ctx, current_time, DS_TYPE_COUNTER);
953 /* Record types in the cache */
954 if (view->cacherrsets != 0) /* {{{ */
956 char plugin_instance[DATA_MAX_NAME_LEN];
957 list_info_ptr_t list_info =
960 /* type = */ "dns_qtype_cached"
963 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-cache_rr_sets",
966 bind_parse_generic_name_value (/* xpath = */ "cache/rrset",
967 /* callback = */ bind_xml_list_callback,
968 /* user_data = */ &list_info,
969 doc, path_ctx, current_time, DS_TYPE_GAUGE);
972 // v3 does not provide per-zone stats any more
973 if (version < 3 && view->zones_num > 0)
974 bind_xml_stats_search_zones (version, doc, path_ctx, node, view,
978 } /* }}} int bind_xml_stats_handle_view */
980 static int bind_xml_stats_search_views (int version, xmlDoc *doc, /* {{{ */
981 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
983 xmlXPathObject *view_nodes = NULL;
984 xmlXPathContext *view_path_context;
987 view_path_context = xmlXPathNewContext (doc);
988 if (view_path_context == NULL)
990 ERROR ("bind plugin: xmlXPathNewContext failed.");
994 view_nodes = xmlXPathEvalExpression (BAD_CAST "views/view", xpathCtx);
995 if (view_nodes == NULL)
997 ERROR ("bind plugin: Cannot find any <view> tags.");
998 xmlXPathFreeContext (view_path_context);
1002 for (i = 0; i < view_nodes->nodesetval->nodeNr; i++)
1006 node = view_nodes->nodesetval->nodeTab[i];
1007 assert (node != NULL);
1009 view_path_context->node = node;
1011 bind_xml_stats_handle_view (version, doc, view_path_context, node,
1015 xmlXPathFreeObject (view_nodes);
1016 xmlXPathFreeContext (view_path_context);
1018 } /* }}} int bind_xml_stats_search_views */
1020 static void bind_xml_stats_v3 (xmlDoc *doc, /* {{{ */
1021 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
1023 /* XPath: server/counters[@type='opcode']
1024 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1026 * <counters type="opcode">
1027 * <counter name="A">1</counter>
1031 if (global_opcodes != 0)
1033 list_info_ptr_t list_info =
1035 /* plugin instance = */ "global-opcodes",
1036 /* type = */ "dns_opcode"
1038 bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='opcode']",
1039 /* callback = */ bind_xml_list_callback,
1040 /* user_data = */ &list_info,
1041 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1044 /* XPath: server/counters[@type='qtype']
1045 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1046 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1047 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1049 * <counters type="opcode">
1050 * <counter name="A">1</counter>
1054 if (global_qtypes != 0)
1056 list_info_ptr_t list_info =
1058 /* plugin instance = */ "global-qtypes",
1059 /* type = */ "dns_qtype"
1062 bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='qtype']",
1063 /* callback = */ bind_xml_list_callback,
1064 /* user_data = */ &list_info,
1065 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1068 /* XPath: server/counters[@type='nsstat']
1069 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1070 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1071 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1072 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1073 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1074 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1075 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1078 * <counters type="nsstat"
1079 * <counter name="Requestv4">1</counter>
1080 * <counter name="Requestv6">0</counter>
1084 if (global_server_stats)
1086 translation_table_ptr_t table_ptr =
1088 nsstats_translation_table,
1089 nsstats_translation_table_length,
1090 /* plugin_instance = */ "global-server_stats"
1093 bind_parse_generic_name_attr_value_list ("server/counters[@type='nsstat']",
1094 /* callback = */ bind_xml_table_callback,
1095 /* user_data = */ &table_ptr,
1096 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1099 /* XPath: server/zonestats, server/zonestat, server/counters[@type='zonestat']
1100 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1101 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1102 * XfrSuccess, XfrFail
1104 * <counters type="zonestat"
1105 * <counter name="NotifyOutv4">0</counter>
1106 * <counter name="NotifyOutv6">0</counter>
1110 if (global_zone_maint_stats)
1112 translation_table_ptr_t table_ptr =
1114 zonestats_translation_table,
1115 zonestats_translation_table_length,
1116 /* plugin_instance = */ "global-zone_maint_stats"
1119 bind_parse_generic_name_attr_value_list ("server/counters[@type='zonestat']",
1120 /* callback = */ bind_xml_table_callback,
1121 /* user_data = */ &table_ptr,
1122 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1125 /* XPath: server/resstats, server/counters[@type='resstat']
1126 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1127 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1128 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1129 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1131 * <counters type="resstat"
1132 * <counter name="Queryv4">0</counter>
1133 * <counter name="Queryv6">0</counter>
1137 if (global_resolver_stats != 0)
1139 translation_table_ptr_t table_ptr =
1141 resstats_translation_table,
1142 resstats_translation_table_length,
1143 /* plugin_instance = */ "global-resolver_stats"
1146 bind_parse_generic_name_attr_value_list ("server/counters[@type='resstat']",
1147 /* callback = */ bind_xml_table_callback,
1148 /* user_data = */ &table_ptr,
1149 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1151 } /* }}} bind_xml_stats_v3 */
1153 static void bind_xml_stats_v1_v2 (int version, xmlDoc *doc, /* {{{ */
1154 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
1156 /* XPath: server/requests/opcode, server/counters[@type='opcode']
1157 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1161 * <counter>1</counter>
1165 if (global_opcodes != 0)
1167 list_info_ptr_t list_info =
1169 /* plugin instance = */ "global-opcodes",
1170 /* type = */ "dns_opcode"
1173 bind_parse_generic_name_value (/* xpath = */ "server/requests/opcode",
1174 /* callback = */ bind_xml_list_callback,
1175 /* user_data = */ &list_info,
1176 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1179 /* XPath: server/queries-in/rdtype, server/counters[@type='qtype']
1180 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1181 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1182 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1186 * <counter>1</counter>
1190 if (global_qtypes != 0)
1192 list_info_ptr_t list_info =
1194 /* plugin instance = */ "global-qtypes",
1195 /* type = */ "dns_qtype"
1198 bind_parse_generic_name_value (/* xpath = */ "server/queries-in/rdtype",
1199 /* callback = */ bind_xml_list_callback,
1200 /* user_data = */ &list_info,
1201 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1204 /* XPath: server/nsstats, server/nsstat, server/counters[@type='nsstat']
1205 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1206 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1207 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1208 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1209 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1210 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1211 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1215 * <Requestv4>1</Requestv4>
1216 * <Requestv6>0</Requestv6>
1221 * <name>Requestv4</name>
1222 * <counter>1</counter>
1225 * <name>Requestv6</name>
1226 * <counter>0</counter>
1230 if (global_server_stats)
1232 translation_table_ptr_t table_ptr =
1234 nsstats_translation_table,
1235 nsstats_translation_table_length,
1236 /* plugin_instance = */ "global-server_stats"
1241 bind_parse_generic_value_list ("server/nsstats",
1242 /* callback = */ bind_xml_table_callback,
1243 /* user_data = */ &table_ptr,
1244 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1248 bind_parse_generic_name_value ("server/nsstat",
1249 /* callback = */ bind_xml_table_callback,
1250 /* user_data = */ &table_ptr,
1251 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1255 /* XPath: server/zonestats, server/zonestat, server/counters[@type='zonestat']
1256 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1257 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1258 * XfrSuccess, XfrFail
1261 * <NotifyOutv4>0</NotifyOutv4>
1262 * <NotifyOutv6>0</NotifyOutv6>
1267 * <name>NotifyOutv4</name>
1268 * <counter>0</counter>
1271 * <name>NotifyOutv6</name>
1272 * <counter>0</counter>
1276 if (global_zone_maint_stats)
1278 translation_table_ptr_t table_ptr =
1280 zonestats_translation_table,
1281 zonestats_translation_table_length,
1282 /* plugin_instance = */ "global-zone_maint_stats"
1287 bind_parse_generic_value_list ("server/zonestats",
1288 /* callback = */ bind_xml_table_callback,
1289 /* user_data = */ &table_ptr,
1290 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1294 bind_parse_generic_name_value ("server/zonestat",
1295 /* callback = */ bind_xml_table_callback,
1296 /* user_data = */ &table_ptr,
1297 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1301 /* XPath: server/resstats, server/counters[@type='resstat']
1302 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1303 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1304 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1305 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1308 * <Queryv4>0</Queryv4>
1309 * <Queryv6>0</Queryv6>
1314 * <name>Queryv4</name>
1315 * <counter>0</counter>
1318 * <name>Queryv6</name>
1319 * <counter>0</counter>
1323 if (global_resolver_stats != 0)
1325 translation_table_ptr_t table_ptr =
1327 resstats_translation_table,
1328 resstats_translation_table_length,
1329 /* plugin_instance = */ "global-resolver_stats"
1334 bind_parse_generic_value_list ("server/resstats",
1335 /* callback = */ bind_xml_table_callback,
1336 /* user_data = */ &table_ptr,
1337 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1341 bind_parse_generic_name_value ("server/resstat",
1342 /* callback = */ bind_xml_table_callback,
1343 /* user_data = */ &table_ptr,
1344 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1347 } /* }}} bind_xml_stats_v1_v2 */
1349 static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
1350 xmlXPathContext *xpathCtx, xmlNode *statsnode)
1352 time_t current_time = 0;
1355 xpathCtx->node = statsnode;
1357 /* TODO: Check `server/boot-time' to recognize server restarts. */
1359 status = bind_xml_read_timestamp ("server/current-time",
1360 doc, xpathCtx, ¤t_time);
1363 ERROR ("bind plugin: Reading `server/current-time' failed.");
1366 DEBUG ("bind plugin: Current server time is %i.", (int) current_time);
1370 bind_xml_stats_v3(doc, xpathCtx, statsnode, current_time);
1374 bind_xml_stats_v1_v2(version, doc, xpathCtx, statsnode, current_time);
1377 /* XPath: memory/summary
1378 * Variables: TotalUse, InUse, BlockSize, ContextSize, Lost
1379 * Layout: v2 and v3:
1381 * <TotalUse>6587096</TotalUse>
1382 * <InUse>1345424</InUse>
1383 * <BlockSize>5505024</BlockSize>
1384 * <ContextSize>3732456</ContextSize>
1388 if (global_memory_stats != 0)
1390 translation_table_ptr_t table_ptr =
1392 memsummary_translation_table,
1393 memsummary_translation_table_length,
1394 /* plugin_instance = */ "global-memory_stats"
1397 bind_parse_generic_value_list ("memory/summary",
1398 /* callback = */ bind_xml_table_callback,
1399 /* user_data = */ &table_ptr,
1400 doc, xpathCtx, current_time, DS_TYPE_GAUGE);
1404 bind_xml_stats_search_views (version, doc, xpathCtx, statsnode,
1408 } /* }}} int bind_xml_stats */
1410 static int bind_xml (const char *data) /* {{{ */
1413 xmlXPathContext *xpathCtx = NULL;
1414 xmlXPathObject *xpathObj = NULL;
1418 doc = xmlParseMemory (data, strlen (data));
1421 ERROR ("bind plugin: xmlParseMemory failed.");
1425 xpathCtx = xmlXPathNewContext (doc);
1426 if (xpathCtx == NULL)
1428 ERROR ("bind plugin: xmlXPathNewContext failed.");
1434 // version 3.* of statistics XML (since BIND9.9)
1437 xpathObj = xmlXPathEvalExpression (BAD_CAST "/statistics", xpathCtx);
1438 if (xpathObj == NULL || xpathObj->nodesetval == NULL || xpathObj->nodesetval->nodeNr == 0)
1440 DEBUG ("bind plugin: Statistics appears not to be v3");
1441 // we will fallback to v1 or v2 detection
1442 if (xpathObj != NULL) { xmlXPathFreeObject (xpathObj); }
1446 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++)
1451 node = xpathObj->nodesetval->nodeTab[i];
1452 assert (node != NULL);
1454 attr_version = (char *) xmlGetProp (node, BAD_CAST "version");
1455 if (attr_version == NULL)
1457 NOTICE ("bind plugin: Found <statistics> tag doesn't have a "
1458 "`version' attribute.");
1461 DEBUG ("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1463 if (strncmp ("3.", attr_version, strlen ("3.")) != 0)
1465 /* TODO: Use the complaint mechanism here. */
1466 NOTICE ("bind plugin: Found <statistics> tag with version `%s'. "
1467 "Unfortunately I have no clue how to parse that. "
1468 "Please open a bug report for this.", attr_version);
1469 xmlFree (attr_version);
1472 ret = bind_xml_stats (3, doc, xpathCtx, node);
1474 xmlFree (attr_version);
1475 /* One <statistics> node ought to be enough. */
1479 // we are finished, early-return
1480 xmlXPathFreeObject (xpathObj);
1481 xmlXPathFreeContext (xpathCtx);
1488 // versions 1.* or 2.* of statistics XML
1491 xpathObj = xmlXPathEvalExpression (BAD_CAST "/isc/bind/statistics", xpathCtx);
1492 if (xpathObj == NULL)
1494 ERROR ("bind plugin: Cannot find the <statistics> tag.");
1495 xmlXPathFreeContext (xpathCtx);
1499 else if (xpathObj->nodesetval == NULL)
1501 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
1502 xmlXPathFreeObject (xpathObj);
1503 xmlXPathFreeContext (xpathCtx);
1508 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++)
1512 int parsed_version = 0;
1514 node = xpathObj->nodesetval->nodeTab[i];
1515 assert (node != NULL);
1517 attr_version = (char *) xmlGetProp (node, BAD_CAST "version");
1518 if (attr_version == NULL)
1520 NOTICE ("bind plugin: Found <statistics> tag doesn't have a "
1521 "`version' attribute.");
1524 DEBUG ("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1526 /* At the time this plugin was written, version "1.0" was used by
1527 * BIND 9.5.0, version "2.0" was used by BIND 9.5.1 and 9.6.0. We assume
1528 * that "1.*" and "2.*" don't introduce structural changes, so we just
1529 * check for the first two characters here. */
1530 if (strncmp ("1.", attr_version, strlen ("1.")) == 0)
1532 else if (strncmp ("2.", attr_version, strlen ("2.")) == 0)
1536 /* TODO: Use the complaint mechanism here. */
1537 NOTICE ("bind plugin: Found <statistics> tag with version `%s'. "
1538 "Unfortunately I have no clue how to parse that. "
1539 "Please open a bug report for this.", attr_version);
1540 xmlFree (attr_version);
1544 ret = bind_xml_stats (parsed_version,
1545 doc, xpathCtx, node);
1547 xmlFree (attr_version);
1548 /* One <statistics> node ought to be enough. */
1552 xmlXPathFreeObject (xpathObj);
1553 xmlXPathFreeContext (xpathCtx);
1557 } /* }}} int bind_xml */
1559 static int bind_config_set_bool (const char *name, int *var, /* {{{ */
1562 if ((ci->values_num != 1) || ( ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1564 WARNING ("bind plugin: The `%s' option needs "
1565 "exactly one boolean argument.", name);
1569 if (ci->values[0].value.boolean)
1574 } /* }}} int bind_config_set_bool */
1576 static int bind_config_add_view_zone (cb_view_t *view, /* {{{ */
1581 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1583 WARNING ("bind plugin: The `Zone' option needs "
1584 "exactly one string argument.");
1588 tmp = (char **) realloc (view->zones,
1589 sizeof (char *) * (view->zones_num + 1));
1592 ERROR ("bind plugin: realloc failed.");
1597 view->zones[view->zones_num] = strdup (ci->values[0].value.string);
1598 if (view->zones[view->zones_num] == NULL)
1600 ERROR ("bind plugin: strdup failed.");
1606 } /* }}} int bind_config_add_view_zone */
1608 static int bind_config_add_view (oconfig_item_t *ci) /* {{{ */
1613 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1615 WARNING ("bind plugin: `View' blocks need exactly one string argument.");
1619 tmp = (cb_view_t *) realloc (views, sizeof (*views) * (views_num + 1));
1622 ERROR ("bind plugin: realloc failed.");
1626 tmp = views + views_num;
1628 memset (tmp, 0, sizeof (*tmp));
1630 tmp->resolver_stats = 1;
1631 tmp->cacherrsets = 1;
1635 tmp->name = strdup (ci->values[0].value.string);
1636 if (tmp->name == NULL)
1638 ERROR ("bind plugin: strdup failed.");
1643 for (i = 0; i < ci->children_num; i++)
1645 oconfig_item_t *child = ci->children + i;
1647 if (strcasecmp ("QTypes", child->key) == 0)
1648 bind_config_set_bool ("QTypes", &tmp->qtypes, child);
1649 else if (strcasecmp ("ResolverStats", child->key) == 0)
1650 bind_config_set_bool ("ResolverStats", &tmp->resolver_stats, child);
1651 else if (strcasecmp ("CacheRRSets", child->key) == 0)
1652 bind_config_set_bool ("CacheRRSets", &tmp->cacherrsets, child);
1653 else if (strcasecmp ("Zone", child->key) == 0)
1654 bind_config_add_view_zone (tmp, child);
1657 WARNING ("bind plugin: Unknown configuration option "
1658 "`%s' in view `%s' will be ignored.", child->key, tmp->name);
1660 } /* for (i = 0; i < ci->children_num; i++) */
1664 } /* }}} int bind_config_add_view */
1666 static int bind_config (oconfig_item_t *ci) /* {{{ */
1670 for (i = 0; i < ci->children_num; i++)
1672 oconfig_item_t *child = ci->children + i;
1674 if (strcasecmp ("Url", child->key) == 0) {
1675 if ((child->values_num != 1) || (child->values[0].type != OCONFIG_TYPE_STRING))
1677 WARNING ("bind plugin: The `Url' option needs "
1678 "exactly one string argument.");
1682 url = strdup (child->values[0].value.string);
1683 } else if (strcasecmp ("OpCodes", child->key) == 0)
1684 bind_config_set_bool ("OpCodes", &global_opcodes, child);
1685 else if (strcasecmp ("QTypes", child->key) == 0)
1686 bind_config_set_bool ("QTypes", &global_qtypes, child);
1687 else if (strcasecmp ("ServerStats", child->key) == 0)
1688 bind_config_set_bool ("ServerStats", &global_server_stats, child);
1689 else if (strcasecmp ("ZoneMaintStats", child->key) == 0)
1690 bind_config_set_bool ("ZoneMaintStats", &global_zone_maint_stats, child);
1691 else if (strcasecmp ("ResolverStats", child->key) == 0)
1692 bind_config_set_bool ("ResolverStats", &global_resolver_stats, child);
1693 else if (strcasecmp ("MemoryStats", child->key) == 0)
1694 bind_config_set_bool ("MemoryStats", &global_memory_stats, child);
1695 else if (strcasecmp ("View", child->key) == 0)
1696 bind_config_add_view (child);
1697 else if (strcasecmp ("ParseTime", child->key) == 0)
1698 cf_util_get_boolean (child, &config_parse_time);
1699 else if (strcasecmp ("Timeout", child->key) == 0)
1700 cf_util_get_int (child, &timeout);
1703 WARNING ("bind plugin: Unknown configuration option "
1704 "`%s' will be ignored.", child->key);
1709 } /* }}} int bind_config */
1711 static int bind_init (void) /* {{{ */
1716 curl = curl_easy_init ();
1719 ERROR ("bind plugin: bind_init: curl_easy_init failed.");
1723 curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1L);
1724 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
1725 curl_easy_setopt (curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
1726 curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, bind_curl_error);
1727 curl_easy_setopt (curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
1728 curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L);
1729 curl_easy_setopt (curl, CURLOPT_MAXREDIRS, 50L);
1730 curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, (timeout >= 0) ?
1731 timeout : CDTIME_T_TO_MS(plugin_get_interval()));
1735 } /* }}} int bind_init */
1737 static int bind_read (void) /* {{{ */
1743 ERROR ("bind plugin: I don't have a CURL object.");
1747 bind_buffer_fill = 0;
1748 if (curl_easy_perform (curl) != CURLE_OK)
1750 ERROR ("bind plugin: curl_easy_perform failed: %s",
1755 status = bind_xml (bind_buffer);
1760 } /* }}} int bind_read */
1762 static int bind_shutdown (void) /* {{{ */
1766 curl_easy_cleanup (curl);
1771 } /* }}} int bind_shutdown */
1773 void module_register (void)
1775 plugin_register_complex_config ("bind", bind_config);
1776 plugin_register_init ("bind", bind_init);
1777 plugin_register_read ("bind", bind_read);
1778 plugin_register_shutdown ("bind", bind_shutdown);
1779 } /* void module_register */
1781 /* vim: set sw=2 sts=2 ts=8 et fdm=marker : */