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
34 #define _XOPEN_SOURCE 500
36 #endif /* STRPTIME_NEEDS_STANDARDS */
42 #endif /* TIMEGM_NEEDS_BSD */
51 /* Some versions of libcurl don't include this themselves and then don't have
52 * fd_set available. */
54 #include <sys/select.h>
57 #include <curl/curl.h>
58 #include <libxml/parser.h>
59 #include <libxml/xpath.h>
61 #ifndef BIND_DEFAULT_URL
62 #define BIND_DEFAULT_URL "http://localhost:8053/"
66 * Some types used for the callback functions. `translation_table_ptr_t' and
67 * `list_info_ptr_t' are passed to the callbacks in the `void *user_data'
70 typedef int (*list_callback_t)(const char *name, value_t value,
71 time_t current_time, void *user_data);
83 typedef struct cb_view_s cb_view_t;
85 struct translation_info_s {
88 const char *type_instance;
90 typedef struct translation_info_s translation_info_t;
92 struct translation_table_ptr_s {
93 const translation_info_t *table;
95 const char *plugin_instance;
97 typedef struct translation_table_ptr_s translation_table_ptr_t;
99 struct list_info_ptr_s {
100 const char *plugin_instance;
103 typedef struct list_info_ptr_s list_info_ptr_t;
105 /* FIXME: Enabled by default for backwards compatibility. */
106 /* TODO: Remove time parsing code. */
107 static _Bool config_parse_time = 1;
109 static char *url = NULL;
110 static int global_opcodes = 1;
111 static int global_qtypes = 1;
112 static int global_server_stats = 1;
113 static int global_zone_maint_stats = 1;
114 static int global_resolver_stats = 0;
115 static int global_memory_stats = 1;
116 static int timeout = -1;
118 static cb_view_t *views = NULL;
119 static size_t views_num = 0;
121 static CURL *curl = NULL;
123 static char *bind_buffer = NULL;
124 static size_t bind_buffer_size = 0;
125 static size_t bind_buffer_fill = 0;
126 static char bind_curl_error[CURL_ERROR_SIZE];
128 /* Translation table for the `nsstats' values. */
129 static const translation_info_t nsstats_translation_table[] = /* {{{ */
132 {"Requestv4", "dns_request", "IPv4"},
133 {"Requestv6", "dns_request", "IPv6"},
134 {"ReqEdns0", "dns_request", "EDNS0"},
135 {"ReqBadEDNSVer", "dns_request", "BadEDNSVer"},
136 {"ReqTSIG", "dns_request", "TSIG"},
137 {"ReqSIG0", "dns_request", "SIG0"},
138 {"ReqBadSIG", "dns_request", "BadSIG"},
139 {"ReqTCP", "dns_request", "TCP"},
141 {"AuthQryRej", "dns_reject", "authoritative"},
142 {"RecQryRej", "dns_reject", "recursive"},
143 {"XfrRej", "dns_reject", "transfer"},
144 {"UpdateRej", "dns_reject", "update"},
146 {"Response", "dns_response", "normal"},
147 {"TruncatedResp", "dns_response", "truncated"},
148 {"RespEDNS0", "dns_response", "EDNS0"},
149 {"RespTSIG", "dns_response", "TSIG"},
150 {"RespSIG0", "dns_response", "SIG0"},
152 {"QryAuthAns", "dns_query", "authoritative"},
153 {"QryNoauthAns", "dns_query", "nonauth"},
154 {"QryReferral", "dns_query", "referral"},
155 {"QryRecursion", "dns_query", "recursion"},
156 {"QryDuplicate", "dns_query", "duplicate"},
157 {"QryDropped", "dns_query", "dropped"},
158 {"QryFailure", "dns_query", "failure"},
160 {"QrySuccess", "dns_rcode", "tx-NOERROR"},
161 {"QryNxrrset", "dns_rcode", "tx-NXRRSET"},
162 {"QrySERVFAIL", "dns_rcode", "tx-SERVFAIL"},
163 {"QryFORMERR", "dns_rcode", "tx-FORMERR"},
164 {"QryNXDOMAIN", "dns_rcode", "tx-NXDOMAIN"}
166 { "XfrReqDone", "type", "type_instance" },
167 { "UpdateReqFwd", "type", "type_instance" },
168 { "UpdateRespFwd", "type", "type_instance" },
169 { "UpdateFwdFail", "type", "type_instance" },
170 { "UpdateDone", "type", "type_instance" },
171 { "UpdateFail", "type", "type_instance" },
172 { "UpdateBadPrereq", "type", "type_instance" },
175 static int nsstats_translation_table_length =
176 STATIC_ARRAY_SIZE(nsstats_translation_table);
179 /* Translation table for the `zonestats' values. */
180 static const translation_info_t zonestats_translation_table[] = /* {{{ */
183 {"NotifyOutv4", "dns_notify", "tx-IPv4"},
184 {"NotifyOutv6", "dns_notify", "tx-IPv6"},
185 {"NotifyInv4", "dns_notify", "rx-IPv4"},
186 {"NotifyInv6", "dns_notify", "rx-IPv6"},
187 {"NotifyRej", "dns_notify", "rejected"},
188 /* SOA/AXFS/IXFS requests */
189 {"SOAOutv4", "dns_opcode", "SOA-IPv4"},
190 {"SOAOutv6", "dns_opcode", "SOA-IPv6"},
191 {"AXFRReqv4", "dns_opcode", "AXFR-IPv4"},
192 {"AXFRReqv6", "dns_opcode", "AXFR-IPv6"},
193 {"IXFRReqv4", "dns_opcode", "IXFR-IPv4"},
194 {"IXFRReqv6", "dns_opcode", "IXFR-IPv6"},
195 /* Domain transfers */
196 {"XfrSuccess", "dns_transfer", "success"},
197 {"XfrFail", "dns_transfer", "failure"}};
198 static int zonestats_translation_table_length =
199 STATIC_ARRAY_SIZE(zonestats_translation_table);
202 /* Translation table for the `resstats' values. */
203 static const translation_info_t resstats_translation_table[] = /* {{{ */
205 /* Generic resolver information */
206 {"Queryv4", "dns_query", "IPv4"},
207 {"Queryv6", "dns_query", "IPv6"},
208 {"Responsev4", "dns_response", "IPv4"},
209 {"Responsev6", "dns_response", "IPv6"},
210 /* Received response codes */
211 {"NXDOMAIN", "dns_rcode", "rx-NXDOMAIN"},
212 {"SERVFAIL", "dns_rcode", "rx-SERVFAIL"},
213 {"FORMERR", "dns_rcode", "rx-FORMERR"},
214 {"OtherError", "dns_rcode", "rx-OTHER"},
215 {"EDNS0Fail", "dns_rcode", "rx-EDNS0Fail"},
216 /* Received responses */
217 {"Mismatch", "dns_response", "mismatch"},
218 {"Truncated", "dns_response", "truncated"},
219 {"Lame", "dns_response", "lame"},
220 {"Retry", "dns_query", "retry"},
222 { "GlueFetchv4", "type", "type_instance" },
223 { "GlueFetchv6", "type", "type_instance" },
224 { "GlueFetchv4Fail", "type", "type_instance" },
225 { "GlueFetchv6Fail", "type", "type_instance" },
227 /* DNSSEC information */
228 {"ValAttempt", "dns_resolver", "DNSSEC-attempt"},
229 {"ValOk", "dns_resolver", "DNSSEC-okay"},
230 {"ValNegOk", "dns_resolver", "DNSSEC-negokay"},
231 {"ValFail", "dns_resolver", "DNSSEC-fail"}};
232 static int resstats_translation_table_length =
233 STATIC_ARRAY_SIZE(resstats_translation_table);
236 /* Translation table for the `memory/summary' values. */
237 static const translation_info_t memsummary_translation_table[] = /* {{{ */
238 {{"TotalUse", "memory", "TotalUse"},
239 {"InUse", "memory", "InUse"},
240 {"BlockSize", "memory", "BlockSize"},
241 {"ContextSize", "memory", "ContextSize"},
242 {"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) {
249 value_list_t vl = VALUE_LIST_INIT;
253 if (config_parse_time)
254 vl.time = TIME_T_TO_CDTIME_T(ts);
255 sstrncpy(vl.plugin, "bind", sizeof(vl.plugin));
256 if (plugin_instance) {
257 sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance));
258 replace_special(vl.plugin_instance, sizeof(vl.plugin_instance));
260 sstrncpy(vl.type, type, sizeof(vl.type));
262 sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
263 replace_special(vl.type_instance, sizeof(vl.type_instance));
265 plugin_dispatch_values(&vl);
266 } /* }}} void submit */
268 static size_t bind_curl_callback(void *buf, size_t size, /* {{{ */
270 void __attribute__((unused)) * stream) {
271 size_t len = size * nmemb;
276 if ((bind_buffer_fill + len) >= bind_buffer_size) {
279 temp = realloc(bind_buffer, bind_buffer_fill + len + 1);
281 ERROR("bind plugin: realloc failed.");
285 bind_buffer_size = bind_buffer_fill + len + 1;
288 memcpy(bind_buffer + bind_buffer_fill, (char *)buf, len);
289 bind_buffer_fill += len;
290 bind_buffer[bind_buffer_fill] = 0;
293 } /* }}} size_t bind_curl_callback */
296 * Callback, that's called with a translation table.
297 * (Plugin instance is fixed, type and type instance come from lookup table.)
299 static int bind_xml_table_callback(const char *name, value_t value, /* {{{ */
300 time_t current_time, void *user_data) {
301 translation_table_ptr_t *table = (translation_table_ptr_t *)user_data;
306 for (size_t i = 0; i < table->table_length; i++) {
307 if (strcmp(table->table[i].xml_name, name) != 0)
310 submit(current_time, table->plugin_instance, table->table[i].type,
311 table->table[i].type_instance, value);
316 } /* }}} int bind_xml_table_callback */
319 * Callback, that's used for lists.
320 * (Plugin instance and type are fixed, xml name is used as type instance.)
322 static int bind_xml_list_callback(const char *name, /* {{{ */
323 value_t value, time_t current_time,
325 list_info_ptr_t *list_info = (list_info_ptr_t *)user_data;
327 if (list_info == NULL)
330 submit(current_time, list_info->plugin_instance, list_info->type,
331 /* type instance = */ name, value);
334 } /* }}} int bind_xml_list_callback */
336 static int bind_xml_read_derive(xmlDoc *doc, xmlNode *node, /* {{{ */
337 derive_t *ret_value) {
342 str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
343 if (str_ptr == NULL) {
344 ERROR("bind plugin: bind_xml_read_derive: xmlNodeListGetString failed.");
348 status = parse_value(str_ptr, &value, DS_TYPE_DERIVE);
350 ERROR("bind plugin: Parsing string \"%s\" to derive value failed.",
357 *ret_value = value.derive;
359 } /* }}} int bind_xml_read_derive */
361 static int bind_xml_read_gauge(xmlDoc *doc, xmlNode *node, /* {{{ */
362 gauge_t *ret_value) {
363 char *str_ptr, *end_ptr;
366 str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
367 if (str_ptr == NULL) {
368 ERROR("bind plugin: bind_xml_read_gauge: xmlNodeListGetString failed.");
373 value = strtod(str_ptr, &end_ptr);
375 if (str_ptr == end_ptr || errno) {
376 if (errno && (value < 0))
377 ERROR("bind plugin: bind_xml_read_gauge: strtod failed with underflow.");
378 else if (errno && (value > 0))
379 ERROR("bind plugin: bind_xml_read_gauge: strtod failed with overflow.");
381 ERROR("bind plugin: bind_xml_read_gauge: strtod failed.");
385 *ret_value = (gauge_t)value;
387 } /* }}} int bind_xml_read_gauge */
389 static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */
390 xmlDoc *doc, xmlXPathContext *xpathCtx,
392 xmlXPathObject *xpathObj = NULL;
398 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
399 if (xpathObj == NULL) {
400 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
405 if ((xpathObj->nodesetval == NULL) || (xpathObj->nodesetval->nodeNr < 1)) {
406 xmlXPathFreeObject(xpathObj);
410 if (xpathObj->nodesetval->nodeNr != 1) {
411 NOTICE("bind plugin: Evaluating the XPath expression `%s' returned "
412 "%i nodes. Only handling the first one.",
413 xpath_expression, xpathObj->nodesetval->nodeNr);
416 node = xpathObj->nodesetval->nodeTab[0];
418 if (node->xmlChildrenNode == NULL) {
419 ERROR("bind plugin: bind_xml_read_timestamp: "
420 "node->xmlChildrenNode == NULL");
421 xmlXPathFreeObject(xpathObj);
425 str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
426 if (str_ptr == NULL) {
427 ERROR("bind plugin: bind_xml_read_timestamp: xmlNodeListGetString failed.");
428 xmlXPathFreeObject(xpathObj);
432 tmp = strptime(str_ptr, "%Y-%m-%dT%T", &tm);
435 ERROR("bind plugin: bind_xml_read_timestamp: strptime failed.");
436 xmlXPathFreeObject(xpathObj);
441 time_t t = timegm(&tm);
442 if (t == ((time_t)-1)) {
444 ERROR("bind plugin: timegm() failed: %s",
445 sstrerror(errno, errbuf, sizeof(errbuf)));
450 time_t t = mktime(&tm);
451 if (t == ((time_t)-1)) {
453 ERROR("bind plugin: mktime() failed: %s",
454 sstrerror(errno, errbuf, sizeof(errbuf)));
457 /* mktime assumes that tm is local time. Luckily, it also sets timezone to
458 * the offset used for the conversion, and we undo the conversion to convert
460 *ret_value = t - timezone;
463 xmlXPathFreeObject(xpathObj);
465 } /* }}} int bind_xml_read_timestamp */
468 * bind_parse_generic_name_value
470 * Reads statistics in the form:
473 * <counter>123</counter>
476 static int bind_parse_generic_name_value(const char *xpath_expression, /* {{{ */
477 list_callback_t list_callback,
478 void *user_data, xmlDoc *doc,
479 xmlXPathContext *xpathCtx,
480 time_t current_time, int ds_type) {
481 xmlXPathObject *xpathObj = NULL;
484 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
485 if (xpathObj == NULL) {
486 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
492 /* Iterate over all matching nodes. */
493 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
495 xmlNode *name_node = NULL;
496 xmlNode *counter = NULL;
499 parent = xpathObj->nodesetval->nodeTab[i];
500 DEBUG("bind plugin: bind_parse_generic_name_value: parent->name = %s;",
501 (char *)parent->name);
503 /* Iterate over all child nodes. */
504 for (xmlNode *child = parent->xmlChildrenNode; child != NULL;
505 child = child->next) {
506 if (child->type != XML_ELEMENT_NODE)
509 if (xmlStrcmp(BAD_CAST "name", child->name) == 0)
511 else if (xmlStrcmp(BAD_CAST "counter", child->name) == 0)
515 if ((name_node != NULL) && (counter != NULL)) {
517 (char *)xmlNodeListGetString(doc, name_node->xmlChildrenNode, 1);
521 if (ds_type == DS_TYPE_GAUGE)
522 status = bind_xml_read_gauge(doc, counter, &value.gauge);
524 status = bind_xml_read_derive(doc, counter, &value.derive);
530 status = (*list_callback)(name, value, current_time, user_data);
538 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
539 (num_entries == 1) ? "entry" : "entries", xpath_expression);
541 xmlXPathFreeObject(xpathObj);
544 } /* }}} int bind_parse_generic_name_value */
547 * bind_parse_generic_value_list
549 * Reads statistics in the form:
557 static int bind_parse_generic_value_list(const char *xpath_expression, /* {{{ */
558 list_callback_t list_callback,
559 void *user_data, xmlDoc *doc,
560 xmlXPathContext *xpathCtx,
561 time_t current_time, int ds_type) {
562 xmlXPathObject *xpathObj = NULL;
565 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
566 if (xpathObj == NULL) {
567 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
573 /* Iterate over all matching nodes. */
574 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
576 /* Iterate over all child nodes. */
577 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
578 child != NULL; child = child->next) {
583 if (child->type != XML_ELEMENT_NODE)
586 node_name = (char *)child->name;
588 if (ds_type == DS_TYPE_GAUGE)
589 status = bind_xml_read_gauge(doc, child, &value.gauge);
591 status = bind_xml_read_derive(doc, child, &value.derive);
595 status = (*list_callback)(node_name, value, current_time, user_data);
601 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
602 (num_entries == 1) ? "entry" : "entries", xpath_expression);
604 xmlXPathFreeObject(xpathObj);
607 } /* }}} int bind_parse_generic_value_list */
610 * bind_parse_generic_name_attr_value_list
612 * Reads statistics in the form:
614 * <counter name="name0">123</counter>
615 * <counter name="name1">234</counter>
616 * <counter name="name2">345</counter>
620 static int bind_parse_generic_name_attr_value_list(
621 const char *xpath_expression, /* {{{ */
622 list_callback_t list_callback, void *user_data, xmlDoc *doc,
623 xmlXPathContext *xpathCtx, time_t current_time, int ds_type) {
624 xmlXPathObject *xpathObj = NULL;
627 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
628 if (xpathObj == NULL) {
629 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
635 /* Iterate over all matching nodes. */
636 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
638 /* Iterate over all child nodes. */
639 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
640 child != NULL; child = child->next) {
641 if (child->type != XML_ELEMENT_NODE)
644 if (strncmp("counter", (char *)child->name, strlen("counter")) != 0)
651 attr_name = (char *)xmlGetProp(child, BAD_CAST "name");
652 if (attr_name == NULL) {
653 DEBUG("bind plugin: found <counter> without name.");
656 if (ds_type == DS_TYPE_GAUGE)
657 status = bind_xml_read_gauge(doc, child, &value.gauge);
659 status = bind_xml_read_derive(doc, child, &value.derive);
665 status = (*list_callback)(attr_name, value, current_time, user_data);
673 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
674 (num_entries == 1) ? "entry" : "entries", xpath_expression);
676 xmlXPathFreeObject(xpathObj);
679 } /* }}} int bind_parse_generic_name_attr_value_list */
681 static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */
682 xmlXPathContext *path_ctx, xmlNode *node,
683 cb_view_t *view, time_t current_time) {
684 xmlXPathObject *path_obj;
685 char *zone_name = NULL;
689 char *n = (char *)xmlGetProp(node, BAD_CAST "name");
690 char *c = (char *)xmlGetProp(node, BAD_CAST "rdataclass");
692 zone_name = (char *)xmlMalloc(strlen(n) + strlen(c) + 2);
693 snprintf(zone_name, strlen(n) + strlen(c) + 2, "%s/%s", n, c);
698 path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
699 if (path_obj == NULL) {
700 ERROR("bind plugin: xmlXPathEvalExpression failed.");
704 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
706 zone_name = (char *)xmlNodeListGetString(
707 doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
708 if (zone_name != NULL)
711 xmlXPathFreeObject(path_obj);
714 if (zone_name == NULL) {
715 ERROR("bind plugin: Could not determine zone name.");
719 for (j = 0; j < view->zones_num; j++) {
720 if (strcasecmp(zone_name, view->zones[j]) == 0)
727 if (j >= view->zones_num)
730 zone_name = view->zones[j];
732 DEBUG("bind plugin: bind_xml_stats_handle_zone: Found zone `%s'.", zone_name);
734 { /* Parse the <counters> tag {{{ */
735 char plugin_instance[DATA_MAX_NAME_LEN];
736 translation_table_ptr_t table_ptr = {nsstats_translation_table,
737 nsstats_translation_table_length,
740 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-zone-%s",
741 view->name, zone_name);
744 list_info_ptr_t list_info = {plugin_instance,
745 /* type = */ "dns_qtype"};
746 bind_parse_generic_name_attr_value_list(
747 /* xpath = */ "counters[@type='rcode']",
748 /* callback = */ bind_xml_table_callback,
749 /* user_data = */ &table_ptr, doc, path_ctx, current_time,
751 bind_parse_generic_name_attr_value_list(
752 /* xpath = */ "counters[@type='qtype']",
753 /* callback = */ bind_xml_list_callback,
754 /* user_data = */ &list_info, doc, path_ctx, current_time,
757 bind_parse_generic_value_list(/* xpath = */ "counters",
758 /* callback = */ bind_xml_table_callback,
759 /* user_data = */ &table_ptr, doc, path_ctx,
760 current_time, DS_TYPE_COUNTER);
765 } /* }}} int bind_xml_stats_handle_zone */
767 static int bind_xml_stats_search_zones(int version, xmlDoc *doc, /* {{{ */
768 xmlXPathContext *path_ctx, xmlNode *node,
769 cb_view_t *view, time_t current_time) {
770 xmlXPathObject *zone_nodes = NULL;
771 xmlXPathContext *zone_path_context;
773 zone_path_context = xmlXPathNewContext(doc);
774 if (zone_path_context == NULL) {
775 ERROR("bind plugin: xmlXPathNewContext failed.");
779 zone_nodes = xmlXPathEvalExpression(BAD_CAST "zones/zone", path_ctx);
780 if (zone_nodes == NULL) {
781 ERROR("bind plugin: Cannot find any <view> tags.");
782 xmlXPathFreeContext(zone_path_context);
786 for (int i = 0; i < zone_nodes->nodesetval->nodeNr; i++) {
787 node = zone_nodes->nodesetval->nodeTab[i];
788 assert(node != NULL);
790 zone_path_context->node = node;
792 bind_xml_stats_handle_zone(version, doc, zone_path_context, node, view,
796 xmlXPathFreeObject(zone_nodes);
797 xmlXPathFreeContext(zone_path_context);
799 } /* }}} int bind_xml_stats_search_zones */
801 static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */
802 xmlXPathContext *path_ctx, xmlNode *node,
803 time_t current_time) {
804 char *view_name = NULL;
809 view_name = (char *)xmlGetProp(node, BAD_CAST "name");
811 if (view_name == NULL) {
812 ERROR("bind plugin: Could not determine view name.");
816 for (j = 0; j < views_num; j++) {
817 if (strcasecmp(view_name, views[j].name) == 0)
824 xmlXPathObject *path_obj;
825 path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
826 if (path_obj == NULL) {
827 ERROR("bind plugin: xmlXPathEvalExpression failed.");
831 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
833 view_name = (char *)xmlNodeListGetString(
834 doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
835 if (view_name != NULL)
839 if (view_name == NULL) {
840 ERROR("bind plugin: Could not determine view name.");
841 xmlXPathFreeObject(path_obj);
845 for (j = 0; j < views_num; j++) {
846 if (strcasecmp(view_name, views[j].name) == 0)
851 xmlXPathFreeObject(path_obj);
862 DEBUG("bind plugin: bind_xml_stats_handle_view: Found view `%s'.",
865 if (view->qtypes != 0) /* {{{ */
867 char plugin_instance[DATA_MAX_NAME_LEN];
868 list_info_ptr_t list_info = {plugin_instance,
869 /* type = */ "dns_qtype"};
871 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-qtypes",
874 bind_parse_generic_name_attr_value_list(
875 /* xpath = */ "counters[@type='resqtype']",
876 /* callback = */ bind_xml_list_callback,
877 /* user_data = */ &list_info, doc, path_ctx, current_time,
880 bind_parse_generic_name_value(/* xpath = */ "rdtype",
881 /* callback = */ bind_xml_list_callback,
882 /* user_data = */ &list_info, doc, path_ctx,
883 current_time, DS_TYPE_COUNTER);
887 if (view->resolver_stats != 0) /* {{{ */
889 char plugin_instance[DATA_MAX_NAME_LEN];
890 translation_table_ptr_t table_ptr = {resstats_translation_table,
891 resstats_translation_table_length,
894 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-resolver_stats",
897 bind_parse_generic_name_attr_value_list(
898 "counters[@type='resstats']",
899 /* callback = */ bind_xml_table_callback,
900 /* user_data = */ &table_ptr, doc, path_ctx, current_time,
903 bind_parse_generic_name_value("resstat",
904 /* callback = */ bind_xml_table_callback,
905 /* user_data = */ &table_ptr, doc, path_ctx,
906 current_time, DS_TYPE_COUNTER);
910 /* Record types in the cache */
911 if (view->cacherrsets != 0) /* {{{ */
913 char plugin_instance[DATA_MAX_NAME_LEN];
914 list_info_ptr_t list_info = {plugin_instance,
915 /* type = */ "dns_qtype_cached"};
917 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-cache_rr_sets",
920 bind_parse_generic_name_value(/* xpath = */ "cache/rrset",
921 /* callback = */ bind_xml_list_callback,
922 /* user_data = */ &list_info, doc, path_ctx,
923 current_time, DS_TYPE_GAUGE);
926 if (view->zones_num > 0)
927 bind_xml_stats_search_zones(version, doc, path_ctx, node, view,
931 } /* }}} int bind_xml_stats_handle_view */
933 static int bind_xml_stats_search_views(int version, xmlDoc *doc, /* {{{ */
934 xmlXPathContext *xpathCtx,
936 time_t current_time) {
937 xmlXPathObject *view_nodes = NULL;
938 xmlXPathContext *view_path_context;
940 view_path_context = xmlXPathNewContext(doc);
941 if (view_path_context == NULL) {
942 ERROR("bind plugin: xmlXPathNewContext failed.");
946 view_nodes = xmlXPathEvalExpression(BAD_CAST "views/view", xpathCtx);
947 if (view_nodes == NULL) {
948 ERROR("bind plugin: Cannot find any <view> tags.");
949 xmlXPathFreeContext(view_path_context);
953 for (int i = 0; i < view_nodes->nodesetval->nodeNr; i++) {
956 node = view_nodes->nodesetval->nodeTab[i];
957 assert(node != NULL);
959 view_path_context->node = node;
961 bind_xml_stats_handle_view(version, doc, view_path_context, node,
965 xmlXPathFreeObject(view_nodes);
966 xmlXPathFreeContext(view_path_context);
968 } /* }}} int bind_xml_stats_search_views */
970 static void bind_xml_stats_v3(xmlDoc *doc, /* {{{ */
971 xmlXPathContext *xpathCtx, xmlNode *statsnode,
972 time_t current_time) {
973 /* XPath: server/counters[@type='opcode']
974 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
976 * <counters type="opcode">
977 * <counter name="A">1</counter>
981 if (global_opcodes != 0) {
982 list_info_ptr_t list_info = {/* plugin instance = */ "global-opcodes",
983 /* type = */ "dns_opcode"};
984 bind_parse_generic_name_attr_value_list(
985 /* xpath = */ "server/counters[@type='opcode']",
986 /* callback = */ bind_xml_list_callback,
987 /* user_data = */ &list_info, doc, xpathCtx, current_time,
991 /* XPath: server/counters[@type='qtype']
992 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
993 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
994 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
996 * <counters type="opcode">
997 * <counter name="A">1</counter>
1001 if (global_qtypes != 0) {
1002 list_info_ptr_t list_info = {/* plugin instance = */ "global-qtypes",
1003 /* type = */ "dns_qtype"};
1005 bind_parse_generic_name_attr_value_list(
1006 /* xpath = */ "server/counters[@type='qtype']",
1007 /* callback = */ bind_xml_list_callback,
1008 /* user_data = */ &list_info, doc, xpathCtx, current_time,
1012 /* XPath: server/counters[@type='nsstat']
1013 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1014 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1015 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1016 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1017 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1018 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1019 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1022 * <counters type="nsstat"
1023 * <counter name="Requestv4">1</counter>
1024 * <counter name="Requestv6">0</counter>
1028 if (global_server_stats) {
1029 translation_table_ptr_t table_ptr = {
1030 nsstats_translation_table, nsstats_translation_table_length,
1031 /* plugin_instance = */ "global-server_stats"};
1033 bind_parse_generic_name_attr_value_list(
1034 "server/counters[@type='nsstat']",
1035 /* callback = */ bind_xml_table_callback,
1036 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1040 /* XPath: server/zonestats, server/zonestat,
1041 * server/counters[@type='zonestat']
1042 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1043 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1044 * XfrSuccess, XfrFail
1046 * <counters type="zonestat"
1047 * <counter name="NotifyOutv4">0</counter>
1048 * <counter name="NotifyOutv6">0</counter>
1052 if (global_zone_maint_stats) {
1053 translation_table_ptr_t table_ptr = {
1054 zonestats_translation_table, zonestats_translation_table_length,
1055 /* plugin_instance = */ "global-zone_maint_stats"};
1057 bind_parse_generic_name_attr_value_list(
1058 "server/counters[@type='zonestat']",
1059 /* callback = */ bind_xml_table_callback,
1060 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1064 /* XPath: server/resstats, server/counters[@type='resstat']
1065 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1066 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1067 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1068 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1070 * <counters type="resstat"
1071 * <counter name="Queryv4">0</counter>
1072 * <counter name="Queryv6">0</counter>
1076 if (global_resolver_stats != 0) {
1077 translation_table_ptr_t table_ptr = {
1078 resstats_translation_table, resstats_translation_table_length,
1079 /* plugin_instance = */ "global-resolver_stats"};
1081 bind_parse_generic_name_attr_value_list(
1082 "server/counters[@type='resstat']",
1083 /* callback = */ bind_xml_table_callback,
1084 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1087 } /* }}} bind_xml_stats_v3 */
1089 static void bind_xml_stats_v1_v2(int version, xmlDoc *doc, /* {{{ */
1090 xmlXPathContext *xpathCtx, xmlNode *statsnode,
1091 time_t current_time) {
1092 /* XPath: server/requests/opcode, server/counters[@type='opcode']
1093 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1097 * <counter>1</counter>
1101 if (global_opcodes != 0) {
1102 list_info_ptr_t list_info = {/* plugin instance = */ "global-opcodes",
1103 /* type = */ "dns_opcode"};
1105 bind_parse_generic_name_value(/* xpath = */ "server/requests/opcode",
1106 /* callback = */ bind_xml_list_callback,
1107 /* user_data = */ &list_info, doc, xpathCtx,
1108 current_time, DS_TYPE_COUNTER);
1111 /* XPath: server/queries-in/rdtype, server/counters[@type='qtype']
1112 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1113 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1114 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1118 * <counter>1</counter>
1122 if (global_qtypes != 0) {
1123 list_info_ptr_t list_info = {/* plugin instance = */ "global-qtypes",
1124 /* type = */ "dns_qtype"};
1126 bind_parse_generic_name_value(/* xpath = */ "server/queries-in/rdtype",
1127 /* callback = */ bind_xml_list_callback,
1128 /* user_data = */ &list_info, doc, xpathCtx,
1129 current_time, DS_TYPE_COUNTER);
1132 /* XPath: server/nsstats, server/nsstat, server/counters[@type='nsstat']
1133 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1134 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1135 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1136 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1137 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1138 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1139 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1143 * <Requestv4>1</Requestv4>
1144 * <Requestv6>0</Requestv6>
1149 * <name>Requestv4</name>
1150 * <counter>1</counter>
1153 * <name>Requestv6</name>
1154 * <counter>0</counter>
1158 if (global_server_stats) {
1159 translation_table_ptr_t table_ptr = {
1160 nsstats_translation_table, nsstats_translation_table_length,
1161 /* plugin_instance = */ "global-server_stats"};
1164 bind_parse_generic_value_list("server/nsstats",
1165 /* callback = */ bind_xml_table_callback,
1166 /* user_data = */ &table_ptr, doc, xpathCtx,
1167 current_time, DS_TYPE_COUNTER);
1169 bind_parse_generic_name_value("server/nsstat",
1170 /* callback = */ bind_xml_table_callback,
1171 /* user_data = */ &table_ptr, doc, xpathCtx,
1172 current_time, DS_TYPE_COUNTER);
1176 /* XPath: server/zonestats, server/zonestat,
1177 * server/counters[@type='zonestat']
1178 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1179 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1180 * XfrSuccess, XfrFail
1183 * <NotifyOutv4>0</NotifyOutv4>
1184 * <NotifyOutv6>0</NotifyOutv6>
1189 * <name>NotifyOutv4</name>
1190 * <counter>0</counter>
1193 * <name>NotifyOutv6</name>
1194 * <counter>0</counter>
1198 if (global_zone_maint_stats) {
1199 translation_table_ptr_t table_ptr = {
1200 zonestats_translation_table, zonestats_translation_table_length,
1201 /* plugin_instance = */ "global-zone_maint_stats"};
1204 bind_parse_generic_value_list("server/zonestats",
1205 /* callback = */ bind_xml_table_callback,
1206 /* user_data = */ &table_ptr, doc, xpathCtx,
1207 current_time, DS_TYPE_COUNTER);
1209 bind_parse_generic_name_value("server/zonestat",
1210 /* callback = */ bind_xml_table_callback,
1211 /* user_data = */ &table_ptr, doc, xpathCtx,
1212 current_time, DS_TYPE_COUNTER);
1216 /* XPath: server/resstats, server/counters[@type='resstat']
1217 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1218 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1219 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1220 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1223 * <Queryv4>0</Queryv4>
1224 * <Queryv6>0</Queryv6>
1229 * <name>Queryv4</name>
1230 * <counter>0</counter>
1233 * <name>Queryv6</name>
1234 * <counter>0</counter>
1238 if (global_resolver_stats != 0) {
1239 translation_table_ptr_t table_ptr = {
1240 resstats_translation_table, resstats_translation_table_length,
1241 /* plugin_instance = */ "global-resolver_stats"};
1244 bind_parse_generic_value_list("server/resstats",
1245 /* callback = */ bind_xml_table_callback,
1246 /* user_data = */ &table_ptr, doc, xpathCtx,
1247 current_time, DS_TYPE_COUNTER);
1249 bind_parse_generic_name_value("server/resstat",
1250 /* callback = */ bind_xml_table_callback,
1251 /* user_data = */ &table_ptr, doc, xpathCtx,
1252 current_time, DS_TYPE_COUNTER);
1255 } /* }}} bind_xml_stats_v1_v2 */
1257 static int bind_xml_stats(int version, xmlDoc *doc, /* {{{ */
1258 xmlXPathContext *xpathCtx, xmlNode *statsnode) {
1259 time_t current_time = 0;
1262 xpathCtx->node = statsnode;
1264 /* TODO: Check `server/boot-time' to recognize server restarts. */
1266 status = bind_xml_read_timestamp("server/current-time", doc, xpathCtx,
1269 ERROR("bind plugin: Reading `server/current-time' failed.");
1272 DEBUG("bind plugin: Current server time is %i.", (int)current_time);
1275 bind_xml_stats_v3(doc, xpathCtx, statsnode, current_time);
1277 bind_xml_stats_v1_v2(version, doc, xpathCtx, statsnode, current_time);
1280 /* XPath: memory/summary
1281 * Variables: TotalUse, InUse, BlockSize, ContextSize, Lost
1282 * Layout: v2 and v3:
1284 * <TotalUse>6587096</TotalUse>
1285 * <InUse>1345424</InUse>
1286 * <BlockSize>5505024</BlockSize>
1287 * <ContextSize>3732456</ContextSize>
1291 if (global_memory_stats != 0) {
1292 translation_table_ptr_t table_ptr = {
1293 memsummary_translation_table, memsummary_translation_table_length,
1294 /* plugin_instance = */ "global-memory_stats"};
1296 bind_parse_generic_value_list("memory/summary",
1297 /* callback = */ bind_xml_table_callback,
1298 /* user_data = */ &table_ptr, doc, xpathCtx,
1299 current_time, DS_TYPE_GAUGE);
1303 bind_xml_stats_search_views(version, doc, xpathCtx, statsnode,
1307 } /* }}} int bind_xml_stats */
1309 static int bind_xml(const char *data) /* {{{ */
1312 xmlXPathContext *xpathCtx = NULL;
1313 xmlXPathObject *xpathObj = NULL;
1316 doc = xmlParseMemory(data, strlen(data));
1318 ERROR("bind plugin: xmlParseMemory failed.");
1322 xpathCtx = xmlXPathNewContext(doc);
1323 if (xpathCtx == NULL) {
1324 ERROR("bind plugin: xmlXPathNewContext failed.");
1330 // version 3.* of statistics XML (since BIND9.9)
1333 xpathObj = xmlXPathEvalExpression(BAD_CAST "/statistics", xpathCtx);
1334 if (xpathObj == NULL || xpathObj->nodesetval == NULL ||
1335 xpathObj->nodesetval->nodeNr == 0) {
1336 DEBUG("bind plugin: Statistics appears not to be v3");
1337 // we will fallback to v1 or v2 detection
1338 if (xpathObj != NULL) {
1339 xmlXPathFreeObject(xpathObj);
1342 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
1346 node = xpathObj->nodesetval->nodeTab[i];
1347 assert(node != NULL);
1349 attr_version = (char *)xmlGetProp(node, BAD_CAST "version");
1350 if (attr_version == NULL) {
1351 NOTICE("bind plugin: Found <statistics> tag doesn't have a "
1352 "`version' attribute.");
1355 DEBUG("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1357 if (strncmp("3.", attr_version, strlen("3.")) != 0) {
1358 /* TODO: Use the complaint mechanism here. */
1359 NOTICE("bind plugin: Found <statistics> tag with version `%s'. "
1360 "Unfortunately I have no clue how to parse that. "
1361 "Please open a bug report for this.",
1363 xmlFree(attr_version);
1366 ret = bind_xml_stats(3, doc, xpathCtx, node);
1368 xmlFree(attr_version);
1369 /* One <statistics> node ought to be enough. */
1373 // we are finished, early-return
1374 xmlXPathFreeObject(xpathObj);
1375 xmlXPathFreeContext(xpathCtx);
1382 // versions 1.* or 2.* of statistics XML
1385 xpathObj = xmlXPathEvalExpression(BAD_CAST "/isc/bind/statistics", xpathCtx);
1386 if (xpathObj == NULL) {
1387 ERROR("bind plugin: Cannot find the <statistics> tag.");
1388 xmlXPathFreeContext(xpathCtx);
1391 } else if (xpathObj->nodesetval == NULL) {
1392 ERROR("bind plugin: xmlXPathEvalExpression failed.");
1393 xmlXPathFreeObject(xpathObj);
1394 xmlXPathFreeContext(xpathCtx);
1399 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
1402 int parsed_version = 0;
1404 node = xpathObj->nodesetval->nodeTab[i];
1405 assert(node != NULL);
1407 attr_version = (char *)xmlGetProp(node, BAD_CAST "version");
1408 if (attr_version == NULL) {
1409 NOTICE("bind plugin: Found <statistics> tag doesn't have a "
1410 "`version' attribute.");
1413 DEBUG("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1415 /* At the time this plugin was written, version "1.0" was used by
1416 * BIND 9.5.0, version "2.0" was used by BIND 9.5.1 and 9.6.0. We assume
1417 * that "1.*" and "2.*" don't introduce structural changes, so we just
1418 * check for the first two characters here. */
1419 if (strncmp("1.", attr_version, strlen("1.")) == 0)
1421 else if (strncmp("2.", attr_version, strlen("2.")) == 0)
1424 /* TODO: Use the complaint mechanism here. */
1425 NOTICE("bind plugin: Found <statistics> tag with version `%s'. "
1426 "Unfortunately I have no clue how to parse that. "
1427 "Please open a bug report for this.",
1429 xmlFree(attr_version);
1433 ret = bind_xml_stats(parsed_version, doc, xpathCtx, node);
1435 xmlFree(attr_version);
1436 /* One <statistics> node ought to be enough. */
1440 xmlXPathFreeObject(xpathObj);
1441 xmlXPathFreeContext(xpathCtx);
1445 } /* }}} int bind_xml */
1447 static int bind_config_set_bool(const char *name, int *var, /* {{{ */
1448 oconfig_item_t *ci) {
1449 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
1450 WARNING("bind plugin: The `%s' option needs "
1451 "exactly one boolean argument.",
1456 if (ci->values[0].value.boolean)
1461 } /* }}} int bind_config_set_bool */
1463 static int bind_config_add_view_zone(cb_view_t *view, /* {{{ */
1464 oconfig_item_t *ci) {
1467 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1468 WARNING("bind plugin: The `Zone' option needs "
1469 "exactly one string argument.");
1473 tmp = realloc(view->zones, sizeof(char *) * (view->zones_num + 1));
1475 ERROR("bind plugin: realloc failed.");
1480 view->zones[view->zones_num] = strdup(ci->values[0].value.string);
1481 if (view->zones[view->zones_num] == NULL) {
1482 ERROR("bind plugin: strdup failed.");
1488 } /* }}} int bind_config_add_view_zone */
1490 static int bind_config_add_view(oconfig_item_t *ci) /* {{{ */
1494 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1495 WARNING("bind plugin: `View' blocks need exactly one string argument.");
1499 tmp = realloc(views, sizeof(*views) * (views_num + 1));
1501 ERROR("bind plugin: realloc failed.");
1505 tmp = views + views_num;
1507 memset(tmp, 0, sizeof(*tmp));
1509 tmp->resolver_stats = 1;
1510 tmp->cacherrsets = 1;
1514 tmp->name = strdup(ci->values[0].value.string);
1515 if (tmp->name == NULL) {
1516 ERROR("bind plugin: strdup failed.");
1521 for (int i = 0; i < ci->children_num; i++) {
1522 oconfig_item_t *child = ci->children + i;
1524 if (strcasecmp("QTypes", child->key) == 0)
1525 bind_config_set_bool("QTypes", &tmp->qtypes, child);
1526 else if (strcasecmp("ResolverStats", child->key) == 0)
1527 bind_config_set_bool("ResolverStats", &tmp->resolver_stats, child);
1528 else if (strcasecmp("CacheRRSets", child->key) == 0)
1529 bind_config_set_bool("CacheRRSets", &tmp->cacherrsets, child);
1530 else if (strcasecmp("Zone", child->key) == 0)
1531 bind_config_add_view_zone(tmp, child);
1533 WARNING("bind plugin: Unknown configuration option "
1534 "`%s' in view `%s' will be ignored.",
1535 child->key, tmp->name);
1537 } /* for (i = 0; i < ci->children_num; i++) */
1541 } /* }}} int bind_config_add_view */
1543 static int bind_config(oconfig_item_t *ci) /* {{{ */
1545 for (int i = 0; i < ci->children_num; i++) {
1546 oconfig_item_t *child = ci->children + i;
1548 if (strcasecmp("Url", child->key) == 0) {
1549 if ((child->values_num != 1) ||
1550 (child->values[0].type != OCONFIG_TYPE_STRING)) {
1551 WARNING("bind plugin: The `Url' option needs "
1552 "exactly one string argument.");
1557 url = strdup(child->values[0].value.string);
1558 } else if (strcasecmp("OpCodes", child->key) == 0)
1559 bind_config_set_bool("OpCodes", &global_opcodes, child);
1560 else if (strcasecmp("QTypes", child->key) == 0)
1561 bind_config_set_bool("QTypes", &global_qtypes, child);
1562 else if (strcasecmp("ServerStats", child->key) == 0)
1563 bind_config_set_bool("ServerStats", &global_server_stats, child);
1564 else if (strcasecmp("ZoneMaintStats", child->key) == 0)
1565 bind_config_set_bool("ZoneMaintStats", &global_zone_maint_stats, child);
1566 else if (strcasecmp("ResolverStats", child->key) == 0)
1567 bind_config_set_bool("ResolverStats", &global_resolver_stats, child);
1568 else if (strcasecmp("MemoryStats", child->key) == 0)
1569 bind_config_set_bool("MemoryStats", &global_memory_stats, child);
1570 else if (strcasecmp("View", child->key) == 0)
1571 bind_config_add_view(child);
1572 else if (strcasecmp("ParseTime", child->key) == 0)
1573 cf_util_get_boolean(child, &config_parse_time);
1574 else if (strcasecmp("Timeout", child->key) == 0)
1575 cf_util_get_int(child, &timeout);
1577 WARNING("bind plugin: Unknown configuration option "
1578 "`%s' will be ignored.",
1584 } /* }}} int bind_config */
1586 static int bind_init(void) /* {{{ */
1591 curl = curl_easy_init();
1593 ERROR("bind plugin: bind_init: curl_easy_init failed.");
1597 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
1598 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
1599 curl_easy_setopt(curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
1600 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, bind_curl_error);
1601 curl_easy_setopt(curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
1602 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
1603 curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
1604 #ifdef HAVE_CURLOPT_TIMEOUT_MS
1605 curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS,
1606 (timeout >= 0) ? (long)timeout : (long)CDTIME_T_TO_MS(
1607 plugin_get_interval()));
1611 } /* }}} int bind_init */
1613 static int bind_read(void) /* {{{ */
1618 ERROR("bind plugin: I don't have a CURL object.");
1622 bind_buffer_fill = 0;
1623 if (curl_easy_perform(curl) != CURLE_OK) {
1624 ERROR("bind plugin: curl_easy_perform failed: %s", bind_curl_error);
1628 status = bind_xml(bind_buffer);
1633 } /* }}} int bind_read */
1635 static int bind_shutdown(void) /* {{{ */
1638 curl_easy_cleanup(curl);
1643 } /* }}} int bind_shutdown */
1645 void module_register(void) {
1646 plugin_register_complex_config("bind", bind_config);
1647 plugin_register_init("bind", bind_init);
1648 plugin_register_read("bind", bind_read);
1649 plugin_register_shutdown("bind", bind_shutdown);
1650 } /* void module_register */