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);
436 *ret_value = mktime(&tm);
438 xmlXPathFreeObject(xpathObj);
440 } /* }}} int bind_xml_read_timestamp */
443 * bind_parse_generic_name_value
445 * Reads statistics in the form:
448 * <counter>123</counter>
451 static int bind_parse_generic_name_value(const char *xpath_expression, /* {{{ */
452 list_callback_t list_callback,
453 void *user_data, xmlDoc *doc,
454 xmlXPathContext *xpathCtx,
455 time_t current_time, int ds_type) {
456 xmlXPathObject *xpathObj = NULL;
459 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
460 if (xpathObj == NULL) {
461 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
467 /* Iterate over all matching nodes. */
468 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
470 xmlNode *name_node = NULL;
471 xmlNode *counter = NULL;
474 parent = xpathObj->nodesetval->nodeTab[i];
475 DEBUG("bind plugin: bind_parse_generic_name_value: parent->name = %s;",
476 (char *)parent->name);
478 /* Iterate over all child nodes. */
479 for (xmlNode *child = parent->xmlChildrenNode; child != NULL;
480 child = child->next) {
481 if (child->type != XML_ELEMENT_NODE)
484 if (xmlStrcmp(BAD_CAST "name", child->name) == 0)
486 else if (xmlStrcmp(BAD_CAST "counter", child->name) == 0)
490 if ((name_node != NULL) && (counter != NULL)) {
492 (char *)xmlNodeListGetString(doc, name_node->xmlChildrenNode, 1);
496 if (ds_type == DS_TYPE_GAUGE)
497 status = bind_xml_read_gauge(doc, counter, &value.gauge);
499 status = bind_xml_read_derive(doc, counter, &value.derive);
503 status = (*list_callback)(name, value, current_time, user_data);
511 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
512 (num_entries == 1) ? "entry" : "entries", xpath_expression);
514 xmlXPathFreeObject(xpathObj);
517 } /* }}} int bind_parse_generic_name_value */
520 * bind_parse_generic_value_list
522 * Reads statistics in the form:
530 static int bind_parse_generic_value_list(const char *xpath_expression, /* {{{ */
531 list_callback_t list_callback,
532 void *user_data, xmlDoc *doc,
533 xmlXPathContext *xpathCtx,
534 time_t current_time, int ds_type) {
535 xmlXPathObject *xpathObj = NULL;
538 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
539 if (xpathObj == NULL) {
540 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
546 /* Iterate over all matching nodes. */
547 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
549 /* Iterate over all child nodes. */
550 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
551 child != NULL; child = child->next) {
556 if (child->type != XML_ELEMENT_NODE)
559 node_name = (char *)child->name;
561 if (ds_type == DS_TYPE_GAUGE)
562 status = bind_xml_read_gauge(doc, child, &value.gauge);
564 status = bind_xml_read_derive(doc, child, &value.derive);
568 status = (*list_callback)(node_name, value, current_time, user_data);
574 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
575 (num_entries == 1) ? "entry" : "entries", xpath_expression);
577 xmlXPathFreeObject(xpathObj);
580 } /* }}} int bind_parse_generic_value_list */
583 * bind_parse_generic_name_attr_value_list
585 * Reads statistics in the form:
587 * <counter name="name0">123</counter>
588 * <counter name="name1">234</counter>
589 * <counter name="name2">345</counter>
593 static int bind_parse_generic_name_attr_value_list(
594 const char *xpath_expression, /* {{{ */
595 list_callback_t list_callback, void *user_data, xmlDoc *doc,
596 xmlXPathContext *xpathCtx, time_t current_time, int ds_type) {
597 xmlXPathObject *xpathObj = NULL;
600 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
601 if (xpathObj == NULL) {
602 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
608 /* Iterate over all matching nodes. */
609 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr);
611 /* Iterate over all child nodes. */
612 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
613 child != NULL; child = child->next) {
614 if (child->type != XML_ELEMENT_NODE)
617 if (strncmp("counter", (char *)child->name, strlen("counter")) != 0)
624 attr_name = (char *)xmlGetProp(child, BAD_CAST "name");
625 if (attr_name == NULL) {
626 DEBUG("bind plugin: found <counter> without name.");
629 if (ds_type == DS_TYPE_GAUGE)
630 status = bind_xml_read_gauge(doc, child, &value.gauge);
632 status = bind_xml_read_derive(doc, child, &value.derive);
636 status = (*list_callback)(attr_name, value, current_time, user_data);
642 DEBUG("bind plugin: Found %d %s for XPath expression `%s'", num_entries,
643 (num_entries == 1) ? "entry" : "entries", xpath_expression);
645 xmlXPathFreeObject(xpathObj);
648 } /* }}} int bind_parse_generic_name_attr_value_list */
650 static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */
651 xmlXPathContext *path_ctx, xmlNode *node,
652 cb_view_t *view, time_t current_time) {
653 xmlXPathObject *path_obj;
654 char *zone_name = NULL;
658 char *n = (char *)xmlGetProp(node, BAD_CAST "name");
659 char *c = (char *)xmlGetProp(node, BAD_CAST "rdataclass");
661 zone_name = (char *)xmlMalloc(strlen(n) + strlen(c) + 2);
662 snprintf(zone_name, strlen(n) + strlen(c) + 2, "%s/%s", n, c);
667 path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
668 if (path_obj == NULL) {
669 ERROR("bind plugin: xmlXPathEvalExpression failed.");
673 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
675 zone_name = (char *)xmlNodeListGetString(
676 doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
677 if (zone_name != NULL)
680 xmlXPathFreeObject(path_obj);
683 if (zone_name == NULL) {
684 ERROR("bind plugin: Could not determine zone name.");
688 for (j = 0; j < view->zones_num; j++) {
689 if (strcasecmp(zone_name, view->zones[j]) == 0)
696 if (j >= view->zones_num)
699 zone_name = view->zones[j];
701 DEBUG("bind plugin: bind_xml_stats_handle_zone: Found zone `%s'.", zone_name);
703 { /* Parse the <counters> tag {{{ */
704 char plugin_instance[DATA_MAX_NAME_LEN];
705 translation_table_ptr_t table_ptr = {nsstats_translation_table,
706 nsstats_translation_table_length,
709 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-zone-%s",
710 view->name, zone_name);
713 list_info_ptr_t list_info = {plugin_instance,
714 /* type = */ "dns_qtype"};
715 bind_parse_generic_name_attr_value_list(
716 /* xpath = */ "counters[@type='rcode']",
717 /* callback = */ bind_xml_table_callback,
718 /* user_data = */ &table_ptr, doc, path_ctx, current_time,
720 bind_parse_generic_name_attr_value_list(
721 /* xpath = */ "counters[@type='qtype']",
722 /* callback = */ bind_xml_list_callback,
723 /* user_data = */ &list_info, doc, path_ctx, current_time,
726 bind_parse_generic_value_list(/* xpath = */ "counters",
727 /* callback = */ bind_xml_table_callback,
728 /* user_data = */ &table_ptr, doc, path_ctx,
729 current_time, DS_TYPE_COUNTER);
734 } /* }}} int bind_xml_stats_handle_zone */
736 static int bind_xml_stats_search_zones(int version, xmlDoc *doc, /* {{{ */
737 xmlXPathContext *path_ctx, xmlNode *node,
738 cb_view_t *view, time_t current_time) {
739 xmlXPathObject *zone_nodes = NULL;
740 xmlXPathContext *zone_path_context;
742 zone_path_context = xmlXPathNewContext(doc);
743 if (zone_path_context == NULL) {
744 ERROR("bind plugin: xmlXPathNewContext failed.");
748 zone_nodes = xmlXPathEvalExpression(BAD_CAST "zones/zone", path_ctx);
749 if (zone_nodes == NULL) {
750 ERROR("bind plugin: Cannot find any <view> tags.");
751 xmlXPathFreeContext(zone_path_context);
755 for (int i = 0; i < zone_nodes->nodesetval->nodeNr; i++) {
756 node = zone_nodes->nodesetval->nodeTab[i];
757 assert(node != NULL);
759 zone_path_context->node = node;
761 bind_xml_stats_handle_zone(version, doc, zone_path_context, node, view,
765 xmlXPathFreeObject(zone_nodes);
766 xmlXPathFreeContext(zone_path_context);
768 } /* }}} int bind_xml_stats_search_zones */
770 static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */
771 xmlXPathContext *path_ctx, xmlNode *node,
772 time_t current_time) {
773 char *view_name = NULL;
778 view_name = (char *)xmlGetProp(node, BAD_CAST "name");
780 if (view_name == NULL) {
781 ERROR("bind plugin: Could not determine view name.");
785 for (j = 0; j < views_num; j++) {
786 if (strcasecmp(view_name, views[j].name) == 0)
793 xmlXPathObject *path_obj;
794 path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
795 if (path_obj == NULL) {
796 ERROR("bind plugin: xmlXPathEvalExpression failed.");
800 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
802 view_name = (char *)xmlNodeListGetString(
803 doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
804 if (view_name != NULL)
808 if (view_name == NULL) {
809 ERROR("bind plugin: Could not determine view name.");
810 xmlXPathFreeObject(path_obj);
814 for (j = 0; j < views_num; j++) {
815 if (strcasecmp(view_name, views[j].name) == 0)
820 xmlXPathFreeObject(path_obj);
831 DEBUG("bind plugin: bind_xml_stats_handle_view: Found view `%s'.",
834 if (view->qtypes != 0) /* {{{ */
836 char plugin_instance[DATA_MAX_NAME_LEN];
837 list_info_ptr_t list_info = {plugin_instance,
838 /* type = */ "dns_qtype"};
840 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-qtypes",
843 bind_parse_generic_name_attr_value_list(
844 /* xpath = */ "counters[@type='resqtype']",
845 /* callback = */ bind_xml_list_callback,
846 /* user_data = */ &list_info, doc, path_ctx, current_time,
849 bind_parse_generic_name_value(/* xpath = */ "rdtype",
850 /* callback = */ bind_xml_list_callback,
851 /* user_data = */ &list_info, doc, path_ctx,
852 current_time, DS_TYPE_COUNTER);
856 if (view->resolver_stats != 0) /* {{{ */
858 char plugin_instance[DATA_MAX_NAME_LEN];
859 translation_table_ptr_t table_ptr = {resstats_translation_table,
860 resstats_translation_table_length,
863 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-resolver_stats",
866 bind_parse_generic_name_attr_value_list(
867 "counters[@type='resstats']",
868 /* callback = */ bind_xml_table_callback,
869 /* user_data = */ &table_ptr, doc, path_ctx, current_time,
872 bind_parse_generic_name_value("resstat",
873 /* callback = */ bind_xml_table_callback,
874 /* user_data = */ &table_ptr, doc, path_ctx,
875 current_time, DS_TYPE_COUNTER);
879 /* Record types in the cache */
880 if (view->cacherrsets != 0) /* {{{ */
882 char plugin_instance[DATA_MAX_NAME_LEN];
883 list_info_ptr_t list_info = {plugin_instance,
884 /* type = */ "dns_qtype_cached"};
886 ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-cache_rr_sets",
889 bind_parse_generic_name_value(/* xpath = */ "cache/rrset",
890 /* callback = */ bind_xml_list_callback,
891 /* user_data = */ &list_info, doc, path_ctx,
892 current_time, DS_TYPE_GAUGE);
895 if (view->zones_num > 0)
896 bind_xml_stats_search_zones(version, doc, path_ctx, node, view,
900 } /* }}} int bind_xml_stats_handle_view */
902 static int bind_xml_stats_search_views(int version, xmlDoc *doc, /* {{{ */
903 xmlXPathContext *xpathCtx,
905 time_t current_time) {
906 xmlXPathObject *view_nodes = NULL;
907 xmlXPathContext *view_path_context;
909 view_path_context = xmlXPathNewContext(doc);
910 if (view_path_context == NULL) {
911 ERROR("bind plugin: xmlXPathNewContext failed.");
915 view_nodes = xmlXPathEvalExpression(BAD_CAST "views/view", xpathCtx);
916 if (view_nodes == NULL) {
917 ERROR("bind plugin: Cannot find any <view> tags.");
918 xmlXPathFreeContext(view_path_context);
922 for (int i = 0; i < view_nodes->nodesetval->nodeNr; i++) {
925 node = view_nodes->nodesetval->nodeTab[i];
926 assert(node != NULL);
928 view_path_context->node = node;
930 bind_xml_stats_handle_view(version, doc, view_path_context, node,
934 xmlXPathFreeObject(view_nodes);
935 xmlXPathFreeContext(view_path_context);
937 } /* }}} int bind_xml_stats_search_views */
939 static void bind_xml_stats_v3(xmlDoc *doc, /* {{{ */
940 xmlXPathContext *xpathCtx, xmlNode *statsnode,
941 time_t current_time) {
942 /* XPath: server/counters[@type='opcode']
943 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
945 * <counters type="opcode">
946 * <counter name="A">1</counter>
950 if (global_opcodes != 0) {
951 list_info_ptr_t list_info = {/* plugin instance = */ "global-opcodes",
952 /* type = */ "dns_opcode"};
953 bind_parse_generic_name_attr_value_list(
954 /* xpath = */ "server/counters[@type='opcode']",
955 /* callback = */ bind_xml_list_callback,
956 /* user_data = */ &list_info, doc, xpathCtx, current_time,
960 /* XPath: server/counters[@type='qtype']
961 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
962 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
963 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
965 * <counters type="opcode">
966 * <counter name="A">1</counter>
970 if (global_qtypes != 0) {
971 list_info_ptr_t list_info = {/* plugin instance = */ "global-qtypes",
972 /* type = */ "dns_qtype"};
974 bind_parse_generic_name_attr_value_list(
975 /* xpath = */ "server/counters[@type='qtype']",
976 /* callback = */ bind_xml_list_callback,
977 /* user_data = */ &list_info, doc, xpathCtx, current_time,
981 /* XPath: server/counters[@type='nsstat']
982 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
983 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
984 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
985 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
986 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
987 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
988 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
991 * <counters type="nsstat"
992 * <counter name="Requestv4">1</counter>
993 * <counter name="Requestv6">0</counter>
997 if (global_server_stats) {
998 translation_table_ptr_t table_ptr = {
999 nsstats_translation_table, nsstats_translation_table_length,
1000 /* plugin_instance = */ "global-server_stats"};
1002 bind_parse_generic_name_attr_value_list(
1003 "server/counters[@type='nsstat']",
1004 /* callback = */ bind_xml_table_callback,
1005 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1009 /* XPath: server/zonestats, server/zonestat,
1010 * server/counters[@type='zonestat']
1011 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1012 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1013 * XfrSuccess, XfrFail
1015 * <counters type="zonestat"
1016 * <counter name="NotifyOutv4">0</counter>
1017 * <counter name="NotifyOutv6">0</counter>
1021 if (global_zone_maint_stats) {
1022 translation_table_ptr_t table_ptr = {
1023 zonestats_translation_table, zonestats_translation_table_length,
1024 /* plugin_instance = */ "global-zone_maint_stats"};
1026 bind_parse_generic_name_attr_value_list(
1027 "server/counters[@type='zonestat']",
1028 /* callback = */ bind_xml_table_callback,
1029 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1033 /* XPath: server/resstats, server/counters[@type='resstat']
1034 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1035 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1036 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1037 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1039 * <counters type="resstat"
1040 * <counter name="Queryv4">0</counter>
1041 * <counter name="Queryv6">0</counter>
1045 if (global_resolver_stats != 0) {
1046 translation_table_ptr_t table_ptr = {
1047 resstats_translation_table, resstats_translation_table_length,
1048 /* plugin_instance = */ "global-resolver_stats"};
1050 bind_parse_generic_name_attr_value_list(
1051 "server/counters[@type='resstat']",
1052 /* callback = */ bind_xml_table_callback,
1053 /* user_data = */ &table_ptr, doc, xpathCtx, current_time,
1056 } /* }}} bind_xml_stats_v3 */
1058 static void bind_xml_stats_v1_v2(int version, xmlDoc *doc, /* {{{ */
1059 xmlXPathContext *xpathCtx, xmlNode *statsnode,
1060 time_t current_time) {
1061 /* XPath: server/requests/opcode, server/counters[@type='opcode']
1062 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1066 * <counter>1</counter>
1070 if (global_opcodes != 0) {
1071 list_info_ptr_t list_info = {/* plugin instance = */ "global-opcodes",
1072 /* type = */ "dns_opcode"};
1074 bind_parse_generic_name_value(/* xpath = */ "server/requests/opcode",
1075 /* callback = */ bind_xml_list_callback,
1076 /* user_data = */ &list_info, doc, xpathCtx,
1077 current_time, DS_TYPE_COUNTER);
1080 /* XPath: server/queries-in/rdtype, server/counters[@type='qtype']
1081 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1082 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1083 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1087 * <counter>1</counter>
1091 if (global_qtypes != 0) {
1092 list_info_ptr_t list_info = {/* plugin instance = */ "global-qtypes",
1093 /* type = */ "dns_qtype"};
1095 bind_parse_generic_name_value(/* xpath = */ "server/queries-in/rdtype",
1096 /* callback = */ bind_xml_list_callback,
1097 /* user_data = */ &list_info, doc, xpathCtx,
1098 current_time, DS_TYPE_COUNTER);
1101 /* XPath: server/nsstats, server/nsstat, server/counters[@type='nsstat']
1102 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1103 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1104 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1105 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1106 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1107 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1108 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1112 * <Requestv4>1</Requestv4>
1113 * <Requestv6>0</Requestv6>
1118 * <name>Requestv4</name>
1119 * <counter>1</counter>
1122 * <name>Requestv6</name>
1123 * <counter>0</counter>
1127 if (global_server_stats) {
1128 translation_table_ptr_t table_ptr = {
1129 nsstats_translation_table, nsstats_translation_table_length,
1130 /* plugin_instance = */ "global-server_stats"};
1133 bind_parse_generic_value_list("server/nsstats",
1134 /* callback = */ bind_xml_table_callback,
1135 /* user_data = */ &table_ptr, doc, xpathCtx,
1136 current_time, DS_TYPE_COUNTER);
1138 bind_parse_generic_name_value("server/nsstat",
1139 /* callback = */ bind_xml_table_callback,
1140 /* user_data = */ &table_ptr, doc, xpathCtx,
1141 current_time, DS_TYPE_COUNTER);
1145 /* XPath: server/zonestats, server/zonestat,
1146 * server/counters[@type='zonestat']
1147 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1148 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1149 * XfrSuccess, XfrFail
1152 * <NotifyOutv4>0</NotifyOutv4>
1153 * <NotifyOutv6>0</NotifyOutv6>
1158 * <name>NotifyOutv4</name>
1159 * <counter>0</counter>
1162 * <name>NotifyOutv6</name>
1163 * <counter>0</counter>
1167 if (global_zone_maint_stats) {
1168 translation_table_ptr_t table_ptr = {
1169 zonestats_translation_table, zonestats_translation_table_length,
1170 /* plugin_instance = */ "global-zone_maint_stats"};
1173 bind_parse_generic_value_list("server/zonestats",
1174 /* callback = */ bind_xml_table_callback,
1175 /* user_data = */ &table_ptr, doc, xpathCtx,
1176 current_time, DS_TYPE_COUNTER);
1178 bind_parse_generic_name_value("server/zonestat",
1179 /* callback = */ bind_xml_table_callback,
1180 /* user_data = */ &table_ptr, doc, xpathCtx,
1181 current_time, DS_TYPE_COUNTER);
1185 /* XPath: server/resstats, server/counters[@type='resstat']
1186 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1187 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1188 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1189 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1192 * <Queryv4>0</Queryv4>
1193 * <Queryv6>0</Queryv6>
1198 * <name>Queryv4</name>
1199 * <counter>0</counter>
1202 * <name>Queryv6</name>
1203 * <counter>0</counter>
1207 if (global_resolver_stats != 0) {
1208 translation_table_ptr_t table_ptr = {
1209 resstats_translation_table, resstats_translation_table_length,
1210 /* plugin_instance = */ "global-resolver_stats"};
1213 bind_parse_generic_value_list("server/resstats",
1214 /* callback = */ bind_xml_table_callback,
1215 /* user_data = */ &table_ptr, doc, xpathCtx,
1216 current_time, DS_TYPE_COUNTER);
1218 bind_parse_generic_name_value("server/resstat",
1219 /* callback = */ bind_xml_table_callback,
1220 /* user_data = */ &table_ptr, doc, xpathCtx,
1221 current_time, DS_TYPE_COUNTER);
1224 } /* }}} bind_xml_stats_v1_v2 */
1226 static int bind_xml_stats(int version, xmlDoc *doc, /* {{{ */
1227 xmlXPathContext *xpathCtx, xmlNode *statsnode) {
1228 time_t current_time = 0;
1231 xpathCtx->node = statsnode;
1233 /* TODO: Check `server/boot-time' to recognize server restarts. */
1235 status = bind_xml_read_timestamp("server/current-time", doc, xpathCtx,
1238 ERROR("bind plugin: Reading `server/current-time' failed.");
1241 DEBUG("bind plugin: Current server time is %i.", (int)current_time);
1244 bind_xml_stats_v3(doc, xpathCtx, statsnode, current_time);
1246 bind_xml_stats_v1_v2(version, doc, xpathCtx, statsnode, current_time);
1249 /* XPath: memory/summary
1250 * Variables: TotalUse, InUse, BlockSize, ContextSize, Lost
1251 * Layout: v2 and v3:
1253 * <TotalUse>6587096</TotalUse>
1254 * <InUse>1345424</InUse>
1255 * <BlockSize>5505024</BlockSize>
1256 * <ContextSize>3732456</ContextSize>
1260 if (global_memory_stats != 0) {
1261 translation_table_ptr_t table_ptr = {
1262 memsummary_translation_table, memsummary_translation_table_length,
1263 /* plugin_instance = */ "global-memory_stats"};
1265 bind_parse_generic_value_list("memory/summary",
1266 /* callback = */ bind_xml_table_callback,
1267 /* user_data = */ &table_ptr, doc, xpathCtx,
1268 current_time, DS_TYPE_GAUGE);
1272 bind_xml_stats_search_views(version, doc, xpathCtx, statsnode,
1276 } /* }}} int bind_xml_stats */
1278 static int bind_xml(const char *data) /* {{{ */
1281 xmlXPathContext *xpathCtx = NULL;
1282 xmlXPathObject *xpathObj = NULL;
1285 doc = xmlParseMemory(data, strlen(data));
1287 ERROR("bind plugin: xmlParseMemory failed.");
1291 xpathCtx = xmlXPathNewContext(doc);
1292 if (xpathCtx == NULL) {
1293 ERROR("bind plugin: xmlXPathNewContext failed.");
1299 // version 3.* of statistics XML (since BIND9.9)
1302 xpathObj = xmlXPathEvalExpression(BAD_CAST "/statistics", xpathCtx);
1303 if (xpathObj == NULL || xpathObj->nodesetval == NULL ||
1304 xpathObj->nodesetval->nodeNr == 0) {
1305 DEBUG("bind plugin: Statistics appears not to be v3");
1306 // we will fallback to v1 or v2 detection
1307 if (xpathObj != NULL) {
1308 xmlXPathFreeObject(xpathObj);
1311 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
1315 node = xpathObj->nodesetval->nodeTab[i];
1316 assert(node != NULL);
1318 attr_version = (char *)xmlGetProp(node, BAD_CAST "version");
1319 if (attr_version == NULL) {
1320 NOTICE("bind plugin: Found <statistics> tag doesn't have a "
1321 "`version' attribute.");
1324 DEBUG("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1326 if (strncmp("3.", attr_version, strlen("3.")) != 0) {
1327 /* TODO: Use the complaint mechanism here. */
1328 NOTICE("bind plugin: Found <statistics> tag with version `%s'. "
1329 "Unfortunately I have no clue how to parse that. "
1330 "Please open a bug report for this.",
1332 xmlFree(attr_version);
1335 ret = bind_xml_stats(3, doc, xpathCtx, node);
1337 xmlFree(attr_version);
1338 /* One <statistics> node ought to be enough. */
1342 // we are finished, early-return
1343 xmlXPathFreeObject(xpathObj);
1344 xmlXPathFreeContext(xpathCtx);
1351 // versions 1.* or 2.* of statistics XML
1354 xpathObj = xmlXPathEvalExpression(BAD_CAST "/isc/bind/statistics", xpathCtx);
1355 if (xpathObj == NULL) {
1356 ERROR("bind plugin: Cannot find the <statistics> tag.");
1357 xmlXPathFreeContext(xpathCtx);
1360 } else if (xpathObj->nodesetval == NULL) {
1361 ERROR("bind plugin: xmlXPathEvalExpression failed.");
1362 xmlXPathFreeObject(xpathObj);
1363 xmlXPathFreeContext(xpathCtx);
1368 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
1371 int parsed_version = 0;
1373 node = xpathObj->nodesetval->nodeTab[i];
1374 assert(node != NULL);
1376 attr_version = (char *)xmlGetProp(node, BAD_CAST "version");
1377 if (attr_version == NULL) {
1378 NOTICE("bind plugin: Found <statistics> tag doesn't have a "
1379 "`version' attribute.");
1382 DEBUG("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1384 /* At the time this plugin was written, version "1.0" was used by
1385 * BIND 9.5.0, version "2.0" was used by BIND 9.5.1 and 9.6.0. We assume
1386 * that "1.*" and "2.*" don't introduce structural changes, so we just
1387 * check for the first two characters here. */
1388 if (strncmp("1.", attr_version, strlen("1.")) == 0)
1390 else if (strncmp("2.", attr_version, strlen("2.")) == 0)
1393 /* TODO: Use the complaint mechanism here. */
1394 NOTICE("bind plugin: Found <statistics> tag with version `%s'. "
1395 "Unfortunately I have no clue how to parse that. "
1396 "Please open a bug report for this.",
1398 xmlFree(attr_version);
1402 ret = bind_xml_stats(parsed_version, doc, xpathCtx, node);
1404 xmlFree(attr_version);
1405 /* One <statistics> node ought to be enough. */
1409 xmlXPathFreeObject(xpathObj);
1410 xmlXPathFreeContext(xpathCtx);
1414 } /* }}} int bind_xml */
1416 static int bind_config_set_bool(const char *name, int *var, /* {{{ */
1417 oconfig_item_t *ci) {
1418 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
1419 WARNING("bind plugin: The `%s' option needs "
1420 "exactly one boolean argument.",
1425 if (ci->values[0].value.boolean)
1430 } /* }}} int bind_config_set_bool */
1432 static int bind_config_add_view_zone(cb_view_t *view, /* {{{ */
1433 oconfig_item_t *ci) {
1436 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1437 WARNING("bind plugin: The `Zone' option needs "
1438 "exactly one string argument.");
1442 tmp = realloc(view->zones, sizeof(char *) * (view->zones_num + 1));
1444 ERROR("bind plugin: realloc failed.");
1449 view->zones[view->zones_num] = strdup(ci->values[0].value.string);
1450 if (view->zones[view->zones_num] == NULL) {
1451 ERROR("bind plugin: strdup failed.");
1457 } /* }}} int bind_config_add_view_zone */
1459 static int bind_config_add_view(oconfig_item_t *ci) /* {{{ */
1463 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1464 WARNING("bind plugin: `View' blocks need exactly one string argument.");
1468 tmp = realloc(views, sizeof(*views) * (views_num + 1));
1470 ERROR("bind plugin: realloc failed.");
1474 tmp = views + views_num;
1476 memset(tmp, 0, sizeof(*tmp));
1478 tmp->resolver_stats = 1;
1479 tmp->cacherrsets = 1;
1483 tmp->name = strdup(ci->values[0].value.string);
1484 if (tmp->name == NULL) {
1485 ERROR("bind plugin: strdup failed.");
1490 for (int i = 0; i < ci->children_num; i++) {
1491 oconfig_item_t *child = ci->children + i;
1493 if (strcasecmp("QTypes", child->key) == 0)
1494 bind_config_set_bool("QTypes", &tmp->qtypes, child);
1495 else if (strcasecmp("ResolverStats", child->key) == 0)
1496 bind_config_set_bool("ResolverStats", &tmp->resolver_stats, child);
1497 else if (strcasecmp("CacheRRSets", child->key) == 0)
1498 bind_config_set_bool("CacheRRSets", &tmp->cacherrsets, child);
1499 else if (strcasecmp("Zone", child->key) == 0)
1500 bind_config_add_view_zone(tmp, child);
1502 WARNING("bind plugin: Unknown configuration option "
1503 "`%s' in view `%s' will be ignored.",
1504 child->key, tmp->name);
1506 } /* for (i = 0; i < ci->children_num; i++) */
1510 } /* }}} int bind_config_add_view */
1512 static int bind_config(oconfig_item_t *ci) /* {{{ */
1514 for (int i = 0; i < ci->children_num; i++) {
1515 oconfig_item_t *child = ci->children + i;
1517 if (strcasecmp("Url", child->key) == 0) {
1518 if ((child->values_num != 1) ||
1519 (child->values[0].type != OCONFIG_TYPE_STRING)) {
1520 WARNING("bind plugin: The `Url' option needs "
1521 "exactly one string argument.");
1526 url = strdup(child->values[0].value.string);
1527 } else if (strcasecmp("OpCodes", child->key) == 0)
1528 bind_config_set_bool("OpCodes", &global_opcodes, child);
1529 else if (strcasecmp("QTypes", child->key) == 0)
1530 bind_config_set_bool("QTypes", &global_qtypes, child);
1531 else if (strcasecmp("ServerStats", child->key) == 0)
1532 bind_config_set_bool("ServerStats", &global_server_stats, child);
1533 else if (strcasecmp("ZoneMaintStats", child->key) == 0)
1534 bind_config_set_bool("ZoneMaintStats", &global_zone_maint_stats, child);
1535 else if (strcasecmp("ResolverStats", child->key) == 0)
1536 bind_config_set_bool("ResolverStats", &global_resolver_stats, child);
1537 else if (strcasecmp("MemoryStats", child->key) == 0)
1538 bind_config_set_bool("MemoryStats", &global_memory_stats, child);
1539 else if (strcasecmp("View", child->key) == 0)
1540 bind_config_add_view(child);
1541 else if (strcasecmp("ParseTime", child->key) == 0)
1542 cf_util_get_boolean(child, &config_parse_time);
1543 else if (strcasecmp("Timeout", child->key) == 0)
1544 cf_util_get_int(child, &timeout);
1546 WARNING("bind plugin: Unknown configuration option "
1547 "`%s' will be ignored.",
1553 } /* }}} int bind_config */
1555 static int bind_init(void) /* {{{ */
1560 curl = curl_easy_init();
1562 ERROR("bind plugin: bind_init: curl_easy_init failed.");
1566 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
1567 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
1568 curl_easy_setopt(curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
1569 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, bind_curl_error);
1570 curl_easy_setopt(curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
1571 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
1572 curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
1573 #ifdef HAVE_CURLOPT_TIMEOUT_MS
1574 curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS,
1575 (timeout >= 0) ? (long)timeout : (long)CDTIME_T_TO_MS(
1576 plugin_get_interval()));
1580 } /* }}} int bind_init */
1582 static int bind_read(void) /* {{{ */
1587 ERROR("bind plugin: I don't have a CURL object.");
1591 bind_buffer_fill = 0;
1592 if (curl_easy_perform(curl) != CURLE_OK) {
1593 ERROR("bind plugin: curl_easy_perform failed: %s", bind_curl_error);
1597 status = bind_xml(bind_buffer);
1602 } /* }}} int bind_read */
1604 static int bind_shutdown(void) /* {{{ */
1607 curl_easy_cleanup(curl);
1612 } /* }}} int bind_shutdown */
1614 void module_register(void) {
1615 plugin_register_complex_config("bind", bind_config);
1616 plugin_register_init("bind", bind_init);
1617 plugin_register_read("bind", bind_read);
1618 plugin_register_shutdown("bind", bind_shutdown);
1619 } /* void module_register */
1621 /* vim: set sw=2 sts=2 ts=8 et fdm=marker : */