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", "authorative"},
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", "authorative"},
153 {"QryNoauthAns", "dns_query", "nonauth"},
154 {"QryReferral", "dns_query", "referral"},
155 {"QryRecursion", "dns_query", "recursion"},
156 {"QryDuplicate", "dns_query", "dupliate"},
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) {
250 value_list_t vl = VALUE_LIST_INIT;
256 if (config_parse_time)
257 vl.time = TIME_T_TO_CDTIME_T(ts);
258 sstrncpy(vl.host, hostname_g, sizeof(vl.host));
259 sstrncpy(vl.plugin, "bind", sizeof(vl.plugin));
260 if (plugin_instance) {
261 sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance));
262 replace_special(vl.plugin_instance, sizeof(vl.plugin_instance));
264 sstrncpy(vl.type, type, sizeof(vl.type));
266 sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
267 replace_special(vl.type_instance, sizeof(vl.type_instance));
269 plugin_dispatch_values(&vl);
270 } /* }}} void submit */
272 static size_t bind_curl_callback(void *buf, size_t size, /* {{{ */
274 void __attribute__((unused)) * stream) {
275 size_t len = size * nmemb;
280 if ((bind_buffer_fill + len) >= bind_buffer_size) {
283 temp = realloc(bind_buffer, bind_buffer_fill + len + 1);
285 ERROR("bind plugin: realloc failed.");
289 bind_buffer_size = bind_buffer_fill + len + 1;
292 memcpy(bind_buffer + bind_buffer_fill, (char *)buf, len);
293 bind_buffer_fill += len;
294 bind_buffer[bind_buffer_fill] = 0;
297 } /* }}} size_t bind_curl_callback */
300 * Callback, that's called with a translation table.
301 * (Plugin instance is fixed, type and type instance come from lookup table.)
303 static int bind_xml_table_callback(const char *name, value_t value, /* {{{ */
304 time_t current_time, void *user_data) {
305 translation_table_ptr_t *table = (translation_table_ptr_t *)user_data;
310 for (size_t i = 0; i < table->table_length; i++) {
311 if (strcmp(table->table[i].xml_name, name) != 0)
314 submit(current_time, table->plugin_instance, table->table[i].type,
315 table->table[i].type_instance, value);
320 } /* }}} int bind_xml_table_callback */
323 * Callback, that's used for lists.
324 * (Plugin instance and type are fixed, xml name is used as type instance.)
326 static int bind_xml_list_callback(const char *name, /* {{{ */
327 value_t value, time_t current_time,
329 list_info_ptr_t *list_info = (list_info_ptr_t *)user_data;
331 if (list_info == NULL)
334 submit(current_time, list_info->plugin_instance, list_info->type,
335 /* type instance = */ name, value);
338 } /* }}} int bind_xml_list_callback */
340 static int bind_xml_read_derive(xmlDoc *doc, xmlNode *node, /* {{{ */
341 derive_t *ret_value) {
346 str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
347 if (str_ptr == NULL) {
348 ERROR("bind plugin: bind_xml_read_derive: xmlNodeListGetString failed.");
352 status = parse_value(str_ptr, &value, DS_TYPE_DERIVE);
354 ERROR("bind plugin: Parsing string \"%s\" to derive value failed.",
361 *ret_value = value.derive;
363 } /* }}} int bind_xml_read_derive */
365 static int bind_xml_read_gauge(xmlDoc *doc, xmlNode *node, /* {{{ */
366 gauge_t *ret_value) {
367 char *str_ptr, *end_ptr;
370 str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
371 if (str_ptr == NULL) {
372 ERROR("bind plugin: bind_xml_read_gauge: xmlNodeListGetString failed.");
377 value = strtod(str_ptr, &end_ptr);
379 if (str_ptr == end_ptr || errno) {
380 if (errno && (value < 0))
381 ERROR("bind plugin: bind_xml_read_gauge: strtod failed with underflow.");
382 else if (errno && (value > 0))
383 ERROR("bind plugin: bind_xml_read_gauge: strtod failed with overflow.");
385 ERROR("bind plugin: bind_xml_read_gauge: strtod failed.");
389 *ret_value = (gauge_t)value;
391 } /* }}} int bind_xml_read_gauge */
393 static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */
394 xmlDoc *doc, xmlXPathContext *xpathCtx,
396 xmlXPathObject *xpathObj = NULL;
402 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
403 if (xpathObj == NULL) {
404 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
409 if ((xpathObj->nodesetval == NULL) || (xpathObj->nodesetval->nodeNr < 1)) {
410 xmlXPathFreeObject(xpathObj);
414 if (xpathObj->nodesetval->nodeNr != 1) {
415 NOTICE("bind plugin: Evaluating the XPath expression `%s' returned "
416 "%i nodes. Only handling the first one.",
417 xpath_expression, xpathObj->nodesetval->nodeNr);
420 node = xpathObj->nodesetval->nodeTab[0];
422 if (node->xmlChildrenNode == NULL) {
423 ERROR("bind plugin: bind_xml_read_timestamp: "
424 "node->xmlChildrenNode == NULL");
425 xmlXPathFreeObject(xpathObj);
429 str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
430 if (str_ptr == NULL) {
431 ERROR("bind plugin: bind_xml_read_timestamp: xmlNodeListGetString failed.");
432 xmlXPathFreeObject(xpathObj);
436 tmp = strptime(str_ptr, "%Y-%m-%dT%T", &tm);
439 ERROR("bind plugin: bind_xml_read_timestamp: strptime failed.");
440 xmlXPathFreeObject(xpathObj);
445 time_t t = timegm(&tm);
446 if (t == ((time_t)-1)) {
448 ERROR("bind plugin: timegm() failed: %s",
449 sstrerror(errno, errbuf, sizeof(errbuf)));
454 time_t t = mktime(&tm);
455 if (t == ((time_t)-1)) {
457 ERROR("bind plugin: mktime() failed: %s",
458 sstrerror(errno, errbuf, sizeof(errbuf)));
461 /* mktime assumes that tm is local time. Luckily, it also sets timezone to
462 * the offset used for the conversion, and we undo the conversion to convert
464 *ret_value = t - timezone;
467 xmlXPathFreeObject(xpathObj);
469 } /* }}} int bind_xml_read_timestamp */
472 * bind_parse_generic_name_value
474 * Reads statistics in the form:
477 * <counter>123</counter>
480 static int bind_parse_generic_name_value(const char *xpath_expression, /* {{{ */
481 list_callback_t list_callback,
482 void *user_data, xmlDoc *doc,
483 xmlXPathContext *xpathCtx,
484 time_t current_time, int ds_type) {
485 xmlXPathObject *xpathObj = NULL;
488 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
489 if (xpathObj == NULL) {
490 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
496 /* Iterate over all matching nodes. */
497 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
499 xmlNode *name_node = NULL;
500 xmlNode *counter = NULL;
503 parent = xpathObj->nodesetval->nodeTab[i];
504 DEBUG("bind plugin: bind_parse_generic_name_value: parent->name = %s;",
505 (char *)parent->name);
507 /* Iterate over all child nodes. */
508 for (xmlNode *child = parent->xmlChildrenNode; child != NULL;
509 child = child->next) {
510 if (child->type != XML_ELEMENT_NODE)
513 if (xmlStrcmp(BAD_CAST "name", child->name) == 0)
515 else if (xmlStrcmp(BAD_CAST "counter", child->name) == 0)
519 if ((name_node != NULL) && (counter != NULL)) {
521 (char *)xmlNodeListGetString(doc, name_node->xmlChildrenNode, 1);
525 if (ds_type == DS_TYPE_GAUGE)
526 status = bind_xml_read_gauge(doc, counter, &value.gauge);
528 status = bind_xml_read_derive(doc, counter, &value.derive);
532 status = (*list_callback)(name, value, current_time, user_data);
540 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
541 (num_entries == 1) ? "entry" : "entries", xpath_expression);
543 xmlXPathFreeObject(xpathObj);
546 } /* }}} int bind_parse_generic_name_value */
549 * bind_parse_generic_value_list
551 * Reads statistics in the form:
559 static int bind_parse_generic_value_list(const char *xpath_expression, /* {{{ */
560 list_callback_t list_callback,
561 void *user_data, xmlDoc *doc,
562 xmlXPathContext *xpathCtx,
563 time_t current_time, int ds_type) {
564 xmlXPathObject *xpathObj = NULL;
567 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
568 if (xpathObj == NULL) {
569 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
575 /* Iterate over all matching nodes. */
576 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
578 /* Iterate over all child nodes. */
579 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
580 child != NULL; child = child->next) {
585 if (child->type != XML_ELEMENT_NODE)
588 node_name = (char *)child->name;
590 if (ds_type == DS_TYPE_GAUGE)
591 status = bind_xml_read_gauge(doc, child, &value.gauge);
593 status = bind_xml_read_derive(doc, child, &value.derive);
597 status = (*list_callback)(node_name, value, current_time, user_data);
603 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
604 (num_entries == 1) ? "entry" : "entries", xpath_expression);
606 xmlXPathFreeObject(xpathObj);
609 } /* }}} int bind_parse_generic_value_list */
612 * bind_parse_generic_name_attr_value_list
614 * Reads statistics in the form:
616 * <counter name="name0">123</counter>
617 * <counter name="name1">234</counter>
618 * <counter name="name2">345</counter>
622 static int bind_parse_generic_name_attr_value_list(
623 const char *xpath_expression, /* {{{ */
624 list_callback_t list_callback, void *user_data, xmlDoc *doc,
625 xmlXPathContext *xpathCtx, time_t current_time, int ds_type) {
626 xmlXPathObject *xpathObj = NULL;
629 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
630 if (xpathObj == NULL) {
631 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
637 /* Iterate over all matching nodes. */
638 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
640 /* Iterate over all child nodes. */
641 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
642 child != NULL; child = child->next) {
643 if (child->type != XML_ELEMENT_NODE)
646 if (strncmp("counter", (char *)child->name, strlen("counter")) != 0)
653 attr_name = (char *)xmlGetProp(child, BAD_CAST "name");
654 if (attr_name == NULL) {
655 DEBUG("bind plugin: found <counter> without name.");
658 if (ds_type == DS_TYPE_GAUGE)
659 status = bind_xml_read_gauge(doc, child, &value.gauge);
661 status = bind_xml_read_derive(doc, child, &value.derive);
665 status = (*list_callback)(attr_name, value, current_time, user_data);
671 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
672 (num_entries == 1) ? "entry" : "entries", xpath_expression);
674 xmlXPathFreeObject(xpathObj);
677 } /* }}} int bind_parse_generic_name_attr_value_list */
679 static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */
680 xmlXPathContext *path_ctx, xmlNode *node,
681 cb_view_t *view, time_t current_time) {
682 xmlXPathObject *path_obj;
683 char *zone_name = NULL;
687 char *n = (char *)xmlGetProp(node, BAD_CAST "name");
688 char *c = (char *)xmlGetProp(node, BAD_CAST "rdataclass");
690 zone_name = (char *)xmlMalloc(strlen(n) + strlen(c) + 2);
691 snprintf(zone_name, strlen(n) + strlen(c) + 2, "%s/%s", n, c);
696 path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
697 if (path_obj == NULL) {
698 ERROR("bind plugin: xmlXPathEvalExpression failed.");
702 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
704 zone_name = (char *)xmlNodeListGetString(
705 doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
706 if (zone_name != NULL)
709 xmlXPathFreeObject(path_obj);
712 if (zone_name == NULL) {
713 ERROR("bind plugin: Could not determine zone name.");
717 for (j = 0; j < view->zones_num; j++) {
718 if (strcasecmp(zone_name, view->zones[j]) == 0)
725 if (j >= view->zones_num)
728 zone_name = view->zones[j];
730 DEBUG("bind plugin: bind_xml_stats_handle_zone: Found zone `%s'.", zone_name);
732 { /* Parse the <counters> tag {{{ */
733 char plugin_instance[DATA_MAX_NAME_LEN];
734 translation_table_ptr_t table_ptr = {nsstats_translation_table,
735 nsstats_translation_table_length,
738 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-zone-%s",
739 view->name, zone_name);
742 list_info_ptr_t list_info = {plugin_instance,
743 /* type = */ "dns_qtype"};
744 bind_parse_generic_name_attr_value_list(
745 /* xpath = */ "counters[@type='rcode']",
746 /* callback = */ bind_xml_table_callback,
747 /* user_data = */ &table_ptr, doc, path_ctx, current_time,
749 bind_parse_generic_name_attr_value_list(
750 /* xpath = */ "counters[@type='qtype']",
751 /* callback = */ bind_xml_list_callback,
752 /* user_data = */ &list_info, doc, path_ctx, current_time,
755 bind_parse_generic_value_list(/* xpath = */ "counters",
756 /* callback = */ bind_xml_table_callback,
757 /* user_data = */ &table_ptr, doc, path_ctx,
758 current_time, DS_TYPE_COUNTER);
763 } /* }}} int bind_xml_stats_handle_zone */
765 static int bind_xml_stats_search_zones(int version, xmlDoc *doc, /* {{{ */
766 xmlXPathContext *path_ctx, xmlNode *node,
767 cb_view_t *view, time_t current_time) {
768 xmlXPathObject *zone_nodes = NULL;
769 xmlXPathContext *zone_path_context;
771 zone_path_context = xmlXPathNewContext(doc);
772 if (zone_path_context == NULL) {
773 ERROR("bind plugin: xmlXPathNewContext failed.");
777 zone_nodes = xmlXPathEvalExpression(BAD_CAST "zones/zone", path_ctx);
778 if (zone_nodes == NULL) {
779 ERROR("bind plugin: Cannot find any <view> tags.");
780 xmlXPathFreeContext(zone_path_context);
784 for (int i = 0; i < zone_nodes->nodesetval->nodeNr; i++) {
785 node = zone_nodes->nodesetval->nodeTab[i];
786 assert(node != NULL);
788 zone_path_context->node = node;
790 bind_xml_stats_handle_zone(version, doc, zone_path_context, node, view,
794 xmlXPathFreeObject(zone_nodes);
795 xmlXPathFreeContext(zone_path_context);
797 } /* }}} int bind_xml_stats_search_zones */
799 static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */
800 xmlXPathContext *path_ctx, xmlNode *node,
801 time_t current_time) {
802 char *view_name = NULL;
807 view_name = (char *)xmlGetProp(node, BAD_CAST "name");
809 if (view_name == NULL) {
810 ERROR("bind plugin: Could not determine view name.");
814 for (j = 0; j < views_num; j++) {
815 if (strcasecmp(view_name, views[j].name) == 0)
822 xmlXPathObject *path_obj;
823 path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
824 if (path_obj == NULL) {
825 ERROR("bind plugin: xmlXPathEvalExpression failed.");
829 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
831 view_name = (char *)xmlNodeListGetString(
832 doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
833 if (view_name != NULL)
837 if (view_name == NULL) {
838 ERROR("bind plugin: Could not determine view name.");
839 xmlXPathFreeObject(path_obj);
843 for (j = 0; j < views_num; j++) {
844 if (strcasecmp(view_name, views[j].name) == 0)
849 xmlXPathFreeObject(path_obj);
860 DEBUG("bind plugin: bind_xml_stats_handle_view: Found view `%s'.",
863 if (view->qtypes != 0) /* {{{ */
865 char plugin_instance[DATA_MAX_NAME_LEN];
866 list_info_ptr_t list_info = {plugin_instance,
867 /* type = */ "dns_qtype"};
869 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-qtypes",
872 bind_parse_generic_name_attr_value_list(
873 /* xpath = */ "counters[@type='resqtype']",
874 /* callback = */ bind_xml_list_callback,
875 /* user_data = */ &list_info, doc, path_ctx, current_time,
878 bind_parse_generic_name_value(/* xpath = */ "rdtype",
879 /* callback = */ bind_xml_list_callback,
880 /* user_data = */ &list_info, doc, path_ctx,
881 current_time, DS_TYPE_COUNTER);
885 if (view->resolver_stats != 0) /* {{{ */
887 char plugin_instance[DATA_MAX_NAME_LEN];
888 translation_table_ptr_t table_ptr = {resstats_translation_table,
889 resstats_translation_table_length,
892 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-resolver_stats",
895 bind_parse_generic_name_attr_value_list(
896 "counters[@type='resstats']",
897 /* callback = */ bind_xml_table_callback,
898 /* user_data = */ &table_ptr, doc, path_ctx, current_time,
901 bind_parse_generic_name_value("resstat",
902 /* callback = */ bind_xml_table_callback,
903 /* user_data = */ &table_ptr, doc, path_ctx,
904 current_time, DS_TYPE_COUNTER);
908 /* Record types in the cache */
909 if (view->cacherrsets != 0) /* {{{ */
911 char plugin_instance[DATA_MAX_NAME_LEN];
912 list_info_ptr_t list_info = {plugin_instance,
913 /* type = */ "dns_qtype_cached"};
915 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-cache_rr_sets",
918 bind_parse_generic_name_value(/* xpath = */ "cache/rrset",
919 /* callback = */ bind_xml_list_callback,
920 /* user_data = */ &list_info, doc, path_ctx,
921 current_time, DS_TYPE_GAUGE);
924 if (view->zones_num > 0)
925 bind_xml_stats_search_zones(version, doc, path_ctx, node, view,
929 } /* }}} int bind_xml_stats_handle_view */
931 static int bind_xml_stats_search_views(int version, xmlDoc *doc, /* {{{ */
932 xmlXPathContext *xpathCtx,
934 time_t current_time) {
935 xmlXPathObject *view_nodes = NULL;
936 xmlXPathContext *view_path_context;
938 view_path_context = xmlXPathNewContext(doc);
939 if (view_path_context == NULL) {
940 ERROR("bind plugin: xmlXPathNewContext failed.");
944 view_nodes = xmlXPathEvalExpression(BAD_CAST "views/view", xpathCtx);
945 if (view_nodes == NULL) {
946 ERROR("bind plugin: Cannot find any <view> tags.");
947 xmlXPathFreeContext(view_path_context);
951 for (int i = 0; i < view_nodes->nodesetval->nodeNr; i++) {
954 node = view_nodes->nodesetval->nodeTab[i];
955 assert(node != NULL);
957 view_path_context->node = node;
959 bind_xml_stats_handle_view(version, doc, view_path_context, node,
963 xmlXPathFreeObject(view_nodes);
964 xmlXPathFreeContext(view_path_context);
966 } /* }}} int bind_xml_stats_search_views */
968 static void bind_xml_stats_v3(xmlDoc *doc, /* {{{ */
969 xmlXPathContext *xpathCtx, xmlNode *statsnode,
970 time_t current_time) {
971 /* XPath: server/counters[@type='opcode']
972 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
974 * <counters type="opcode">
975 * <counter name="A">1</counter>
979 if (global_opcodes != 0) {
980 list_info_ptr_t list_info = {/* plugin instance = */ "global-opcodes",
981 /* type = */ "dns_opcode"};
982 bind_parse_generic_name_attr_value_list(
983 /* xpath = */ "server/counters[@type='opcode']",
984 /* callback = */ bind_xml_list_callback,
985 /* user_data = */ &list_info, doc, xpathCtx, current_time,
989 /* XPath: server/counters[@type='qtype']
990 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
991 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
992 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
994 * <counters type="opcode">
995 * <counter name="A">1</counter>
999 if (global_qtypes != 0) {
1000 list_info_ptr_t list_info = {/* plugin instance = */ "global-qtypes",
1001 /* type = */ "dns_qtype"};
1003 bind_parse_generic_name_attr_value_list(
1004 /* xpath = */ "server/counters[@type='qtype']",
1005 /* callback = */ bind_xml_list_callback,
1006 /* user_data = */ &list_info, doc, xpathCtx, current_time,
1010 /* XPath: server/counters[@type='nsstat']
1011 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1012 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1013 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1014 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1015 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1016 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1017 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1020 * <counters type="nsstat"
1021 * <counter name="Requestv4">1</counter>
1022 * <counter name="Requestv6">0</counter>
1026 if (global_server_stats) {
1027 translation_table_ptr_t table_ptr = {
1028 nsstats_translation_table, nsstats_translation_table_length,
1029 /* plugin_instance = */ "global-server_stats"};
1031 bind_parse_generic_name_attr_value_list(
1032 "server/counters[@type='nsstat']",
1033 /* callback = */ bind_xml_table_callback,
1034 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1038 /* XPath: server/zonestats, server/zonestat,
1039 * server/counters[@type='zonestat']
1040 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1041 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1042 * XfrSuccess, XfrFail
1044 * <counters type="zonestat"
1045 * <counter name="NotifyOutv4">0</counter>
1046 * <counter name="NotifyOutv6">0</counter>
1050 if (global_zone_maint_stats) {
1051 translation_table_ptr_t table_ptr = {
1052 zonestats_translation_table, zonestats_translation_table_length,
1053 /* plugin_instance = */ "global-zone_maint_stats"};
1055 bind_parse_generic_name_attr_value_list(
1056 "server/counters[@type='zonestat']",
1057 /* callback = */ bind_xml_table_callback,
1058 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1062 /* XPath: server/resstats, server/counters[@type='resstat']
1063 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1064 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1065 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1066 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1068 * <counters type="resstat"
1069 * <counter name="Queryv4">0</counter>
1070 * <counter name="Queryv6">0</counter>
1074 if (global_resolver_stats != 0) {
1075 translation_table_ptr_t table_ptr = {
1076 resstats_translation_table, resstats_translation_table_length,
1077 /* plugin_instance = */ "global-resolver_stats"};
1079 bind_parse_generic_name_attr_value_list(
1080 "server/counters[@type='resstat']",
1081 /* callback = */ bind_xml_table_callback,
1082 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1085 } /* }}} bind_xml_stats_v3 */
1087 static void bind_xml_stats_v1_v2(int version, xmlDoc *doc, /* {{{ */
1088 xmlXPathContext *xpathCtx, xmlNode *statsnode,
1089 time_t current_time) {
1090 /* XPath: server/requests/opcode, server/counters[@type='opcode']
1091 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1095 * <counter>1</counter>
1099 if (global_opcodes != 0) {
1100 list_info_ptr_t list_info = {/* plugin instance = */ "global-opcodes",
1101 /* type = */ "dns_opcode"};
1103 bind_parse_generic_name_value(/* xpath = */ "server/requests/opcode",
1104 /* callback = */ bind_xml_list_callback,
1105 /* user_data = */ &list_info, doc, xpathCtx,
1106 current_time, DS_TYPE_COUNTER);
1109 /* XPath: server/queries-in/rdtype, server/counters[@type='qtype']
1110 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1111 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1112 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1116 * <counter>1</counter>
1120 if (global_qtypes != 0) {
1121 list_info_ptr_t list_info = {/* plugin instance = */ "global-qtypes",
1122 /* type = */ "dns_qtype"};
1124 bind_parse_generic_name_value(/* xpath = */ "server/queries-in/rdtype",
1125 /* callback = */ bind_xml_list_callback,
1126 /* user_data = */ &list_info, doc, xpathCtx,
1127 current_time, DS_TYPE_COUNTER);
1130 /* XPath: server/nsstats, server/nsstat, server/counters[@type='nsstat']
1131 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1132 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1133 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1134 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1135 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1136 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1137 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1141 * <Requestv4>1</Requestv4>
1142 * <Requestv6>0</Requestv6>
1147 * <name>Requestv4</name>
1148 * <counter>1</counter>
1151 * <name>Requestv6</name>
1152 * <counter>0</counter>
1156 if (global_server_stats) {
1157 translation_table_ptr_t table_ptr = {
1158 nsstats_translation_table, nsstats_translation_table_length,
1159 /* plugin_instance = */ "global-server_stats"};
1162 bind_parse_generic_value_list("server/nsstats",
1163 /* callback = */ bind_xml_table_callback,
1164 /* user_data = */ &table_ptr, doc, xpathCtx,
1165 current_time, DS_TYPE_COUNTER);
1167 bind_parse_generic_name_value("server/nsstat",
1168 /* callback = */ bind_xml_table_callback,
1169 /* user_data = */ &table_ptr, doc, xpathCtx,
1170 current_time, DS_TYPE_COUNTER);
1174 /* XPath: server/zonestats, server/zonestat,
1175 * server/counters[@type='zonestat']
1176 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1177 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1178 * XfrSuccess, XfrFail
1181 * <NotifyOutv4>0</NotifyOutv4>
1182 * <NotifyOutv6>0</NotifyOutv6>
1187 * <name>NotifyOutv4</name>
1188 * <counter>0</counter>
1191 * <name>NotifyOutv6</name>
1192 * <counter>0</counter>
1196 if (global_zone_maint_stats) {
1197 translation_table_ptr_t table_ptr = {
1198 zonestats_translation_table, zonestats_translation_table_length,
1199 /* plugin_instance = */ "global-zone_maint_stats"};
1202 bind_parse_generic_value_list("server/zonestats",
1203 /* callback = */ bind_xml_table_callback,
1204 /* user_data = */ &table_ptr, doc, xpathCtx,
1205 current_time, DS_TYPE_COUNTER);
1207 bind_parse_generic_name_value("server/zonestat",
1208 /* callback = */ bind_xml_table_callback,
1209 /* user_data = */ &table_ptr, doc, xpathCtx,
1210 current_time, DS_TYPE_COUNTER);
1214 /* XPath: server/resstats, server/counters[@type='resstat']
1215 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1216 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1217 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1218 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1221 * <Queryv4>0</Queryv4>
1222 * <Queryv6>0</Queryv6>
1227 * <name>Queryv4</name>
1228 * <counter>0</counter>
1231 * <name>Queryv6</name>
1232 * <counter>0</counter>
1236 if (global_resolver_stats != 0) {
1237 translation_table_ptr_t table_ptr = {
1238 resstats_translation_table, resstats_translation_table_length,
1239 /* plugin_instance = */ "global-resolver_stats"};
1242 bind_parse_generic_value_list("server/resstats",
1243 /* callback = */ bind_xml_table_callback,
1244 /* user_data = */ &table_ptr, doc, xpathCtx,
1245 current_time, DS_TYPE_COUNTER);
1247 bind_parse_generic_name_value("server/resstat",
1248 /* callback = */ bind_xml_table_callback,
1249 /* user_data = */ &table_ptr, doc, xpathCtx,
1250 current_time, DS_TYPE_COUNTER);
1253 } /* }}} bind_xml_stats_v1_v2 */
1255 static int bind_xml_stats(int version, xmlDoc *doc, /* {{{ */
1256 xmlXPathContext *xpathCtx, xmlNode *statsnode) {
1257 time_t current_time = 0;
1260 xpathCtx->node = statsnode;
1262 /* TODO: Check `server/boot-time' to recognize server restarts. */
1264 status = bind_xml_read_timestamp("server/current-time", doc, xpathCtx,
1267 ERROR("bind plugin: Reading `server/current-time' failed.");
1270 DEBUG("bind plugin: Current server time is %i.", (int)current_time);
1273 bind_xml_stats_v3(doc, xpathCtx, statsnode, current_time);
1275 bind_xml_stats_v1_v2(version, doc, xpathCtx, statsnode, current_time);
1278 /* XPath: memory/summary
1279 * Variables: TotalUse, InUse, BlockSize, ContextSize, Lost
1280 * Layout: v2 and v3:
1282 * <TotalUse>6587096</TotalUse>
1283 * <InUse>1345424</InUse>
1284 * <BlockSize>5505024</BlockSize>
1285 * <ContextSize>3732456</ContextSize>
1289 if (global_memory_stats != 0) {
1290 translation_table_ptr_t table_ptr = {
1291 memsummary_translation_table, memsummary_translation_table_length,
1292 /* plugin_instance = */ "global-memory_stats"};
1294 bind_parse_generic_value_list("memory/summary",
1295 /* callback = */ bind_xml_table_callback,
1296 /* user_data = */ &table_ptr, doc, xpathCtx,
1297 current_time, DS_TYPE_GAUGE);
1301 bind_xml_stats_search_views(version, doc, xpathCtx, statsnode,
1305 } /* }}} int bind_xml_stats */
1307 static int bind_xml(const char *data) /* {{{ */
1310 xmlXPathContext *xpathCtx = NULL;
1311 xmlXPathObject *xpathObj = NULL;
1314 doc = xmlParseMemory(data, strlen(data));
1316 ERROR("bind plugin: xmlParseMemory failed.");
1320 xpathCtx = xmlXPathNewContext(doc);
1321 if (xpathCtx == NULL) {
1322 ERROR("bind plugin: xmlXPathNewContext failed.");
1328 // version 3.* of statistics XML (since BIND9.9)
1331 xpathObj = xmlXPathEvalExpression(BAD_CAST "/statistics", xpathCtx);
1332 if (xpathObj == NULL || xpathObj->nodesetval == NULL ||
1333 xpathObj->nodesetval->nodeNr == 0) {
1334 DEBUG("bind plugin: Statistics appears not to be v3");
1335 // we will fallback to v1 or v2 detection
1336 if (xpathObj != NULL) {
1337 xmlXPathFreeObject(xpathObj);
1340 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
1344 node = xpathObj->nodesetval->nodeTab[i];
1345 assert(node != NULL);
1347 attr_version = (char *)xmlGetProp(node, BAD_CAST "version");
1348 if (attr_version == NULL) {
1349 NOTICE("bind plugin: Found <statistics> tag doesn't have a "
1350 "`version' attribute.");
1353 DEBUG("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1355 if (strncmp("3.", attr_version, strlen("3.")) != 0) {
1356 /* TODO: Use the complaint mechanism here. */
1357 NOTICE("bind plugin: Found <statistics> tag with version `%s'. "
1358 "Unfortunately I have no clue how to parse that. "
1359 "Please open a bug report for this.",
1361 xmlFree(attr_version);
1364 ret = bind_xml_stats(3, doc, xpathCtx, node);
1366 xmlFree(attr_version);
1367 /* One <statistics> node ought to be enough. */
1371 // we are finished, early-return
1372 xmlXPathFreeObject(xpathObj);
1373 xmlXPathFreeContext(xpathCtx);
1380 // versions 1.* or 2.* of statistics XML
1383 xpathObj = xmlXPathEvalExpression(BAD_CAST "/isc/bind/statistics", xpathCtx);
1384 if (xpathObj == NULL) {
1385 ERROR("bind plugin: Cannot find the <statistics> tag.");
1386 xmlXPathFreeContext(xpathCtx);
1389 } else if (xpathObj->nodesetval == NULL) {
1390 ERROR("bind plugin: xmlXPathEvalExpression failed.");
1391 xmlXPathFreeObject(xpathObj);
1392 xmlXPathFreeContext(xpathCtx);
1397 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
1400 int parsed_version = 0;
1402 node = xpathObj->nodesetval->nodeTab[i];
1403 assert(node != NULL);
1405 attr_version = (char *)xmlGetProp(node, BAD_CAST "version");
1406 if (attr_version == NULL) {
1407 NOTICE("bind plugin: Found <statistics> tag doesn't have a "
1408 "`version' attribute.");
1411 DEBUG("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1413 /* At the time this plugin was written, version "1.0" was used by
1414 * BIND 9.5.0, version "2.0" was used by BIND 9.5.1 and 9.6.0. We assume
1415 * that "1.*" and "2.*" don't introduce structural changes, so we just
1416 * check for the first two characters here. */
1417 if (strncmp("1.", attr_version, strlen("1.")) == 0)
1419 else if (strncmp("2.", attr_version, strlen("2.")) == 0)
1422 /* TODO: Use the complaint mechanism here. */
1423 NOTICE("bind plugin: Found <statistics> tag with version `%s'. "
1424 "Unfortunately I have no clue how to parse that. "
1425 "Please open a bug report for this.",
1427 xmlFree(attr_version);
1431 ret = bind_xml_stats(parsed_version, doc, xpathCtx, node);
1433 xmlFree(attr_version);
1434 /* One <statistics> node ought to be enough. */
1438 xmlXPathFreeObject(xpathObj);
1439 xmlXPathFreeContext(xpathCtx);
1443 } /* }}} int bind_xml */
1445 static int bind_config_set_bool(const char *name, int *var, /* {{{ */
1446 oconfig_item_t *ci) {
1447 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
1448 WARNING("bind plugin: The `%s' option needs "
1449 "exactly one boolean argument.",
1454 if (ci->values[0].value.boolean)
1459 } /* }}} int bind_config_set_bool */
1461 static int bind_config_add_view_zone(cb_view_t *view, /* {{{ */
1462 oconfig_item_t *ci) {
1465 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1466 WARNING("bind plugin: The `Zone' option needs "
1467 "exactly one string argument.");
1471 tmp = realloc(view->zones, sizeof(char *) * (view->zones_num + 1));
1473 ERROR("bind plugin: realloc failed.");
1478 view->zones[view->zones_num] = strdup(ci->values[0].value.string);
1479 if (view->zones[view->zones_num] == NULL) {
1480 ERROR("bind plugin: strdup failed.");
1486 } /* }}} int bind_config_add_view_zone */
1488 static int bind_config_add_view(oconfig_item_t *ci) /* {{{ */
1492 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1493 WARNING("bind plugin: `View' blocks need exactly one string argument.");
1497 tmp = realloc(views, sizeof(*views) * (views_num + 1));
1499 ERROR("bind plugin: realloc failed.");
1503 tmp = views + views_num;
1505 memset(tmp, 0, sizeof(*tmp));
1507 tmp->resolver_stats = 1;
1508 tmp->cacherrsets = 1;
1512 tmp->name = strdup(ci->values[0].value.string);
1513 if (tmp->name == NULL) {
1514 ERROR("bind plugin: strdup failed.");
1519 for (int i = 0; i < ci->children_num; i++) {
1520 oconfig_item_t *child = ci->children + i;
1522 if (strcasecmp("QTypes", child->key) == 0)
1523 bind_config_set_bool("QTypes", &tmp->qtypes, child);
1524 else if (strcasecmp("ResolverStats", child->key) == 0)
1525 bind_config_set_bool("ResolverStats", &tmp->resolver_stats, child);
1526 else if (strcasecmp("CacheRRSets", child->key) == 0)
1527 bind_config_set_bool("CacheRRSets", &tmp->cacherrsets, child);
1528 else if (strcasecmp("Zone", child->key) == 0)
1529 bind_config_add_view_zone(tmp, child);
1531 WARNING("bind plugin: Unknown configuration option "
1532 "`%s' in view `%s' will be ignored.",
1533 child->key, tmp->name);
1535 } /* for (i = 0; i < ci->children_num; i++) */
1539 } /* }}} int bind_config_add_view */
1541 static int bind_config(oconfig_item_t *ci) /* {{{ */
1543 for (int i = 0; i < ci->children_num; i++) {
1544 oconfig_item_t *child = ci->children + i;
1546 if (strcasecmp("Url", child->key) == 0) {
1547 if ((child->values_num != 1) ||
1548 (child->values[0].type != OCONFIG_TYPE_STRING)) {
1549 WARNING("bind plugin: The `Url' option needs "
1550 "exactly one string argument.");
1555 url = strdup(child->values[0].value.string);
1556 } else if (strcasecmp("OpCodes", child->key) == 0)
1557 bind_config_set_bool("OpCodes", &global_opcodes, child);
1558 else if (strcasecmp("QTypes", child->key) == 0)
1559 bind_config_set_bool("QTypes", &global_qtypes, child);
1560 else if (strcasecmp("ServerStats", child->key) == 0)
1561 bind_config_set_bool("ServerStats", &global_server_stats, child);
1562 else if (strcasecmp("ZoneMaintStats", child->key) == 0)
1563 bind_config_set_bool("ZoneMaintStats", &global_zone_maint_stats, child);
1564 else if (strcasecmp("ResolverStats", child->key) == 0)
1565 bind_config_set_bool("ResolverStats", &global_resolver_stats, child);
1566 else if (strcasecmp("MemoryStats", child->key) == 0)
1567 bind_config_set_bool("MemoryStats", &global_memory_stats, child);
1568 else if (strcasecmp("View", child->key) == 0)
1569 bind_config_add_view(child);
1570 else if (strcasecmp("ParseTime", child->key) == 0)
1571 cf_util_get_boolean(child, &config_parse_time);
1572 else if (strcasecmp("Timeout", child->key) == 0)
1573 cf_util_get_int(child, &timeout);
1575 WARNING("bind plugin: Unknown configuration option "
1576 "`%s' will be ignored.",
1582 } /* }}} int bind_config */
1584 static int bind_init(void) /* {{{ */
1589 curl = curl_easy_init();
1591 ERROR("bind plugin: bind_init: curl_easy_init failed.");
1595 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
1596 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
1597 curl_easy_setopt(curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
1598 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, bind_curl_error);
1599 curl_easy_setopt(curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
1600 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
1601 curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
1602 #ifdef HAVE_CURLOPT_TIMEOUT_MS
1603 curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS,
1604 (timeout >= 0) ? (long)timeout : (long)CDTIME_T_TO_MS(
1605 plugin_get_interval()));
1609 } /* }}} int bind_init */
1611 static int bind_read(void) /* {{{ */
1616 ERROR("bind plugin: I don't have a CURL object.");
1620 bind_buffer_fill = 0;
1621 if (curl_easy_perform(curl) != CURLE_OK) {
1622 ERROR("bind plugin: curl_easy_perform failed: %s", bind_curl_error);
1626 status = bind_xml(bind_buffer);
1631 } /* }}} int bind_read */
1633 static int bind_shutdown(void) /* {{{ */
1636 curl_easy_cleanup(curl);
1641 } /* }}} int bind_shutdown */
1643 void module_register(void) {
1644 plugin_register_complex_config("bind", bind_config);
1645 plugin_register_init("bind", bind_init);
1646 plugin_register_read("bind", bind_read);
1647 plugin_register_shutdown("bind", bind_shutdown);
1648 } /* void module_register */
1650 /* vim: set sw=2 sts=2 ts=8 et fdm=marker : */