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 */
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);
75 typedef struct cb_view_s cb_view_t;
77 struct translation_info_s {
80 const char *type_instance;
82 typedef struct translation_info_s translation_info_t;
84 struct translation_table_ptr_s {
85 const translation_info_t *table;
87 const char *plugin_instance;
89 typedef struct translation_table_ptr_s translation_table_ptr_t;
91 struct list_info_ptr_s {
92 const char *plugin_instance;
95 typedef struct list_info_ptr_s list_info_ptr_t;
97 /* FIXME: Enabled by default for backwards compatibility. */
98 /* TODO: Remove time parsing code. */
99 static _Bool config_parse_time = 1;
101 static char *url = NULL;
102 static int global_opcodes = 1;
103 static int global_qtypes = 1;
104 static int global_server_stats = 1;
105 static int global_zone_maint_stats = 1;
106 static int global_resolver_stats = 0;
107 static int global_memory_stats = 1;
108 static int timeout = -1;
110 static cb_view_t *views = NULL;
111 static size_t views_num = 0;
113 static CURL *curl = NULL;
115 static char *bind_buffer = NULL;
116 static size_t bind_buffer_size = 0;
117 static size_t bind_buffer_fill = 0;
118 static char bind_curl_error[CURL_ERROR_SIZE];
120 /* Translation table for the `nsstats' values. */
121 static const translation_info_t nsstats_translation_table[] = /* {{{ */
124 {"Requestv4", "dns_request", "IPv4"},
125 {"Requestv6", "dns_request", "IPv6"},
126 {"ReqEdns0", "dns_request", "EDNS0"},
127 {"ReqBadEDNSVer", "dns_request", "BadEDNSVer"},
128 {"ReqTSIG", "dns_request", "TSIG"},
129 {"ReqSIG0", "dns_request", "SIG0"},
130 {"ReqBadSIG", "dns_request", "BadSIG"},
131 {"ReqTCP", "dns_request", "TCP"},
133 {"AuthQryRej", "dns_reject", "authoritative"},
134 {"RecQryRej", "dns_reject", "recursive"},
135 {"XfrRej", "dns_reject", "transfer"},
136 {"UpdateRej", "dns_reject", "update"},
138 {"Response", "dns_response", "normal"},
139 {"TruncatedResp", "dns_response", "truncated"},
140 {"RespEDNS0", "dns_response", "EDNS0"},
141 {"RespTSIG", "dns_response", "TSIG"},
142 {"RespSIG0", "dns_response", "SIG0"},
144 {"QryAuthAns", "dns_query", "authoritative"},
145 {"QryNoauthAns", "dns_query", "nonauth"},
146 {"QryReferral", "dns_query", "referral"},
147 {"QryRecursion", "dns_query", "recursion"},
148 {"QryDuplicate", "dns_query", "duplicate"},
149 {"QryDropped", "dns_query", "dropped"},
150 {"QryFailure", "dns_query", "failure"},
152 {"QrySuccess", "dns_rcode", "tx-NOERROR"},
153 {"QryNxrrset", "dns_rcode", "tx-NXRRSET"},
154 {"QrySERVFAIL", "dns_rcode", "tx-SERVFAIL"},
155 {"QryFORMERR", "dns_rcode", "tx-FORMERR"},
156 {"QryNXDOMAIN", "dns_rcode", "tx-NXDOMAIN"}
158 { "XfrReqDone", "type", "type_instance" },
159 { "UpdateReqFwd", "type", "type_instance" },
160 { "UpdateRespFwd", "type", "type_instance" },
161 { "UpdateFwdFail", "type", "type_instance" },
162 { "UpdateDone", "type", "type_instance" },
163 { "UpdateFail", "type", "type_instance" },
164 { "UpdateBadPrereq", "type", "type_instance" },
167 static int nsstats_translation_table_length =
168 STATIC_ARRAY_SIZE(nsstats_translation_table);
171 /* Translation table for the `zonestats' values. */
172 static const translation_info_t zonestats_translation_table[] = /* {{{ */
175 {"NotifyOutv4", "dns_notify", "tx-IPv4"},
176 {"NotifyOutv6", "dns_notify", "tx-IPv6"},
177 {"NotifyInv4", "dns_notify", "rx-IPv4"},
178 {"NotifyInv6", "dns_notify", "rx-IPv6"},
179 {"NotifyRej", "dns_notify", "rejected"},
180 /* SOA/AXFS/IXFS requests */
181 {"SOAOutv4", "dns_opcode", "SOA-IPv4"},
182 {"SOAOutv6", "dns_opcode", "SOA-IPv6"},
183 {"AXFRReqv4", "dns_opcode", "AXFR-IPv4"},
184 {"AXFRReqv6", "dns_opcode", "AXFR-IPv6"},
185 {"IXFRReqv4", "dns_opcode", "IXFR-IPv4"},
186 {"IXFRReqv6", "dns_opcode", "IXFR-IPv6"},
187 /* Domain transfers */
188 {"XfrSuccess", "dns_transfer", "success"},
189 {"XfrFail", "dns_transfer", "failure"}};
190 static int zonestats_translation_table_length =
191 STATIC_ARRAY_SIZE(zonestats_translation_table);
194 /* Translation table for the `resstats' values. */
195 static const translation_info_t resstats_translation_table[] = /* {{{ */
197 /* Generic resolver information */
198 {"Queryv4", "dns_query", "IPv4"},
199 {"Queryv6", "dns_query", "IPv6"},
200 {"Responsev4", "dns_response", "IPv4"},
201 {"Responsev6", "dns_response", "IPv6"},
202 /* Received response codes */
203 {"NXDOMAIN", "dns_rcode", "rx-NXDOMAIN"},
204 {"SERVFAIL", "dns_rcode", "rx-SERVFAIL"},
205 {"FORMERR", "dns_rcode", "rx-FORMERR"},
206 {"OtherError", "dns_rcode", "rx-OTHER"},
207 {"EDNS0Fail", "dns_rcode", "rx-EDNS0Fail"},
208 /* Received responses */
209 {"Mismatch", "dns_response", "mismatch"},
210 {"Truncated", "dns_response", "truncated"},
211 {"Lame", "dns_response", "lame"},
212 {"Retry", "dns_query", "retry"},
214 { "GlueFetchv4", "type", "type_instance" },
215 { "GlueFetchv6", "type", "type_instance" },
216 { "GlueFetchv4Fail", "type", "type_instance" },
217 { "GlueFetchv6Fail", "type", "type_instance" },
219 /* DNSSEC information */
220 {"ValAttempt", "dns_resolver", "DNSSEC-attempt"},
221 {"ValOk", "dns_resolver", "DNSSEC-okay"},
222 {"ValNegOk", "dns_resolver", "DNSSEC-negokay"},
223 {"ValFail", "dns_resolver", "DNSSEC-fail"}};
224 static int resstats_translation_table_length =
225 STATIC_ARRAY_SIZE(resstats_translation_table);
228 /* Translation table for the `memory/summary' values. */
229 static const translation_info_t memsummary_translation_table[] = /* {{{ */
230 {{"TotalUse", "memory", "TotalUse"},
231 {"InUse", "memory", "InUse"},
232 {"BlockSize", "memory", "BlockSize"},
233 {"ContextSize", "memory", "ContextSize"},
234 {"Lost", "memory", "Lost"}};
235 static int memsummary_translation_table_length =
236 STATIC_ARRAY_SIZE(memsummary_translation_table);
239 static void submit(time_t ts, const char *plugin_instance, /* {{{ */
240 const char *type, const char *type_instance, value_t value) {
241 value_list_t vl = VALUE_LIST_INIT;
245 if (config_parse_time)
246 vl.time = TIME_T_TO_CDTIME_T(ts);
247 sstrncpy(vl.plugin, "bind", sizeof(vl.plugin));
248 if (plugin_instance) {
249 sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance));
250 replace_special(vl.plugin_instance, sizeof(vl.plugin_instance));
252 sstrncpy(vl.type, type, sizeof(vl.type));
254 sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
255 replace_special(vl.type_instance, sizeof(vl.type_instance));
257 plugin_dispatch_values(&vl);
258 } /* }}} void submit */
260 static size_t bind_curl_callback(void *buf, size_t size, /* {{{ */
262 void __attribute__((unused)) * stream) {
263 size_t len = size * nmemb;
268 if ((bind_buffer_fill + len) >= bind_buffer_size) {
271 temp = realloc(bind_buffer, bind_buffer_fill + len + 1);
273 ERROR("bind plugin: realloc failed.");
277 bind_buffer_size = bind_buffer_fill + len + 1;
280 memcpy(bind_buffer + bind_buffer_fill, (char *)buf, len);
281 bind_buffer_fill += len;
282 bind_buffer[bind_buffer_fill] = 0;
285 } /* }}} size_t bind_curl_callback */
288 * Callback, that's called with a translation table.
289 * (Plugin instance is fixed, type and type instance come from lookup table.)
291 static int bind_xml_table_callback(const char *name, value_t value, /* {{{ */
292 time_t current_time, void *user_data) {
293 translation_table_ptr_t *table = (translation_table_ptr_t *)user_data;
298 for (size_t i = 0; i < table->table_length; i++) {
299 if (strcmp(table->table[i].xml_name, name) != 0)
302 submit(current_time, table->plugin_instance, table->table[i].type,
303 table->table[i].type_instance, value);
308 } /* }}} int bind_xml_table_callback */
311 * Callback, that's used for lists.
312 * (Plugin instance and type are fixed, xml name is used as type instance.)
314 static int bind_xml_list_callback(const char *name, /* {{{ */
315 value_t value, time_t current_time,
317 list_info_ptr_t *list_info = (list_info_ptr_t *)user_data;
319 if (list_info == NULL)
322 submit(current_time, list_info->plugin_instance, list_info->type,
323 /* type instance = */ name, value);
326 } /* }}} int bind_xml_list_callback */
328 static int bind_xml_read_derive(xmlDoc *doc, xmlNode *node, /* {{{ */
329 derive_t *ret_value) {
334 str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
335 if (str_ptr == NULL) {
336 ERROR("bind plugin: bind_xml_read_derive: xmlNodeListGetString failed.");
340 status = parse_value(str_ptr, &value, DS_TYPE_DERIVE);
342 ERROR("bind plugin: Parsing string \"%s\" to derive value failed.",
349 *ret_value = value.derive;
351 } /* }}} int bind_xml_read_derive */
353 static int bind_xml_read_gauge(xmlDoc *doc, xmlNode *node, /* {{{ */
354 gauge_t *ret_value) {
355 char *str_ptr, *end_ptr;
358 str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
359 if (str_ptr == NULL) {
360 ERROR("bind plugin: bind_xml_read_gauge: xmlNodeListGetString failed.");
365 value = strtod(str_ptr, &end_ptr);
367 if (str_ptr == end_ptr || errno) {
368 if (errno && (value < 0))
369 ERROR("bind plugin: bind_xml_read_gauge: strtod failed with underflow.");
370 else if (errno && (value > 0))
371 ERROR("bind plugin: bind_xml_read_gauge: strtod failed with overflow.");
373 ERROR("bind plugin: bind_xml_read_gauge: strtod failed.");
377 *ret_value = (gauge_t)value;
379 } /* }}} int bind_xml_read_gauge */
381 static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */
382 xmlDoc *doc, xmlXPathContext *xpathCtx,
384 xmlXPathObject *xpathObj = NULL;
390 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
391 if (xpathObj == NULL) {
392 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
397 if ((xpathObj->nodesetval == NULL) || (xpathObj->nodesetval->nodeNr < 1)) {
398 xmlXPathFreeObject(xpathObj);
402 if (xpathObj->nodesetval->nodeNr != 1) {
403 NOTICE("bind plugin: Evaluating the XPath expression `%s' returned "
404 "%i nodes. Only handling the first one.",
405 xpath_expression, xpathObj->nodesetval->nodeNr);
408 node = xpathObj->nodesetval->nodeTab[0];
410 if (node->xmlChildrenNode == NULL) {
411 ERROR("bind plugin: bind_xml_read_timestamp: "
412 "node->xmlChildrenNode == NULL");
413 xmlXPathFreeObject(xpathObj);
417 str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
418 if (str_ptr == NULL) {
419 ERROR("bind plugin: bind_xml_read_timestamp: xmlNodeListGetString failed.");
420 xmlXPathFreeObject(xpathObj);
424 tmp = strptime(str_ptr, "%Y-%m-%dT%T", &tm);
427 ERROR("bind plugin: bind_xml_read_timestamp: strptime failed.");
428 xmlXPathFreeObject(xpathObj);
433 *ret_value = mktime(&tm) - timezone; /* fix strptime() misinterpretation */
435 xmlXPathFreeObject(xpathObj);
437 } /* }}} int bind_xml_read_timestamp */
440 * bind_parse_generic_name_value
442 * Reads statistics in the form:
445 * <counter>123</counter>
448 static int bind_parse_generic_name_value(const char *xpath_expression, /* {{{ */
449 list_callback_t list_callback,
450 void *user_data, xmlDoc *doc,
451 xmlXPathContext *xpathCtx,
452 time_t current_time, int ds_type) {
453 xmlXPathObject *xpathObj = NULL;
456 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
457 if (xpathObj == NULL) {
458 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
464 /* Iterate over all matching nodes. */
465 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
467 xmlNode *name_node = NULL;
468 xmlNode *counter = NULL;
471 parent = xpathObj->nodesetval->nodeTab[i];
472 DEBUG("bind plugin: bind_parse_generic_name_value: parent->name = %s;",
473 (char *)parent->name);
475 /* Iterate over all child nodes. */
476 for (xmlNode *child = parent->xmlChildrenNode; child != NULL;
477 child = child->next) {
478 if (child->type != XML_ELEMENT_NODE)
481 if (xmlStrcmp(BAD_CAST "name", child->name) == 0)
483 else if (xmlStrcmp(BAD_CAST "counter", child->name) == 0)
487 if ((name_node != NULL) && (counter != NULL)) {
489 (char *)xmlNodeListGetString(doc, name_node->xmlChildrenNode, 1);
493 if (ds_type == DS_TYPE_GAUGE)
494 status = bind_xml_read_gauge(doc, counter, &value.gauge);
496 status = bind_xml_read_derive(doc, counter, &value.derive);
500 status = (*list_callback)(name, value, current_time, user_data);
508 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
509 (num_entries == 1) ? "entry" : "entries", xpath_expression);
511 xmlXPathFreeObject(xpathObj);
514 } /* }}} int bind_parse_generic_name_value */
517 * bind_parse_generic_value_list
519 * Reads statistics in the form:
527 static int bind_parse_generic_value_list(const char *xpath_expression, /* {{{ */
528 list_callback_t list_callback,
529 void *user_data, xmlDoc *doc,
530 xmlXPathContext *xpathCtx,
531 time_t current_time, int ds_type) {
532 xmlXPathObject *xpathObj = NULL;
535 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
536 if (xpathObj == NULL) {
537 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
543 /* Iterate over all matching nodes. */
544 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
546 /* Iterate over all child nodes. */
547 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
548 child != NULL; child = child->next) {
553 if (child->type != XML_ELEMENT_NODE)
556 node_name = (char *)child->name;
558 if (ds_type == DS_TYPE_GAUGE)
559 status = bind_xml_read_gauge(doc, child, &value.gauge);
561 status = bind_xml_read_derive(doc, child, &value.derive);
565 status = (*list_callback)(node_name, value, current_time, user_data);
571 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
572 (num_entries == 1) ? "entry" : "entries", xpath_expression);
574 xmlXPathFreeObject(xpathObj);
577 } /* }}} int bind_parse_generic_value_list */
580 * bind_parse_generic_name_attr_value_list
582 * Reads statistics in the form:
584 * <counter name="name0">123</counter>
585 * <counter name="name1">234</counter>
586 * <counter name="name2">345</counter>
590 static int bind_parse_generic_name_attr_value_list(
591 const char *xpath_expression, /* {{{ */
592 list_callback_t list_callback, void *user_data, xmlDoc *doc,
593 xmlXPathContext *xpathCtx, time_t current_time, int ds_type) {
594 xmlXPathObject *xpathObj = NULL;
597 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
598 if (xpathObj == NULL) {
599 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
605 /* Iterate over all matching nodes. */
606 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
608 /* Iterate over all child nodes. */
609 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
610 child != NULL; child = child->next) {
611 if (child->type != XML_ELEMENT_NODE)
614 if (strncmp("counter", (char *)child->name, strlen("counter")) != 0)
621 attr_name = (char *)xmlGetProp(child, BAD_CAST "name");
622 if (attr_name == NULL) {
623 DEBUG("bind plugin: found <counter> without name.");
626 if (ds_type == DS_TYPE_GAUGE)
627 status = bind_xml_read_gauge(doc, child, &value.gauge);
629 status = bind_xml_read_derive(doc, child, &value.derive);
633 status = (*list_callback)(attr_name, value, current_time, user_data);
639 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
640 (num_entries == 1) ? "entry" : "entries", xpath_expression);
642 xmlXPathFreeObject(xpathObj);
645 } /* }}} int bind_parse_generic_name_attr_value_list */
647 static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */
648 xmlXPathContext *path_ctx, xmlNode *node,
649 cb_view_t *view, time_t current_time) {
650 xmlXPathObject *path_obj;
651 char *zone_name = NULL;
655 char *n = (char *)xmlGetProp(node, BAD_CAST "name");
656 char *c = (char *)xmlGetProp(node, BAD_CAST "rdataclass");
658 zone_name = (char *)xmlMalloc(strlen(n) + strlen(c) + 2);
659 snprintf(zone_name, strlen(n) + strlen(c) + 2, "%s/%s", n, c);
664 path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
665 if (path_obj == NULL) {
666 ERROR("bind plugin: xmlXPathEvalExpression failed.");
670 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
672 zone_name = (char *)xmlNodeListGetString(
673 doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
674 if (zone_name != NULL)
677 xmlXPathFreeObject(path_obj);
680 if (zone_name == NULL) {
681 ERROR("bind plugin: Could not determine zone name.");
685 for (j = 0; j < view->zones_num; j++) {
686 if (strcasecmp(zone_name, view->zones[j]) == 0)
693 if (j >= view->zones_num)
696 zone_name = view->zones[j];
698 DEBUG("bind plugin: bind_xml_stats_handle_zone: Found zone `%s'.", zone_name);
700 { /* Parse the <counters> tag {{{ */
701 char plugin_instance[DATA_MAX_NAME_LEN];
702 translation_table_ptr_t table_ptr = {nsstats_translation_table,
703 nsstats_translation_table_length,
706 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-zone-%s",
707 view->name, zone_name);
710 list_info_ptr_t list_info = {plugin_instance,
711 /* type = */ "dns_qtype"};
712 bind_parse_generic_name_attr_value_list(
713 /* xpath = */ "counters[@type='rcode']",
714 /* callback = */ bind_xml_table_callback,
715 /* user_data = */ &table_ptr, doc, path_ctx, current_time,
717 bind_parse_generic_name_attr_value_list(
718 /* xpath = */ "counters[@type='qtype']",
719 /* callback = */ bind_xml_list_callback,
720 /* user_data = */ &list_info, doc, path_ctx, current_time,
723 bind_parse_generic_value_list(/* xpath = */ "counters",
724 /* callback = */ bind_xml_table_callback,
725 /* user_data = */ &table_ptr, doc, path_ctx,
726 current_time, DS_TYPE_COUNTER);
731 } /* }}} int bind_xml_stats_handle_zone */
733 static int bind_xml_stats_search_zones(int version, xmlDoc *doc, /* {{{ */
734 xmlXPathContext *path_ctx, xmlNode *node,
735 cb_view_t *view, time_t current_time) {
736 xmlXPathObject *zone_nodes = NULL;
737 xmlXPathContext *zone_path_context;
739 zone_path_context = xmlXPathNewContext(doc);
740 if (zone_path_context == NULL) {
741 ERROR("bind plugin: xmlXPathNewContext failed.");
745 zone_nodes = xmlXPathEvalExpression(BAD_CAST "zones/zone", path_ctx);
746 if (zone_nodes == NULL) {
747 ERROR("bind plugin: Cannot find any <view> tags.");
748 xmlXPathFreeContext(zone_path_context);
752 for (int i = 0; i < zone_nodes->nodesetval->nodeNr; i++) {
753 node = zone_nodes->nodesetval->nodeTab[i];
754 assert(node != NULL);
756 zone_path_context->node = node;
758 bind_xml_stats_handle_zone(version, doc, zone_path_context, node, view,
762 xmlXPathFreeObject(zone_nodes);
763 xmlXPathFreeContext(zone_path_context);
765 } /* }}} int bind_xml_stats_search_zones */
767 static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */
768 xmlXPathContext *path_ctx, xmlNode *node,
769 time_t current_time) {
770 char *view_name = NULL;
775 view_name = (char *)xmlGetProp(node, BAD_CAST "name");
777 if (view_name == NULL) {
778 ERROR("bind plugin: Could not determine view name.");
782 for (j = 0; j < views_num; j++) {
783 if (strcasecmp(view_name, views[j].name) == 0)
790 xmlXPathObject *path_obj;
791 path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
792 if (path_obj == NULL) {
793 ERROR("bind plugin: xmlXPathEvalExpression failed.");
797 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
799 view_name = (char *)xmlNodeListGetString(
800 doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
801 if (view_name != NULL)
805 if (view_name == NULL) {
806 ERROR("bind plugin: Could not determine view name.");
807 xmlXPathFreeObject(path_obj);
811 for (j = 0; j < views_num; j++) {
812 if (strcasecmp(view_name, views[j].name) == 0)
817 xmlXPathFreeObject(path_obj);
828 DEBUG("bind plugin: bind_xml_stats_handle_view: Found view `%s'.",
831 if (view->qtypes != 0) /* {{{ */
833 char plugin_instance[DATA_MAX_NAME_LEN];
834 list_info_ptr_t list_info = {plugin_instance,
835 /* type = */ "dns_qtype"};
837 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-qtypes",
840 bind_parse_generic_name_attr_value_list(
841 /* xpath = */ "counters[@type='resqtype']",
842 /* callback = */ bind_xml_list_callback,
843 /* user_data = */ &list_info, doc, path_ctx, current_time,
846 bind_parse_generic_name_value(/* xpath = */ "rdtype",
847 /* callback = */ bind_xml_list_callback,
848 /* user_data = */ &list_info, doc, path_ctx,
849 current_time, DS_TYPE_COUNTER);
853 if (view->resolver_stats != 0) /* {{{ */
855 char plugin_instance[DATA_MAX_NAME_LEN];
856 translation_table_ptr_t table_ptr = {resstats_translation_table,
857 resstats_translation_table_length,
860 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-resolver_stats",
863 bind_parse_generic_name_attr_value_list(
864 "counters[@type='resstats']",
865 /* callback = */ bind_xml_table_callback,
866 /* user_data = */ &table_ptr, doc, path_ctx, current_time,
869 bind_parse_generic_name_value("resstat",
870 /* callback = */ bind_xml_table_callback,
871 /* user_data = */ &table_ptr, doc, path_ctx,
872 current_time, DS_TYPE_COUNTER);
876 /* Record types in the cache */
877 if (view->cacherrsets != 0) /* {{{ */
879 char plugin_instance[DATA_MAX_NAME_LEN];
880 list_info_ptr_t list_info = {plugin_instance,
881 /* type = */ "dns_qtype_cached"};
883 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-cache_rr_sets",
886 bind_parse_generic_name_value(/* xpath = */ "cache/rrset",
887 /* callback = */ bind_xml_list_callback,
888 /* user_data = */ &list_info, doc, path_ctx,
889 current_time, DS_TYPE_GAUGE);
892 if (view->zones_num > 0)
893 bind_xml_stats_search_zones(version, doc, path_ctx, node, view,
897 } /* }}} int bind_xml_stats_handle_view */
899 static int bind_xml_stats_search_views(int version, xmlDoc *doc, /* {{{ */
900 xmlXPathContext *xpathCtx,
902 time_t current_time) {
903 xmlXPathObject *view_nodes = NULL;
904 xmlXPathContext *view_path_context;
906 view_path_context = xmlXPathNewContext(doc);
907 if (view_path_context == NULL) {
908 ERROR("bind plugin: xmlXPathNewContext failed.");
912 view_nodes = xmlXPathEvalExpression(BAD_CAST "views/view", xpathCtx);
913 if (view_nodes == NULL) {
914 ERROR("bind plugin: Cannot find any <view> tags.");
915 xmlXPathFreeContext(view_path_context);
919 for (int i = 0; i < view_nodes->nodesetval->nodeNr; i++) {
922 node = view_nodes->nodesetval->nodeTab[i];
923 assert(node != NULL);
925 view_path_context->node = node;
927 bind_xml_stats_handle_view(version, doc, view_path_context, node,
931 xmlXPathFreeObject(view_nodes);
932 xmlXPathFreeContext(view_path_context);
934 } /* }}} int bind_xml_stats_search_views */
936 static void bind_xml_stats_v3(xmlDoc *doc, /* {{{ */
937 xmlXPathContext *xpathCtx, xmlNode *statsnode,
938 time_t current_time) {
939 /* XPath: server/counters[@type='opcode']
940 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
942 * <counters type="opcode">
943 * <counter name="A">1</counter>
947 if (global_opcodes != 0) {
948 list_info_ptr_t list_info = {/* plugin instance = */ "global-opcodes",
949 /* type = */ "dns_opcode"};
950 bind_parse_generic_name_attr_value_list(
951 /* xpath = */ "server/counters[@type='opcode']",
952 /* callback = */ bind_xml_list_callback,
953 /* user_data = */ &list_info, doc, xpathCtx, current_time,
957 /* XPath: server/counters[@type='qtype']
958 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
959 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
960 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
962 * <counters type="opcode">
963 * <counter name="A">1</counter>
967 if (global_qtypes != 0) {
968 list_info_ptr_t list_info = {/* plugin instance = */ "global-qtypes",
969 /* type = */ "dns_qtype"};
971 bind_parse_generic_name_attr_value_list(
972 /* xpath = */ "server/counters[@type='qtype']",
973 /* callback = */ bind_xml_list_callback,
974 /* user_data = */ &list_info, doc, xpathCtx, current_time,
978 /* XPath: server/counters[@type='nsstat']
979 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
980 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
981 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
982 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
983 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
984 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
985 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
988 * <counters type="nsstat"
989 * <counter name="Requestv4">1</counter>
990 * <counter name="Requestv6">0</counter>
994 if (global_server_stats) {
995 translation_table_ptr_t table_ptr = {
996 nsstats_translation_table, nsstats_translation_table_length,
997 /* plugin_instance = */ "global-server_stats"};
999 bind_parse_generic_name_attr_value_list(
1000 "server/counters[@type='nsstat']",
1001 /* callback = */ bind_xml_table_callback,
1002 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1006 /* XPath: server/zonestats, server/zonestat,
1007 * server/counters[@type='zonestat']
1008 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1009 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1010 * XfrSuccess, XfrFail
1012 * <counters type="zonestat"
1013 * <counter name="NotifyOutv4">0</counter>
1014 * <counter name="NotifyOutv6">0</counter>
1018 if (global_zone_maint_stats) {
1019 translation_table_ptr_t table_ptr = {
1020 zonestats_translation_table, zonestats_translation_table_length,
1021 /* plugin_instance = */ "global-zone_maint_stats"};
1023 bind_parse_generic_name_attr_value_list(
1024 "server/counters[@type='zonestat']",
1025 /* callback = */ bind_xml_table_callback,
1026 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1030 /* XPath: server/resstats, server/counters[@type='resstat']
1031 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1032 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1033 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1034 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1036 * <counters type="resstat"
1037 * <counter name="Queryv4">0</counter>
1038 * <counter name="Queryv6">0</counter>
1042 if (global_resolver_stats != 0) {
1043 translation_table_ptr_t table_ptr = {
1044 resstats_translation_table, resstats_translation_table_length,
1045 /* plugin_instance = */ "global-resolver_stats"};
1047 bind_parse_generic_name_attr_value_list(
1048 "server/counters[@type='resstat']",
1049 /* callback = */ bind_xml_table_callback,
1050 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1053 } /* }}} bind_xml_stats_v3 */
1055 static void bind_xml_stats_v1_v2(int version, xmlDoc *doc, /* {{{ */
1056 xmlXPathContext *xpathCtx, xmlNode *statsnode,
1057 time_t current_time) {
1058 /* XPath: server/requests/opcode, server/counters[@type='opcode']
1059 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1063 * <counter>1</counter>
1067 if (global_opcodes != 0) {
1068 list_info_ptr_t list_info = {/* plugin instance = */ "global-opcodes",
1069 /* type = */ "dns_opcode"};
1071 bind_parse_generic_name_value(/* xpath = */ "server/requests/opcode",
1072 /* callback = */ bind_xml_list_callback,
1073 /* user_data = */ &list_info, doc, xpathCtx,
1074 current_time, DS_TYPE_COUNTER);
1077 /* XPath: server/queries-in/rdtype, server/counters[@type='qtype']
1078 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1079 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1080 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1084 * <counter>1</counter>
1088 if (global_qtypes != 0) {
1089 list_info_ptr_t list_info = {/* plugin instance = */ "global-qtypes",
1090 /* type = */ "dns_qtype"};
1092 bind_parse_generic_name_value(/* xpath = */ "server/queries-in/rdtype",
1093 /* callback = */ bind_xml_list_callback,
1094 /* user_data = */ &list_info, doc, xpathCtx,
1095 current_time, DS_TYPE_COUNTER);
1098 /* XPath: server/nsstats, server/nsstat, server/counters[@type='nsstat']
1099 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1100 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1101 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1102 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1103 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1104 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1105 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1109 * <Requestv4>1</Requestv4>
1110 * <Requestv6>0</Requestv6>
1115 * <name>Requestv4</name>
1116 * <counter>1</counter>
1119 * <name>Requestv6</name>
1120 * <counter>0</counter>
1124 if (global_server_stats) {
1125 translation_table_ptr_t table_ptr = {
1126 nsstats_translation_table, nsstats_translation_table_length,
1127 /* plugin_instance = */ "global-server_stats"};
1130 bind_parse_generic_value_list("server/nsstats",
1131 /* callback = */ bind_xml_table_callback,
1132 /* user_data = */ &table_ptr, doc, xpathCtx,
1133 current_time, DS_TYPE_COUNTER);
1135 bind_parse_generic_name_value("server/nsstat",
1136 /* callback = */ bind_xml_table_callback,
1137 /* user_data = */ &table_ptr, doc, xpathCtx,
1138 current_time, DS_TYPE_COUNTER);
1142 /* XPath: server/zonestats, server/zonestat,
1143 * server/counters[@type='zonestat']
1144 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1145 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1146 * XfrSuccess, XfrFail
1149 * <NotifyOutv4>0</NotifyOutv4>
1150 * <NotifyOutv6>0</NotifyOutv6>
1155 * <name>NotifyOutv4</name>
1156 * <counter>0</counter>
1159 * <name>NotifyOutv6</name>
1160 * <counter>0</counter>
1164 if (global_zone_maint_stats) {
1165 translation_table_ptr_t table_ptr = {
1166 zonestats_translation_table, zonestats_translation_table_length,
1167 /* plugin_instance = */ "global-zone_maint_stats"};
1170 bind_parse_generic_value_list("server/zonestats",
1171 /* callback = */ bind_xml_table_callback,
1172 /* user_data = */ &table_ptr, doc, xpathCtx,
1173 current_time, DS_TYPE_COUNTER);
1175 bind_parse_generic_name_value("server/zonestat",
1176 /* callback = */ bind_xml_table_callback,
1177 /* user_data = */ &table_ptr, doc, xpathCtx,
1178 current_time, DS_TYPE_COUNTER);
1182 /* XPath: server/resstats, server/counters[@type='resstat']
1183 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1184 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1185 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1186 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1189 * <Queryv4>0</Queryv4>
1190 * <Queryv6>0</Queryv6>
1195 * <name>Queryv4</name>
1196 * <counter>0</counter>
1199 * <name>Queryv6</name>
1200 * <counter>0</counter>
1204 if (global_resolver_stats != 0) {
1205 translation_table_ptr_t table_ptr = {
1206 resstats_translation_table, resstats_translation_table_length,
1207 /* plugin_instance = */ "global-resolver_stats"};
1210 bind_parse_generic_value_list("server/resstats",
1211 /* callback = */ bind_xml_table_callback,
1212 /* user_data = */ &table_ptr, doc, xpathCtx,
1213 current_time, DS_TYPE_COUNTER);
1215 bind_parse_generic_name_value("server/resstat",
1216 /* callback = */ bind_xml_table_callback,
1217 /* user_data = */ &table_ptr, doc, xpathCtx,
1218 current_time, DS_TYPE_COUNTER);
1221 } /* }}} bind_xml_stats_v1_v2 */
1223 static int bind_xml_stats(int version, xmlDoc *doc, /* {{{ */
1224 xmlXPathContext *xpathCtx, xmlNode *statsnode) {
1225 time_t current_time = 0;
1228 xpathCtx->node = statsnode;
1230 /* TODO: Check `server/boot-time' to recognize server restarts. */
1232 status = bind_xml_read_timestamp("server/current-time", doc, xpathCtx,
1235 ERROR("bind plugin: Reading `server/current-time' failed.");
1238 DEBUG("bind plugin: Current server time is %i.", (int)current_time);
1241 bind_xml_stats_v3(doc, xpathCtx, statsnode, current_time);
1243 bind_xml_stats_v1_v2(version, doc, xpathCtx, statsnode, current_time);
1246 /* XPath: memory/summary
1247 * Variables: TotalUse, InUse, BlockSize, ContextSize, Lost
1248 * Layout: v2 and v3:
1250 * <TotalUse>6587096</TotalUse>
1251 * <InUse>1345424</InUse>
1252 * <BlockSize>5505024</BlockSize>
1253 * <ContextSize>3732456</ContextSize>
1257 if (global_memory_stats != 0) {
1258 translation_table_ptr_t table_ptr = {
1259 memsummary_translation_table, memsummary_translation_table_length,
1260 /* plugin_instance = */ "global-memory_stats"};
1262 bind_parse_generic_value_list("memory/summary",
1263 /* callback = */ bind_xml_table_callback,
1264 /* user_data = */ &table_ptr, doc, xpathCtx,
1265 current_time, DS_TYPE_GAUGE);
1269 bind_xml_stats_search_views(version, doc, xpathCtx, statsnode,
1273 } /* }}} int bind_xml_stats */
1275 static int bind_xml(const char *data) /* {{{ */
1278 xmlXPathContext *xpathCtx = NULL;
1279 xmlXPathObject *xpathObj = NULL;
1282 doc = xmlParseMemory(data, strlen(data));
1284 ERROR("bind plugin: xmlParseMemory failed.");
1288 xpathCtx = xmlXPathNewContext(doc);
1289 if (xpathCtx == NULL) {
1290 ERROR("bind plugin: xmlXPathNewContext failed.");
1296 // version 3.* of statistics XML (since BIND9.9)
1299 xpathObj = xmlXPathEvalExpression(BAD_CAST "/statistics", xpathCtx);
1300 if (xpathObj == NULL || xpathObj->nodesetval == NULL ||
1301 xpathObj->nodesetval->nodeNr == 0) {
1302 DEBUG("bind plugin: Statistics appears not to be v3");
1303 // we will fallback to v1 or v2 detection
1304 if (xpathObj != NULL) {
1305 xmlXPathFreeObject(xpathObj);
1308 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
1312 node = xpathObj->nodesetval->nodeTab[i];
1313 assert(node != NULL);
1315 attr_version = (char *)xmlGetProp(node, BAD_CAST "version");
1316 if (attr_version == NULL) {
1317 NOTICE("bind plugin: Found <statistics> tag doesn't have a "
1318 "`version' attribute.");
1321 DEBUG("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1323 if (strncmp("3.", attr_version, strlen("3.")) != 0) {
1324 /* TODO: Use the complaint mechanism here. */
1325 NOTICE("bind plugin: Found <statistics> tag with version `%s'. "
1326 "Unfortunately I have no clue how to parse that. "
1327 "Please open a bug report for this.",
1329 xmlFree(attr_version);
1332 ret = bind_xml_stats(3, doc, xpathCtx, node);
1334 xmlFree(attr_version);
1335 /* One <statistics> node ought to be enough. */
1339 // we are finished, early-return
1340 xmlXPathFreeObject(xpathObj);
1341 xmlXPathFreeContext(xpathCtx);
1348 // versions 1.* or 2.* of statistics XML
1351 xpathObj = xmlXPathEvalExpression(BAD_CAST "/isc/bind/statistics", xpathCtx);
1352 if (xpathObj == NULL) {
1353 ERROR("bind plugin: Cannot find the <statistics> tag.");
1354 xmlXPathFreeContext(xpathCtx);
1357 } else if (xpathObj->nodesetval == NULL) {
1358 ERROR("bind plugin: xmlXPathEvalExpression failed.");
1359 xmlXPathFreeObject(xpathObj);
1360 xmlXPathFreeContext(xpathCtx);
1365 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
1368 int parsed_version = 0;
1370 node = xpathObj->nodesetval->nodeTab[i];
1371 assert(node != NULL);
1373 attr_version = (char *)xmlGetProp(node, BAD_CAST "version");
1374 if (attr_version == NULL) {
1375 NOTICE("bind plugin: Found <statistics> tag doesn't have a "
1376 "`version' attribute.");
1379 DEBUG("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1381 /* At the time this plugin was written, version "1.0" was used by
1382 * BIND 9.5.0, version "2.0" was used by BIND 9.5.1 and 9.6.0. We assume
1383 * that "1.*" and "2.*" don't introduce structural changes, so we just
1384 * check for the first two characters here. */
1385 if (strncmp("1.", attr_version, strlen("1.")) == 0)
1387 else if (strncmp("2.", attr_version, strlen("2.")) == 0)
1390 /* TODO: Use the complaint mechanism here. */
1391 NOTICE("bind plugin: Found <statistics> tag with version `%s'. "
1392 "Unfortunately I have no clue how to parse that. "
1393 "Please open a bug report for this.",
1395 xmlFree(attr_version);
1399 ret = bind_xml_stats(parsed_version, doc, xpathCtx, node);
1401 xmlFree(attr_version);
1402 /* One <statistics> node ought to be enough. */
1406 xmlXPathFreeObject(xpathObj);
1407 xmlXPathFreeContext(xpathCtx);
1411 } /* }}} int bind_xml */
1413 static int bind_config_set_bool(const char *name, int *var, /* {{{ */
1414 oconfig_item_t *ci) {
1415 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
1416 WARNING("bind plugin: The `%s' option needs "
1417 "exactly one boolean argument.",
1422 if (ci->values[0].value.boolean)
1427 } /* }}} int bind_config_set_bool */
1429 static int bind_config_add_view_zone(cb_view_t *view, /* {{{ */
1430 oconfig_item_t *ci) {
1433 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1434 WARNING("bind plugin: The `Zone' option needs "
1435 "exactly one string argument.");
1439 tmp = realloc(view->zones, sizeof(char *) * (view->zones_num + 1));
1441 ERROR("bind plugin: realloc failed.");
1446 view->zones[view->zones_num] = strdup(ci->values[0].value.string);
1447 if (view->zones[view->zones_num] == NULL) {
1448 ERROR("bind plugin: strdup failed.");
1454 } /* }}} int bind_config_add_view_zone */
1456 static int bind_config_add_view(oconfig_item_t *ci) /* {{{ */
1460 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1461 WARNING("bind plugin: `View' blocks need exactly one string argument.");
1465 tmp = realloc(views, sizeof(*views) * (views_num + 1));
1467 ERROR("bind plugin: realloc failed.");
1471 tmp = views + views_num;
1473 memset(tmp, 0, sizeof(*tmp));
1475 tmp->resolver_stats = 1;
1476 tmp->cacherrsets = 1;
1480 tmp->name = strdup(ci->values[0].value.string);
1481 if (tmp->name == NULL) {
1482 ERROR("bind plugin: strdup failed.");
1487 for (int i = 0; i < ci->children_num; i++) {
1488 oconfig_item_t *child = ci->children + i;
1490 if (strcasecmp("QTypes", child->key) == 0)
1491 bind_config_set_bool("QTypes", &tmp->qtypes, child);
1492 else if (strcasecmp("ResolverStats", child->key) == 0)
1493 bind_config_set_bool("ResolverStats", &tmp->resolver_stats, child);
1494 else if (strcasecmp("CacheRRSets", child->key) == 0)
1495 bind_config_set_bool("CacheRRSets", &tmp->cacherrsets, child);
1496 else if (strcasecmp("Zone", child->key) == 0)
1497 bind_config_add_view_zone(tmp, child);
1499 WARNING("bind plugin: Unknown configuration option "
1500 "`%s' in view `%s' will be ignored.",
1501 child->key, tmp->name);
1503 } /* for (i = 0; i < ci->children_num; i++) */
1507 } /* }}} int bind_config_add_view */
1509 static int bind_config(oconfig_item_t *ci) /* {{{ */
1511 for (int i = 0; i < ci->children_num; i++) {
1512 oconfig_item_t *child = ci->children + i;
1514 if (strcasecmp("Url", child->key) == 0) {
1515 if ((child->values_num != 1) ||
1516 (child->values[0].type != OCONFIG_TYPE_STRING)) {
1517 WARNING("bind plugin: The `Url' option needs "
1518 "exactly one string argument.");
1523 url = strdup(child->values[0].value.string);
1524 } else if (strcasecmp("OpCodes", child->key) == 0)
1525 bind_config_set_bool("OpCodes", &global_opcodes, child);
1526 else if (strcasecmp("QTypes", child->key) == 0)
1527 bind_config_set_bool("QTypes", &global_qtypes, child);
1528 else if (strcasecmp("ServerStats", child->key) == 0)
1529 bind_config_set_bool("ServerStats", &global_server_stats, child);
1530 else if (strcasecmp("ZoneMaintStats", child->key) == 0)
1531 bind_config_set_bool("ZoneMaintStats", &global_zone_maint_stats, child);
1532 else if (strcasecmp("ResolverStats", child->key) == 0)
1533 bind_config_set_bool("ResolverStats", &global_resolver_stats, child);
1534 else if (strcasecmp("MemoryStats", child->key) == 0)
1535 bind_config_set_bool("MemoryStats", &global_memory_stats, child);
1536 else if (strcasecmp("View", child->key) == 0)
1537 bind_config_add_view(child);
1538 else if (strcasecmp("ParseTime", child->key) == 0)
1539 cf_util_get_boolean(child, &config_parse_time);
1540 else if (strcasecmp("Timeout", child->key) == 0)
1541 cf_util_get_int(child, &timeout);
1543 WARNING("bind plugin: Unknown configuration option "
1544 "`%s' will be ignored.",
1550 } /* }}} int bind_config */
1552 static int bind_init(void) /* {{{ */
1557 curl = curl_easy_init();
1559 ERROR("bind plugin: bind_init: curl_easy_init failed.");
1563 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
1564 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
1565 curl_easy_setopt(curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
1566 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, bind_curl_error);
1567 curl_easy_setopt(curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
1568 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
1569 curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
1570 #ifdef HAVE_CURLOPT_TIMEOUT_MS
1571 curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS,
1572 (timeout >= 0) ? (long)timeout : (long)CDTIME_T_TO_MS(
1573 plugin_get_interval()));
1577 } /* }}} int bind_init */
1579 static int bind_read(void) /* {{{ */
1584 ERROR("bind plugin: I don't have a CURL object.");
1588 bind_buffer_fill = 0;
1589 if (curl_easy_perform(curl) != CURLE_OK) {
1590 ERROR("bind plugin: curl_easy_perform failed: %s", bind_curl_error);
1594 status = bind_xml(bind_buffer);
1599 } /* }}} int bind_read */
1601 static int bind_shutdown(void) /* {{{ */
1604 curl_easy_cleanup(curl);
1609 } /* }}} int bind_shutdown */
1611 void module_register(void) {
1612 plugin_register_complex_config("bind", bind_config);
1613 plugin_register_init("bind", bind_init);
1614 plugin_register_read("bind", bind_read);
1615 plugin_register_shutdown("bind", bind_shutdown);
1616 } /* void module_register */