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);
534 status = (*list_callback)(name, value, current_time, user_data);
542 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
543 (num_entries == 1) ? "entry" : "entries", xpath_expression);
545 xmlXPathFreeObject(xpathObj);
548 } /* }}} int bind_parse_generic_name_value */
551 * bind_parse_generic_value_list
553 * Reads statistics in the form:
561 static int bind_parse_generic_value_list(const char *xpath_expression, /* {{{ */
562 list_callback_t list_callback,
563 void *user_data, xmlDoc *doc,
564 xmlXPathContext *xpathCtx,
565 time_t current_time, int ds_type) {
566 xmlXPathObject *xpathObj = NULL;
569 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
570 if (xpathObj == NULL) {
571 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
577 /* Iterate over all matching nodes. */
578 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
580 /* Iterate over all child nodes. */
581 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
582 child != NULL; child = child->next) {
587 if (child->type != XML_ELEMENT_NODE)
590 node_name = (char *)child->name;
592 if (ds_type == DS_TYPE_GAUGE)
593 status = bind_xml_read_gauge(doc, child, &value.gauge);
595 status = bind_xml_read_derive(doc, child, &value.derive);
599 status = (*list_callback)(node_name, value, current_time, user_data);
605 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
606 (num_entries == 1) ? "entry" : "entries", xpath_expression);
608 xmlXPathFreeObject(xpathObj);
611 } /* }}} int bind_parse_generic_value_list */
614 * bind_parse_generic_name_attr_value_list
616 * Reads statistics in the form:
618 * <counter name="name0">123</counter>
619 * <counter name="name1">234</counter>
620 * <counter name="name2">345</counter>
624 static int bind_parse_generic_name_attr_value_list(
625 const char *xpath_expression, /* {{{ */
626 list_callback_t list_callback, void *user_data, xmlDoc *doc,
627 xmlXPathContext *xpathCtx, time_t current_time, int ds_type) {
628 xmlXPathObject *xpathObj = NULL;
631 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
632 if (xpathObj == NULL) {
633 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
639 /* Iterate over all matching nodes. */
640 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
642 /* Iterate over all child nodes. */
643 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
644 child != NULL; child = child->next) {
645 if (child->type != XML_ELEMENT_NODE)
648 if (strncmp("counter", (char *)child->name, strlen("counter")) != 0)
655 attr_name = (char *)xmlGetProp(child, BAD_CAST "name");
656 if (attr_name == NULL) {
657 DEBUG("bind plugin: found <counter> without name.");
660 if (ds_type == DS_TYPE_GAUGE)
661 status = bind_xml_read_gauge(doc, child, &value.gauge);
663 status = bind_xml_read_derive(doc, child, &value.derive);
669 status = (*list_callback)(attr_name, value, current_time, user_data);
677 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
678 (num_entries == 1) ? "entry" : "entries", xpath_expression);
680 xmlXPathFreeObject(xpathObj);
683 } /* }}} int bind_parse_generic_name_attr_value_list */
685 static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */
686 xmlXPathContext *path_ctx, xmlNode *node,
687 cb_view_t *view, time_t current_time) {
688 xmlXPathObject *path_obj;
689 char *zone_name = NULL;
693 char *n = (char *)xmlGetProp(node, BAD_CAST "name");
694 char *c = (char *)xmlGetProp(node, BAD_CAST "rdataclass");
696 zone_name = (char *)xmlMalloc(strlen(n) + strlen(c) + 2);
697 snprintf(zone_name, strlen(n) + strlen(c) + 2, "%s/%s", n, c);
702 path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
703 if (path_obj == NULL) {
704 ERROR("bind plugin: xmlXPathEvalExpression failed.");
708 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
710 zone_name = (char *)xmlNodeListGetString(
711 doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
712 if (zone_name != NULL)
715 xmlXPathFreeObject(path_obj);
718 if (zone_name == NULL) {
719 ERROR("bind plugin: Could not determine zone name.");
723 for (j = 0; j < view->zones_num; j++) {
724 if (strcasecmp(zone_name, view->zones[j]) == 0)
731 if (j >= view->zones_num)
734 zone_name = view->zones[j];
736 DEBUG("bind plugin: bind_xml_stats_handle_zone: Found zone `%s'.", zone_name);
738 { /* Parse the <counters> tag {{{ */
739 char plugin_instance[DATA_MAX_NAME_LEN];
740 translation_table_ptr_t table_ptr = {nsstats_translation_table,
741 nsstats_translation_table_length,
744 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-zone-%s",
745 view->name, zone_name);
748 list_info_ptr_t list_info = {plugin_instance,
749 /* type = */ "dns_qtype"};
750 bind_parse_generic_name_attr_value_list(
751 /* xpath = */ "counters[@type='rcode']",
752 /* callback = */ bind_xml_table_callback,
753 /* user_data = */ &table_ptr, doc, path_ctx, current_time,
755 bind_parse_generic_name_attr_value_list(
756 /* xpath = */ "counters[@type='qtype']",
757 /* callback = */ bind_xml_list_callback,
758 /* user_data = */ &list_info, doc, path_ctx, current_time,
761 bind_parse_generic_value_list(/* xpath = */ "counters",
762 /* callback = */ bind_xml_table_callback,
763 /* user_data = */ &table_ptr, doc, path_ctx,
764 current_time, DS_TYPE_COUNTER);
769 } /* }}} int bind_xml_stats_handle_zone */
771 static int bind_xml_stats_search_zones(int version, xmlDoc *doc, /* {{{ */
772 xmlXPathContext *path_ctx, xmlNode *node,
773 cb_view_t *view, time_t current_time) {
774 xmlXPathObject *zone_nodes = NULL;
775 xmlXPathContext *zone_path_context;
777 zone_path_context = xmlXPathNewContext(doc);
778 if (zone_path_context == NULL) {
779 ERROR("bind plugin: xmlXPathNewContext failed.");
783 zone_nodes = xmlXPathEvalExpression(BAD_CAST "zones/zone", path_ctx);
784 if (zone_nodes == NULL) {
785 ERROR("bind plugin: Cannot find any <view> tags.");
786 xmlXPathFreeContext(zone_path_context);
790 for (int i = 0; i < zone_nodes->nodesetval->nodeNr; i++) {
791 node = zone_nodes->nodesetval->nodeTab[i];
792 assert(node != NULL);
794 zone_path_context->node = node;
796 bind_xml_stats_handle_zone(version, doc, zone_path_context, node, view,
800 xmlXPathFreeObject(zone_nodes);
801 xmlXPathFreeContext(zone_path_context);
803 } /* }}} int bind_xml_stats_search_zones */
805 static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */
806 xmlXPathContext *path_ctx, xmlNode *node,
807 time_t current_time) {
808 char *view_name = NULL;
813 view_name = (char *)xmlGetProp(node, BAD_CAST "name");
815 if (view_name == NULL) {
816 ERROR("bind plugin: Could not determine view name.");
820 for (j = 0; j < views_num; j++) {
821 if (strcasecmp(view_name, views[j].name) == 0)
828 xmlXPathObject *path_obj;
829 path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
830 if (path_obj == NULL) {
831 ERROR("bind plugin: xmlXPathEvalExpression failed.");
835 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
837 view_name = (char *)xmlNodeListGetString(
838 doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
839 if (view_name != NULL)
843 if (view_name == NULL) {
844 ERROR("bind plugin: Could not determine view name.");
845 xmlXPathFreeObject(path_obj);
849 for (j = 0; j < views_num; j++) {
850 if (strcasecmp(view_name, views[j].name) == 0)
855 xmlXPathFreeObject(path_obj);
866 DEBUG("bind plugin: bind_xml_stats_handle_view: Found view `%s'.",
869 if (view->qtypes != 0) /* {{{ */
871 char plugin_instance[DATA_MAX_NAME_LEN];
872 list_info_ptr_t list_info = {plugin_instance,
873 /* type = */ "dns_qtype"};
875 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-qtypes",
878 bind_parse_generic_name_attr_value_list(
879 /* xpath = */ "counters[@type='resqtype']",
880 /* callback = */ bind_xml_list_callback,
881 /* user_data = */ &list_info, doc, path_ctx, current_time,
884 bind_parse_generic_name_value(/* xpath = */ "rdtype",
885 /* callback = */ bind_xml_list_callback,
886 /* user_data = */ &list_info, doc, path_ctx,
887 current_time, DS_TYPE_COUNTER);
891 if (view->resolver_stats != 0) /* {{{ */
893 char plugin_instance[DATA_MAX_NAME_LEN];
894 translation_table_ptr_t table_ptr = {resstats_translation_table,
895 resstats_translation_table_length,
898 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-resolver_stats",
901 bind_parse_generic_name_attr_value_list(
902 "counters[@type='resstats']",
903 /* callback = */ bind_xml_table_callback,
904 /* user_data = */ &table_ptr, doc, path_ctx, current_time,
907 bind_parse_generic_name_value("resstat",
908 /* callback = */ bind_xml_table_callback,
909 /* user_data = */ &table_ptr, doc, path_ctx,
910 current_time, DS_TYPE_COUNTER);
914 /* Record types in the cache */
915 if (view->cacherrsets != 0) /* {{{ */
917 char plugin_instance[DATA_MAX_NAME_LEN];
918 list_info_ptr_t list_info = {plugin_instance,
919 /* type = */ "dns_qtype_cached"};
921 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-cache_rr_sets",
924 bind_parse_generic_name_value(/* xpath = */ "cache/rrset",
925 /* callback = */ bind_xml_list_callback,
926 /* user_data = */ &list_info, doc, path_ctx,
927 current_time, DS_TYPE_GAUGE);
930 if (view->zones_num > 0)
931 bind_xml_stats_search_zones(version, doc, path_ctx, node, view,
935 } /* }}} int bind_xml_stats_handle_view */
937 static int bind_xml_stats_search_views(int version, xmlDoc *doc, /* {{{ */
938 xmlXPathContext *xpathCtx,
940 time_t current_time) {
941 xmlXPathObject *view_nodes = NULL;
942 xmlXPathContext *view_path_context;
944 view_path_context = xmlXPathNewContext(doc);
945 if (view_path_context == NULL) {
946 ERROR("bind plugin: xmlXPathNewContext failed.");
950 view_nodes = xmlXPathEvalExpression(BAD_CAST "views/view", xpathCtx);
951 if (view_nodes == NULL) {
952 ERROR("bind plugin: Cannot find any <view> tags.");
953 xmlXPathFreeContext(view_path_context);
957 for (int i = 0; i < view_nodes->nodesetval->nodeNr; i++) {
960 node = view_nodes->nodesetval->nodeTab[i];
961 assert(node != NULL);
963 view_path_context->node = node;
965 bind_xml_stats_handle_view(version, doc, view_path_context, node,
969 xmlXPathFreeObject(view_nodes);
970 xmlXPathFreeContext(view_path_context);
972 } /* }}} int bind_xml_stats_search_views */
974 static void bind_xml_stats_v3(xmlDoc *doc, /* {{{ */
975 xmlXPathContext *xpathCtx, xmlNode *statsnode,
976 time_t current_time) {
977 /* XPath: server/counters[@type='opcode']
978 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
980 * <counters type="opcode">
981 * <counter name="A">1</counter>
985 if (global_opcodes != 0) {
986 list_info_ptr_t list_info = {/* plugin instance = */ "global-opcodes",
987 /* type = */ "dns_opcode"};
988 bind_parse_generic_name_attr_value_list(
989 /* xpath = */ "server/counters[@type='opcode']",
990 /* callback = */ bind_xml_list_callback,
991 /* user_data = */ &list_info, doc, xpathCtx, current_time,
995 /* XPath: server/counters[@type='qtype']
996 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
997 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
998 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1000 * <counters type="opcode">
1001 * <counter name="A">1</counter>
1005 if (global_qtypes != 0) {
1006 list_info_ptr_t list_info = {/* plugin instance = */ "global-qtypes",
1007 /* type = */ "dns_qtype"};
1009 bind_parse_generic_name_attr_value_list(
1010 /* xpath = */ "server/counters[@type='qtype']",
1011 /* callback = */ bind_xml_list_callback,
1012 /* user_data = */ &list_info, doc, xpathCtx, current_time,
1016 /* XPath: server/counters[@type='nsstat']
1017 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1018 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1019 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1020 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1021 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1022 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1023 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1026 * <counters type="nsstat"
1027 * <counter name="Requestv4">1</counter>
1028 * <counter name="Requestv6">0</counter>
1032 if (global_server_stats) {
1033 translation_table_ptr_t table_ptr = {
1034 nsstats_translation_table, nsstats_translation_table_length,
1035 /* plugin_instance = */ "global-server_stats"};
1037 bind_parse_generic_name_attr_value_list(
1038 "server/counters[@type='nsstat']",
1039 /* callback = */ bind_xml_table_callback,
1040 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1044 /* XPath: server/zonestats, server/zonestat,
1045 * server/counters[@type='zonestat']
1046 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1047 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1048 * XfrSuccess, XfrFail
1050 * <counters type="zonestat"
1051 * <counter name="NotifyOutv4">0</counter>
1052 * <counter name="NotifyOutv6">0</counter>
1056 if (global_zone_maint_stats) {
1057 translation_table_ptr_t table_ptr = {
1058 zonestats_translation_table, zonestats_translation_table_length,
1059 /* plugin_instance = */ "global-zone_maint_stats"};
1061 bind_parse_generic_name_attr_value_list(
1062 "server/counters[@type='zonestat']",
1063 /* callback = */ bind_xml_table_callback,
1064 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1068 /* XPath: server/resstats, server/counters[@type='resstat']
1069 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1070 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1071 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1072 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1074 * <counters type="resstat"
1075 * <counter name="Queryv4">0</counter>
1076 * <counter name="Queryv6">0</counter>
1080 if (global_resolver_stats != 0) {
1081 translation_table_ptr_t table_ptr = {
1082 resstats_translation_table, resstats_translation_table_length,
1083 /* plugin_instance = */ "global-resolver_stats"};
1085 bind_parse_generic_name_attr_value_list(
1086 "server/counters[@type='resstat']",
1087 /* callback = */ bind_xml_table_callback,
1088 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1091 } /* }}} bind_xml_stats_v3 */
1093 static void bind_xml_stats_v1_v2(int version, xmlDoc *doc, /* {{{ */
1094 xmlXPathContext *xpathCtx, xmlNode *statsnode,
1095 time_t current_time) {
1096 /* XPath: server/requests/opcode, server/counters[@type='opcode']
1097 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1101 * <counter>1</counter>
1105 if (global_opcodes != 0) {
1106 list_info_ptr_t list_info = {/* plugin instance = */ "global-opcodes",
1107 /* type = */ "dns_opcode"};
1109 bind_parse_generic_name_value(/* xpath = */ "server/requests/opcode",
1110 /* callback = */ bind_xml_list_callback,
1111 /* user_data = */ &list_info, doc, xpathCtx,
1112 current_time, DS_TYPE_COUNTER);
1115 /* XPath: server/queries-in/rdtype, server/counters[@type='qtype']
1116 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1117 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1118 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1122 * <counter>1</counter>
1126 if (global_qtypes != 0) {
1127 list_info_ptr_t list_info = {/* plugin instance = */ "global-qtypes",
1128 /* type = */ "dns_qtype"};
1130 bind_parse_generic_name_value(/* xpath = */ "server/queries-in/rdtype",
1131 /* callback = */ bind_xml_list_callback,
1132 /* user_data = */ &list_info, doc, xpathCtx,
1133 current_time, DS_TYPE_COUNTER);
1136 /* XPath: server/nsstats, server/nsstat, server/counters[@type='nsstat']
1137 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1138 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1139 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1140 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1141 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1142 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1143 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1147 * <Requestv4>1</Requestv4>
1148 * <Requestv6>0</Requestv6>
1153 * <name>Requestv4</name>
1154 * <counter>1</counter>
1157 * <name>Requestv6</name>
1158 * <counter>0</counter>
1162 if (global_server_stats) {
1163 translation_table_ptr_t table_ptr = {
1164 nsstats_translation_table, nsstats_translation_table_length,
1165 /* plugin_instance = */ "global-server_stats"};
1168 bind_parse_generic_value_list("server/nsstats",
1169 /* callback = */ bind_xml_table_callback,
1170 /* user_data = */ &table_ptr, doc, xpathCtx,
1171 current_time, DS_TYPE_COUNTER);
1173 bind_parse_generic_name_value("server/nsstat",
1174 /* callback = */ bind_xml_table_callback,
1175 /* user_data = */ &table_ptr, doc, xpathCtx,
1176 current_time, DS_TYPE_COUNTER);
1180 /* XPath: server/zonestats, server/zonestat,
1181 * server/counters[@type='zonestat']
1182 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1183 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1184 * XfrSuccess, XfrFail
1187 * <NotifyOutv4>0</NotifyOutv4>
1188 * <NotifyOutv6>0</NotifyOutv6>
1193 * <name>NotifyOutv4</name>
1194 * <counter>0</counter>
1197 * <name>NotifyOutv6</name>
1198 * <counter>0</counter>
1202 if (global_zone_maint_stats) {
1203 translation_table_ptr_t table_ptr = {
1204 zonestats_translation_table, zonestats_translation_table_length,
1205 /* plugin_instance = */ "global-zone_maint_stats"};
1208 bind_parse_generic_value_list("server/zonestats",
1209 /* callback = */ bind_xml_table_callback,
1210 /* user_data = */ &table_ptr, doc, xpathCtx,
1211 current_time, DS_TYPE_COUNTER);
1213 bind_parse_generic_name_value("server/zonestat",
1214 /* callback = */ bind_xml_table_callback,
1215 /* user_data = */ &table_ptr, doc, xpathCtx,
1216 current_time, DS_TYPE_COUNTER);
1220 /* XPath: server/resstats, server/counters[@type='resstat']
1221 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1222 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1223 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1224 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1227 * <Queryv4>0</Queryv4>
1228 * <Queryv6>0</Queryv6>
1233 * <name>Queryv4</name>
1234 * <counter>0</counter>
1237 * <name>Queryv6</name>
1238 * <counter>0</counter>
1242 if (global_resolver_stats != 0) {
1243 translation_table_ptr_t table_ptr = {
1244 resstats_translation_table, resstats_translation_table_length,
1245 /* plugin_instance = */ "global-resolver_stats"};
1248 bind_parse_generic_value_list("server/resstats",
1249 /* callback = */ bind_xml_table_callback,
1250 /* user_data = */ &table_ptr, doc, xpathCtx,
1251 current_time, DS_TYPE_COUNTER);
1253 bind_parse_generic_name_value("server/resstat",
1254 /* callback = */ bind_xml_table_callback,
1255 /* user_data = */ &table_ptr, doc, xpathCtx,
1256 current_time, DS_TYPE_COUNTER);
1259 } /* }}} bind_xml_stats_v1_v2 */
1261 static int bind_xml_stats(int version, xmlDoc *doc, /* {{{ */
1262 xmlXPathContext *xpathCtx, xmlNode *statsnode) {
1263 time_t current_time = 0;
1266 xpathCtx->node = statsnode;
1268 /* TODO: Check `server/boot-time' to recognize server restarts. */
1270 status = bind_xml_read_timestamp("server/current-time", doc, xpathCtx,
1273 ERROR("bind plugin: Reading `server/current-time' failed.");
1276 DEBUG("bind plugin: Current server time is %i.", (int)current_time);
1279 bind_xml_stats_v3(doc, xpathCtx, statsnode, current_time);
1281 bind_xml_stats_v1_v2(version, doc, xpathCtx, statsnode, current_time);
1284 /* XPath: memory/summary
1285 * Variables: TotalUse, InUse, BlockSize, ContextSize, Lost
1286 * Layout: v2 and v3:
1288 * <TotalUse>6587096</TotalUse>
1289 * <InUse>1345424</InUse>
1290 * <BlockSize>5505024</BlockSize>
1291 * <ContextSize>3732456</ContextSize>
1295 if (global_memory_stats != 0) {
1296 translation_table_ptr_t table_ptr = {
1297 memsummary_translation_table, memsummary_translation_table_length,
1298 /* plugin_instance = */ "global-memory_stats"};
1300 bind_parse_generic_value_list("memory/summary",
1301 /* callback = */ bind_xml_table_callback,
1302 /* user_data = */ &table_ptr, doc, xpathCtx,
1303 current_time, DS_TYPE_GAUGE);
1307 bind_xml_stats_search_views(version, doc, xpathCtx, statsnode,
1311 } /* }}} int bind_xml_stats */
1313 static int bind_xml(const char *data) /* {{{ */
1316 xmlXPathContext *xpathCtx = NULL;
1317 xmlXPathObject *xpathObj = NULL;
1320 doc = xmlParseMemory(data, strlen(data));
1322 ERROR("bind plugin: xmlParseMemory failed.");
1326 xpathCtx = xmlXPathNewContext(doc);
1327 if (xpathCtx == NULL) {
1328 ERROR("bind plugin: xmlXPathNewContext failed.");
1334 // version 3.* of statistics XML (since BIND9.9)
1337 xpathObj = xmlXPathEvalExpression(BAD_CAST "/statistics", xpathCtx);
1338 if (xpathObj == NULL || xpathObj->nodesetval == NULL ||
1339 xpathObj->nodesetval->nodeNr == 0) {
1340 DEBUG("bind plugin: Statistics appears not to be v3");
1341 // we will fallback to v1 or v2 detection
1342 if (xpathObj != NULL) {
1343 xmlXPathFreeObject(xpathObj);
1346 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
1350 node = xpathObj->nodesetval->nodeTab[i];
1351 assert(node != NULL);
1353 attr_version = (char *)xmlGetProp(node, BAD_CAST "version");
1354 if (attr_version == NULL) {
1355 NOTICE("bind plugin: Found <statistics> tag doesn't have a "
1356 "`version' attribute.");
1359 DEBUG("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1361 if (strncmp("3.", attr_version, strlen("3.")) != 0) {
1362 /* TODO: Use the complaint mechanism here. */
1363 NOTICE("bind plugin: Found <statistics> tag with version `%s'. "
1364 "Unfortunately I have no clue how to parse that. "
1365 "Please open a bug report for this.",
1367 xmlFree(attr_version);
1370 ret = bind_xml_stats(3, doc, xpathCtx, node);
1372 xmlFree(attr_version);
1373 /* One <statistics> node ought to be enough. */
1377 // we are finished, early-return
1378 xmlXPathFreeObject(xpathObj);
1379 xmlXPathFreeContext(xpathCtx);
1386 // versions 1.* or 2.* of statistics XML
1389 xpathObj = xmlXPathEvalExpression(BAD_CAST "/isc/bind/statistics", xpathCtx);
1390 if (xpathObj == NULL) {
1391 ERROR("bind plugin: Cannot find the <statistics> tag.");
1392 xmlXPathFreeContext(xpathCtx);
1395 } else if (xpathObj->nodesetval == NULL) {
1396 ERROR("bind plugin: xmlXPathEvalExpression failed.");
1397 xmlXPathFreeObject(xpathObj);
1398 xmlXPathFreeContext(xpathCtx);
1403 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
1406 int parsed_version = 0;
1408 node = xpathObj->nodesetval->nodeTab[i];
1409 assert(node != NULL);
1411 attr_version = (char *)xmlGetProp(node, BAD_CAST "version");
1412 if (attr_version == NULL) {
1413 NOTICE("bind plugin: Found <statistics> tag doesn't have a "
1414 "`version' attribute.");
1417 DEBUG("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1419 /* At the time this plugin was written, version "1.0" was used by
1420 * BIND 9.5.0, version "2.0" was used by BIND 9.5.1 and 9.6.0. We assume
1421 * that "1.*" and "2.*" don't introduce structural changes, so we just
1422 * check for the first two characters here. */
1423 if (strncmp("1.", attr_version, strlen("1.")) == 0)
1425 else if (strncmp("2.", attr_version, strlen("2.")) == 0)
1428 /* TODO: Use the complaint mechanism here. */
1429 NOTICE("bind plugin: Found <statistics> tag with version `%s'. "
1430 "Unfortunately I have no clue how to parse that. "
1431 "Please open a bug report for this.",
1433 xmlFree(attr_version);
1437 ret = bind_xml_stats(parsed_version, doc, xpathCtx, node);
1439 xmlFree(attr_version);
1440 /* One <statistics> node ought to be enough. */
1444 xmlXPathFreeObject(xpathObj);
1445 xmlXPathFreeContext(xpathCtx);
1449 } /* }}} int bind_xml */
1451 static int bind_config_set_bool(const char *name, int *var, /* {{{ */
1452 oconfig_item_t *ci) {
1453 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
1454 WARNING("bind plugin: The `%s' option needs "
1455 "exactly one boolean argument.",
1460 if (ci->values[0].value.boolean)
1465 } /* }}} int bind_config_set_bool */
1467 static int bind_config_add_view_zone(cb_view_t *view, /* {{{ */
1468 oconfig_item_t *ci) {
1471 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1472 WARNING("bind plugin: The `Zone' option needs "
1473 "exactly one string argument.");
1477 tmp = realloc(view->zones, sizeof(char *) * (view->zones_num + 1));
1479 ERROR("bind plugin: realloc failed.");
1484 view->zones[view->zones_num] = strdup(ci->values[0].value.string);
1485 if (view->zones[view->zones_num] == NULL) {
1486 ERROR("bind plugin: strdup failed.");
1492 } /* }}} int bind_config_add_view_zone */
1494 static int bind_config_add_view(oconfig_item_t *ci) /* {{{ */
1498 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1499 WARNING("bind plugin: `View' blocks need exactly one string argument.");
1503 tmp = realloc(views, sizeof(*views) * (views_num + 1));
1505 ERROR("bind plugin: realloc failed.");
1509 tmp = views + views_num;
1511 memset(tmp, 0, sizeof(*tmp));
1513 tmp->resolver_stats = 1;
1514 tmp->cacherrsets = 1;
1518 tmp->name = strdup(ci->values[0].value.string);
1519 if (tmp->name == NULL) {
1520 ERROR("bind plugin: strdup failed.");
1525 for (int i = 0; i < ci->children_num; i++) {
1526 oconfig_item_t *child = ci->children + i;
1528 if (strcasecmp("QTypes", child->key) == 0)
1529 bind_config_set_bool("QTypes", &tmp->qtypes, child);
1530 else if (strcasecmp("ResolverStats", child->key) == 0)
1531 bind_config_set_bool("ResolverStats", &tmp->resolver_stats, child);
1532 else if (strcasecmp("CacheRRSets", child->key) == 0)
1533 bind_config_set_bool("CacheRRSets", &tmp->cacherrsets, child);
1534 else if (strcasecmp("Zone", child->key) == 0)
1535 bind_config_add_view_zone(tmp, child);
1537 WARNING("bind plugin: Unknown configuration option "
1538 "`%s' in view `%s' will be ignored.",
1539 child->key, tmp->name);
1541 } /* for (i = 0; i < ci->children_num; i++) */
1545 } /* }}} int bind_config_add_view */
1547 static int bind_config(oconfig_item_t *ci) /* {{{ */
1549 for (int i = 0; i < ci->children_num; i++) {
1550 oconfig_item_t *child = ci->children + i;
1552 if (strcasecmp("Url", child->key) == 0) {
1553 if ((child->values_num != 1) ||
1554 (child->values[0].type != OCONFIG_TYPE_STRING)) {
1555 WARNING("bind plugin: The `Url' option needs "
1556 "exactly one string argument.");
1561 url = strdup(child->values[0].value.string);
1562 } else if (strcasecmp("OpCodes", child->key) == 0)
1563 bind_config_set_bool("OpCodes", &global_opcodes, child);
1564 else if (strcasecmp("QTypes", child->key) == 0)
1565 bind_config_set_bool("QTypes", &global_qtypes, child);
1566 else if (strcasecmp("ServerStats", child->key) == 0)
1567 bind_config_set_bool("ServerStats", &global_server_stats, child);
1568 else if (strcasecmp("ZoneMaintStats", child->key) == 0)
1569 bind_config_set_bool("ZoneMaintStats", &global_zone_maint_stats, child);
1570 else if (strcasecmp("ResolverStats", child->key) == 0)
1571 bind_config_set_bool("ResolverStats", &global_resolver_stats, child);
1572 else if (strcasecmp("MemoryStats", child->key) == 0)
1573 bind_config_set_bool("MemoryStats", &global_memory_stats, child);
1574 else if (strcasecmp("View", child->key) == 0)
1575 bind_config_add_view(child);
1576 else if (strcasecmp("ParseTime", child->key) == 0)
1577 cf_util_get_boolean(child, &config_parse_time);
1578 else if (strcasecmp("Timeout", child->key) == 0)
1579 cf_util_get_int(child, &timeout);
1581 WARNING("bind plugin: Unknown configuration option "
1582 "`%s' will be ignored.",
1588 } /* }}} int bind_config */
1590 static int bind_init(void) /* {{{ */
1595 curl = curl_easy_init();
1597 ERROR("bind plugin: bind_init: curl_easy_init failed.");
1601 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
1602 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
1603 curl_easy_setopt(curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
1604 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, bind_curl_error);
1605 curl_easy_setopt(curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
1606 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
1607 curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
1608 #ifdef HAVE_CURLOPT_TIMEOUT_MS
1609 curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS,
1610 (timeout >= 0) ? (long)timeout : (long)CDTIME_T_TO_MS(
1611 plugin_get_interval()));
1615 } /* }}} int bind_init */
1617 static int bind_read(void) /* {{{ */
1622 ERROR("bind plugin: I don't have a CURL object.");
1626 bind_buffer_fill = 0;
1627 if (curl_easy_perform(curl) != CURLE_OK) {
1628 ERROR("bind plugin: curl_easy_perform failed: %s", bind_curl_error);
1632 status = bind_xml(bind_buffer);
1637 } /* }}} int bind_read */
1639 static int bind_shutdown(void) /* {{{ */
1642 curl_easy_cleanup(curl);
1647 } /* }}} int bind_shutdown */
1649 void module_register(void) {
1650 plugin_register_complex_config("bind", bind_config);
1651 plugin_register_init("bind", bind_init);
1652 plugin_register_read("bind", bind_read);
1653 plugin_register_shutdown("bind", bind_shutdown);
1654 } /* void module_register */
1656 /* vim: set sw=2 sts=2 ts=8 et fdm=marker : */