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);
432 *ret_value = mktime(&tm);
434 xmlXPathFreeObject(xpathObj);
436 } /* }}} int bind_xml_read_timestamp */
439 * bind_parse_generic_name_value
441 * Reads statistics in the form:
444 * <counter>123</counter>
447 static int bind_parse_generic_name_value(const char *xpath_expression, /* {{{ */
448 list_callback_t list_callback,
449 void *user_data, xmlDoc *doc,
450 xmlXPathContext *xpathCtx,
451 time_t current_time, int ds_type) {
452 xmlXPathObject *xpathObj = NULL;
455 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
456 if (xpathObj == NULL) {
457 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
463 /* Iterate over all matching nodes. */
464 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
466 xmlNode *name_node = NULL;
467 xmlNode *counter = NULL;
470 parent = xpathObj->nodesetval->nodeTab[i];
471 DEBUG("bind plugin: bind_parse_generic_name_value: parent->name = %s;",
472 (char *)parent->name);
474 /* Iterate over all child nodes. */
475 for (xmlNode *child = parent->xmlChildrenNode; child != NULL;
476 child = child->next) {
477 if (child->type != XML_ELEMENT_NODE)
480 if (xmlStrcmp(BAD_CAST "name", child->name) == 0)
482 else if (xmlStrcmp(BAD_CAST "counter", child->name) == 0)
486 if ((name_node != NULL) && (counter != NULL)) {
488 (char *)xmlNodeListGetString(doc, name_node->xmlChildrenNode, 1);
492 if (ds_type == DS_TYPE_GAUGE)
493 status = bind_xml_read_gauge(doc, counter, &value.gauge);
495 status = bind_xml_read_derive(doc, counter, &value.derive);
499 status = (*list_callback)(name, value, current_time, user_data);
507 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
508 (num_entries == 1) ? "entry" : "entries", xpath_expression);
510 xmlXPathFreeObject(xpathObj);
513 } /* }}} int bind_parse_generic_name_value */
516 * bind_parse_generic_value_list
518 * Reads statistics in the form:
526 static int bind_parse_generic_value_list(const char *xpath_expression, /* {{{ */
527 list_callback_t list_callback,
528 void *user_data, xmlDoc *doc,
529 xmlXPathContext *xpathCtx,
530 time_t current_time, int ds_type) {
531 xmlXPathObject *xpathObj = NULL;
534 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
535 if (xpathObj == NULL) {
536 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
542 /* Iterate over all matching nodes. */
543 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
545 /* Iterate over all child nodes. */
546 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
547 child != NULL; child = child->next) {
552 if (child->type != XML_ELEMENT_NODE)
555 node_name = (char *)child->name;
557 if (ds_type == DS_TYPE_GAUGE)
558 status = bind_xml_read_gauge(doc, child, &value.gauge);
560 status = bind_xml_read_derive(doc, child, &value.derive);
564 status = (*list_callback)(node_name, value, current_time, user_data);
570 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
571 (num_entries == 1) ? "entry" : "entries", xpath_expression);
573 xmlXPathFreeObject(xpathObj);
576 } /* }}} int bind_parse_generic_value_list */
579 * bind_parse_generic_name_attr_value_list
581 * Reads statistics in the form:
583 * <counter name="name0">123</counter>
584 * <counter name="name1">234</counter>
585 * <counter name="name2">345</counter>
589 static int bind_parse_generic_name_attr_value_list(
590 const char *xpath_expression, /* {{{ */
591 list_callback_t list_callback, void *user_data, xmlDoc *doc,
592 xmlXPathContext *xpathCtx, time_t current_time, int ds_type) {
593 xmlXPathObject *xpathObj = NULL;
596 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
597 if (xpathObj == NULL) {
598 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
604 /* Iterate over all matching nodes. */
605 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
607 /* Iterate over all child nodes. */
608 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
609 child != NULL; child = child->next) {
610 if (child->type != XML_ELEMENT_NODE)
613 if (strncmp("counter", (char *)child->name, strlen("counter")) != 0)
620 attr_name = (char *)xmlGetProp(child, BAD_CAST "name");
621 if (attr_name == NULL) {
622 DEBUG("bind plugin: found <counter> without name.");
625 if (ds_type == DS_TYPE_GAUGE)
626 status = bind_xml_read_gauge(doc, child, &value.gauge);
628 status = bind_xml_read_derive(doc, child, &value.derive);
632 status = (*list_callback)(attr_name, value, current_time, user_data);
638 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
639 (num_entries == 1) ? "entry" : "entries", xpath_expression);
641 xmlXPathFreeObject(xpathObj);
644 } /* }}} int bind_parse_generic_name_attr_value_list */
646 static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */
647 xmlXPathContext *path_ctx, xmlNode *node,
648 cb_view_t *view, time_t current_time) {
649 xmlXPathObject *path_obj;
650 char *zone_name = NULL;
654 char *n = (char *)xmlGetProp(node, BAD_CAST "name");
655 char *c = (char *)xmlGetProp(node, BAD_CAST "rdataclass");
657 zone_name = (char *)xmlMalloc(strlen(n) + strlen(c) + 2);
658 snprintf(zone_name, strlen(n) + strlen(c) + 2, "%s/%s", n, c);
663 path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
664 if (path_obj == NULL) {
665 ERROR("bind plugin: xmlXPathEvalExpression failed.");
669 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
671 zone_name = (char *)xmlNodeListGetString(
672 doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
673 if (zone_name != NULL)
676 xmlXPathFreeObject(path_obj);
679 if (zone_name == NULL) {
680 ERROR("bind plugin: Could not determine zone name.");
684 for (j = 0; j < view->zones_num; j++) {
685 if (strcasecmp(zone_name, view->zones[j]) == 0)
692 if (j >= view->zones_num)
695 zone_name = view->zones[j];
697 DEBUG("bind plugin: bind_xml_stats_handle_zone: Found zone `%s'.", zone_name);
699 { /* Parse the <counters> tag {{{ */
700 char plugin_instance[DATA_MAX_NAME_LEN];
701 translation_table_ptr_t table_ptr = {nsstats_translation_table,
702 nsstats_translation_table_length,
705 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-zone-%s",
706 view->name, zone_name);
709 list_info_ptr_t list_info = {plugin_instance,
710 /* type = */ "dns_qtype"};
711 bind_parse_generic_name_attr_value_list(
712 /* xpath = */ "counters[@type='rcode']",
713 /* callback = */ bind_xml_table_callback,
714 /* user_data = */ &table_ptr, doc, path_ctx, current_time,
716 bind_parse_generic_name_attr_value_list(
717 /* xpath = */ "counters[@type='qtype']",
718 /* callback = */ bind_xml_list_callback,
719 /* user_data = */ &list_info, doc, path_ctx, current_time,
722 bind_parse_generic_value_list(/* xpath = */ "counters",
723 /* callback = */ bind_xml_table_callback,
724 /* user_data = */ &table_ptr, doc, path_ctx,
725 current_time, DS_TYPE_COUNTER);
730 } /* }}} int bind_xml_stats_handle_zone */
732 static int bind_xml_stats_search_zones(int version, xmlDoc *doc, /* {{{ */
733 xmlXPathContext *path_ctx, xmlNode *node,
734 cb_view_t *view, time_t current_time) {
735 xmlXPathObject *zone_nodes = NULL;
736 xmlXPathContext *zone_path_context;
738 zone_path_context = xmlXPathNewContext(doc);
739 if (zone_path_context == NULL) {
740 ERROR("bind plugin: xmlXPathNewContext failed.");
744 zone_nodes = xmlXPathEvalExpression(BAD_CAST "zones/zone", path_ctx);
745 if (zone_nodes == NULL) {
746 ERROR("bind plugin: Cannot find any <view> tags.");
747 xmlXPathFreeContext(zone_path_context);
751 for (int i = 0; i < zone_nodes->nodesetval->nodeNr; i++) {
752 node = zone_nodes->nodesetval->nodeTab[i];
753 assert(node != NULL);
755 zone_path_context->node = node;
757 bind_xml_stats_handle_zone(version, doc, zone_path_context, node, view,
761 xmlXPathFreeObject(zone_nodes);
762 xmlXPathFreeContext(zone_path_context);
764 } /* }}} int bind_xml_stats_search_zones */
766 static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */
767 xmlXPathContext *path_ctx, xmlNode *node,
768 time_t current_time) {
769 char *view_name = NULL;
774 view_name = (char *)xmlGetProp(node, BAD_CAST "name");
776 if (view_name == NULL) {
777 ERROR("bind plugin: Could not determine view name.");
781 for (j = 0; j < views_num; j++) {
782 if (strcasecmp(view_name, views[j].name) == 0)
789 xmlXPathObject *path_obj;
790 path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
791 if (path_obj == NULL) {
792 ERROR("bind plugin: xmlXPathEvalExpression failed.");
796 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
798 view_name = (char *)xmlNodeListGetString(
799 doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
800 if (view_name != NULL)
804 if (view_name == NULL) {
805 ERROR("bind plugin: Could not determine view name.");
806 xmlXPathFreeObject(path_obj);
810 for (j = 0; j < views_num; j++) {
811 if (strcasecmp(view_name, views[j].name) == 0)
816 xmlXPathFreeObject(path_obj);
827 DEBUG("bind plugin: bind_xml_stats_handle_view: Found view `%s'.",
830 if (view->qtypes != 0) /* {{{ */
832 char plugin_instance[DATA_MAX_NAME_LEN];
833 list_info_ptr_t list_info = {plugin_instance,
834 /* type = */ "dns_qtype"};
836 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-qtypes",
839 bind_parse_generic_name_attr_value_list(
840 /* xpath = */ "counters[@type='resqtype']",
841 /* callback = */ bind_xml_list_callback,
842 /* user_data = */ &list_info, doc, path_ctx, current_time,
845 bind_parse_generic_name_value(/* xpath = */ "rdtype",
846 /* callback = */ bind_xml_list_callback,
847 /* user_data = */ &list_info, doc, path_ctx,
848 current_time, DS_TYPE_COUNTER);
852 if (view->resolver_stats != 0) /* {{{ */
854 char plugin_instance[DATA_MAX_NAME_LEN];
855 translation_table_ptr_t table_ptr = {resstats_translation_table,
856 resstats_translation_table_length,
859 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-resolver_stats",
862 bind_parse_generic_name_attr_value_list(
863 "counters[@type='resstats']",
864 /* callback = */ bind_xml_table_callback,
865 /* user_data = */ &table_ptr, doc, path_ctx, current_time,
868 bind_parse_generic_name_value("resstat",
869 /* callback = */ bind_xml_table_callback,
870 /* user_data = */ &table_ptr, doc, path_ctx,
871 current_time, DS_TYPE_COUNTER);
875 /* Record types in the cache */
876 if (view->cacherrsets != 0) /* {{{ */
878 char plugin_instance[DATA_MAX_NAME_LEN];
879 list_info_ptr_t list_info = {plugin_instance,
880 /* type = */ "dns_qtype_cached"};
882 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-cache_rr_sets",
885 bind_parse_generic_name_value(/* xpath = */ "cache/rrset",
886 /* callback = */ bind_xml_list_callback,
887 /* user_data = */ &list_info, doc, path_ctx,
888 current_time, DS_TYPE_GAUGE);
891 if (view->zones_num > 0)
892 bind_xml_stats_search_zones(version, doc, path_ctx, node, view,
896 } /* }}} int bind_xml_stats_handle_view */
898 static int bind_xml_stats_search_views(int version, xmlDoc *doc, /* {{{ */
899 xmlXPathContext *xpathCtx,
901 time_t current_time) {
902 xmlXPathObject *view_nodes = NULL;
903 xmlXPathContext *view_path_context;
905 view_path_context = xmlXPathNewContext(doc);
906 if (view_path_context == NULL) {
907 ERROR("bind plugin: xmlXPathNewContext failed.");
911 view_nodes = xmlXPathEvalExpression(BAD_CAST "views/view", xpathCtx);
912 if (view_nodes == NULL) {
913 ERROR("bind plugin: Cannot find any <view> tags.");
914 xmlXPathFreeContext(view_path_context);
918 for (int i = 0; i < view_nodes->nodesetval->nodeNr; i++) {
921 node = view_nodes->nodesetval->nodeTab[i];
922 assert(node != NULL);
924 view_path_context->node = node;
926 bind_xml_stats_handle_view(version, doc, view_path_context, node,
930 xmlXPathFreeObject(view_nodes);
931 xmlXPathFreeContext(view_path_context);
933 } /* }}} int bind_xml_stats_search_views */
935 static void bind_xml_stats_v3(xmlDoc *doc, /* {{{ */
936 xmlXPathContext *xpathCtx, xmlNode *statsnode,
937 time_t current_time) {
938 /* XPath: server/counters[@type='opcode']
939 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
941 * <counters type="opcode">
942 * <counter name="A">1</counter>
946 if (global_opcodes != 0) {
947 list_info_ptr_t list_info = {/* plugin instance = */ "global-opcodes",
948 /* type = */ "dns_opcode"};
949 bind_parse_generic_name_attr_value_list(
950 /* xpath = */ "server/counters[@type='opcode']",
951 /* callback = */ bind_xml_list_callback,
952 /* user_data = */ &list_info, doc, xpathCtx, current_time,
956 /* XPath: server/counters[@type='qtype']
957 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
958 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
959 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
961 * <counters type="opcode">
962 * <counter name="A">1</counter>
966 if (global_qtypes != 0) {
967 list_info_ptr_t list_info = {/* plugin instance = */ "global-qtypes",
968 /* type = */ "dns_qtype"};
970 bind_parse_generic_name_attr_value_list(
971 /* xpath = */ "server/counters[@type='qtype']",
972 /* callback = */ bind_xml_list_callback,
973 /* user_data = */ &list_info, doc, xpathCtx, current_time,
977 /* XPath: server/counters[@type='nsstat']
978 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
979 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
980 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
981 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
982 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
983 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
984 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
987 * <counters type="nsstat"
988 * <counter name="Requestv4">1</counter>
989 * <counter name="Requestv6">0</counter>
993 if (global_server_stats) {
994 translation_table_ptr_t table_ptr = {
995 nsstats_translation_table, nsstats_translation_table_length,
996 /* plugin_instance = */ "global-server_stats"};
998 bind_parse_generic_name_attr_value_list(
999 "server/counters[@type='nsstat']",
1000 /* callback = */ bind_xml_table_callback,
1001 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1005 /* XPath: server/zonestats, server/zonestat,
1006 * server/counters[@type='zonestat']
1007 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1008 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1009 * XfrSuccess, XfrFail
1011 * <counters type="zonestat"
1012 * <counter name="NotifyOutv4">0</counter>
1013 * <counter name="NotifyOutv6">0</counter>
1017 if (global_zone_maint_stats) {
1018 translation_table_ptr_t table_ptr = {
1019 zonestats_translation_table, zonestats_translation_table_length,
1020 /* plugin_instance = */ "global-zone_maint_stats"};
1022 bind_parse_generic_name_attr_value_list(
1023 "server/counters[@type='zonestat']",
1024 /* callback = */ bind_xml_table_callback,
1025 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1029 /* XPath: server/resstats, server/counters[@type='resstat']
1030 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1031 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1032 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1033 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1035 * <counters type="resstat"
1036 * <counter name="Queryv4">0</counter>
1037 * <counter name="Queryv6">0</counter>
1041 if (global_resolver_stats != 0) {
1042 translation_table_ptr_t table_ptr = {
1043 resstats_translation_table, resstats_translation_table_length,
1044 /* plugin_instance = */ "global-resolver_stats"};
1046 bind_parse_generic_name_attr_value_list(
1047 "server/counters[@type='resstat']",
1048 /* callback = */ bind_xml_table_callback,
1049 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1052 } /* }}} bind_xml_stats_v3 */
1054 static void bind_xml_stats_v1_v2(int version, xmlDoc *doc, /* {{{ */
1055 xmlXPathContext *xpathCtx, xmlNode *statsnode,
1056 time_t current_time) {
1057 /* XPath: server/requests/opcode, server/counters[@type='opcode']
1058 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1062 * <counter>1</counter>
1066 if (global_opcodes != 0) {
1067 list_info_ptr_t list_info = {/* plugin instance = */ "global-opcodes",
1068 /* type = */ "dns_opcode"};
1070 bind_parse_generic_name_value(/* xpath = */ "server/requests/opcode",
1071 /* callback = */ bind_xml_list_callback,
1072 /* user_data = */ &list_info, doc, xpathCtx,
1073 current_time, DS_TYPE_COUNTER);
1076 /* XPath: server/queries-in/rdtype, server/counters[@type='qtype']
1077 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1078 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1079 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1083 * <counter>1</counter>
1087 if (global_qtypes != 0) {
1088 list_info_ptr_t list_info = {/* plugin instance = */ "global-qtypes",
1089 /* type = */ "dns_qtype"};
1091 bind_parse_generic_name_value(/* xpath = */ "server/queries-in/rdtype",
1092 /* callback = */ bind_xml_list_callback,
1093 /* user_data = */ &list_info, doc, xpathCtx,
1094 current_time, DS_TYPE_COUNTER);
1097 /* XPath: server/nsstats, server/nsstat, server/counters[@type='nsstat']
1098 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1099 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1100 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1101 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1102 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1103 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1104 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1108 * <Requestv4>1</Requestv4>
1109 * <Requestv6>0</Requestv6>
1114 * <name>Requestv4</name>
1115 * <counter>1</counter>
1118 * <name>Requestv6</name>
1119 * <counter>0</counter>
1123 if (global_server_stats) {
1124 translation_table_ptr_t table_ptr = {
1125 nsstats_translation_table, nsstats_translation_table_length,
1126 /* plugin_instance = */ "global-server_stats"};
1129 bind_parse_generic_value_list("server/nsstats",
1130 /* callback = */ bind_xml_table_callback,
1131 /* user_data = */ &table_ptr, doc, xpathCtx,
1132 current_time, DS_TYPE_COUNTER);
1134 bind_parse_generic_name_value("server/nsstat",
1135 /* callback = */ bind_xml_table_callback,
1136 /* user_data = */ &table_ptr, doc, xpathCtx,
1137 current_time, DS_TYPE_COUNTER);
1141 /* XPath: server/zonestats, server/zonestat,
1142 * server/counters[@type='zonestat']
1143 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1144 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1145 * XfrSuccess, XfrFail
1148 * <NotifyOutv4>0</NotifyOutv4>
1149 * <NotifyOutv6>0</NotifyOutv6>
1154 * <name>NotifyOutv4</name>
1155 * <counter>0</counter>
1158 * <name>NotifyOutv6</name>
1159 * <counter>0</counter>
1163 if (global_zone_maint_stats) {
1164 translation_table_ptr_t table_ptr = {
1165 zonestats_translation_table, zonestats_translation_table_length,
1166 /* plugin_instance = */ "global-zone_maint_stats"};
1169 bind_parse_generic_value_list("server/zonestats",
1170 /* callback = */ bind_xml_table_callback,
1171 /* user_data = */ &table_ptr, doc, xpathCtx,
1172 current_time, DS_TYPE_COUNTER);
1174 bind_parse_generic_name_value("server/zonestat",
1175 /* callback = */ bind_xml_table_callback,
1176 /* user_data = */ &table_ptr, doc, xpathCtx,
1177 current_time, DS_TYPE_COUNTER);
1181 /* XPath: server/resstats, server/counters[@type='resstat']
1182 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1183 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1184 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1185 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1188 * <Queryv4>0</Queryv4>
1189 * <Queryv6>0</Queryv6>
1194 * <name>Queryv4</name>
1195 * <counter>0</counter>
1198 * <name>Queryv6</name>
1199 * <counter>0</counter>
1203 if (global_resolver_stats != 0) {
1204 translation_table_ptr_t table_ptr = {
1205 resstats_translation_table, resstats_translation_table_length,
1206 /* plugin_instance = */ "global-resolver_stats"};
1209 bind_parse_generic_value_list("server/resstats",
1210 /* callback = */ bind_xml_table_callback,
1211 /* user_data = */ &table_ptr, doc, xpathCtx,
1212 current_time, DS_TYPE_COUNTER);
1214 bind_parse_generic_name_value("server/resstat",
1215 /* callback = */ bind_xml_table_callback,
1216 /* user_data = */ &table_ptr, doc, xpathCtx,
1217 current_time, DS_TYPE_COUNTER);
1220 } /* }}} bind_xml_stats_v1_v2 */
1222 static int bind_xml_stats(int version, xmlDoc *doc, /* {{{ */
1223 xmlXPathContext *xpathCtx, xmlNode *statsnode) {
1224 time_t current_time = 0;
1227 xpathCtx->node = statsnode;
1229 /* TODO: Check `server/boot-time' to recognize server restarts. */
1231 status = bind_xml_read_timestamp("server/current-time", doc, xpathCtx,
1234 ERROR("bind plugin: Reading `server/current-time' failed.");
1237 DEBUG("bind plugin: Current server time is %i.", (int)current_time);
1240 bind_xml_stats_v3(doc, xpathCtx, statsnode, current_time);
1242 bind_xml_stats_v1_v2(version, doc, xpathCtx, statsnode, current_time);
1245 /* XPath: memory/summary
1246 * Variables: TotalUse, InUse, BlockSize, ContextSize, Lost
1247 * Layout: v2 and v3:
1249 * <TotalUse>6587096</TotalUse>
1250 * <InUse>1345424</InUse>
1251 * <BlockSize>5505024</BlockSize>
1252 * <ContextSize>3732456</ContextSize>
1256 if (global_memory_stats != 0) {
1257 translation_table_ptr_t table_ptr = {
1258 memsummary_translation_table, memsummary_translation_table_length,
1259 /* plugin_instance = */ "global-memory_stats"};
1261 bind_parse_generic_value_list("memory/summary",
1262 /* callback = */ bind_xml_table_callback,
1263 /* user_data = */ &table_ptr, doc, xpathCtx,
1264 current_time, DS_TYPE_GAUGE);
1268 bind_xml_stats_search_views(version, doc, xpathCtx, statsnode,
1272 } /* }}} int bind_xml_stats */
1274 static int bind_xml(const char *data) /* {{{ */
1277 xmlXPathContext *xpathCtx = NULL;
1278 xmlXPathObject *xpathObj = NULL;
1281 doc = xmlParseMemory(data, strlen(data));
1283 ERROR("bind plugin: xmlParseMemory failed.");
1287 xpathCtx = xmlXPathNewContext(doc);
1288 if (xpathCtx == NULL) {
1289 ERROR("bind plugin: xmlXPathNewContext failed.");
1295 // version 3.* of statistics XML (since BIND9.9)
1298 xpathObj = xmlXPathEvalExpression(BAD_CAST "/statistics", xpathCtx);
1299 if (xpathObj == NULL || xpathObj->nodesetval == NULL ||
1300 xpathObj->nodesetval->nodeNr == 0) {
1301 DEBUG("bind plugin: Statistics appears not to be v3");
1302 // we will fallback to v1 or v2 detection
1303 if (xpathObj != NULL) {
1304 xmlXPathFreeObject(xpathObj);
1307 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
1311 node = xpathObj->nodesetval->nodeTab[i];
1312 assert(node != NULL);
1314 attr_version = (char *)xmlGetProp(node, BAD_CAST "version");
1315 if (attr_version == NULL) {
1316 NOTICE("bind plugin: Found <statistics> tag doesn't have a "
1317 "`version' attribute.");
1320 DEBUG("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1322 if (strncmp("3.", attr_version, strlen("3.")) != 0) {
1323 /* TODO: Use the complaint mechanism here. */
1324 NOTICE("bind plugin: Found <statistics> tag with version `%s'. "
1325 "Unfortunately I have no clue how to parse that. "
1326 "Please open a bug report for this.",
1328 xmlFree(attr_version);
1331 ret = bind_xml_stats(3, doc, xpathCtx, node);
1333 xmlFree(attr_version);
1334 /* One <statistics> node ought to be enough. */
1338 // we are finished, early-return
1339 xmlXPathFreeObject(xpathObj);
1340 xmlXPathFreeContext(xpathCtx);
1347 // versions 1.* or 2.* of statistics XML
1350 xpathObj = xmlXPathEvalExpression(BAD_CAST "/isc/bind/statistics", xpathCtx);
1351 if (xpathObj == NULL) {
1352 ERROR("bind plugin: Cannot find the <statistics> tag.");
1353 xmlXPathFreeContext(xpathCtx);
1356 } else if (xpathObj->nodesetval == NULL) {
1357 ERROR("bind plugin: xmlXPathEvalExpression failed.");
1358 xmlXPathFreeObject(xpathObj);
1359 xmlXPathFreeContext(xpathCtx);
1364 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
1367 int parsed_version = 0;
1369 node = xpathObj->nodesetval->nodeTab[i];
1370 assert(node != NULL);
1372 attr_version = (char *)xmlGetProp(node, BAD_CAST "version");
1373 if (attr_version == NULL) {
1374 NOTICE("bind plugin: Found <statistics> tag doesn't have a "
1375 "`version' attribute.");
1378 DEBUG("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1380 /* At the time this plugin was written, version "1.0" was used by
1381 * BIND 9.5.0, version "2.0" was used by BIND 9.5.1 and 9.6.0. We assume
1382 * that "1.*" and "2.*" don't introduce structural changes, so we just
1383 * check for the first two characters here. */
1384 if (strncmp("1.", attr_version, strlen("1.")) == 0)
1386 else if (strncmp("2.", attr_version, strlen("2.")) == 0)
1389 /* TODO: Use the complaint mechanism here. */
1390 NOTICE("bind plugin: Found <statistics> tag with version `%s'. "
1391 "Unfortunately I have no clue how to parse that. "
1392 "Please open a bug report for this.",
1394 xmlFree(attr_version);
1398 ret = bind_xml_stats(parsed_version, doc, xpathCtx, node);
1400 xmlFree(attr_version);
1401 /* One <statistics> node ought to be enough. */
1405 xmlXPathFreeObject(xpathObj);
1406 xmlXPathFreeContext(xpathCtx);
1410 } /* }}} int bind_xml */
1412 static int bind_config_set_bool(const char *name, int *var, /* {{{ */
1413 oconfig_item_t *ci) {
1414 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
1415 WARNING("bind plugin: The `%s' option needs "
1416 "exactly one boolean argument.",
1421 if (ci->values[0].value.boolean)
1426 } /* }}} int bind_config_set_bool */
1428 static int bind_config_add_view_zone(cb_view_t *view, /* {{{ */
1429 oconfig_item_t *ci) {
1432 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1433 WARNING("bind plugin: The `Zone' option needs "
1434 "exactly one string argument.");
1438 tmp = realloc(view->zones, sizeof(char *) * (view->zones_num + 1));
1440 ERROR("bind plugin: realloc failed.");
1445 view->zones[view->zones_num] = strdup(ci->values[0].value.string);
1446 if (view->zones[view->zones_num] == NULL) {
1447 ERROR("bind plugin: strdup failed.");
1453 } /* }}} int bind_config_add_view_zone */
1455 static int bind_config_add_view(oconfig_item_t *ci) /* {{{ */
1459 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1460 WARNING("bind plugin: `View' blocks need exactly one string argument.");
1464 tmp = realloc(views, sizeof(*views) * (views_num + 1));
1466 ERROR("bind plugin: realloc failed.");
1470 tmp = views + views_num;
1472 memset(tmp, 0, sizeof(*tmp));
1474 tmp->resolver_stats = 1;
1475 tmp->cacherrsets = 1;
1479 tmp->name = strdup(ci->values[0].value.string);
1480 if (tmp->name == NULL) {
1481 ERROR("bind plugin: strdup failed.");
1486 for (int i = 0; i < ci->children_num; i++) {
1487 oconfig_item_t *child = ci->children + i;
1489 if (strcasecmp("QTypes", child->key) == 0)
1490 bind_config_set_bool("QTypes", &tmp->qtypes, child);
1491 else if (strcasecmp("ResolverStats", child->key) == 0)
1492 bind_config_set_bool("ResolverStats", &tmp->resolver_stats, child);
1493 else if (strcasecmp("CacheRRSets", child->key) == 0)
1494 bind_config_set_bool("CacheRRSets", &tmp->cacherrsets, child);
1495 else if (strcasecmp("Zone", child->key) == 0)
1496 bind_config_add_view_zone(tmp, child);
1498 WARNING("bind plugin: Unknown configuration option "
1499 "`%s' in view `%s' will be ignored.",
1500 child->key, tmp->name);
1502 } /* for (i = 0; i < ci->children_num; i++) */
1506 } /* }}} int bind_config_add_view */
1508 static int bind_config(oconfig_item_t *ci) /* {{{ */
1510 for (int i = 0; i < ci->children_num; i++) {
1511 oconfig_item_t *child = ci->children + i;
1513 if (strcasecmp("Url", child->key) == 0) {
1514 if ((child->values_num != 1) ||
1515 (child->values[0].type != OCONFIG_TYPE_STRING)) {
1516 WARNING("bind plugin: The `Url' option needs "
1517 "exactly one string argument.");
1522 url = strdup(child->values[0].value.string);
1523 } else if (strcasecmp("OpCodes", child->key) == 0)
1524 bind_config_set_bool("OpCodes", &global_opcodes, child);
1525 else if (strcasecmp("QTypes", child->key) == 0)
1526 bind_config_set_bool("QTypes", &global_qtypes, child);
1527 else if (strcasecmp("ServerStats", child->key) == 0)
1528 bind_config_set_bool("ServerStats", &global_server_stats, child);
1529 else if (strcasecmp("ZoneMaintStats", child->key) == 0)
1530 bind_config_set_bool("ZoneMaintStats", &global_zone_maint_stats, child);
1531 else if (strcasecmp("ResolverStats", child->key) == 0)
1532 bind_config_set_bool("ResolverStats", &global_resolver_stats, child);
1533 else if (strcasecmp("MemoryStats", child->key) == 0)
1534 bind_config_set_bool("MemoryStats", &global_memory_stats, child);
1535 else if (strcasecmp("View", child->key) == 0)
1536 bind_config_add_view(child);
1537 else if (strcasecmp("ParseTime", child->key) == 0)
1538 cf_util_get_boolean(child, &config_parse_time);
1539 else if (strcasecmp("Timeout", child->key) == 0)
1540 cf_util_get_int(child, &timeout);
1542 WARNING("bind plugin: Unknown configuration option "
1543 "`%s' will be ignored.",
1549 } /* }}} int bind_config */
1551 static int bind_init(void) /* {{{ */
1556 curl = curl_easy_init();
1558 ERROR("bind plugin: bind_init: curl_easy_init failed.");
1562 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
1563 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
1564 curl_easy_setopt(curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
1565 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, bind_curl_error);
1566 curl_easy_setopt(curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
1567 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
1568 curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
1569 #ifdef HAVE_CURLOPT_TIMEOUT_MS
1570 curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS,
1571 (timeout >= 0) ? (long)timeout : (long)CDTIME_T_TO_MS(
1572 plugin_get_interval()));
1576 } /* }}} int bind_init */
1578 static int bind_read(void) /* {{{ */
1583 ERROR("bind plugin: I don't have a CURL object.");
1587 bind_buffer_fill = 0;
1588 if (curl_easy_perform(curl) != CURLE_OK) {
1589 ERROR("bind plugin: curl_easy_perform failed: %s", bind_curl_error);
1593 status = bind_xml(bind_buffer);
1598 } /* }}} int bind_read */
1600 static int bind_shutdown(void) /* {{{ */
1603 curl_easy_cleanup(curl);
1608 } /* }}} int bind_shutdown */
1610 void module_register(void) {
1611 plugin_register_complex_config("bind", bind_config);
1612 plugin_register_init("bind", bind_init);
1613 plugin_register_read("bind", bind_read);
1614 plugin_register_shutdown("bind", bind_shutdown);
1615 } /* void module_register */