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", "authorative"},
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", "authorative"},
145 {"QryNoauthAns", "dns_query", "nonauth"},
146 {"QryReferral", "dns_query", "referral"},
147 {"QryRecursion", "dns_query", "recursion"},
148 {"QryDuplicate", "dns_query", "dupliate"},
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) {
242 value_list_t vl = VALUE_LIST_INIT;
248 if (config_parse_time)
249 vl.time = TIME_T_TO_CDTIME_T(ts);
250 sstrncpy(vl.host, hostname_g, sizeof(vl.host));
251 sstrncpy(vl.plugin, "bind", sizeof(vl.plugin));
252 if (plugin_instance) {
253 sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance));
254 replace_special(vl.plugin_instance, sizeof(vl.plugin_instance));
256 sstrncpy(vl.type, type, sizeof(vl.type));
258 sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
259 replace_special(vl.type_instance, sizeof(vl.type_instance));
261 plugin_dispatch_values(&vl);
262 } /* }}} void submit */
264 static size_t bind_curl_callback(void *buf, size_t size, /* {{{ */
266 void __attribute__((unused)) * stream) {
267 size_t len = size * nmemb;
272 if ((bind_buffer_fill + len) >= bind_buffer_size) {
275 temp = realloc(bind_buffer, bind_buffer_fill + len + 1);
277 ERROR("bind plugin: realloc failed.");
281 bind_buffer_size = bind_buffer_fill + len + 1;
284 memcpy(bind_buffer + bind_buffer_fill, (char *)buf, len);
285 bind_buffer_fill += len;
286 bind_buffer[bind_buffer_fill] = 0;
289 } /* }}} size_t bind_curl_callback */
292 * Callback, that's called with a translation table.
293 * (Plugin instance is fixed, type and type instance come from lookup table.)
295 static int bind_xml_table_callback(const char *name, value_t value, /* {{{ */
296 time_t current_time, void *user_data) {
297 translation_table_ptr_t *table = (translation_table_ptr_t *)user_data;
302 for (size_t i = 0; i < table->table_length; i++) {
303 if (strcmp(table->table[i].xml_name, name) != 0)
306 submit(current_time, table->plugin_instance, table->table[i].type,
307 table->table[i].type_instance, value);
312 } /* }}} int bind_xml_table_callback */
315 * Callback, that's used for lists.
316 * (Plugin instance and type are fixed, xml name is used as type instance.)
318 static int bind_xml_list_callback(const char *name, /* {{{ */
319 value_t value, time_t current_time,
321 list_info_ptr_t *list_info = (list_info_ptr_t *)user_data;
323 if (list_info == NULL)
326 submit(current_time, list_info->plugin_instance, list_info->type,
327 /* type instance = */ name, value);
330 } /* }}} int bind_xml_list_callback */
332 static int bind_xml_read_derive(xmlDoc *doc, xmlNode *node, /* {{{ */
333 derive_t *ret_value) {
338 str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
339 if (str_ptr == NULL) {
340 ERROR("bind plugin: bind_xml_read_derive: xmlNodeListGetString failed.");
344 status = parse_value(str_ptr, &value, DS_TYPE_DERIVE);
346 ERROR("bind plugin: Parsing string \"%s\" to derive value failed.",
353 *ret_value = value.derive;
355 } /* }}} int bind_xml_read_derive */
357 static int bind_xml_read_gauge(xmlDoc *doc, xmlNode *node, /* {{{ */
358 gauge_t *ret_value) {
359 char *str_ptr, *end_ptr;
362 str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
363 if (str_ptr == NULL) {
364 ERROR("bind plugin: bind_xml_read_gauge: xmlNodeListGetString failed.");
369 value = strtod(str_ptr, &end_ptr);
371 if (str_ptr == end_ptr || errno) {
372 if (errno && (value < 0))
373 ERROR("bind plugin: bind_xml_read_gauge: strtod failed with underflow.");
374 else if (errno && (value > 0))
375 ERROR("bind plugin: bind_xml_read_gauge: strtod failed with overflow.");
377 ERROR("bind plugin: bind_xml_read_gauge: strtod failed.");
381 *ret_value = (gauge_t)value;
383 } /* }}} int bind_xml_read_gauge */
385 static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */
386 xmlDoc *doc, xmlXPathContext *xpathCtx,
388 xmlXPathObject *xpathObj = NULL;
394 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
395 if (xpathObj == NULL) {
396 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
401 if ((xpathObj->nodesetval == NULL) || (xpathObj->nodesetval->nodeNr < 1)) {
402 xmlXPathFreeObject(xpathObj);
406 if (xpathObj->nodesetval->nodeNr != 1) {
407 NOTICE("bind plugin: Evaluating the XPath expression `%s' returned "
408 "%i nodes. Only handling the first one.",
409 xpath_expression, xpathObj->nodesetval->nodeNr);
412 node = xpathObj->nodesetval->nodeTab[0];
414 if (node->xmlChildrenNode == NULL) {
415 ERROR("bind plugin: bind_xml_read_timestamp: "
416 "node->xmlChildrenNode == NULL");
417 xmlXPathFreeObject(xpathObj);
421 str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
422 if (str_ptr == NULL) {
423 ERROR("bind plugin: bind_xml_read_timestamp: xmlNodeListGetString failed.");
424 xmlXPathFreeObject(xpathObj);
428 tmp = strptime(str_ptr, "%Y-%m-%dT%T", &tm);
431 ERROR("bind plugin: bind_xml_read_timestamp: strptime failed.");
432 xmlXPathFreeObject(xpathObj);
437 *ret_value = mktime(&tm) - timezone; /* fix strptime() misinterpretation */
439 xmlXPathFreeObject(xpathObj);
441 } /* }}} int bind_xml_read_timestamp */
444 * bind_parse_generic_name_value
446 * Reads statistics in the form:
449 * <counter>123</counter>
452 static int bind_parse_generic_name_value(const char *xpath_expression, /* {{{ */
453 list_callback_t list_callback,
454 void *user_data, xmlDoc *doc,
455 xmlXPathContext *xpathCtx,
456 time_t current_time, int ds_type) {
457 xmlXPathObject *xpathObj = NULL;
460 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
461 if (xpathObj == NULL) {
462 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
468 /* Iterate over all matching nodes. */
469 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
471 xmlNode *name_node = NULL;
472 xmlNode *counter = NULL;
475 parent = xpathObj->nodesetval->nodeTab[i];
476 DEBUG("bind plugin: bind_parse_generic_name_value: parent->name = %s;",
477 (char *)parent->name);
479 /* Iterate over all child nodes. */
480 for (xmlNode *child = parent->xmlChildrenNode; child != NULL;
481 child = child->next) {
482 if (child->type != XML_ELEMENT_NODE)
485 if (xmlStrcmp(BAD_CAST "name", child->name) == 0)
487 else if (xmlStrcmp(BAD_CAST "counter", child->name) == 0)
491 if ((name_node != NULL) && (counter != NULL)) {
493 (char *)xmlNodeListGetString(doc, name_node->xmlChildrenNode, 1);
497 if (ds_type == DS_TYPE_GAUGE)
498 status = bind_xml_read_gauge(doc, counter, &value.gauge);
500 status = bind_xml_read_derive(doc, counter, &value.derive);
504 status = (*list_callback)(name, value, current_time, user_data);
512 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
513 (num_entries == 1) ? "entry" : "entries", xpath_expression);
515 xmlXPathFreeObject(xpathObj);
518 } /* }}} int bind_parse_generic_name_value */
521 * bind_parse_generic_value_list
523 * Reads statistics in the form:
531 static int bind_parse_generic_value_list(const char *xpath_expression, /* {{{ */
532 list_callback_t list_callback,
533 void *user_data, xmlDoc *doc,
534 xmlXPathContext *xpathCtx,
535 time_t current_time, int ds_type) {
536 xmlXPathObject *xpathObj = NULL;
539 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
540 if (xpathObj == NULL) {
541 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
547 /* Iterate over all matching nodes. */
548 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
550 /* Iterate over all child nodes. */
551 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
552 child != NULL; child = child->next) {
557 if (child->type != XML_ELEMENT_NODE)
560 node_name = (char *)child->name;
562 if (ds_type == DS_TYPE_GAUGE)
563 status = bind_xml_read_gauge(doc, child, &value.gauge);
565 status = bind_xml_read_derive(doc, child, &value.derive);
569 status = (*list_callback)(node_name, value, current_time, user_data);
575 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
576 (num_entries == 1) ? "entry" : "entries", xpath_expression);
578 xmlXPathFreeObject(xpathObj);
581 } /* }}} int bind_parse_generic_value_list */
584 * bind_parse_generic_name_attr_value_list
586 * Reads statistics in the form:
588 * <counter name="name0">123</counter>
589 * <counter name="name1">234</counter>
590 * <counter name="name2">345</counter>
594 static int bind_parse_generic_name_attr_value_list(
595 const char *xpath_expression, /* {{{ */
596 list_callback_t list_callback, void *user_data, xmlDoc *doc,
597 xmlXPathContext *xpathCtx, time_t current_time, int ds_type) {
598 xmlXPathObject *xpathObj = NULL;
601 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
602 if (xpathObj == NULL) {
603 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
609 /* Iterate over all matching nodes. */
610 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
612 /* Iterate over all child nodes. */
613 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
614 child != NULL; child = child->next) {
615 if (child->type != XML_ELEMENT_NODE)
618 if (strncmp("counter", (char *)child->name, strlen("counter")) != 0)
625 attr_name = (char *)xmlGetProp(child, BAD_CAST "name");
626 if (attr_name == NULL) {
627 DEBUG("bind plugin: found <counter> without name.");
630 if (ds_type == DS_TYPE_GAUGE)
631 status = bind_xml_read_gauge(doc, child, &value.gauge);
633 status = bind_xml_read_derive(doc, child, &value.derive);
637 status = (*list_callback)(attr_name, value, current_time, user_data);
643 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
644 (num_entries == 1) ? "entry" : "entries", xpath_expression);
646 xmlXPathFreeObject(xpathObj);
649 } /* }}} int bind_parse_generic_name_attr_value_list */
651 static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */
652 xmlXPathContext *path_ctx, xmlNode *node,
653 cb_view_t *view, time_t current_time) {
654 xmlXPathObject *path_obj;
655 char *zone_name = NULL;
659 char *n = (char *)xmlGetProp(node, BAD_CAST "name");
660 char *c = (char *)xmlGetProp(node, BAD_CAST "rdataclass");
662 zone_name = (char *)xmlMalloc(strlen(n) + strlen(c) + 2);
663 snprintf(zone_name, strlen(n) + strlen(c) + 2, "%s/%s", n, c);
668 path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
669 if (path_obj == NULL) {
670 ERROR("bind plugin: xmlXPathEvalExpression failed.");
674 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
676 zone_name = (char *)xmlNodeListGetString(
677 doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
678 if (zone_name != NULL)
681 xmlXPathFreeObject(path_obj);
684 if (zone_name == NULL) {
685 ERROR("bind plugin: Could not determine zone name.");
689 for (j = 0; j < view->zones_num; j++) {
690 if (strcasecmp(zone_name, view->zones[j]) == 0)
697 if (j >= view->zones_num)
700 zone_name = view->zones[j];
702 DEBUG("bind plugin: bind_xml_stats_handle_zone: Found zone `%s'.", zone_name);
704 { /* Parse the <counters> tag {{{ */
705 char plugin_instance[DATA_MAX_NAME_LEN];
706 translation_table_ptr_t table_ptr = {nsstats_translation_table,
707 nsstats_translation_table_length,
710 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-zone-%s",
711 view->name, zone_name);
714 list_info_ptr_t list_info = {plugin_instance,
715 /* type = */ "dns_qtype"};
716 bind_parse_generic_name_attr_value_list(
717 /* xpath = */ "counters[@type='rcode']",
718 /* callback = */ bind_xml_table_callback,
719 /* user_data = */ &table_ptr, doc, path_ctx, current_time,
721 bind_parse_generic_name_attr_value_list(
722 /* xpath = */ "counters[@type='qtype']",
723 /* callback = */ bind_xml_list_callback,
724 /* user_data = */ &list_info, doc, path_ctx, current_time,
727 bind_parse_generic_value_list(/* xpath = */ "counters",
728 /* callback = */ bind_xml_table_callback,
729 /* user_data = */ &table_ptr, doc, path_ctx,
730 current_time, DS_TYPE_COUNTER);
735 } /* }}} int bind_xml_stats_handle_zone */
737 static int bind_xml_stats_search_zones(int version, xmlDoc *doc, /* {{{ */
738 xmlXPathContext *path_ctx, xmlNode *node,
739 cb_view_t *view, time_t current_time) {
740 xmlXPathObject *zone_nodes = NULL;
741 xmlXPathContext *zone_path_context;
743 zone_path_context = xmlXPathNewContext(doc);
744 if (zone_path_context == NULL) {
745 ERROR("bind plugin: xmlXPathNewContext failed.");
749 zone_nodes = xmlXPathEvalExpression(BAD_CAST "zones/zone", path_ctx);
750 if (zone_nodes == NULL) {
751 ERROR("bind plugin: Cannot find any <view> tags.");
752 xmlXPathFreeContext(zone_path_context);
756 for (int i = 0; i < zone_nodes->nodesetval->nodeNr; i++) {
757 node = zone_nodes->nodesetval->nodeTab[i];
758 assert(node != NULL);
760 zone_path_context->node = node;
762 bind_xml_stats_handle_zone(version, doc, zone_path_context, node, view,
766 xmlXPathFreeObject(zone_nodes);
767 xmlXPathFreeContext(zone_path_context);
769 } /* }}} int bind_xml_stats_search_zones */
771 static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */
772 xmlXPathContext *path_ctx, xmlNode *node,
773 time_t current_time) {
774 char *view_name = NULL;
779 view_name = (char *)xmlGetProp(node, BAD_CAST "name");
781 if (view_name == NULL) {
782 ERROR("bind plugin: Could not determine view name.");
786 for (j = 0; j < views_num; j++) {
787 if (strcasecmp(view_name, views[j].name) == 0)
794 xmlXPathObject *path_obj;
795 path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
796 if (path_obj == NULL) {
797 ERROR("bind plugin: xmlXPathEvalExpression failed.");
801 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
803 view_name = (char *)xmlNodeListGetString(
804 doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
805 if (view_name != NULL)
809 if (view_name == NULL) {
810 ERROR("bind plugin: Could not determine view name.");
811 xmlXPathFreeObject(path_obj);
815 for (j = 0; j < views_num; j++) {
816 if (strcasecmp(view_name, views[j].name) == 0)
821 xmlXPathFreeObject(path_obj);
832 DEBUG("bind plugin: bind_xml_stats_handle_view: Found view `%s'.",
835 if (view->qtypes != 0) /* {{{ */
837 char plugin_instance[DATA_MAX_NAME_LEN];
838 list_info_ptr_t list_info = {plugin_instance,
839 /* type = */ "dns_qtype"};
841 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-qtypes",
844 bind_parse_generic_name_attr_value_list(
845 /* xpath = */ "counters[@type='resqtype']",
846 /* callback = */ bind_xml_list_callback,
847 /* user_data = */ &list_info, doc, path_ctx, current_time,
850 bind_parse_generic_name_value(/* xpath = */ "rdtype",
851 /* callback = */ bind_xml_list_callback,
852 /* user_data = */ &list_info, doc, path_ctx,
853 current_time, DS_TYPE_COUNTER);
857 if (view->resolver_stats != 0) /* {{{ */
859 char plugin_instance[DATA_MAX_NAME_LEN];
860 translation_table_ptr_t table_ptr = {resstats_translation_table,
861 resstats_translation_table_length,
864 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-resolver_stats",
867 bind_parse_generic_name_attr_value_list(
868 "counters[@type='resstats']",
869 /* callback = */ bind_xml_table_callback,
870 /* user_data = */ &table_ptr, doc, path_ctx, current_time,
873 bind_parse_generic_name_value("resstat",
874 /* callback = */ bind_xml_table_callback,
875 /* user_data = */ &table_ptr, doc, path_ctx,
876 current_time, DS_TYPE_COUNTER);
880 /* Record types in the cache */
881 if (view->cacherrsets != 0) /* {{{ */
883 char plugin_instance[DATA_MAX_NAME_LEN];
884 list_info_ptr_t list_info = {plugin_instance,
885 /* type = */ "dns_qtype_cached"};
887 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-cache_rr_sets",
890 bind_parse_generic_name_value(/* xpath = */ "cache/rrset",
891 /* callback = */ bind_xml_list_callback,
892 /* user_data = */ &list_info, doc, path_ctx,
893 current_time, DS_TYPE_GAUGE);
896 if (view->zones_num > 0)
897 bind_xml_stats_search_zones(version, doc, path_ctx, node, view,
901 } /* }}} int bind_xml_stats_handle_view */
903 static int bind_xml_stats_search_views(int version, xmlDoc *doc, /* {{{ */
904 xmlXPathContext *xpathCtx,
906 time_t current_time) {
907 xmlXPathObject *view_nodes = NULL;
908 xmlXPathContext *view_path_context;
910 view_path_context = xmlXPathNewContext(doc);
911 if (view_path_context == NULL) {
912 ERROR("bind plugin: xmlXPathNewContext failed.");
916 view_nodes = xmlXPathEvalExpression(BAD_CAST "views/view", xpathCtx);
917 if (view_nodes == NULL) {
918 ERROR("bind plugin: Cannot find any <view> tags.");
919 xmlXPathFreeContext(view_path_context);
923 for (int i = 0; i < view_nodes->nodesetval->nodeNr; i++) {
926 node = view_nodes->nodesetval->nodeTab[i];
927 assert(node != NULL);
929 view_path_context->node = node;
931 bind_xml_stats_handle_view(version, doc, view_path_context, node,
935 xmlXPathFreeObject(view_nodes);
936 xmlXPathFreeContext(view_path_context);
938 } /* }}} int bind_xml_stats_search_views */
940 static void bind_xml_stats_v3(xmlDoc *doc, /* {{{ */
941 xmlXPathContext *xpathCtx, xmlNode *statsnode,
942 time_t current_time) {
943 /* XPath: server/counters[@type='opcode']
944 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
946 * <counters type="opcode">
947 * <counter name="A">1</counter>
951 if (global_opcodes != 0) {
952 list_info_ptr_t list_info = {/* plugin instance = */ "global-opcodes",
953 /* type = */ "dns_opcode"};
954 bind_parse_generic_name_attr_value_list(
955 /* xpath = */ "server/counters[@type='opcode']",
956 /* callback = */ bind_xml_list_callback,
957 /* user_data = */ &list_info, doc, xpathCtx, current_time,
961 /* XPath: server/counters[@type='qtype']
962 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
963 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
964 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
966 * <counters type="opcode">
967 * <counter name="A">1</counter>
971 if (global_qtypes != 0) {
972 list_info_ptr_t list_info = {/* plugin instance = */ "global-qtypes",
973 /* type = */ "dns_qtype"};
975 bind_parse_generic_name_attr_value_list(
976 /* xpath = */ "server/counters[@type='qtype']",
977 /* callback = */ bind_xml_list_callback,
978 /* user_data = */ &list_info, doc, xpathCtx, current_time,
982 /* XPath: server/counters[@type='nsstat']
983 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
984 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
985 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
986 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
987 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
988 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
989 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
992 * <counters type="nsstat"
993 * <counter name="Requestv4">1</counter>
994 * <counter name="Requestv6">0</counter>
998 if (global_server_stats) {
999 translation_table_ptr_t table_ptr = {
1000 nsstats_translation_table, nsstats_translation_table_length,
1001 /* plugin_instance = */ "global-server_stats"};
1003 bind_parse_generic_name_attr_value_list(
1004 "server/counters[@type='nsstat']",
1005 /* callback = */ bind_xml_table_callback,
1006 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1010 /* XPath: server/zonestats, server/zonestat,
1011 * server/counters[@type='zonestat']
1012 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1013 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1014 * XfrSuccess, XfrFail
1016 * <counters type="zonestat"
1017 * <counter name="NotifyOutv4">0</counter>
1018 * <counter name="NotifyOutv6">0</counter>
1022 if (global_zone_maint_stats) {
1023 translation_table_ptr_t table_ptr = {
1024 zonestats_translation_table, zonestats_translation_table_length,
1025 /* plugin_instance = */ "global-zone_maint_stats"};
1027 bind_parse_generic_name_attr_value_list(
1028 "server/counters[@type='zonestat']",
1029 /* callback = */ bind_xml_table_callback,
1030 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1034 /* XPath: server/resstats, server/counters[@type='resstat']
1035 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1036 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1037 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1038 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1040 * <counters type="resstat"
1041 * <counter name="Queryv4">0</counter>
1042 * <counter name="Queryv6">0</counter>
1046 if (global_resolver_stats != 0) {
1047 translation_table_ptr_t table_ptr = {
1048 resstats_translation_table, resstats_translation_table_length,
1049 /* plugin_instance = */ "global-resolver_stats"};
1051 bind_parse_generic_name_attr_value_list(
1052 "server/counters[@type='resstat']",
1053 /* callback = */ bind_xml_table_callback,
1054 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1057 } /* }}} bind_xml_stats_v3 */
1059 static void bind_xml_stats_v1_v2(int version, xmlDoc *doc, /* {{{ */
1060 xmlXPathContext *xpathCtx, xmlNode *statsnode,
1061 time_t current_time) {
1062 /* XPath: server/requests/opcode, server/counters[@type='opcode']
1063 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1067 * <counter>1</counter>
1071 if (global_opcodes != 0) {
1072 list_info_ptr_t list_info = {/* plugin instance = */ "global-opcodes",
1073 /* type = */ "dns_opcode"};
1075 bind_parse_generic_name_value(/* xpath = */ "server/requests/opcode",
1076 /* callback = */ bind_xml_list_callback,
1077 /* user_data = */ &list_info, doc, xpathCtx,
1078 current_time, DS_TYPE_COUNTER);
1081 /* XPath: server/queries-in/rdtype, server/counters[@type='qtype']
1082 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1083 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1084 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1088 * <counter>1</counter>
1092 if (global_qtypes != 0) {
1093 list_info_ptr_t list_info = {/* plugin instance = */ "global-qtypes",
1094 /* type = */ "dns_qtype"};
1096 bind_parse_generic_name_value(/* xpath = */ "server/queries-in/rdtype",
1097 /* callback = */ bind_xml_list_callback,
1098 /* user_data = */ &list_info, doc, xpathCtx,
1099 current_time, DS_TYPE_COUNTER);
1102 /* XPath: server/nsstats, server/nsstat, server/counters[@type='nsstat']
1103 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1104 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1105 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1106 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1107 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1108 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1109 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1113 * <Requestv4>1</Requestv4>
1114 * <Requestv6>0</Requestv6>
1119 * <name>Requestv4</name>
1120 * <counter>1</counter>
1123 * <name>Requestv6</name>
1124 * <counter>0</counter>
1128 if (global_server_stats) {
1129 translation_table_ptr_t table_ptr = {
1130 nsstats_translation_table, nsstats_translation_table_length,
1131 /* plugin_instance = */ "global-server_stats"};
1134 bind_parse_generic_value_list("server/nsstats",
1135 /* callback = */ bind_xml_table_callback,
1136 /* user_data = */ &table_ptr, doc, xpathCtx,
1137 current_time, DS_TYPE_COUNTER);
1139 bind_parse_generic_name_value("server/nsstat",
1140 /* callback = */ bind_xml_table_callback,
1141 /* user_data = */ &table_ptr, doc, xpathCtx,
1142 current_time, DS_TYPE_COUNTER);
1146 /* XPath: server/zonestats, server/zonestat,
1147 * server/counters[@type='zonestat']
1148 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1149 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1150 * XfrSuccess, XfrFail
1153 * <NotifyOutv4>0</NotifyOutv4>
1154 * <NotifyOutv6>0</NotifyOutv6>
1159 * <name>NotifyOutv4</name>
1160 * <counter>0</counter>
1163 * <name>NotifyOutv6</name>
1164 * <counter>0</counter>
1168 if (global_zone_maint_stats) {
1169 translation_table_ptr_t table_ptr = {
1170 zonestats_translation_table, zonestats_translation_table_length,
1171 /* plugin_instance = */ "global-zone_maint_stats"};
1174 bind_parse_generic_value_list("server/zonestats",
1175 /* callback = */ bind_xml_table_callback,
1176 /* user_data = */ &table_ptr, doc, xpathCtx,
1177 current_time, DS_TYPE_COUNTER);
1179 bind_parse_generic_name_value("server/zonestat",
1180 /* callback = */ bind_xml_table_callback,
1181 /* user_data = */ &table_ptr, doc, xpathCtx,
1182 current_time, DS_TYPE_COUNTER);
1186 /* XPath: server/resstats, server/counters[@type='resstat']
1187 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1188 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1189 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1190 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1193 * <Queryv4>0</Queryv4>
1194 * <Queryv6>0</Queryv6>
1199 * <name>Queryv4</name>
1200 * <counter>0</counter>
1203 * <name>Queryv6</name>
1204 * <counter>0</counter>
1208 if (global_resolver_stats != 0) {
1209 translation_table_ptr_t table_ptr = {
1210 resstats_translation_table, resstats_translation_table_length,
1211 /* plugin_instance = */ "global-resolver_stats"};
1214 bind_parse_generic_value_list("server/resstats",
1215 /* callback = */ bind_xml_table_callback,
1216 /* user_data = */ &table_ptr, doc, xpathCtx,
1217 current_time, DS_TYPE_COUNTER);
1219 bind_parse_generic_name_value("server/resstat",
1220 /* callback = */ bind_xml_table_callback,
1221 /* user_data = */ &table_ptr, doc, xpathCtx,
1222 current_time, DS_TYPE_COUNTER);
1225 } /* }}} bind_xml_stats_v1_v2 */
1227 static int bind_xml_stats(int version, xmlDoc *doc, /* {{{ */
1228 xmlXPathContext *xpathCtx, xmlNode *statsnode) {
1229 time_t current_time = 0;
1232 xpathCtx->node = statsnode;
1234 /* TODO: Check `server/boot-time' to recognize server restarts. */
1236 status = bind_xml_read_timestamp("server/current-time", doc, xpathCtx,
1239 ERROR("bind plugin: Reading `server/current-time' failed.");
1242 DEBUG("bind plugin: Current server time is %i.", (int)current_time);
1245 bind_xml_stats_v3(doc, xpathCtx, statsnode, current_time);
1247 bind_xml_stats_v1_v2(version, doc, xpathCtx, statsnode, current_time);
1250 /* XPath: memory/summary
1251 * Variables: TotalUse, InUse, BlockSize, ContextSize, Lost
1252 * Layout: v2 and v3:
1254 * <TotalUse>6587096</TotalUse>
1255 * <InUse>1345424</InUse>
1256 * <BlockSize>5505024</BlockSize>
1257 * <ContextSize>3732456</ContextSize>
1261 if (global_memory_stats != 0) {
1262 translation_table_ptr_t table_ptr = {
1263 memsummary_translation_table, memsummary_translation_table_length,
1264 /* plugin_instance = */ "global-memory_stats"};
1266 bind_parse_generic_value_list("memory/summary",
1267 /* callback = */ bind_xml_table_callback,
1268 /* user_data = */ &table_ptr, doc, xpathCtx,
1269 current_time, DS_TYPE_GAUGE);
1273 bind_xml_stats_search_views(version, doc, xpathCtx, statsnode,
1277 } /* }}} int bind_xml_stats */
1279 static int bind_xml(const char *data) /* {{{ */
1282 xmlXPathContext *xpathCtx = NULL;
1283 xmlXPathObject *xpathObj = NULL;
1286 doc = xmlParseMemory(data, strlen(data));
1288 ERROR("bind plugin: xmlParseMemory failed.");
1292 xpathCtx = xmlXPathNewContext(doc);
1293 if (xpathCtx == NULL) {
1294 ERROR("bind plugin: xmlXPathNewContext failed.");
1300 // version 3.* of statistics XML (since BIND9.9)
1303 xpathObj = xmlXPathEvalExpression(BAD_CAST "/statistics", xpathCtx);
1304 if (xpathObj == NULL || xpathObj->nodesetval == NULL ||
1305 xpathObj->nodesetval->nodeNr == 0) {
1306 DEBUG("bind plugin: Statistics appears not to be v3");
1307 // we will fallback to v1 or v2 detection
1308 if (xpathObj != NULL) {
1309 xmlXPathFreeObject(xpathObj);
1312 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
1316 node = xpathObj->nodesetval->nodeTab[i];
1317 assert(node != NULL);
1319 attr_version = (char *)xmlGetProp(node, BAD_CAST "version");
1320 if (attr_version == NULL) {
1321 NOTICE("bind plugin: Found <statistics> tag doesn't have a "
1322 "`version' attribute.");
1325 DEBUG("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1327 if (strncmp("3.", attr_version, strlen("3.")) != 0) {
1328 /* TODO: Use the complaint mechanism here. */
1329 NOTICE("bind plugin: Found <statistics> tag with version `%s'. "
1330 "Unfortunately I have no clue how to parse that. "
1331 "Please open a bug report for this.",
1333 xmlFree(attr_version);
1336 ret = bind_xml_stats(3, doc, xpathCtx, node);
1338 xmlFree(attr_version);
1339 /* One <statistics> node ought to be enough. */
1343 // we are finished, early-return
1344 xmlXPathFreeObject(xpathObj);
1345 xmlXPathFreeContext(xpathCtx);
1352 // versions 1.* or 2.* of statistics XML
1355 xpathObj = xmlXPathEvalExpression(BAD_CAST "/isc/bind/statistics", xpathCtx);
1356 if (xpathObj == NULL) {
1357 ERROR("bind plugin: Cannot find the <statistics> tag.");
1358 xmlXPathFreeContext(xpathCtx);
1361 } else if (xpathObj->nodesetval == NULL) {
1362 ERROR("bind plugin: xmlXPathEvalExpression failed.");
1363 xmlXPathFreeObject(xpathObj);
1364 xmlXPathFreeContext(xpathCtx);
1369 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
1372 int parsed_version = 0;
1374 node = xpathObj->nodesetval->nodeTab[i];
1375 assert(node != NULL);
1377 attr_version = (char *)xmlGetProp(node, BAD_CAST "version");
1378 if (attr_version == NULL) {
1379 NOTICE("bind plugin: Found <statistics> tag doesn't have a "
1380 "`version' attribute.");
1383 DEBUG("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1385 /* At the time this plugin was written, version "1.0" was used by
1386 * BIND 9.5.0, version "2.0" was used by BIND 9.5.1 and 9.6.0. We assume
1387 * that "1.*" and "2.*" don't introduce structural changes, so we just
1388 * check for the first two characters here. */
1389 if (strncmp("1.", attr_version, strlen("1.")) == 0)
1391 else if (strncmp("2.", attr_version, strlen("2.")) == 0)
1394 /* TODO: Use the complaint mechanism here. */
1395 NOTICE("bind plugin: Found <statistics> tag with version `%s'. "
1396 "Unfortunately I have no clue how to parse that. "
1397 "Please open a bug report for this.",
1399 xmlFree(attr_version);
1403 ret = bind_xml_stats(parsed_version, doc, xpathCtx, node);
1405 xmlFree(attr_version);
1406 /* One <statistics> node ought to be enough. */
1410 xmlXPathFreeObject(xpathObj);
1411 xmlXPathFreeContext(xpathCtx);
1415 } /* }}} int bind_xml */
1417 static int bind_config_set_bool(const char *name, int *var, /* {{{ */
1418 oconfig_item_t *ci) {
1419 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
1420 WARNING("bind plugin: The `%s' option needs "
1421 "exactly one boolean argument.",
1426 if (ci->values[0].value.boolean)
1431 } /* }}} int bind_config_set_bool */
1433 static int bind_config_add_view_zone(cb_view_t *view, /* {{{ */
1434 oconfig_item_t *ci) {
1437 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1438 WARNING("bind plugin: The `Zone' option needs "
1439 "exactly one string argument.");
1443 tmp = realloc(view->zones, sizeof(char *) * (view->zones_num + 1));
1445 ERROR("bind plugin: realloc failed.");
1450 view->zones[view->zones_num] = strdup(ci->values[0].value.string);
1451 if (view->zones[view->zones_num] == NULL) {
1452 ERROR("bind plugin: strdup failed.");
1458 } /* }}} int bind_config_add_view_zone */
1460 static int bind_config_add_view(oconfig_item_t *ci) /* {{{ */
1464 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1465 WARNING("bind plugin: `View' blocks need exactly one string argument.");
1469 tmp = realloc(views, sizeof(*views) * (views_num + 1));
1471 ERROR("bind plugin: realloc failed.");
1475 tmp = views + views_num;
1477 memset(tmp, 0, sizeof(*tmp));
1479 tmp->resolver_stats = 1;
1480 tmp->cacherrsets = 1;
1484 tmp->name = strdup(ci->values[0].value.string);
1485 if (tmp->name == NULL) {
1486 ERROR("bind plugin: strdup failed.");
1491 for (int i = 0; i < ci->children_num; i++) {
1492 oconfig_item_t *child = ci->children + i;
1494 if (strcasecmp("QTypes", child->key) == 0)
1495 bind_config_set_bool("QTypes", &tmp->qtypes, child);
1496 else if (strcasecmp("ResolverStats", child->key) == 0)
1497 bind_config_set_bool("ResolverStats", &tmp->resolver_stats, child);
1498 else if (strcasecmp("CacheRRSets", child->key) == 0)
1499 bind_config_set_bool("CacheRRSets", &tmp->cacherrsets, child);
1500 else if (strcasecmp("Zone", child->key) == 0)
1501 bind_config_add_view_zone(tmp, child);
1503 WARNING("bind plugin: Unknown configuration option "
1504 "`%s' in view `%s' will be ignored.",
1505 child->key, tmp->name);
1507 } /* for (i = 0; i < ci->children_num; i++) */
1511 } /* }}} int bind_config_add_view */
1513 static int bind_config(oconfig_item_t *ci) /* {{{ */
1515 for (int i = 0; i < ci->children_num; i++) {
1516 oconfig_item_t *child = ci->children + i;
1518 if (strcasecmp("Url", child->key) == 0) {
1519 if ((child->values_num != 1) ||
1520 (child->values[0].type != OCONFIG_TYPE_STRING)) {
1521 WARNING("bind plugin: The `Url' option needs "
1522 "exactly one string argument.");
1527 url = strdup(child->values[0].value.string);
1528 } else if (strcasecmp("OpCodes", child->key) == 0)
1529 bind_config_set_bool("OpCodes", &global_opcodes, child);
1530 else if (strcasecmp("QTypes", child->key) == 0)
1531 bind_config_set_bool("QTypes", &global_qtypes, child);
1532 else if (strcasecmp("ServerStats", child->key) == 0)
1533 bind_config_set_bool("ServerStats", &global_server_stats, child);
1534 else if (strcasecmp("ZoneMaintStats", child->key) == 0)
1535 bind_config_set_bool("ZoneMaintStats", &global_zone_maint_stats, child);
1536 else if (strcasecmp("ResolverStats", child->key) == 0)
1537 bind_config_set_bool("ResolverStats", &global_resolver_stats, child);
1538 else if (strcasecmp("MemoryStats", child->key) == 0)
1539 bind_config_set_bool("MemoryStats", &global_memory_stats, child);
1540 else if (strcasecmp("View", child->key) == 0)
1541 bind_config_add_view(child);
1542 else if (strcasecmp("ParseTime", child->key) == 0)
1543 cf_util_get_boolean(child, &config_parse_time);
1544 else if (strcasecmp("Timeout", child->key) == 0)
1545 cf_util_get_int(child, &timeout);
1547 WARNING("bind plugin: Unknown configuration option "
1548 "`%s' will be ignored.",
1554 } /* }}} int bind_config */
1556 static int bind_init(void) /* {{{ */
1561 curl = curl_easy_init();
1563 ERROR("bind plugin: bind_init: curl_easy_init failed.");
1567 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
1568 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
1569 curl_easy_setopt(curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
1570 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, bind_curl_error);
1571 curl_easy_setopt(curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
1572 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
1573 curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
1574 #ifdef HAVE_CURLOPT_TIMEOUT_MS
1575 curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS,
1576 (timeout >= 0) ? (long)timeout : (long)CDTIME_T_TO_MS(
1577 plugin_get_interval()));
1581 } /* }}} int bind_init */
1583 static int bind_read(void) /* {{{ */
1588 ERROR("bind plugin: I don't have a CURL object.");
1592 bind_buffer_fill = 0;
1593 if (curl_easy_perform(curl) != CURLE_OK) {
1594 ERROR("bind plugin: curl_easy_perform failed: %s", bind_curl_error);
1598 status = bind_xml(bind_buffer);
1603 } /* }}} int bind_read */
1605 static int bind_shutdown(void) /* {{{ */
1608 curl_easy_cleanup(curl);
1613 } /* }}} int bind_shutdown */
1615 void module_register(void) {
1616 plugin_register_complex_config("bind", bind_config);
1617 plugin_register_init("bind", bind_init);
1618 plugin_register_read("bind", bind_read);
1619 plugin_register_shutdown("bind", bind_shutdown);
1620 } /* void module_register */
1622 /* vim: set sw=2 sts=2 ts=8 et fdm=marker : */