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
33 # ifndef _XOPEN_SOURCE
34 # define _XOPEN_SOURCE 500
36 #endif /* STRPTIME_NEEDS_STANDARDS */
42 #include "configfile.h"
44 /* Some versions of libcurl don't include this themselves and then don't have
45 * fd_set available. */
47 # include <sys/select.h>
50 #include <curl/curl.h>
51 #include <libxml/parser.h>
52 #include <libxml/xpath.h>
54 #ifndef BIND_DEFAULT_URL
55 # define BIND_DEFAULT_URL "http://localhost:8053/"
59 * Some types used for the callback functions. `translation_table_ptr_t' and
60 * `list_info_ptr_t' are passed to the callbacks in the `void *user_data'
63 typedef int (*list_callback_t) (const char *name, value_t value,
64 time_t current_time, void *user_data);
77 typedef struct cb_view_s cb_view_t;
79 struct translation_info_s
83 const char *type_instance;
85 typedef struct translation_info_s translation_info_t;
87 struct translation_table_ptr_s
89 const translation_info_t *table;
91 const char *plugin_instance;
93 typedef struct translation_table_ptr_s translation_table_ptr_t;
95 struct list_info_ptr_s
97 const char *plugin_instance;
100 typedef struct list_info_ptr_s list_info_ptr_t;
102 /* FIXME: Enabled by default for backwards compatibility. */
103 /* TODO: Remove time parsing code. */
104 static _Bool config_parse_time = 1;
106 static char *url = NULL;
107 static int global_opcodes = 1;
108 static int global_qtypes = 1;
109 static int global_server_stats = 1;
110 static int global_zone_maint_stats = 1;
111 static int global_resolver_stats = 0;
112 static int global_memory_stats = 1;
113 static int timeout = -1;
115 static cb_view_t *views = NULL;
116 static size_t views_num = 0;
118 static CURL *curl = NULL;
120 static char *bind_buffer = NULL;
121 static size_t bind_buffer_size = 0;
122 static size_t bind_buffer_fill = 0;
123 static char bind_curl_error[CURL_ERROR_SIZE];
125 /* Translation table for the `nsstats' values. */
126 static const translation_info_t nsstats_translation_table[] = /* {{{ */
129 { "Requestv4", "dns_request", "IPv4" },
130 { "Requestv6", "dns_request", "IPv6" },
131 { "ReqEdns0", "dns_request", "EDNS0" },
132 { "ReqBadEDNSVer", "dns_request", "BadEDNSVer" },
133 { "ReqTSIG", "dns_request", "TSIG" },
134 { "ReqSIG0", "dns_request", "SIG0" },
135 { "ReqBadSIG", "dns_request", "BadSIG" },
136 { "ReqTCP", "dns_request", "TCP" },
138 { "AuthQryRej", "dns_reject", "authorative" },
139 { "RecQryRej", "dns_reject", "recursive" },
140 { "XfrRej", "dns_reject", "transfer" },
141 { "UpdateRej", "dns_reject", "update" },
143 { "Response", "dns_response", "normal" },
144 { "TruncatedResp", "dns_response", "truncated" },
145 { "RespEDNS0", "dns_response", "EDNS0" },
146 { "RespTSIG", "dns_response", "TSIG" },
147 { "RespSIG0", "dns_response", "SIG0" },
149 { "QryAuthAns", "dns_query", "authorative" },
150 { "QryNoauthAns", "dns_query", "nonauth" },
151 { "QryReferral", "dns_query", "referral" },
152 { "QryRecursion", "dns_query", "recursion" },
153 { "QryDuplicate", "dns_query", "dupliate" },
154 { "QryDropped", "dns_query", "dropped" },
155 { "QryFailure", "dns_query", "failure" },
157 { "QrySuccess", "dns_rcode", "tx-NOERROR" },
158 { "QryNxrrset", "dns_rcode", "tx-NXRRSET" },
159 { "QrySERVFAIL", "dns_rcode", "tx-SERVFAIL" },
160 { "QryFORMERR", "dns_rcode", "tx-FORMERR" },
161 { "QryNXDOMAIN", "dns_rcode", "tx-NXDOMAIN" }
163 { "XfrReqDone", "type", "type_instance" },
164 { "UpdateReqFwd", "type", "type_instance" },
165 { "UpdateRespFwd", "type", "type_instance" },
166 { "UpdateFwdFail", "type", "type_instance" },
167 { "UpdateDone", "type", "type_instance" },
168 { "UpdateFail", "type", "type_instance" },
169 { "UpdateBadPrereq", "type", "type_instance" },
172 static int nsstats_translation_table_length =
173 STATIC_ARRAY_SIZE (nsstats_translation_table);
176 /* Translation table for the `zonestats' values. */
177 static const translation_info_t zonestats_translation_table[] = /* {{{ */
180 { "NotifyOutv4", "dns_notify", "tx-IPv4" },
181 { "NotifyOutv6", "dns_notify", "tx-IPv6" },
182 { "NotifyInv4", "dns_notify", "rx-IPv4" },
183 { "NotifyInv6", "dns_notify", "rx-IPv6" },
184 { "NotifyRej", "dns_notify", "rejected" },
185 /* SOA/AXFS/IXFS requests */
186 { "SOAOutv4", "dns_opcode", "SOA-IPv4" },
187 { "SOAOutv6", "dns_opcode", "SOA-IPv6" },
188 { "AXFRReqv4", "dns_opcode", "AXFR-IPv4" },
189 { "AXFRReqv6", "dns_opcode", "AXFR-IPv6" },
190 { "IXFRReqv4", "dns_opcode", "IXFR-IPv4" },
191 { "IXFRReqv6", "dns_opcode", "IXFR-IPv6" },
192 /* Domain transfers */
193 { "XfrSuccess", "dns_transfer", "success" },
194 { "XfrFail", "dns_transfer", "failure" }
196 static int zonestats_translation_table_length =
197 STATIC_ARRAY_SIZE (zonestats_translation_table);
200 /* Translation table for the `resstats' values. */
201 static const translation_info_t resstats_translation_table[] = /* {{{ */
203 /* Generic resolver information */
204 { "Queryv4", "dns_query", "IPv4" },
205 { "Queryv6", "dns_query", "IPv6" },
206 { "Responsev4", "dns_response", "IPv4" },
207 { "Responsev6", "dns_response", "IPv6" },
208 /* Received response codes */
209 { "NXDOMAIN", "dns_rcode", "rx-NXDOMAIN" },
210 { "SERVFAIL", "dns_rcode", "rx-SERVFAIL" },
211 { "FORMERR", "dns_rcode", "rx-FORMERR" },
212 { "OtherError", "dns_rcode", "rx-OTHER" },
213 { "EDNS0Fail", "dns_rcode", "rx-EDNS0Fail"},
214 /* Received responses */
215 { "Mismatch", "dns_response", "mismatch" },
216 { "Truncated", "dns_response", "truncated" },
217 { "Lame", "dns_response", "lame" },
218 { "Retry", "dns_query", "retry" },
220 { "GlueFetchv4", "type", "type_instance" },
221 { "GlueFetchv6", "type", "type_instance" },
222 { "GlueFetchv4Fail", "type", "type_instance" },
223 { "GlueFetchv6Fail", "type", "type_instance" },
225 /* DNSSEC information */
226 { "ValAttempt", "dns_resolver", "DNSSEC-attempt" },
227 { "ValOk", "dns_resolver", "DNSSEC-okay" },
228 { "ValNegOk", "dns_resolver", "DNSSEC-negokay" },
229 { "ValFail", "dns_resolver", "DNSSEC-fail" }
231 static int resstats_translation_table_length =
232 STATIC_ARRAY_SIZE (resstats_translation_table);
235 /* Translation table for the `memory/summary' values. */
236 static const translation_info_t memsummary_translation_table[] = /* {{{ */
238 { "TotalUse", "memory", "TotalUse" },
239 { "InUse", "memory", "InUse" },
240 { "BlockSize", "memory", "BlockSize" },
241 { "ContextSize", "memory", "ContextSize" },
242 { "Lost", "memory", "Lost" }
244 static int memsummary_translation_table_length =
245 STATIC_ARRAY_SIZE (memsummary_translation_table);
248 static void submit (time_t ts, const char *plugin_instance, /* {{{ */
249 const char *type, const char *type_instance, value_t value)
252 value_list_t vl = VALUE_LIST_INIT;
258 if (config_parse_time)
259 vl.time = TIME_T_TO_CDTIME_T (ts);
260 sstrncpy(vl.host, hostname_g, sizeof(vl.host));
261 sstrncpy(vl.plugin, "bind", sizeof(vl.plugin));
262 if (plugin_instance) {
263 sstrncpy(vl.plugin_instance, plugin_instance,
264 sizeof(vl.plugin_instance));
265 replace_special (vl.plugin_instance, sizeof (vl.plugin_instance));
267 sstrncpy(vl.type, type, sizeof(vl.type));
269 sstrncpy(vl.type_instance, type_instance,
270 sizeof(vl.type_instance));
271 replace_special (vl.type_instance, sizeof (vl.type_instance));
273 plugin_dispatch_values(&vl);
274 } /* }}} void submit */
276 static size_t bind_curl_callback (void *buf, size_t size, /* {{{ */
277 size_t nmemb, void __attribute__((unused)) *stream)
279 size_t len = size * nmemb;
284 if ((bind_buffer_fill + len) >= bind_buffer_size)
288 temp = realloc (bind_buffer, bind_buffer_fill + len + 1);
291 ERROR ("bind plugin: realloc failed.");
295 bind_buffer_size = bind_buffer_fill + len + 1;
298 memcpy (bind_buffer + bind_buffer_fill, (char *) buf, len);
299 bind_buffer_fill += len;
300 bind_buffer[bind_buffer_fill] = 0;
303 } /* }}} size_t bind_curl_callback */
306 * Callback, that's called with a translation table.
307 * (Plugin instance is fixed, type and type instance come from lookup table.)
309 static int bind_xml_table_callback (const char *name, value_t value, /* {{{ */
310 time_t current_time, void *user_data)
312 translation_table_ptr_t *table = (translation_table_ptr_t *) user_data;
317 for (size_t i = 0; i < table->table_length; i++)
319 if (strcmp (table->table[i].xml_name, name) != 0)
322 submit (current_time,
323 table->plugin_instance,
324 table->table[i].type,
325 table->table[i].type_instance,
331 } /* }}} int bind_xml_table_callback */
334 * Callback, that's used for lists.
335 * (Plugin instance and type are fixed, xml name is used as type instance.)
337 static int bind_xml_list_callback (const char *name, /* {{{ */
338 value_t value, time_t current_time, void *user_data)
340 list_info_ptr_t *list_info = (list_info_ptr_t *) user_data;
342 if (list_info == NULL)
345 submit (current_time,
346 list_info->plugin_instance,
348 /* type instance = */ name,
352 } /* }}} int bind_xml_list_callback */
354 static int bind_xml_read_derive (xmlDoc *doc, xmlNode *node, /* {{{ */
361 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
364 ERROR ("bind plugin: bind_xml_read_derive: xmlNodeListGetString failed.");
368 status = parse_value (str_ptr, &value, DS_TYPE_DERIVE);
371 ERROR ("bind plugin: Parsing string \"%s\" to derive value failed.",
378 *ret_value = value.derive;
380 } /* }}} int bind_xml_read_derive */
382 static int bind_xml_read_gauge (xmlDoc *doc, xmlNode *node, /* {{{ */
385 char *str_ptr, *end_ptr;
388 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
391 ERROR ("bind plugin: bind_xml_read_gauge: xmlNodeListGetString failed.");
396 value = strtod (str_ptr, &end_ptr);
398 if (str_ptr == end_ptr || errno)
400 if (errno && (value < 0))
401 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed with underflow.");
402 else if (errno && (value > 0))
403 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed with overflow.");
405 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed.");
409 *ret_value = (gauge_t) value;
411 } /* }}} int bind_xml_read_gauge */
413 static int bind_xml_read_timestamp (const char *xpath_expression, /* {{{ */
414 xmlDoc *doc, xmlXPathContext *xpathCtx, time_t *ret_value)
416 xmlXPathObject *xpathObj = NULL;
420 struct tm tm = { 0 };
422 xpathObj = xmlXPathEvalExpression (BAD_CAST xpath_expression, xpathCtx);
423 if (xpathObj == NULL)
425 ERROR ("bind plugin: Unable to evaluate XPath expression `%s'.",
430 if ((xpathObj->nodesetval == NULL) || (xpathObj->nodesetval->nodeNr < 1))
432 xmlXPathFreeObject (xpathObj);
436 if (xpathObj->nodesetval->nodeNr != 1)
438 NOTICE ("bind plugin: Evaluating the XPath expression `%s' returned "
439 "%i nodes. Only handling the first one.",
440 xpath_expression, xpathObj->nodesetval->nodeNr);
443 node = xpathObj->nodesetval->nodeTab[0];
445 if (node->xmlChildrenNode == NULL)
447 ERROR ("bind plugin: bind_xml_read_timestamp: "
448 "node->xmlChildrenNode == NULL");
449 xmlXPathFreeObject (xpathObj);
453 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
456 ERROR ("bind plugin: bind_xml_read_timestamp: xmlNodeListGetString failed.");
457 xmlXPathFreeObject (xpathObj);
461 tmp = strptime (str_ptr, "%Y-%m-%dT%T", &tm);
465 ERROR ("bind plugin: bind_xml_read_timestamp: strptime failed.");
466 xmlXPathFreeObject (xpathObj);
470 *ret_value = mktime(&tm);
472 xmlXPathFreeObject (xpathObj);
474 } /* }}} int bind_xml_read_timestamp */
477 * bind_parse_generic_name_value
479 * Reads statistics in the form:
482 * <counter>123</counter>
485 static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ */
486 list_callback_t list_callback,
488 xmlDoc *doc, xmlXPathContext *xpathCtx,
489 time_t current_time, int ds_type)
491 xmlXPathObject *xpathObj = NULL;
494 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
495 if (xpathObj == NULL)
497 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
503 /* Iterate over all matching nodes. */
504 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
506 xmlNode *name_node = NULL;
507 xmlNode *counter = NULL;
510 parent = xpathObj->nodesetval->nodeTab[i];
511 DEBUG ("bind plugin: bind_parse_generic_name_value: parent->name = %s;",
512 (char *) parent->name);
514 /* Iterate over all child nodes. */
515 for (xmlNode *child = parent->xmlChildrenNode;
519 if (child->type != XML_ELEMENT_NODE)
522 if (xmlStrcmp (BAD_CAST "name", child->name) == 0)
524 else if (xmlStrcmp (BAD_CAST "counter", child->name) == 0)
528 if ((name_node != NULL) && (counter != NULL))
530 char *name = (char *) xmlNodeListGetString (doc,
531 name_node->xmlChildrenNode, 1);
535 if (ds_type == DS_TYPE_GAUGE)
536 status = bind_xml_read_gauge (doc, counter, &value.gauge);
538 status = bind_xml_read_derive (doc, counter, &value.derive);
542 status = (*list_callback) (name, value, current_time, user_data);
550 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
551 num_entries, (num_entries == 1) ? "entry" : "entries",
554 xmlXPathFreeObject(xpathObj);
557 } /* }}} int bind_parse_generic_name_value */
560 * bind_parse_generic_value_list
562 * Reads statistics in the form:
570 static int bind_parse_generic_value_list (const char *xpath_expression, /* {{{ */
571 list_callback_t list_callback,
573 xmlDoc *doc, xmlXPathContext *xpathCtx,
574 time_t current_time, int ds_type)
576 xmlXPathObject *xpathObj = NULL;
579 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
580 if (xpathObj == NULL)
582 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
588 /* Iterate over all matching nodes. */
589 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
591 /* Iterate over all child nodes. */
592 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
600 if (child->type != XML_ELEMENT_NODE)
603 node_name = (char *) child->name;
605 if (ds_type == DS_TYPE_GAUGE)
606 status = bind_xml_read_gauge (doc, child, &value.gauge);
608 status = bind_xml_read_derive (doc, child, &value.derive);
612 status = (*list_callback) (node_name, value, current_time, user_data);
618 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
619 num_entries, (num_entries == 1) ? "entry" : "entries",
622 xmlXPathFreeObject(xpathObj);
625 } /* }}} int bind_parse_generic_value_list */
628 * bind_parse_generic_name_attr_value_list
630 * Reads statistics in the form:
632 * <counter name="name0">123</counter>
633 * <counter name="name1">234</counter>
634 * <counter name="name2">345</counter>
638 static int bind_parse_generic_name_attr_value_list (const char *xpath_expression, /* {{{ */
639 list_callback_t list_callback,
641 xmlDoc *doc, xmlXPathContext *xpathCtx,
642 time_t current_time, int ds_type)
644 xmlXPathObject *xpathObj = NULL;
647 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
648 if (xpathObj == NULL)
650 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
656 /* Iterate over all matching nodes. */
657 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
659 /* Iterate over all child nodes. */
660 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
664 if (child->type != XML_ELEMENT_NODE)
667 if (strncmp ("counter", (char *) child->name, strlen ("counter")) != 0)
674 attr_name = (char *) xmlGetProp (child, BAD_CAST "name");
675 if (attr_name == NULL)
677 DEBUG ("bind plugin: found <counter> without name.");
680 if (ds_type == DS_TYPE_GAUGE)
681 status = bind_xml_read_gauge (doc, child, &value.gauge);
683 status = bind_xml_read_derive (doc, child, &value.derive);
687 status = (*list_callback) (attr_name, value, current_time, user_data);
693 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
694 num_entries, (num_entries == 1) ? "entry" : "entries",
697 xmlXPathFreeObject(xpathObj);
700 } /* }}} int bind_parse_generic_name_attr_value_list */
702 static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */
703 xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view,
706 xmlXPathObject *path_obj;
707 char *zone_name = NULL;
712 char *n = (char *) xmlGetProp (node, BAD_CAST "name");
713 char *c = (char *) xmlGetProp (node, BAD_CAST "rdataclass");
716 zone_name = (char *) xmlMalloc(strlen(n) + strlen(c) + 2);
717 snprintf(zone_name, strlen(n) + strlen(c) + 2, "%s/%s", n, c);
724 path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
725 if (path_obj == NULL)
727 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
731 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
733 zone_name = (char *) xmlNodeListGetString (doc,
734 path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
735 if (zone_name != NULL)
738 xmlXPathFreeObject (path_obj);
741 if (zone_name == NULL)
743 ERROR ("bind plugin: Could not determine zone name.");
747 for (j = 0; j < view->zones_num; j++)
749 if (strcasecmp (zone_name, view->zones[j]) == 0)
756 if (j >= view->zones_num)
759 zone_name = view->zones[j];
761 DEBUG ("bind plugin: bind_xml_stats_handle_zone: Found zone `%s'.",
764 { /* Parse the <counters> tag {{{ */
765 char plugin_instance[DATA_MAX_NAME_LEN];
766 translation_table_ptr_t table_ptr =
768 nsstats_translation_table,
769 nsstats_translation_table_length,
773 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-zone-%s",
774 view->name, zone_name);
778 list_info_ptr_t list_info =
781 /* type = */ "dns_qtype"
783 bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='rcode']",
784 /* callback = */ bind_xml_table_callback,
785 /* user_data = */ &table_ptr,
786 doc, path_ctx, current_time, DS_TYPE_COUNTER);
787 bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='qtype']",
788 /* callback = */ bind_xml_list_callback,
789 /* user_data = */ &list_info,
790 doc, path_ctx, current_time, DS_TYPE_COUNTER);
794 bind_parse_generic_value_list (/* xpath = */ "counters",
795 /* callback = */ bind_xml_table_callback,
796 /* user_data = */ &table_ptr,
797 doc, path_ctx, current_time, DS_TYPE_COUNTER);
802 } /* }}} int bind_xml_stats_handle_zone */
804 static int bind_xml_stats_search_zones (int version, xmlDoc *doc, /* {{{ */
805 xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view,
808 xmlXPathObject *zone_nodes = NULL;
809 xmlXPathContext *zone_path_context;
811 zone_path_context = xmlXPathNewContext (doc);
812 if (zone_path_context == NULL)
814 ERROR ("bind plugin: xmlXPathNewContext failed.");
818 zone_nodes = xmlXPathEvalExpression (BAD_CAST "zones/zone", path_ctx);
819 if (zone_nodes == NULL)
821 ERROR ("bind plugin: Cannot find any <view> tags.");
822 xmlXPathFreeContext (zone_path_context);
826 for (int i = 0; i < zone_nodes->nodesetval->nodeNr; i++)
828 node = zone_nodes->nodesetval->nodeTab[i];
829 assert (node != NULL);
831 zone_path_context->node = node;
833 bind_xml_stats_handle_zone (version, doc, zone_path_context, node, view,
837 xmlXPathFreeObject (zone_nodes);
838 xmlXPathFreeContext (zone_path_context);
840 } /* }}} int bind_xml_stats_search_zones */
842 static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */
843 xmlXPathContext *path_ctx, xmlNode *node, time_t current_time)
845 char *view_name = NULL;
851 view_name = (char*) xmlGetProp(node, BAD_CAST "name");
853 if (view_name == NULL)
855 ERROR ("bind plugin: Could not determine view name.");
859 for (j = 0; j < views_num; j++)
861 if (strcasecmp (view_name, views[j].name) == 0)
870 xmlXPathObject *path_obj;
871 path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
872 if (path_obj == NULL)
874 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
878 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
880 view_name = (char *) xmlNodeListGetString (doc,
881 path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
882 if (view_name != NULL)
886 if (view_name == NULL)
888 ERROR ("bind plugin: Could not determine view name.");
889 xmlXPathFreeObject (path_obj);
893 for (j = 0; j < views_num; j++)
895 if (strcasecmp (view_name, views[j].name) == 0)
900 xmlXPathFreeObject (path_obj);
912 DEBUG ("bind plugin: bind_xml_stats_handle_view: Found view `%s'.",
915 if (view->qtypes != 0) /* {{{ */
917 char plugin_instance[DATA_MAX_NAME_LEN];
918 list_info_ptr_t list_info =
921 /* type = */ "dns_qtype"
924 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-qtypes",
928 bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='resqtype']",
929 /* callback = */ bind_xml_list_callback,
930 /* user_data = */ &list_info,
931 doc, path_ctx, current_time, DS_TYPE_COUNTER);
935 bind_parse_generic_name_value (/* xpath = */ "rdtype",
936 /* callback = */ bind_xml_list_callback,
937 /* user_data = */ &list_info,
938 doc, path_ctx, current_time, DS_TYPE_COUNTER);
942 if (view->resolver_stats != 0) /* {{{ */
944 char plugin_instance[DATA_MAX_NAME_LEN];
945 translation_table_ptr_t table_ptr =
947 resstats_translation_table,
948 resstats_translation_table_length,
952 ssnprintf (plugin_instance, sizeof (plugin_instance),
953 "%s-resolver_stats", view->name);
956 bind_parse_generic_name_attr_value_list ("counters[@type='resstats']",
957 /* callback = */ bind_xml_table_callback,
958 /* user_data = */ &table_ptr,
959 doc, path_ctx, current_time, DS_TYPE_COUNTER);
963 bind_parse_generic_name_value ("resstat",
964 /* callback = */ bind_xml_table_callback,
965 /* user_data = */ &table_ptr,
966 doc, path_ctx, current_time, DS_TYPE_COUNTER);
970 /* Record types in the cache */
971 if (view->cacherrsets != 0) /* {{{ */
973 char plugin_instance[DATA_MAX_NAME_LEN];
974 list_info_ptr_t list_info =
977 /* type = */ "dns_qtype_cached"
980 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-cache_rr_sets",
983 bind_parse_generic_name_value (/* xpath = */ "cache/rrset",
984 /* callback = */ bind_xml_list_callback,
985 /* user_data = */ &list_info,
986 doc, path_ctx, current_time, DS_TYPE_GAUGE);
989 if (view->zones_num > 0)
990 bind_xml_stats_search_zones (version, doc, path_ctx, node, view,
994 } /* }}} int bind_xml_stats_handle_view */
996 static int bind_xml_stats_search_views (int version, xmlDoc *doc, /* {{{ */
997 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
999 xmlXPathObject *view_nodes = NULL;
1000 xmlXPathContext *view_path_context;
1002 view_path_context = xmlXPathNewContext (doc);
1003 if (view_path_context == NULL)
1005 ERROR ("bind plugin: xmlXPathNewContext failed.");
1009 view_nodes = xmlXPathEvalExpression (BAD_CAST "views/view", xpathCtx);
1010 if (view_nodes == NULL)
1012 ERROR ("bind plugin: Cannot find any <view> tags.");
1013 xmlXPathFreeContext (view_path_context);
1017 for (int i = 0; i < view_nodes->nodesetval->nodeNr; i++)
1021 node = view_nodes->nodesetval->nodeTab[i];
1022 assert (node != NULL);
1024 view_path_context->node = node;
1026 bind_xml_stats_handle_view (version, doc, view_path_context, node,
1030 xmlXPathFreeObject (view_nodes);
1031 xmlXPathFreeContext (view_path_context);
1033 } /* }}} int bind_xml_stats_search_views */
1035 static void bind_xml_stats_v3 (xmlDoc *doc, /* {{{ */
1036 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
1038 /* XPath: server/counters[@type='opcode']
1039 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1041 * <counters type="opcode">
1042 * <counter name="A">1</counter>
1046 if (global_opcodes != 0)
1048 list_info_ptr_t list_info =
1050 /* plugin instance = */ "global-opcodes",
1051 /* type = */ "dns_opcode"
1053 bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='opcode']",
1054 /* callback = */ bind_xml_list_callback,
1055 /* user_data = */ &list_info,
1056 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1059 /* XPath: server/counters[@type='qtype']
1060 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1061 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1062 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1064 * <counters type="opcode">
1065 * <counter name="A">1</counter>
1069 if (global_qtypes != 0)
1071 list_info_ptr_t list_info =
1073 /* plugin instance = */ "global-qtypes",
1074 /* type = */ "dns_qtype"
1077 bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='qtype']",
1078 /* callback = */ bind_xml_list_callback,
1079 /* user_data = */ &list_info,
1080 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1083 /* XPath: server/counters[@type='nsstat']
1084 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1085 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1086 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1087 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1088 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1089 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1090 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1093 * <counters type="nsstat"
1094 * <counter name="Requestv4">1</counter>
1095 * <counter name="Requestv6">0</counter>
1099 if (global_server_stats)
1101 translation_table_ptr_t table_ptr =
1103 nsstats_translation_table,
1104 nsstats_translation_table_length,
1105 /* plugin_instance = */ "global-server_stats"
1108 bind_parse_generic_name_attr_value_list ("server/counters[@type='nsstat']",
1109 /* callback = */ bind_xml_table_callback,
1110 /* user_data = */ &table_ptr,
1111 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1114 /* XPath: server/zonestats, server/zonestat, server/counters[@type='zonestat']
1115 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1116 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1117 * XfrSuccess, XfrFail
1119 * <counters type="zonestat"
1120 * <counter name="NotifyOutv4">0</counter>
1121 * <counter name="NotifyOutv6">0</counter>
1125 if (global_zone_maint_stats)
1127 translation_table_ptr_t table_ptr =
1129 zonestats_translation_table,
1130 zonestats_translation_table_length,
1131 /* plugin_instance = */ "global-zone_maint_stats"
1134 bind_parse_generic_name_attr_value_list ("server/counters[@type='zonestat']",
1135 /* callback = */ bind_xml_table_callback,
1136 /* user_data = */ &table_ptr,
1137 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1140 /* XPath: server/resstats, server/counters[@type='resstat']
1141 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1142 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1143 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1144 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1146 * <counters type="resstat"
1147 * <counter name="Queryv4">0</counter>
1148 * <counter name="Queryv6">0</counter>
1152 if (global_resolver_stats != 0)
1154 translation_table_ptr_t table_ptr =
1156 resstats_translation_table,
1157 resstats_translation_table_length,
1158 /* plugin_instance = */ "global-resolver_stats"
1161 bind_parse_generic_name_attr_value_list ("server/counters[@type='resstat']",
1162 /* callback = */ bind_xml_table_callback,
1163 /* user_data = */ &table_ptr,
1164 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1166 } /* }}} bind_xml_stats_v3 */
1168 static void bind_xml_stats_v1_v2 (int version, xmlDoc *doc, /* {{{ */
1169 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
1171 /* XPath: server/requests/opcode, server/counters[@type='opcode']
1172 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1176 * <counter>1</counter>
1180 if (global_opcodes != 0)
1182 list_info_ptr_t list_info =
1184 /* plugin instance = */ "global-opcodes",
1185 /* type = */ "dns_opcode"
1188 bind_parse_generic_name_value (/* xpath = */ "server/requests/opcode",
1189 /* callback = */ bind_xml_list_callback,
1190 /* user_data = */ &list_info,
1191 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1194 /* XPath: server/queries-in/rdtype, server/counters[@type='qtype']
1195 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1196 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1197 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1201 * <counter>1</counter>
1205 if (global_qtypes != 0)
1207 list_info_ptr_t list_info =
1209 /* plugin instance = */ "global-qtypes",
1210 /* type = */ "dns_qtype"
1213 bind_parse_generic_name_value (/* xpath = */ "server/queries-in/rdtype",
1214 /* callback = */ bind_xml_list_callback,
1215 /* user_data = */ &list_info,
1216 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1219 /* XPath: server/nsstats, server/nsstat, server/counters[@type='nsstat']
1220 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1221 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1222 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1223 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1224 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1225 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1226 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1230 * <Requestv4>1</Requestv4>
1231 * <Requestv6>0</Requestv6>
1236 * <name>Requestv4</name>
1237 * <counter>1</counter>
1240 * <name>Requestv6</name>
1241 * <counter>0</counter>
1245 if (global_server_stats)
1247 translation_table_ptr_t table_ptr =
1249 nsstats_translation_table,
1250 nsstats_translation_table_length,
1251 /* plugin_instance = */ "global-server_stats"
1256 bind_parse_generic_value_list ("server/nsstats",
1257 /* callback = */ bind_xml_table_callback,
1258 /* user_data = */ &table_ptr,
1259 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1263 bind_parse_generic_name_value ("server/nsstat",
1264 /* callback = */ bind_xml_table_callback,
1265 /* user_data = */ &table_ptr,
1266 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1270 /* XPath: server/zonestats, server/zonestat, server/counters[@type='zonestat']
1271 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1272 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1273 * XfrSuccess, XfrFail
1276 * <NotifyOutv4>0</NotifyOutv4>
1277 * <NotifyOutv6>0</NotifyOutv6>
1282 * <name>NotifyOutv4</name>
1283 * <counter>0</counter>
1286 * <name>NotifyOutv6</name>
1287 * <counter>0</counter>
1291 if (global_zone_maint_stats)
1293 translation_table_ptr_t table_ptr =
1295 zonestats_translation_table,
1296 zonestats_translation_table_length,
1297 /* plugin_instance = */ "global-zone_maint_stats"
1302 bind_parse_generic_value_list ("server/zonestats",
1303 /* callback = */ bind_xml_table_callback,
1304 /* user_data = */ &table_ptr,
1305 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1309 bind_parse_generic_name_value ("server/zonestat",
1310 /* callback = */ bind_xml_table_callback,
1311 /* user_data = */ &table_ptr,
1312 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1316 /* XPath: server/resstats, server/counters[@type='resstat']
1317 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1318 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1319 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1320 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1323 * <Queryv4>0</Queryv4>
1324 * <Queryv6>0</Queryv6>
1329 * <name>Queryv4</name>
1330 * <counter>0</counter>
1333 * <name>Queryv6</name>
1334 * <counter>0</counter>
1338 if (global_resolver_stats != 0)
1340 translation_table_ptr_t table_ptr =
1342 resstats_translation_table,
1343 resstats_translation_table_length,
1344 /* plugin_instance = */ "global-resolver_stats"
1349 bind_parse_generic_value_list ("server/resstats",
1350 /* callback = */ bind_xml_table_callback,
1351 /* user_data = */ &table_ptr,
1352 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1356 bind_parse_generic_name_value ("server/resstat",
1357 /* callback = */ bind_xml_table_callback,
1358 /* user_data = */ &table_ptr,
1359 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1362 } /* }}} bind_xml_stats_v1_v2 */
1364 static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
1365 xmlXPathContext *xpathCtx, xmlNode *statsnode)
1367 time_t current_time = 0;
1370 xpathCtx->node = statsnode;
1372 /* TODO: Check `server/boot-time' to recognize server restarts. */
1374 status = bind_xml_read_timestamp ("server/current-time",
1375 doc, xpathCtx, ¤t_time);
1378 ERROR ("bind plugin: Reading `server/current-time' failed.");
1381 DEBUG ("bind plugin: Current server time is %i.", (int) current_time);
1385 bind_xml_stats_v3(doc, xpathCtx, statsnode, current_time);
1389 bind_xml_stats_v1_v2(version, doc, xpathCtx, statsnode, current_time);
1392 /* XPath: memory/summary
1393 * Variables: TotalUse, InUse, BlockSize, ContextSize, Lost
1394 * Layout: v2 and v3:
1396 * <TotalUse>6587096</TotalUse>
1397 * <InUse>1345424</InUse>
1398 * <BlockSize>5505024</BlockSize>
1399 * <ContextSize>3732456</ContextSize>
1403 if (global_memory_stats != 0)
1405 translation_table_ptr_t table_ptr =
1407 memsummary_translation_table,
1408 memsummary_translation_table_length,
1409 /* plugin_instance = */ "global-memory_stats"
1412 bind_parse_generic_value_list ("memory/summary",
1413 /* callback = */ bind_xml_table_callback,
1414 /* user_data = */ &table_ptr,
1415 doc, xpathCtx, current_time, DS_TYPE_GAUGE);
1419 bind_xml_stats_search_views (version, doc, xpathCtx, statsnode,
1423 } /* }}} int bind_xml_stats */
1425 static int bind_xml (const char *data) /* {{{ */
1428 xmlXPathContext *xpathCtx = NULL;
1429 xmlXPathObject *xpathObj = NULL;
1432 doc = xmlParseMemory (data, strlen (data));
1435 ERROR ("bind plugin: xmlParseMemory failed.");
1439 xpathCtx = xmlXPathNewContext (doc);
1440 if (xpathCtx == NULL)
1442 ERROR ("bind plugin: xmlXPathNewContext failed.");
1448 // version 3.* of statistics XML (since BIND9.9)
1451 xpathObj = xmlXPathEvalExpression (BAD_CAST "/statistics", xpathCtx);
1452 if (xpathObj == NULL || xpathObj->nodesetval == NULL || xpathObj->nodesetval->nodeNr == 0)
1454 DEBUG ("bind plugin: Statistics appears not to be v3");
1455 // we will fallback to v1 or v2 detection
1456 if (xpathObj != NULL) { xmlXPathFreeObject (xpathObj); }
1460 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++)
1465 node = xpathObj->nodesetval->nodeTab[i];
1466 assert (node != NULL);
1468 attr_version = (char *) xmlGetProp (node, BAD_CAST "version");
1469 if (attr_version == NULL)
1471 NOTICE ("bind plugin: Found <statistics> tag doesn't have a "
1472 "`version' attribute.");
1475 DEBUG ("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1477 if (strncmp ("3.", attr_version, strlen ("3.")) != 0)
1479 /* TODO: Use the complaint mechanism here. */
1480 NOTICE ("bind plugin: Found <statistics> tag with version `%s'. "
1481 "Unfortunately I have no clue how to parse that. "
1482 "Please open a bug report for this.", attr_version);
1483 xmlFree (attr_version);
1486 ret = bind_xml_stats (3, doc, xpathCtx, node);
1488 xmlFree (attr_version);
1489 /* One <statistics> node ought to be enough. */
1493 // we are finished, early-return
1494 xmlXPathFreeObject (xpathObj);
1495 xmlXPathFreeContext (xpathCtx);
1502 // versions 1.* or 2.* of statistics XML
1505 xpathObj = xmlXPathEvalExpression (BAD_CAST "/isc/bind/statistics", xpathCtx);
1506 if (xpathObj == NULL)
1508 ERROR ("bind plugin: Cannot find the <statistics> tag.");
1509 xmlXPathFreeContext (xpathCtx);
1513 else if (xpathObj->nodesetval == NULL)
1515 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
1516 xmlXPathFreeObject (xpathObj);
1517 xmlXPathFreeContext (xpathCtx);
1522 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++)
1526 int parsed_version = 0;
1528 node = xpathObj->nodesetval->nodeTab[i];
1529 assert (node != NULL);
1531 attr_version = (char *) xmlGetProp (node, BAD_CAST "version");
1532 if (attr_version == NULL)
1534 NOTICE ("bind plugin: Found <statistics> tag doesn't have a "
1535 "`version' attribute.");
1538 DEBUG ("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1540 /* At the time this plugin was written, version "1.0" was used by
1541 * BIND 9.5.0, version "2.0" was used by BIND 9.5.1 and 9.6.0. We assume
1542 * that "1.*" and "2.*" don't introduce structural changes, so we just
1543 * check for the first two characters here. */
1544 if (strncmp ("1.", attr_version, strlen ("1.")) == 0)
1546 else if (strncmp ("2.", attr_version, strlen ("2.")) == 0)
1550 /* TODO: Use the complaint mechanism here. */
1551 NOTICE ("bind plugin: Found <statistics> tag with version `%s'. "
1552 "Unfortunately I have no clue how to parse that. "
1553 "Please open a bug report for this.", attr_version);
1554 xmlFree (attr_version);
1558 ret = bind_xml_stats (parsed_version,
1559 doc, xpathCtx, node);
1561 xmlFree (attr_version);
1562 /* One <statistics> node ought to be enough. */
1566 xmlXPathFreeObject (xpathObj);
1567 xmlXPathFreeContext (xpathCtx);
1571 } /* }}} int bind_xml */
1573 static int bind_config_set_bool (const char *name, int *var, /* {{{ */
1576 if ((ci->values_num != 1) || ( ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1578 WARNING ("bind plugin: The `%s' option needs "
1579 "exactly one boolean argument.", name);
1583 if (ci->values[0].value.boolean)
1588 } /* }}} int bind_config_set_bool */
1590 static int bind_config_add_view_zone (cb_view_t *view, /* {{{ */
1595 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1597 WARNING ("bind plugin: The `Zone' option needs "
1598 "exactly one string argument.");
1602 tmp = realloc (view->zones,
1603 sizeof (char *) * (view->zones_num + 1));
1606 ERROR ("bind plugin: realloc failed.");
1611 view->zones[view->zones_num] = strdup (ci->values[0].value.string);
1612 if (view->zones[view->zones_num] == NULL)
1614 ERROR ("bind plugin: strdup failed.");
1620 } /* }}} int bind_config_add_view_zone */
1622 static int bind_config_add_view (oconfig_item_t *ci) /* {{{ */
1626 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1628 WARNING ("bind plugin: `View' blocks need exactly one string argument.");
1632 tmp = realloc (views, sizeof (*views) * (views_num + 1));
1635 ERROR ("bind plugin: realloc failed.");
1639 tmp = views + views_num;
1641 memset (tmp, 0, sizeof (*tmp));
1643 tmp->resolver_stats = 1;
1644 tmp->cacherrsets = 1;
1648 tmp->name = strdup (ci->values[0].value.string);
1649 if (tmp->name == NULL)
1651 ERROR ("bind plugin: strdup failed.");
1656 for (int i = 0; i < ci->children_num; i++)
1658 oconfig_item_t *child = ci->children + i;
1660 if (strcasecmp ("QTypes", child->key) == 0)
1661 bind_config_set_bool ("QTypes", &tmp->qtypes, child);
1662 else if (strcasecmp ("ResolverStats", child->key) == 0)
1663 bind_config_set_bool ("ResolverStats", &tmp->resolver_stats, child);
1664 else if (strcasecmp ("CacheRRSets", child->key) == 0)
1665 bind_config_set_bool ("CacheRRSets", &tmp->cacherrsets, child);
1666 else if (strcasecmp ("Zone", child->key) == 0)
1667 bind_config_add_view_zone (tmp, child);
1670 WARNING ("bind plugin: Unknown configuration option "
1671 "`%s' in view `%s' will be ignored.", child->key, tmp->name);
1673 } /* for (i = 0; i < ci->children_num; i++) */
1677 } /* }}} int bind_config_add_view */
1679 static int bind_config (oconfig_item_t *ci) /* {{{ */
1681 for (int i = 0; i < ci->children_num; i++)
1683 oconfig_item_t *child = ci->children + i;
1685 if (strcasecmp ("Url", child->key) == 0) {
1686 if ((child->values_num != 1) || (child->values[0].type != OCONFIG_TYPE_STRING))
1688 WARNING ("bind plugin: The `Url' option needs "
1689 "exactly one string argument.");
1694 url = strdup (child->values[0].value.string);
1695 } else if (strcasecmp ("OpCodes", child->key) == 0)
1696 bind_config_set_bool ("OpCodes", &global_opcodes, child);
1697 else if (strcasecmp ("QTypes", child->key) == 0)
1698 bind_config_set_bool ("QTypes", &global_qtypes, child);
1699 else if (strcasecmp ("ServerStats", child->key) == 0)
1700 bind_config_set_bool ("ServerStats", &global_server_stats, child);
1701 else if (strcasecmp ("ZoneMaintStats", child->key) == 0)
1702 bind_config_set_bool ("ZoneMaintStats", &global_zone_maint_stats, child);
1703 else if (strcasecmp ("ResolverStats", child->key) == 0)
1704 bind_config_set_bool ("ResolverStats", &global_resolver_stats, child);
1705 else if (strcasecmp ("MemoryStats", child->key) == 0)
1706 bind_config_set_bool ("MemoryStats", &global_memory_stats, child);
1707 else if (strcasecmp ("View", child->key) == 0)
1708 bind_config_add_view (child);
1709 else if (strcasecmp ("ParseTime", child->key) == 0)
1710 cf_util_get_boolean (child, &config_parse_time);
1711 else if (strcasecmp ("Timeout", child->key) == 0)
1712 cf_util_get_int (child, &timeout);
1715 WARNING ("bind plugin: Unknown configuration option "
1716 "`%s' will be ignored.", child->key);
1721 } /* }}} int bind_config */
1723 static int bind_init (void) /* {{{ */
1728 curl = curl_easy_init ();
1731 ERROR ("bind plugin: bind_init: curl_easy_init failed.");
1735 curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1L);
1736 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
1737 curl_easy_setopt (curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
1738 curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, bind_curl_error);
1739 curl_easy_setopt (curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
1740 curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L);
1741 curl_easy_setopt (curl, CURLOPT_MAXREDIRS, 50L);
1742 #ifdef HAVE_CURLOPT_TIMEOUT_MS
1743 curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, (timeout >= 0) ?
1744 (long) timeout : (long) CDTIME_T_TO_MS(plugin_get_interval()));
1749 } /* }}} int bind_init */
1751 static int bind_read (void) /* {{{ */
1757 ERROR ("bind plugin: I don't have a CURL object.");
1761 bind_buffer_fill = 0;
1762 if (curl_easy_perform (curl) != CURLE_OK)
1764 ERROR ("bind plugin: curl_easy_perform failed: %s",
1769 status = bind_xml (bind_buffer);
1774 } /* }}} int bind_read */
1776 static int bind_shutdown (void) /* {{{ */
1780 curl_easy_cleanup (curl);
1785 } /* }}} int bind_shutdown */
1787 void module_register (void)
1789 plugin_register_complex_config ("bind", bind_config);
1790 plugin_register_init ("bind", bind_init);
1791 plugin_register_read ("bind", bind_read);
1792 plugin_register_shutdown ("bind", bind_shutdown);
1793 } /* void module_register */
1795 /* vim: set sw=2 sts=2 ts=8 et fdm=marker : */