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 */
41 #include "configfile.h"
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);
76 typedef struct cb_view_s cb_view_t;
78 struct translation_info_s
82 const char *type_instance;
84 typedef struct translation_info_s translation_info_t;
86 struct translation_table_ptr_s
88 const translation_info_t *table;
90 const char *plugin_instance;
92 typedef struct translation_table_ptr_s translation_table_ptr_t;
94 struct list_info_ptr_s
96 const char *plugin_instance;
99 typedef struct list_info_ptr_s list_info_ptr_t;
101 /* FIXME: Enabled by default for backwards compatibility. */
102 /* TODO: Remove time parsing code. */
103 static _Bool config_parse_time = 1;
105 static char *url = NULL;
106 static int global_opcodes = 1;
107 static int global_qtypes = 1;
108 static int global_server_stats = 1;
109 static int global_zone_maint_stats = 1;
110 static int global_resolver_stats = 0;
111 static int global_memory_stats = 1;
112 static int timeout = -1;
114 static cb_view_t *views = NULL;
115 static size_t views_num = 0;
117 static CURL *curl = NULL;
119 static char *bind_buffer = NULL;
120 static size_t bind_buffer_size = 0;
121 static size_t bind_buffer_fill = 0;
122 static char bind_curl_error[CURL_ERROR_SIZE];
124 /* Translation table for the `nsstats' values. */
125 static const translation_info_t nsstats_translation_table[] = /* {{{ */
128 { "Requestv4", "dns_request", "IPv4" },
129 { "Requestv6", "dns_request", "IPv6" },
130 { "ReqEdns0", "dns_request", "EDNS0" },
131 { "ReqBadEDNSVer", "dns_request", "BadEDNSVer" },
132 { "ReqTSIG", "dns_request", "TSIG" },
133 { "ReqSIG0", "dns_request", "SIG0" },
134 { "ReqBadSIG", "dns_request", "BadSIG" },
135 { "ReqTCP", "dns_request", "TCP" },
137 { "AuthQryRej", "dns_reject", "authorative" },
138 { "RecQryRej", "dns_reject", "recursive" },
139 { "XfrRej", "dns_reject", "transfer" },
140 { "UpdateRej", "dns_reject", "update" },
142 { "Response", "dns_response", "normal" },
143 { "TruncatedResp", "dns_response", "truncated" },
144 { "RespEDNS0", "dns_response", "EDNS0" },
145 { "RespTSIG", "dns_response", "TSIG" },
146 { "RespSIG0", "dns_response", "SIG0" },
148 { "QryAuthAns", "dns_query", "authorative" },
149 { "QryNoauthAns", "dns_query", "nonauth" },
150 { "QryReferral", "dns_query", "referral" },
151 { "QryRecursion", "dns_query", "recursion" },
152 { "QryDuplicate", "dns_query", "dupliate" },
153 { "QryDropped", "dns_query", "dropped" },
154 { "QryFailure", "dns_query", "failure" },
156 { "QrySuccess", "dns_rcode", "tx-NOERROR" },
157 { "QryNxrrset", "dns_rcode", "tx-NXRRSET" },
158 { "QrySERVFAIL", "dns_rcode", "tx-SERVFAIL" },
159 { "QryFORMERR", "dns_rcode", "tx-FORMERR" },
160 { "QryNXDOMAIN", "dns_rcode", "tx-NXDOMAIN" }
162 { "XfrReqDone", "type", "type_instance" },
163 { "UpdateReqFwd", "type", "type_instance" },
164 { "UpdateRespFwd", "type", "type_instance" },
165 { "UpdateFwdFail", "type", "type_instance" },
166 { "UpdateDone", "type", "type_instance" },
167 { "UpdateFail", "type", "type_instance" },
168 { "UpdateBadPrereq", "type", "type_instance" },
171 static int nsstats_translation_table_length =
172 STATIC_ARRAY_SIZE (nsstats_translation_table);
175 /* Translation table for the `zonestats' values. */
176 static const translation_info_t zonestats_translation_table[] = /* {{{ */
179 { "NotifyOutv4", "dns_notify", "tx-IPv4" },
180 { "NotifyOutv6", "dns_notify", "tx-IPv6" },
181 { "NotifyInv4", "dns_notify", "rx-IPv4" },
182 { "NotifyInv6", "dns_notify", "rx-IPv6" },
183 { "NotifyRej", "dns_notify", "rejected" },
184 /* SOA/AXFS/IXFS requests */
185 { "SOAOutv4", "dns_opcode", "SOA-IPv4" },
186 { "SOAOutv6", "dns_opcode", "SOA-IPv6" },
187 { "AXFRReqv4", "dns_opcode", "AXFR-IPv4" },
188 { "AXFRReqv6", "dns_opcode", "AXFR-IPv6" },
189 { "IXFRReqv4", "dns_opcode", "IXFR-IPv4" },
190 { "IXFRReqv6", "dns_opcode", "IXFR-IPv6" },
191 /* Domain transfers */
192 { "XfrSuccess", "dns_transfer", "success" },
193 { "XfrFail", "dns_transfer", "failure" }
195 static int zonestats_translation_table_length =
196 STATIC_ARRAY_SIZE (zonestats_translation_table);
199 /* Translation table for the `resstats' values. */
200 static const translation_info_t resstats_translation_table[] = /* {{{ */
202 /* Generic resolver information */
203 { "Queryv4", "dns_query", "IPv4" },
204 { "Queryv6", "dns_query", "IPv6" },
205 { "Responsev4", "dns_response", "IPv4" },
206 { "Responsev6", "dns_response", "IPv6" },
207 /* Received response codes */
208 { "NXDOMAIN", "dns_rcode", "rx-NXDOMAIN" },
209 { "SERVFAIL", "dns_rcode", "rx-SERVFAIL" },
210 { "FORMERR", "dns_rcode", "rx-FORMERR" },
211 { "OtherError", "dns_rcode", "rx-OTHER" },
212 { "EDNS0Fail", "dns_rcode", "rx-EDNS0Fail"},
213 /* Received responses */
214 { "Mismatch", "dns_response", "mismatch" },
215 { "Truncated", "dns_response", "truncated" },
216 { "Lame", "dns_response", "lame" },
217 { "Retry", "dns_query", "retry" },
219 { "GlueFetchv4", "type", "type_instance" },
220 { "GlueFetchv6", "type", "type_instance" },
221 { "GlueFetchv4Fail", "type", "type_instance" },
222 { "GlueFetchv6Fail", "type", "type_instance" },
224 /* DNSSEC information */
225 { "ValAttempt", "dns_resolver", "DNSSEC-attempt" },
226 { "ValOk", "dns_resolver", "DNSSEC-okay" },
227 { "ValNegOk", "dns_resolver", "DNSSEC-negokay" },
228 { "ValFail", "dns_resolver", "DNSSEC-fail" }
230 static int resstats_translation_table_length =
231 STATIC_ARRAY_SIZE (resstats_translation_table);
234 /* Translation table for the `memory/summary' values. */
235 static const translation_info_t memsummary_translation_table[] = /* {{{ */
237 { "TotalUse", "memory", "TotalUse" },
238 { "InUse", "memory", "InUse" },
239 { "BlockSize", "memory", "BlockSize" },
240 { "ContextSize", "memory", "ContextSize" },
241 { "Lost", "memory", "Lost" }
243 static int memsummary_translation_table_length =
244 STATIC_ARRAY_SIZE (memsummary_translation_table);
247 static void submit (time_t ts, const char *plugin_instance, /* {{{ */
248 const char *type, const char *type_instance, value_t value)
251 value_list_t vl = VALUE_LIST_INIT;
257 if (config_parse_time)
258 vl.time = TIME_T_TO_CDTIME_T (ts);
259 sstrncpy(vl.host, hostname_g, sizeof(vl.host));
260 sstrncpy(vl.plugin, "bind", sizeof(vl.plugin));
261 if (plugin_instance) {
262 sstrncpy(vl.plugin_instance, plugin_instance,
263 sizeof(vl.plugin_instance));
264 replace_special (vl.plugin_instance, sizeof (vl.plugin_instance));
266 sstrncpy(vl.type, type, sizeof(vl.type));
268 sstrncpy(vl.type_instance, type_instance,
269 sizeof(vl.type_instance));
270 replace_special (vl.type_instance, sizeof (vl.type_instance));
272 plugin_dispatch_values(&vl);
273 } /* }}} void submit */
275 static size_t bind_curl_callback (void *buf, size_t size, /* {{{ */
276 size_t nmemb, void __attribute__((unused)) *stream)
278 size_t len = size * nmemb;
283 if ((bind_buffer_fill + len) >= bind_buffer_size)
287 temp = realloc(bind_buffer, bind_buffer_fill + len + 1);
290 ERROR ("bind plugin: realloc failed.");
294 bind_buffer_size = bind_buffer_fill + len + 1;
297 memcpy (bind_buffer + bind_buffer_fill, (char *) buf, len);
298 bind_buffer_fill += len;
299 bind_buffer[bind_buffer_fill] = 0;
302 } /* }}} size_t bind_curl_callback */
305 * Callback, that's called with a translation table.
306 * (Plugin instance is fixed, type and type instance come from lookup table.)
308 static int bind_xml_table_callback (const char *name, value_t value, /* {{{ */
309 time_t current_time, void *user_data)
311 translation_table_ptr_t *table = (translation_table_ptr_t *) user_data;
317 for (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;
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 memset (&tm, 0, sizeof(tm));
462 tmp = strptime (str_ptr, "%Y-%m-%dT%T", &tm);
466 ERROR ("bind plugin: bind_xml_read_timestamp: strptime failed.");
467 xmlXPathFreeObject (xpathObj);
471 *ret_value = mktime(&tm);
473 xmlXPathFreeObject (xpathObj);
475 } /* }}} int bind_xml_read_timestamp */
478 * bind_parse_generic_name_value
480 * Reads statistics in the form:
483 * <counter>123</counter>
486 static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ */
487 list_callback_t list_callback,
489 xmlDoc *doc, xmlXPathContext *xpathCtx,
490 time_t current_time, int ds_type)
492 xmlXPathObject *xpathObj = NULL;
496 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
497 if (xpathObj == NULL)
499 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
505 /* Iterate over all matching nodes. */
506 for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
508 xmlNode *name_node = NULL;
509 xmlNode *counter = NULL;
513 parent = xpathObj->nodesetval->nodeTab[i];
514 DEBUG ("bind plugin: bind_parse_generic_name_value: parent->name = %s;",
515 (char *) parent->name);
517 /* Iterate over all child nodes. */
518 for (child = parent->xmlChildrenNode;
522 if (child->type != XML_ELEMENT_NODE)
525 if (xmlStrcmp (BAD_CAST "name", child->name) == 0)
527 else if (xmlStrcmp (BAD_CAST "counter", child->name) == 0)
531 if ((name_node != NULL) && (counter != NULL))
533 char *name = (char *) xmlNodeListGetString (doc,
534 name_node->xmlChildrenNode, 1);
538 if (ds_type == DS_TYPE_GAUGE)
539 status = bind_xml_read_gauge (doc, counter, &value.gauge);
541 status = bind_xml_read_derive (doc, counter, &value.derive);
545 status = (*list_callback) (name, value, current_time, user_data);
553 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
554 num_entries, (num_entries == 1) ? "entry" : "entries",
557 xmlXPathFreeObject(xpathObj);
560 } /* }}} int bind_parse_generic_name_value */
563 * bind_parse_generic_value_list
565 * Reads statistics in the form:
573 static int bind_parse_generic_value_list (const char *xpath_expression, /* {{{ */
574 list_callback_t list_callback,
576 xmlDoc *doc, xmlXPathContext *xpathCtx,
577 time_t current_time, int ds_type)
579 xmlXPathObject *xpathObj = NULL;
583 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
584 if (xpathObj == NULL)
586 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
592 /* Iterate over all matching nodes. */
593 for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
597 /* Iterate over all child nodes. */
598 for (child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
606 if (child->type != XML_ELEMENT_NODE)
609 node_name = (char *) child->name;
611 if (ds_type == DS_TYPE_GAUGE)
612 status = bind_xml_read_gauge (doc, child, &value.gauge);
614 status = bind_xml_read_derive (doc, child, &value.derive);
618 status = (*list_callback) (node_name, value, current_time, user_data);
624 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
625 num_entries, (num_entries == 1) ? "entry" : "entries",
628 xmlXPathFreeObject(xpathObj);
631 } /* }}} int bind_parse_generic_value_list */
634 * bind_parse_generic_name_attr_value_list
636 * Reads statistics in the form:
638 * <counter name="name0">123</counter>
639 * <counter name="name1">234</counter>
640 * <counter name="name2">345</counter>
644 static int bind_parse_generic_name_attr_value_list (const char *xpath_expression, /* {{{ */
645 list_callback_t list_callback,
647 xmlDoc *doc, xmlXPathContext *xpathCtx,
648 time_t current_time, int ds_type)
650 xmlXPathObject *xpathObj = NULL;
654 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
655 if (xpathObj == NULL)
657 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
663 /* Iterate over all matching nodes. */
664 for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
668 /* Iterate over all child nodes. */
669 for (child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
673 if (child->type != XML_ELEMENT_NODE)
676 if (strncmp ("counter", (char *) child->name, strlen ("counter")) != 0)
683 attr_name = (char *) xmlGetProp (child, BAD_CAST "name");
684 if (attr_name == NULL)
686 DEBUG ("bind plugin: found <counter> without name.");
689 if (ds_type == DS_TYPE_GAUGE)
690 status = bind_xml_read_gauge (doc, child, &value.gauge);
692 status = bind_xml_read_derive (doc, child, &value.derive);
696 status = (*list_callback) (attr_name, value, current_time, user_data);
702 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
703 num_entries, (num_entries == 1) ? "entry" : "entries",
706 xmlXPathFreeObject(xpathObj);
709 } /* }}} int bind_parse_generic_name_attr_value_list */
711 static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */
712 xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view,
715 xmlXPathObject *path_obj;
716 char *zone_name = NULL;
722 char *n = (char *) xmlGetProp (node, BAD_CAST "name");
723 char *c = (char *) xmlGetProp (node, BAD_CAST "rdataclass");
726 zone_name = (char *) xmlMalloc(strlen(n) + strlen(c) + 2);
727 snprintf(zone_name, strlen(n) + strlen(c) + 2, "%s/%s", n, c);
734 path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
735 if (path_obj == NULL)
737 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
741 for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
743 zone_name = (char *) xmlNodeListGetString (doc,
744 path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
745 if (zone_name != NULL)
748 xmlXPathFreeObject (path_obj);
751 if (zone_name == NULL)
753 ERROR ("bind plugin: Could not determine zone name.");
757 for (j = 0; j < view->zones_num; j++)
759 if (strcasecmp (zone_name, view->zones[j]) == 0)
766 if (j >= view->zones_num)
769 zone_name = view->zones[j];
771 DEBUG ("bind plugin: bind_xml_stats_handle_zone: Found zone `%s'.",
774 { /* Parse the <counters> tag {{{ */
775 char plugin_instance[DATA_MAX_NAME_LEN];
776 translation_table_ptr_t table_ptr =
778 nsstats_translation_table,
779 nsstats_translation_table_length,
783 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-zone-%s",
784 view->name, zone_name);
788 list_info_ptr_t list_info =
791 /* type = */ "dns_qtype"
793 bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='rcode']",
794 /* callback = */ bind_xml_table_callback,
795 /* user_data = */ &table_ptr,
796 doc, path_ctx, current_time, DS_TYPE_COUNTER);
797 bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='qtype']",
798 /* callback = */ bind_xml_list_callback,
799 /* user_data = */ &list_info,
800 doc, path_ctx, current_time, DS_TYPE_COUNTER);
804 bind_parse_generic_value_list (/* xpath = */ "counters",
805 /* callback = */ bind_xml_table_callback,
806 /* user_data = */ &table_ptr,
807 doc, path_ctx, current_time, DS_TYPE_COUNTER);
812 } /* }}} int bind_xml_stats_handle_zone */
814 static int bind_xml_stats_search_zones (int version, xmlDoc *doc, /* {{{ */
815 xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view,
818 xmlXPathObject *zone_nodes = NULL;
819 xmlXPathContext *zone_path_context;
822 zone_path_context = xmlXPathNewContext (doc);
823 if (zone_path_context == NULL)
825 ERROR ("bind plugin: xmlXPathNewContext failed.");
829 zone_nodes = xmlXPathEvalExpression (BAD_CAST "zones/zone", path_ctx);
830 if (zone_nodes == NULL)
832 ERROR ("bind plugin: Cannot find any <view> tags.");
833 xmlXPathFreeContext (zone_path_context);
837 for (i = 0; i < zone_nodes->nodesetval->nodeNr; i++)
841 node = zone_nodes->nodesetval->nodeTab[i];
842 assert (node != NULL);
844 zone_path_context->node = node;
846 bind_xml_stats_handle_zone (version, doc, zone_path_context, node, view,
850 xmlXPathFreeObject (zone_nodes);
851 xmlXPathFreeContext (zone_path_context);
853 } /* }}} int bind_xml_stats_search_zones */
855 static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */
856 xmlXPathContext *path_ctx, xmlNode *node, time_t current_time)
858 char *view_name = NULL;
865 view_name = (char*) xmlGetProp(node, BAD_CAST "name");
867 if (view_name == NULL)
869 ERROR ("bind plugin: Could not determine view name.");
873 for (j = 0; j < views_num; j++)
875 if (strcasecmp (view_name, views[j].name) == 0)
884 xmlXPathObject *path_obj;
885 path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
886 if (path_obj == NULL)
888 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
892 for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
894 view_name = (char *) xmlNodeListGetString (doc,
895 path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
896 if (view_name != NULL)
900 if (view_name == NULL)
902 ERROR ("bind plugin: Could not determine view name.");
903 xmlXPathFreeObject (path_obj);
907 for (j = 0; j < views_num; j++)
909 if (strcasecmp (view_name, views[j].name) == 0)
914 xmlXPathFreeObject (path_obj);
926 DEBUG ("bind plugin: bind_xml_stats_handle_view: Found view `%s'.",
929 if (view->qtypes != 0) /* {{{ */
931 char plugin_instance[DATA_MAX_NAME_LEN];
932 list_info_ptr_t list_info =
935 /* type = */ "dns_qtype"
938 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-qtypes",
942 bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='resqtype']",
943 /* callback = */ bind_xml_list_callback,
944 /* user_data = */ &list_info,
945 doc, path_ctx, current_time, DS_TYPE_COUNTER);
949 bind_parse_generic_name_value (/* xpath = */ "rdtype",
950 /* callback = */ bind_xml_list_callback,
951 /* user_data = */ &list_info,
952 doc, path_ctx, current_time, DS_TYPE_COUNTER);
956 if (view->resolver_stats != 0) /* {{{ */
958 char plugin_instance[DATA_MAX_NAME_LEN];
959 translation_table_ptr_t table_ptr =
961 resstats_translation_table,
962 resstats_translation_table_length,
966 ssnprintf (plugin_instance, sizeof (plugin_instance),
967 "%s-resolver_stats", view->name);
970 bind_parse_generic_name_attr_value_list ("counters[@type='resstats']",
971 /* callback = */ bind_xml_table_callback,
972 /* user_data = */ &table_ptr,
973 doc, path_ctx, current_time, DS_TYPE_COUNTER);
977 bind_parse_generic_name_value ("resstat",
978 /* callback = */ bind_xml_table_callback,
979 /* user_data = */ &table_ptr,
980 doc, path_ctx, current_time, DS_TYPE_COUNTER);
984 /* Record types in the cache */
985 if (view->cacherrsets != 0) /* {{{ */
987 char plugin_instance[DATA_MAX_NAME_LEN];
988 list_info_ptr_t list_info =
991 /* type = */ "dns_qtype_cached"
994 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-cache_rr_sets",
997 bind_parse_generic_name_value (/* xpath = */ "cache/rrset",
998 /* callback = */ bind_xml_list_callback,
999 /* user_data = */ &list_info,
1000 doc, path_ctx, current_time, DS_TYPE_GAUGE);
1003 if (view->zones_num > 0)
1004 bind_xml_stats_search_zones (version, doc, path_ctx, node, view,
1008 } /* }}} int bind_xml_stats_handle_view */
1010 static int bind_xml_stats_search_views (int version, xmlDoc *doc, /* {{{ */
1011 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
1013 xmlXPathObject *view_nodes = NULL;
1014 xmlXPathContext *view_path_context;
1017 view_path_context = xmlXPathNewContext (doc);
1018 if (view_path_context == NULL)
1020 ERROR ("bind plugin: xmlXPathNewContext failed.");
1024 view_nodes = xmlXPathEvalExpression (BAD_CAST "views/view", xpathCtx);
1025 if (view_nodes == NULL)
1027 ERROR ("bind plugin: Cannot find any <view> tags.");
1028 xmlXPathFreeContext (view_path_context);
1032 for (i = 0; i < view_nodes->nodesetval->nodeNr; i++)
1036 node = view_nodes->nodesetval->nodeTab[i];
1037 assert (node != NULL);
1039 view_path_context->node = node;
1041 bind_xml_stats_handle_view (version, doc, view_path_context, node,
1045 xmlXPathFreeObject (view_nodes);
1046 xmlXPathFreeContext (view_path_context);
1048 } /* }}} int bind_xml_stats_search_views */
1050 static void bind_xml_stats_v3 (xmlDoc *doc, /* {{{ */
1051 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
1053 /* XPath: server/counters[@type='opcode']
1054 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1056 * <counters type="opcode">
1057 * <counter name="A">1</counter>
1061 if (global_opcodes != 0)
1063 list_info_ptr_t list_info =
1065 /* plugin instance = */ "global-opcodes",
1066 /* type = */ "dns_opcode"
1068 bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='opcode']",
1069 /* callback = */ bind_xml_list_callback,
1070 /* user_data = */ &list_info,
1071 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1074 /* XPath: server/counters[@type='qtype']
1075 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1076 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1077 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1079 * <counters type="opcode">
1080 * <counter name="A">1</counter>
1084 if (global_qtypes != 0)
1086 list_info_ptr_t list_info =
1088 /* plugin instance = */ "global-qtypes",
1089 /* type = */ "dns_qtype"
1092 bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='qtype']",
1093 /* callback = */ bind_xml_list_callback,
1094 /* user_data = */ &list_info,
1095 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1098 /* XPath: server/counters[@type='nsstat']
1099 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1100 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1101 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1102 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1103 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1104 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1105 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1108 * <counters type="nsstat"
1109 * <counter name="Requestv4">1</counter>
1110 * <counter name="Requestv6">0</counter>
1114 if (global_server_stats)
1116 translation_table_ptr_t table_ptr =
1118 nsstats_translation_table,
1119 nsstats_translation_table_length,
1120 /* plugin_instance = */ "global-server_stats"
1123 bind_parse_generic_name_attr_value_list ("server/counters[@type='nsstat']",
1124 /* callback = */ bind_xml_table_callback,
1125 /* user_data = */ &table_ptr,
1126 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1129 /* XPath: server/zonestats, server/zonestat, server/counters[@type='zonestat']
1130 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1131 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1132 * XfrSuccess, XfrFail
1134 * <counters type="zonestat"
1135 * <counter name="NotifyOutv4">0</counter>
1136 * <counter name="NotifyOutv6">0</counter>
1140 if (global_zone_maint_stats)
1142 translation_table_ptr_t table_ptr =
1144 zonestats_translation_table,
1145 zonestats_translation_table_length,
1146 /* plugin_instance = */ "global-zone_maint_stats"
1149 bind_parse_generic_name_attr_value_list ("server/counters[@type='zonestat']",
1150 /* callback = */ bind_xml_table_callback,
1151 /* user_data = */ &table_ptr,
1152 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1155 /* XPath: server/resstats, server/counters[@type='resstat']
1156 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1157 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1158 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1159 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1161 * <counters type="resstat"
1162 * <counter name="Queryv4">0</counter>
1163 * <counter name="Queryv6">0</counter>
1167 if (global_resolver_stats != 0)
1169 translation_table_ptr_t table_ptr =
1171 resstats_translation_table,
1172 resstats_translation_table_length,
1173 /* plugin_instance = */ "global-resolver_stats"
1176 bind_parse_generic_name_attr_value_list ("server/counters[@type='resstat']",
1177 /* callback = */ bind_xml_table_callback,
1178 /* user_data = */ &table_ptr,
1179 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1181 } /* }}} bind_xml_stats_v3 */
1183 static void bind_xml_stats_v1_v2 (int version, xmlDoc *doc, /* {{{ */
1184 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
1186 /* XPath: server/requests/opcode, server/counters[@type='opcode']
1187 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1191 * <counter>1</counter>
1195 if (global_opcodes != 0)
1197 list_info_ptr_t list_info =
1199 /* plugin instance = */ "global-opcodes",
1200 /* type = */ "dns_opcode"
1203 bind_parse_generic_name_value (/* xpath = */ "server/requests/opcode",
1204 /* callback = */ bind_xml_list_callback,
1205 /* user_data = */ &list_info,
1206 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1209 /* XPath: server/queries-in/rdtype, server/counters[@type='qtype']
1210 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1211 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1212 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1216 * <counter>1</counter>
1220 if (global_qtypes != 0)
1222 list_info_ptr_t list_info =
1224 /* plugin instance = */ "global-qtypes",
1225 /* type = */ "dns_qtype"
1228 bind_parse_generic_name_value (/* xpath = */ "server/queries-in/rdtype",
1229 /* callback = */ bind_xml_list_callback,
1230 /* user_data = */ &list_info,
1231 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1234 /* XPath: server/nsstats, server/nsstat, server/counters[@type='nsstat']
1235 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1236 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1237 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1238 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1239 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1240 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1241 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1245 * <Requestv4>1</Requestv4>
1246 * <Requestv6>0</Requestv6>
1251 * <name>Requestv4</name>
1252 * <counter>1</counter>
1255 * <name>Requestv6</name>
1256 * <counter>0</counter>
1260 if (global_server_stats)
1262 translation_table_ptr_t table_ptr =
1264 nsstats_translation_table,
1265 nsstats_translation_table_length,
1266 /* plugin_instance = */ "global-server_stats"
1271 bind_parse_generic_value_list ("server/nsstats",
1272 /* callback = */ bind_xml_table_callback,
1273 /* user_data = */ &table_ptr,
1274 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1278 bind_parse_generic_name_value ("server/nsstat",
1279 /* callback = */ bind_xml_table_callback,
1280 /* user_data = */ &table_ptr,
1281 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1285 /* XPath: server/zonestats, server/zonestat, server/counters[@type='zonestat']
1286 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1287 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1288 * XfrSuccess, XfrFail
1291 * <NotifyOutv4>0</NotifyOutv4>
1292 * <NotifyOutv6>0</NotifyOutv6>
1297 * <name>NotifyOutv4</name>
1298 * <counter>0</counter>
1301 * <name>NotifyOutv6</name>
1302 * <counter>0</counter>
1306 if (global_zone_maint_stats)
1308 translation_table_ptr_t table_ptr =
1310 zonestats_translation_table,
1311 zonestats_translation_table_length,
1312 /* plugin_instance = */ "global-zone_maint_stats"
1317 bind_parse_generic_value_list ("server/zonestats",
1318 /* callback = */ bind_xml_table_callback,
1319 /* user_data = */ &table_ptr,
1320 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1324 bind_parse_generic_name_value ("server/zonestat",
1325 /* callback = */ bind_xml_table_callback,
1326 /* user_data = */ &table_ptr,
1327 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1331 /* XPath: server/resstats, server/counters[@type='resstat']
1332 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1333 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1334 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1335 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1338 * <Queryv4>0</Queryv4>
1339 * <Queryv6>0</Queryv6>
1344 * <name>Queryv4</name>
1345 * <counter>0</counter>
1348 * <name>Queryv6</name>
1349 * <counter>0</counter>
1353 if (global_resolver_stats != 0)
1355 translation_table_ptr_t table_ptr =
1357 resstats_translation_table,
1358 resstats_translation_table_length,
1359 /* plugin_instance = */ "global-resolver_stats"
1364 bind_parse_generic_value_list ("server/resstats",
1365 /* callback = */ bind_xml_table_callback,
1366 /* user_data = */ &table_ptr,
1367 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1371 bind_parse_generic_name_value ("server/resstat",
1372 /* callback = */ bind_xml_table_callback,
1373 /* user_data = */ &table_ptr,
1374 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1377 } /* }}} bind_xml_stats_v1_v2 */
1379 static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
1380 xmlXPathContext *xpathCtx, xmlNode *statsnode)
1382 time_t current_time = 0;
1385 xpathCtx->node = statsnode;
1387 /* TODO: Check `server/boot-time' to recognize server restarts. */
1389 status = bind_xml_read_timestamp ("server/current-time",
1390 doc, xpathCtx, ¤t_time);
1393 ERROR ("bind plugin: Reading `server/current-time' failed.");
1396 DEBUG ("bind plugin: Current server time is %i.", (int) current_time);
1400 bind_xml_stats_v3(doc, xpathCtx, statsnode, current_time);
1404 bind_xml_stats_v1_v2(version, doc, xpathCtx, statsnode, current_time);
1407 /* XPath: memory/summary
1408 * Variables: TotalUse, InUse, BlockSize, ContextSize, Lost
1409 * Layout: v2 and v3:
1411 * <TotalUse>6587096</TotalUse>
1412 * <InUse>1345424</InUse>
1413 * <BlockSize>5505024</BlockSize>
1414 * <ContextSize>3732456</ContextSize>
1418 if (global_memory_stats != 0)
1420 translation_table_ptr_t table_ptr =
1422 memsummary_translation_table,
1423 memsummary_translation_table_length,
1424 /* plugin_instance = */ "global-memory_stats"
1427 bind_parse_generic_value_list ("memory/summary",
1428 /* callback = */ bind_xml_table_callback,
1429 /* user_data = */ &table_ptr,
1430 doc, xpathCtx, current_time, DS_TYPE_GAUGE);
1434 bind_xml_stats_search_views (version, doc, xpathCtx, statsnode,
1438 } /* }}} int bind_xml_stats */
1440 static int bind_xml (const char *data) /* {{{ */
1443 xmlXPathContext *xpathCtx = NULL;
1444 xmlXPathObject *xpathObj = NULL;
1448 doc = xmlParseMemory (data, strlen (data));
1451 ERROR ("bind plugin: xmlParseMemory failed.");
1455 xpathCtx = xmlXPathNewContext (doc);
1456 if (xpathCtx == NULL)
1458 ERROR ("bind plugin: xmlXPathNewContext failed.");
1464 // version 3.* of statistics XML (since BIND9.9)
1467 xpathObj = xmlXPathEvalExpression (BAD_CAST "/statistics", xpathCtx);
1468 if (xpathObj == NULL || xpathObj->nodesetval == NULL || xpathObj->nodesetval->nodeNr == 0)
1470 DEBUG ("bind plugin: Statistics appears not to be v3");
1471 // we will fallback to v1 or v2 detection
1472 if (xpathObj != NULL) { xmlXPathFreeObject (xpathObj); }
1476 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++)
1481 node = xpathObj->nodesetval->nodeTab[i];
1482 assert (node != NULL);
1484 attr_version = (char *) xmlGetProp (node, BAD_CAST "version");
1485 if (attr_version == NULL)
1487 NOTICE ("bind plugin: Found <statistics> tag doesn't have a "
1488 "`version' attribute.");
1491 DEBUG ("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1493 if (strncmp ("3.", attr_version, strlen ("3.")) != 0)
1495 /* TODO: Use the complaint mechanism here. */
1496 NOTICE ("bind plugin: Found <statistics> tag with version `%s'. "
1497 "Unfortunately I have no clue how to parse that. "
1498 "Please open a bug report for this.", attr_version);
1499 xmlFree (attr_version);
1502 ret = bind_xml_stats (3, doc, xpathCtx, node);
1504 xmlFree (attr_version);
1505 /* One <statistics> node ought to be enough. */
1509 // we are finished, early-return
1510 xmlXPathFreeObject (xpathObj);
1511 xmlXPathFreeContext (xpathCtx);
1518 // versions 1.* or 2.* of statistics XML
1521 xpathObj = xmlXPathEvalExpression (BAD_CAST "/isc/bind/statistics", xpathCtx);
1522 if (xpathObj == NULL)
1524 ERROR ("bind plugin: Cannot find the <statistics> tag.");
1525 xmlXPathFreeContext (xpathCtx);
1529 else if (xpathObj->nodesetval == NULL)
1531 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
1532 xmlXPathFreeObject (xpathObj);
1533 xmlXPathFreeContext (xpathCtx);
1538 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++)
1542 int parsed_version = 0;
1544 node = xpathObj->nodesetval->nodeTab[i];
1545 assert (node != NULL);
1547 attr_version = (char *) xmlGetProp (node, BAD_CAST "version");
1548 if (attr_version == NULL)
1550 NOTICE ("bind plugin: Found <statistics> tag doesn't have a "
1551 "`version' attribute.");
1554 DEBUG ("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1556 /* At the time this plugin was written, version "1.0" was used by
1557 * BIND 9.5.0, version "2.0" was used by BIND 9.5.1 and 9.6.0. We assume
1558 * that "1.*" and "2.*" don't introduce structural changes, so we just
1559 * check for the first two characters here. */
1560 if (strncmp ("1.", attr_version, strlen ("1.")) == 0)
1562 else if (strncmp ("2.", attr_version, strlen ("2.")) == 0)
1566 /* TODO: Use the complaint mechanism here. */
1567 NOTICE ("bind plugin: Found <statistics> tag with version `%s'. "
1568 "Unfortunately I have no clue how to parse that. "
1569 "Please open a bug report for this.", attr_version);
1570 xmlFree (attr_version);
1574 ret = bind_xml_stats (parsed_version,
1575 doc, xpathCtx, node);
1577 xmlFree (attr_version);
1578 /* One <statistics> node ought to be enough. */
1582 xmlXPathFreeObject (xpathObj);
1583 xmlXPathFreeContext (xpathCtx);
1587 } /* }}} int bind_xml */
1589 static int bind_config_set_bool (const char *name, int *var, /* {{{ */
1592 if ((ci->values_num != 1) || ( ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1594 WARNING ("bind plugin: The `%s' option needs "
1595 "exactly one boolean argument.", name);
1599 if (ci->values[0].value.boolean)
1604 } /* }}} int bind_config_set_bool */
1606 static int bind_config_add_view_zone (cb_view_t *view, /* {{{ */
1611 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1613 WARNING ("bind plugin: The `Zone' option needs "
1614 "exactly one string argument.");
1618 tmp = (char **) realloc (view->zones,
1619 sizeof (char *) * (view->zones_num + 1));
1622 ERROR ("bind plugin: realloc failed.");
1627 view->zones[view->zones_num] = strdup (ci->values[0].value.string);
1628 if (view->zones[view->zones_num] == NULL)
1630 ERROR ("bind plugin: strdup failed.");
1636 } /* }}} int bind_config_add_view_zone */
1638 static int bind_config_add_view (oconfig_item_t *ci) /* {{{ */
1643 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1645 WARNING ("bind plugin: `View' blocks need exactly one string argument.");
1649 tmp = (cb_view_t *) realloc (views, sizeof (*views) * (views_num + 1));
1652 ERROR ("bind plugin: realloc failed.");
1656 tmp = views + views_num;
1658 memset (tmp, 0, sizeof (*tmp));
1660 tmp->resolver_stats = 1;
1661 tmp->cacherrsets = 1;
1665 tmp->name = strdup (ci->values[0].value.string);
1666 if (tmp->name == NULL)
1668 ERROR ("bind plugin: strdup failed.");
1673 for (i = 0; i < ci->children_num; i++)
1675 oconfig_item_t *child = ci->children + i;
1677 if (strcasecmp ("QTypes", child->key) == 0)
1678 bind_config_set_bool ("QTypes", &tmp->qtypes, child);
1679 else if (strcasecmp ("ResolverStats", child->key) == 0)
1680 bind_config_set_bool ("ResolverStats", &tmp->resolver_stats, child);
1681 else if (strcasecmp ("CacheRRSets", child->key) == 0)
1682 bind_config_set_bool ("CacheRRSets", &tmp->cacherrsets, child);
1683 else if (strcasecmp ("Zone", child->key) == 0)
1684 bind_config_add_view_zone (tmp, child);
1687 WARNING ("bind plugin: Unknown configuration option "
1688 "`%s' in view `%s' will be ignored.", child->key, tmp->name);
1690 } /* for (i = 0; i < ci->children_num; i++) */
1694 } /* }}} int bind_config_add_view */
1696 static int bind_config (oconfig_item_t *ci) /* {{{ */
1700 for (i = 0; i < ci->children_num; i++)
1702 oconfig_item_t *child = ci->children + i;
1704 if (strcasecmp ("Url", child->key) == 0) {
1705 if ((child->values_num != 1) || (child->values[0].type != OCONFIG_TYPE_STRING))
1707 WARNING ("bind plugin: The `Url' option needs "
1708 "exactly one string argument.");
1712 url = strdup (child->values[0].value.string);
1713 } else if (strcasecmp ("OpCodes", child->key) == 0)
1714 bind_config_set_bool ("OpCodes", &global_opcodes, child);
1715 else if (strcasecmp ("QTypes", child->key) == 0)
1716 bind_config_set_bool ("QTypes", &global_qtypes, child);
1717 else if (strcasecmp ("ServerStats", child->key) == 0)
1718 bind_config_set_bool ("ServerStats", &global_server_stats, child);
1719 else if (strcasecmp ("ZoneMaintStats", child->key) == 0)
1720 bind_config_set_bool ("ZoneMaintStats", &global_zone_maint_stats, child);
1721 else if (strcasecmp ("ResolverStats", child->key) == 0)
1722 bind_config_set_bool ("ResolverStats", &global_resolver_stats, child);
1723 else if (strcasecmp ("MemoryStats", child->key) == 0)
1724 bind_config_set_bool ("MemoryStats", &global_memory_stats, child);
1725 else if (strcasecmp ("View", child->key) == 0)
1726 bind_config_add_view (child);
1727 else if (strcasecmp ("ParseTime", child->key) == 0)
1728 cf_util_get_boolean (child, &config_parse_time);
1729 else if (strcasecmp ("Timeout", child->key) == 0)
1730 cf_util_get_int (child, &timeout);
1733 WARNING ("bind plugin: Unknown configuration option "
1734 "`%s' will be ignored.", child->key);
1739 } /* }}} int bind_config */
1741 static int bind_init (void) /* {{{ */
1746 curl = curl_easy_init ();
1749 ERROR ("bind plugin: bind_init: curl_easy_init failed.");
1753 curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1L);
1754 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
1755 curl_easy_setopt (curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
1756 curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, bind_curl_error);
1757 curl_easy_setopt (curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
1758 curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L);
1759 curl_easy_setopt (curl, CURLOPT_MAXREDIRS, 50L);
1760 #ifdef HAVE_CURLOPT_TIMEOUT_MS
1761 curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, (timeout >= 0) ?
1762 (long) timeout : CDTIME_T_TO_MS(plugin_get_interval()));
1767 } /* }}} int bind_init */
1769 static int bind_read (void) /* {{{ */
1775 ERROR ("bind plugin: I don't have a CURL object.");
1779 bind_buffer_fill = 0;
1780 if (curl_easy_perform (curl) != CURLE_OK)
1782 ERROR ("bind plugin: curl_easy_perform failed: %s",
1787 status = bind_xml (bind_buffer);
1792 } /* }}} int bind_read */
1794 static int bind_shutdown (void) /* {{{ */
1798 curl_easy_cleanup (curl);
1803 } /* }}} int bind_shutdown */
1805 void module_register (void)
1807 plugin_register_complex_config ("bind", bind_config);
1808 plugin_register_init ("bind", bind_init);
1809 plugin_register_read ("bind", bind_read);
1810 plugin_register_shutdown ("bind", bind_shutdown);
1811 } /* void module_register */
1813 /* vim: set sw=2 sts=2 ts=8 et fdm=marker : */