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;
113 static cb_view_t *views = NULL;
114 static size_t views_num = 0;
116 static CURL *curl = NULL;
118 static char *bind_buffer = NULL;
119 static size_t bind_buffer_size = 0;
120 static size_t bind_buffer_fill = 0;
121 static char bind_curl_error[CURL_ERROR_SIZE];
123 /* Translation table for the `nsstats' values. */
124 static const translation_info_t nsstats_translation_table[] = /* {{{ */
127 { "Requestv4", "dns_request", "IPv4" },
128 { "Requestv6", "dns_request", "IPv6" },
129 { "ReqEdns0", "dns_request", "EDNS0" },
130 { "ReqBadEDNSVer", "dns_request", "BadEDNSVer" },
131 { "ReqTSIG", "dns_request", "TSIG" },
132 { "ReqSIG0", "dns_request", "SIG0" },
133 { "ReqBadSIG", "dns_request", "BadSIG" },
134 { "ReqTCP", "dns_request", "TCP" },
136 { "AuthQryRej", "dns_reject", "authorative" },
137 { "RecQryRej", "dns_reject", "recursive" },
138 { "XfrRej", "dns_reject", "transfer" },
139 { "UpdateRej", "dns_reject", "update" },
141 { "Response", "dns_response", "normal" },
142 { "TruncatedResp", "dns_response", "truncated" },
143 { "RespEDNS0", "dns_response", "EDNS0" },
144 { "RespTSIG", "dns_response", "TSIG" },
145 { "RespSIG0", "dns_response", "SIG0" },
147 { "QryAuthAns", "dns_query", "authorative" },
148 { "QryNoauthAns", "dns_query", "nonauth" },
149 { "QryReferral", "dns_query", "referral" },
150 { "QryRecursion", "dns_query", "recursion" },
151 { "QryDuplicate", "dns_query", "dupliate" },
152 { "QryDropped", "dns_query", "dropped" },
153 { "QryFailure", "dns_query", "failure" },
155 { "QrySuccess", "dns_rcode", "tx-NOERROR" },
156 { "QryNxrrset", "dns_rcode", "tx-NXRRSET" },
157 { "QrySERVFAIL", "dns_rcode", "tx-SERVFAIL" },
158 { "QryFORMERR", "dns_rcode", "tx-FORMERR" },
159 { "QryNXDOMAIN", "dns_rcode", "tx-NXDOMAIN" }
161 { "XfrReqDone", "type", "type_instance" },
162 { "UpdateReqFwd", "type", "type_instance" },
163 { "UpdateRespFwd", "type", "type_instance" },
164 { "UpdateFwdFail", "type", "type_instance" },
165 { "UpdateDone", "type", "type_instance" },
166 { "UpdateFail", "type", "type_instance" },
167 { "UpdateBadPrereq", "type", "type_instance" },
170 static int nsstats_translation_table_length =
171 STATIC_ARRAY_SIZE (nsstats_translation_table);
174 /* Translation table for the `zonestats' values. */
175 static const translation_info_t zonestats_translation_table[] = /* {{{ */
178 { "NotifyOutv4", "dns_notify", "tx-IPv4" },
179 { "NotifyOutv6", "dns_notify", "tx-IPv6" },
180 { "NotifyInv4", "dns_notify", "rx-IPv4" },
181 { "NotifyInv6", "dns_notify", "rx-IPv6" },
182 { "NotifyRej", "dns_notify", "rejected" },
183 /* SOA/AXFS/IXFS requests */
184 { "SOAOutv4", "dns_opcode", "SOA-IPv4" },
185 { "SOAOutv6", "dns_opcode", "SOA-IPv6" },
186 { "AXFRReqv4", "dns_opcode", "AXFR-IPv4" },
187 { "AXFRReqv6", "dns_opcode", "AXFR-IPv6" },
188 { "IXFRReqv4", "dns_opcode", "IXFR-IPv4" },
189 { "IXFRReqv6", "dns_opcode", "IXFR-IPv6" },
190 /* Domain transfers */
191 { "XfrSuccess", "dns_transfer", "success" },
192 { "XfrFail", "dns_transfer", "failure" }
194 static int zonestats_translation_table_length =
195 STATIC_ARRAY_SIZE (zonestats_translation_table);
198 /* Translation table for the `resstats' values. */
199 static const translation_info_t resstats_translation_table[] = /* {{{ */
201 /* Generic resolver information */
202 { "Queryv4", "dns_query", "IPv4" },
203 { "Queryv6", "dns_query", "IPv6" },
204 { "Responsev4", "dns_response", "IPv4" },
205 { "Responsev6", "dns_response", "IPv6" },
206 /* Received response codes */
207 { "NXDOMAIN", "dns_rcode", "rx-NXDOMAIN" },
208 { "SERVFAIL", "dns_rcode", "rx-SERVFAIL" },
209 { "FORMERR", "dns_rcode", "rx-FORMERR" },
210 { "OtherError", "dns_rcode", "rx-OTHER" },
211 { "EDNS0Fail", "dns_rcode", "rx-EDNS0Fail"},
212 /* Received responses */
213 { "Mismatch", "dns_response", "mismatch" },
214 { "Truncated", "dns_response", "truncated" },
215 { "Lame", "dns_response", "lame" },
216 { "Retry", "dns_query", "retry" },
218 { "GlueFetchv4", "type", "type_instance" },
219 { "GlueFetchv6", "type", "type_instance" },
220 { "GlueFetchv4Fail", "type", "type_instance" },
221 { "GlueFetchv6Fail", "type", "type_instance" },
223 /* DNSSEC information */
224 { "ValAttempt", "dns_resolver", "DNSSEC-attempt" },
225 { "ValOk", "dns_resolver", "DNSSEC-okay" },
226 { "ValNegOk", "dns_resolver", "DNSSEC-negokay" },
227 { "ValFail", "dns_resolver", "DNSSEC-fail" }
229 static int resstats_translation_table_length =
230 STATIC_ARRAY_SIZE (resstats_translation_table);
233 /* Translation table for the `memory/summary' values. */
234 static const translation_info_t memsummary_translation_table[] = /* {{{ */
236 { "TotalUse", "memory", "TotalUse" },
237 { "InUse", "memory", "InUse" },
238 { "BlockSize", "memory", "BlockSize" },
239 { "ContextSize", "memory", "ContextSize" },
240 { "Lost", "memory", "Lost" }
242 static int memsummary_translation_table_length =
243 STATIC_ARRAY_SIZE (memsummary_translation_table);
246 static void submit (time_t ts, const char *plugin_instance, /* {{{ */
247 const char *type, const char *type_instance, value_t value)
250 value_list_t vl = VALUE_LIST_INIT;
256 if (config_parse_time)
257 vl.time = TIME_T_TO_CDTIME_T (ts);
258 sstrncpy(vl.host, hostname_g, sizeof(vl.host));
259 sstrncpy(vl.plugin, "bind", sizeof(vl.plugin));
260 if (plugin_instance) {
261 sstrncpy(vl.plugin_instance, plugin_instance,
262 sizeof(vl.plugin_instance));
263 replace_special (vl.plugin_instance, sizeof (vl.plugin_instance));
265 sstrncpy(vl.type, type, sizeof(vl.type));
267 sstrncpy(vl.type_instance, type_instance,
268 sizeof(vl.type_instance));
269 replace_special (vl.plugin_instance, sizeof (vl.plugin_instance));
271 plugin_dispatch_values(&vl);
272 } /* }}} void submit */
274 static size_t bind_curl_callback (void *buf, size_t size, /* {{{ */
275 size_t nmemb, void __attribute__((unused)) *stream)
277 size_t len = size * nmemb;
282 if ((bind_buffer_fill + len) >= bind_buffer_size)
286 temp = realloc(bind_buffer, bind_buffer_fill + len + 1);
289 ERROR ("bind plugin: realloc failed.");
293 bind_buffer_size = bind_buffer_fill + len + 1;
296 memcpy (bind_buffer + bind_buffer_fill, (char *) buf, len);
297 bind_buffer_fill += len;
298 bind_buffer[bind_buffer_fill] = 0;
301 } /* }}} size_t bind_curl_callback */
304 * Callback, that's called with a translation table.
305 * (Plugin instance is fixed, type and type instance come from lookup table.)
307 static int bind_xml_table_callback (const char *name, value_t value, /* {{{ */
308 time_t current_time, void *user_data)
310 translation_table_ptr_t *table = (translation_table_ptr_t *) user_data;
316 for (i = 0; i < table->table_length; i++)
318 if (strcmp (table->table[i].xml_name, name) != 0)
321 submit (current_time,
322 table->plugin_instance,
323 table->table[i].type,
324 table->table[i].type_instance,
330 } /* }}} int bind_xml_table_callback */
333 * Callback, that's used for lists.
334 * (Plugin instance and type are fixed, xml name is used as type instance.)
336 static int bind_xml_list_callback (const char *name, /* {{{ */
337 value_t value, time_t current_time, void *user_data)
339 list_info_ptr_t *list_info = (list_info_ptr_t *) user_data;
341 if (list_info == NULL)
344 submit (current_time,
345 list_info->plugin_instance,
347 /* type instance = */ name,
351 } /* }}} int bind_xml_list_callback */
353 static int bind_xml_read_derive (xmlDoc *doc, xmlNode *node, /* {{{ */
360 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
363 ERROR ("bind plugin: bind_xml_read_derive: xmlNodeListGetString failed.");
367 status = parse_value (str_ptr, &value, DS_TYPE_DERIVE);
370 ERROR ("bind plugin: Parsing string \"%s\" to derive value failed.",
375 *ret_value = value.derive;
377 } /* }}} int bind_xml_read_derive */
379 static int bind_xml_read_gauge (xmlDoc *doc, xmlNode *node, /* {{{ */
382 char *str_ptr, *end_ptr;
385 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
388 ERROR ("bind plugin: bind_xml_read_gauge: xmlNodeListGetString failed.");
393 value = strtod (str_ptr, &end_ptr);
395 if (str_ptr == end_ptr || errno)
397 if (errno && (value < 0))
398 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed with underflow.");
399 else if (errno && (value > 0))
400 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed with overflow.");
402 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed.");
406 *ret_value = (gauge_t) value;
408 } /* }}} int bind_xml_read_gauge */
410 static int bind_xml_read_timestamp (const char *xpath_expression, /* {{{ */
411 xmlDoc *doc, xmlXPathContext *xpathCtx, time_t *ret_value)
413 xmlXPathObject *xpathObj = NULL;
419 xpathObj = xmlXPathEvalExpression (BAD_CAST xpath_expression, xpathCtx);
420 if (xpathObj == NULL)
422 ERROR ("bind plugin: Unable to evaluate XPath expression `%s'.",
427 if ((xpathObj->nodesetval == NULL) || (xpathObj->nodesetval->nodeNr < 1))
429 xmlXPathFreeObject (xpathObj);
433 if (xpathObj->nodesetval->nodeNr != 1)
435 NOTICE ("bind plugin: Evaluating the XPath expression `%s' returned "
436 "%i nodes. Only handling the first one.",
437 xpath_expression, xpathObj->nodesetval->nodeNr);
440 node = xpathObj->nodesetval->nodeTab[0];
442 if (node->xmlChildrenNode == NULL)
444 ERROR ("bind plugin: bind_xml_read_timestamp: "
445 "node->xmlChildrenNode == NULL");
446 xmlXPathFreeObject (xpathObj);
450 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
453 ERROR ("bind plugin: bind_xml_read_timestamp: xmlNodeListGetString failed.");
454 xmlXPathFreeObject (xpathObj);
458 memset (&tm, 0, sizeof(tm));
459 tmp = strptime (str_ptr, "%Y-%m-%dT%T", &tm);
463 ERROR ("bind plugin: bind_xml_read_timestamp: strptime failed.");
464 xmlXPathFreeObject (xpathObj);
468 *ret_value = mktime(&tm);
470 xmlXPathFreeObject (xpathObj);
472 } /* }}} int bind_xml_read_timestamp */
475 * bind_parse_generic_name_value
477 * Reads statistics in the form:
480 * <counter>123</counter>
483 static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ */
484 list_callback_t list_callback,
486 xmlDoc *doc, xmlXPathContext *xpathCtx,
487 time_t current_time, int ds_type)
489 xmlXPathObject *xpathObj = NULL;
493 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
494 if (xpathObj == NULL)
496 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
502 /* Iterate over all matching nodes. */
503 for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
505 xmlNode *name_node = NULL;
506 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 (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;
580 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
581 if (xpathObj == NULL)
583 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
589 /* Iterate over all matching nodes. */
590 for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
594 /* Iterate over all child nodes. */
595 for (child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
603 if (child->type != XML_ELEMENT_NODE)
606 node_name = (char *) child->name;
608 if (ds_type == DS_TYPE_GAUGE)
609 status = bind_xml_read_gauge (doc, child, &value.gauge);
611 status = bind_xml_read_derive (doc, child, &value.derive);
615 status = (*list_callback) (node_name, value, current_time, user_data);
621 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
622 num_entries, (num_entries == 1) ? "entry" : "entries",
625 xmlXPathFreeObject(xpathObj);
628 } /* }}} int bind_parse_generic_value_list */
631 * bind_parse_generic_name_attr_value_list
633 * Reads statistics in the form:
635 * <counter name="name0">123</counter>
636 * <counter name="name1">234</counter>
637 * <counter name="name2">345</counter>
641 static int bind_parse_generic_name_attr_value_list (const char *xpath_expression, /* {{{ */
642 list_callback_t list_callback,
644 xmlDoc *doc, xmlXPathContext *xpathCtx,
645 time_t current_time, int ds_type)
647 xmlXPathObject *xpathObj = NULL;
651 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
652 if (xpathObj == NULL)
654 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
660 /* Iterate over all matching nodes. */
661 for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
665 /* Iterate over all child nodes. */
666 for (child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
670 if (child->type != XML_ELEMENT_NODE)
673 if (strncmp ("counter", (char *) child->name, strlen ("counter")) != 0)
680 attr_name = (char *) xmlGetProp (child, BAD_CAST "name");
681 if (attr_name == NULL)
683 DEBUG ("bind plugin: found <counter> without name.");
686 if (ds_type == DS_TYPE_GAUGE)
687 status = bind_xml_read_gauge (doc, child, &value.gauge);
689 status = bind_xml_read_derive (doc, child, &value.derive);
693 status = (*list_callback) (attr_name, value, current_time, user_data);
699 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
700 num_entries, (num_entries == 1) ? "entry" : "entries",
703 xmlXPathFreeObject(xpathObj);
706 } /* }}} int bind_parse_generic_name_attr_value_list */
708 static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */
709 xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view,
712 xmlXPathObject *path_obj;
713 char *zone_name = NULL;
719 char *n = (char *) xmlGetProp (node, BAD_CAST "name");
720 char *c = (char *) xmlGetProp (node, BAD_CAST "rdataclass");
723 zone_name = (char *) xmlMalloc(strlen(n) + strlen(c) + 2);
724 snprintf(zone_name, strlen(n) + strlen(c) + 2, "%s/%s", n, c);
731 path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
732 if (path_obj == NULL)
734 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
738 for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
740 zone_name = (char *) xmlNodeListGetString (doc,
741 path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
742 if (zone_name != NULL)
745 xmlXPathFreeObject (path_obj);
748 if (zone_name == NULL)
750 ERROR ("bind plugin: Could not determine zone name.");
754 for (j = 0; j < view->zones_num; j++)
756 if (strcasecmp (zone_name, view->zones[j]) == 0)
763 if (j >= views->zones_num)
766 zone_name = view->zones[j];
768 DEBUG ("bind plugin: bind_xml_stats_handle_zone: Found zone `%s'.",
771 { /* Parse the <counters> tag {{{ */
772 char plugin_instance[DATA_MAX_NAME_LEN];
773 translation_table_ptr_t table_ptr =
775 nsstats_translation_table,
776 nsstats_translation_table_length,
780 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-zone-%s",
781 view->name, zone_name);
785 list_info_ptr_t list_info =
788 /* type = */ "dns_qtype"
790 bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='rcode']",
791 /* callback = */ bind_xml_table_callback,
792 /* user_data = */ &table_ptr,
793 doc, path_ctx, current_time, DS_TYPE_COUNTER);
794 bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='qtype']",
795 /* callback = */ bind_xml_list_callback,
796 /* user_data = */ &list_info,
797 doc, path_ctx, current_time, DS_TYPE_COUNTER);
801 bind_parse_generic_value_list (/* xpath = */ "counters",
802 /* callback = */ bind_xml_table_callback,
803 /* user_data = */ &table_ptr,
804 doc, path_ctx, current_time, DS_TYPE_COUNTER);
809 } /* }}} int bind_xml_stats_handle_zone */
811 static int bind_xml_stats_search_zones (int version, xmlDoc *doc, /* {{{ */
812 xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view,
815 xmlXPathObject *zone_nodes = NULL;
816 xmlXPathContext *zone_path_context;
819 zone_path_context = xmlXPathNewContext (doc);
820 if (zone_path_context == NULL)
822 ERROR ("bind plugin: xmlXPathNewContext failed.");
826 zone_nodes = xmlXPathEvalExpression (BAD_CAST "zones/zone", path_ctx);
827 if (zone_nodes == NULL)
829 ERROR ("bind plugin: Cannot find any <view> tags.");
830 xmlXPathFreeContext (zone_path_context);
834 for (i = 0; i < zone_nodes->nodesetval->nodeNr; i++)
838 node = zone_nodes->nodesetval->nodeTab[i];
839 assert (node != NULL);
841 zone_path_context->node = node;
843 bind_xml_stats_handle_zone (version, doc, zone_path_context, node, view,
847 xmlXPathFreeObject (zone_nodes);
848 xmlXPathFreeContext (zone_path_context);
850 } /* }}} int bind_xml_stats_search_zones */
852 static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */
853 xmlXPathContext *path_ctx, xmlNode *node, time_t current_time)
855 char *view_name = NULL;
862 view_name = (char*) xmlGetProp(node, BAD_CAST "name");
864 if (view_name == NULL)
866 ERROR ("bind plugin: Could not determine view name.");
870 for (j = 0; j < views_num; j++)
872 if (strcasecmp (view_name, views[j].name) == 0)
881 xmlXPathObject *path_obj;
882 path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
883 if (path_obj == NULL)
885 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
889 for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
891 view_name = (char *) xmlNodeListGetString (doc,
892 path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
893 if (view_name != NULL)
897 if (view_name == NULL)
899 ERROR ("bind plugin: Could not determine view name.");
900 xmlXPathFreeObject (path_obj);
904 for (j = 0; j < views_num; j++)
906 if (strcasecmp (view_name, views[j].name) == 0)
911 xmlXPathFreeObject (path_obj);
923 DEBUG ("bind plugin: bind_xml_stats_handle_view: Found view `%s'.",
926 if (view->qtypes != 0) /* {{{ */
928 char plugin_instance[DATA_MAX_NAME_LEN];
929 list_info_ptr_t list_info =
932 /* type = */ "dns_qtype"
935 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-qtypes",
939 bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='resqtype']",
940 /* callback = */ bind_xml_list_callback,
941 /* user_data = */ &list_info,
942 doc, path_ctx, current_time, DS_TYPE_COUNTER);
946 bind_parse_generic_name_value (/* xpath = */ "rdtype",
947 /* callback = */ bind_xml_list_callback,
948 /* user_data = */ &list_info,
949 doc, path_ctx, current_time, DS_TYPE_COUNTER);
953 if (view->resolver_stats != 0) /* {{{ */
955 char plugin_instance[DATA_MAX_NAME_LEN];
956 translation_table_ptr_t table_ptr =
958 resstats_translation_table,
959 resstats_translation_table_length,
963 ssnprintf (plugin_instance, sizeof (plugin_instance),
964 "%s-resolver_stats", view->name);
967 bind_parse_generic_name_attr_value_list ("counters[@type='resstats']",
968 /* callback = */ bind_xml_table_callback,
969 /* user_data = */ &table_ptr,
970 doc, path_ctx, current_time, DS_TYPE_COUNTER);
974 bind_parse_generic_name_value ("resstat",
975 /* callback = */ bind_xml_table_callback,
976 /* user_data = */ &table_ptr,
977 doc, path_ctx, current_time, DS_TYPE_COUNTER);
981 /* Record types in the cache */
982 if (view->cacherrsets != 0) /* {{{ */
984 char plugin_instance[DATA_MAX_NAME_LEN];
985 list_info_ptr_t list_info =
988 /* type = */ "dns_qtype_cached"
991 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-cache_rr_sets",
994 bind_parse_generic_name_value (/* xpath = */ "cache/rrset",
995 /* callback = */ bind_xml_list_callback,
996 /* user_data = */ &list_info,
997 doc, path_ctx, current_time, DS_TYPE_GAUGE);
1000 if (view->zones_num > 0)
1001 bind_xml_stats_search_zones (version, doc, path_ctx, node, view,
1005 } /* }}} int bind_xml_stats_handle_view */
1007 static int bind_xml_stats_search_views (int version, xmlDoc *doc, /* {{{ */
1008 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
1010 xmlXPathObject *view_nodes = NULL;
1011 xmlXPathContext *view_path_context;
1014 view_path_context = xmlXPathNewContext (doc);
1015 if (view_path_context == NULL)
1017 ERROR ("bind plugin: xmlXPathNewContext failed.");
1021 view_nodes = xmlXPathEvalExpression (BAD_CAST "views/view", xpathCtx);
1022 if (view_nodes == NULL)
1024 ERROR ("bind plugin: Cannot find any <view> tags.");
1025 xmlXPathFreeContext (view_path_context);
1029 for (i = 0; i < view_nodes->nodesetval->nodeNr; i++)
1033 node = view_nodes->nodesetval->nodeTab[i];
1034 assert (node != NULL);
1036 view_path_context->node = node;
1038 bind_xml_stats_handle_view (version, doc, view_path_context, node,
1042 xmlXPathFreeObject (view_nodes);
1043 xmlXPathFreeContext (view_path_context);
1045 } /* }}} int bind_xml_stats_search_views */
1047 static void bind_xml_stats_v3 (xmlDoc *doc, /* {{{ */
1048 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
1050 /* XPath: server/counters[@type='opcode']
1051 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1053 * <counters type="opcode">
1054 * <counter name="A">1</counter>
1058 if (global_opcodes != 0)
1060 list_info_ptr_t list_info =
1062 /* plugin instance = */ "global-opcodes",
1063 /* type = */ "dns_opcode"
1065 bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='opcode']",
1066 /* callback = */ bind_xml_list_callback,
1067 /* user_data = */ &list_info,
1068 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1071 /* XPath: server/counters[@type='qtype']
1072 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1073 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1074 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1076 * <counters type="opcode">
1077 * <counter name="A">1</counter>
1081 if (global_qtypes != 0)
1083 list_info_ptr_t list_info =
1085 /* plugin instance = */ "global-qtypes",
1086 /* type = */ "dns_qtype"
1089 bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='qtype']",
1090 /* callback = */ bind_xml_list_callback,
1091 /* user_data = */ &list_info,
1092 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1095 /* XPath: server/counters[@type='nsstat']
1096 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1097 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1098 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1099 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1100 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1101 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1102 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1105 * <counters type="nsstat"
1106 * <counter name="Requestv4">1</counter>
1107 * <counter name="Requestv6">0</counter>
1111 if (global_server_stats)
1113 translation_table_ptr_t table_ptr =
1115 nsstats_translation_table,
1116 nsstats_translation_table_length,
1117 /* plugin_instance = */ "global-server_stats"
1120 bind_parse_generic_name_attr_value_list ("server/counters[@type='nsstat']",
1121 /* callback = */ bind_xml_table_callback,
1122 /* user_data = */ &table_ptr,
1123 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1126 /* XPath: server/zonestats, server/zonestat, server/counters[@type='zonestat']
1127 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1128 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1129 * XfrSuccess, XfrFail
1131 * <counters type="zonestat"
1132 * <counter name="NotifyOutv4">0</counter>
1133 * <counter name="NotifyOutv6">0</counter>
1137 if (global_zone_maint_stats)
1139 translation_table_ptr_t table_ptr =
1141 zonestats_translation_table,
1142 zonestats_translation_table_length,
1143 /* plugin_instance = */ "global-zone_maint_stats"
1146 bind_parse_generic_name_attr_value_list ("server/counters[@type='zonestat']",
1147 /* callback = */ bind_xml_table_callback,
1148 /* user_data = */ &table_ptr,
1149 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1152 /* XPath: server/resstats, server/counters[@type='resstat']
1153 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1154 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1155 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1156 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1158 * <counters type="resstat"
1159 * <counter name="Queryv4">0</counter>
1160 * <counter name="Queryv6">0</counter>
1164 if (global_resolver_stats != 0)
1166 translation_table_ptr_t table_ptr =
1168 resstats_translation_table,
1169 resstats_translation_table_length,
1170 /* plugin_instance = */ "global-resolver_stats"
1173 bind_parse_generic_name_attr_value_list ("server/counters[@type='resstat']",
1174 /* callback = */ bind_xml_table_callback,
1175 /* user_data = */ &table_ptr,
1176 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1178 } /* }}} bind_xml_stats_v3 */
1180 static void bind_xml_stats_v1_v2 (int version, xmlDoc *doc, /* {{{ */
1181 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
1183 /* XPath: server/requests/opcode, server/counters[@type='opcode']
1184 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1188 * <counter>1</counter>
1192 if (global_opcodes != 0)
1194 list_info_ptr_t list_info =
1196 /* plugin instance = */ "global-opcodes",
1197 /* type = */ "dns_opcode"
1200 bind_parse_generic_name_value (/* xpath = */ "server/requests/opcode",
1201 /* callback = */ bind_xml_list_callback,
1202 /* user_data = */ &list_info,
1203 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1206 /* XPath: server/queries-in/rdtype, server/counters[@type='qtype']
1207 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1208 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1209 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1213 * <counter>1</counter>
1217 if (global_qtypes != 0)
1219 list_info_ptr_t list_info =
1221 /* plugin instance = */ "global-qtypes",
1222 /* type = */ "dns_qtype"
1225 bind_parse_generic_name_value (/* xpath = */ "server/queries-in/rdtype",
1226 /* callback = */ bind_xml_list_callback,
1227 /* user_data = */ &list_info,
1228 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1231 /* XPath: server/nsstats, server/nsstat, server/counters[@type='nsstat']
1232 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1233 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1234 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1235 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1236 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1237 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1238 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1242 * <Requestv4>1</Requestv4>
1243 * <Requestv6>0</Requestv6>
1248 * <name>Requestv4</name>
1249 * <counter>1</counter>
1252 * <name>Requestv6</name>
1253 * <counter>0</counter>
1257 if (global_server_stats)
1259 translation_table_ptr_t table_ptr =
1261 nsstats_translation_table,
1262 nsstats_translation_table_length,
1263 /* plugin_instance = */ "global-server_stats"
1268 bind_parse_generic_value_list ("server/nsstats",
1269 /* callback = */ bind_xml_table_callback,
1270 /* user_data = */ &table_ptr,
1271 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1275 bind_parse_generic_name_value ("server/nsstat",
1276 /* callback = */ bind_xml_table_callback,
1277 /* user_data = */ &table_ptr,
1278 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1282 /* XPath: server/zonestats, server/zonestat, server/counters[@type='zonestat']
1283 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1284 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1285 * XfrSuccess, XfrFail
1288 * <NotifyOutv4>0</NotifyOutv4>
1289 * <NotifyOutv6>0</NotifyOutv6>
1294 * <name>NotifyOutv4</name>
1295 * <counter>0</counter>
1298 * <name>NotifyOutv6</name>
1299 * <counter>0</counter>
1303 if (global_zone_maint_stats)
1305 translation_table_ptr_t table_ptr =
1307 zonestats_translation_table,
1308 zonestats_translation_table_length,
1309 /* plugin_instance = */ "global-zone_maint_stats"
1314 bind_parse_generic_value_list ("server/zonestats",
1315 /* callback = */ bind_xml_table_callback,
1316 /* user_data = */ &table_ptr,
1317 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1321 bind_parse_generic_name_value ("server/zonestat",
1322 /* callback = */ bind_xml_table_callback,
1323 /* user_data = */ &table_ptr,
1324 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1328 /* XPath: server/resstats, server/counters[@type='resstat']
1329 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1330 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1331 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1332 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1335 * <Queryv4>0</Queryv4>
1336 * <Queryv6>0</Queryv6>
1341 * <name>Queryv4</name>
1342 * <counter>0</counter>
1345 * <name>Queryv6</name>
1346 * <counter>0</counter>
1350 if (global_resolver_stats != 0)
1352 translation_table_ptr_t table_ptr =
1354 resstats_translation_table,
1355 resstats_translation_table_length,
1356 /* plugin_instance = */ "global-resolver_stats"
1361 bind_parse_generic_value_list ("server/resstats",
1362 /* callback = */ bind_xml_table_callback,
1363 /* user_data = */ &table_ptr,
1364 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1368 bind_parse_generic_name_value ("server/resstat",
1369 /* callback = */ bind_xml_table_callback,
1370 /* user_data = */ &table_ptr,
1371 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1374 } /* }}} bind_xml_stats_v1_v2 */
1376 static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
1377 xmlXPathContext *xpathCtx, xmlNode *statsnode)
1379 time_t current_time = 0;
1382 xpathCtx->node = statsnode;
1384 /* TODO: Check `server/boot-time' to recognize server restarts. */
1386 status = bind_xml_read_timestamp ("server/current-time",
1387 doc, xpathCtx, ¤t_time);
1390 ERROR ("bind plugin: Reading `server/current-time' failed.");
1393 DEBUG ("bind plugin: Current server time is %i.", (int) current_time);
1397 bind_xml_stats_v3(doc, xpathCtx, statsnode, current_time);
1401 bind_xml_stats_v1_v2(version, doc, xpathCtx, statsnode, current_time);
1404 /* XPath: memory/summary
1405 * Variables: TotalUse, InUse, BlockSize, ContextSize, Lost
1406 * Layout: v2 and v3:
1408 * <TotalUse>6587096</TotalUse>
1409 * <InUse>1345424</InUse>
1410 * <BlockSize>5505024</BlockSize>
1411 * <ContextSize>3732456</ContextSize>
1415 if (global_memory_stats != 0)
1417 translation_table_ptr_t table_ptr =
1419 memsummary_translation_table,
1420 memsummary_translation_table_length,
1421 /* plugin_instance = */ "global-memory_stats"
1424 bind_parse_generic_value_list ("memory/summary",
1425 /* callback = */ bind_xml_table_callback,
1426 /* user_data = */ &table_ptr,
1427 doc, xpathCtx, current_time, DS_TYPE_GAUGE);
1431 bind_xml_stats_search_views (version, doc, xpathCtx, statsnode,
1435 } /* }}} int bind_xml_stats */
1437 static int bind_xml (const char *data) /* {{{ */
1440 xmlXPathContext *xpathCtx = NULL;
1441 xmlXPathObject *xpathObj = NULL;
1445 doc = xmlParseMemory (data, strlen (data));
1448 ERROR ("bind plugin: xmlParseMemory failed.");
1452 xpathCtx = xmlXPathNewContext (doc);
1453 if (xpathCtx == NULL)
1455 ERROR ("bind plugin: xmlXPathNewContext failed.");
1461 // version 3.* of statistics XML (since BIND9.9)
1464 xpathObj = xmlXPathEvalExpression (BAD_CAST "/statistics", xpathCtx);
1465 if (xpathObj == NULL || xpathObj->nodesetval == NULL || xpathObj->nodesetval->nodeNr == 0)
1467 DEBUG ("bind plugin: Statistics appears not to be v3");
1468 // we will fallback to v1 or v2 detection
1469 if (xpathObj != NULL) { xmlXPathFreeObject (xpathObj); }
1473 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++)
1478 node = xpathObj->nodesetval->nodeTab[i];
1479 assert (node != NULL);
1481 attr_version = (char *) xmlGetProp (node, BAD_CAST "version");
1482 if (attr_version == NULL)
1484 NOTICE ("bind plugin: Found <statistics> tag doesn't have a "
1485 "`version' attribute.");
1488 DEBUG ("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1490 if (strncmp ("3.", attr_version, strlen ("3.")) != 0)
1492 /* TODO: Use the complaint mechanism here. */
1493 NOTICE ("bind plugin: Found <statistics> tag with version `%s'. "
1494 "Unfortunately I have no clue how to parse that. "
1495 "Please open a bug report for this.", attr_version);
1496 xmlFree (attr_version);
1499 ret = bind_xml_stats (3, doc, xpathCtx, node);
1501 xmlFree (attr_version);
1502 /* One <statistics> node ought to be enough. */
1506 // we are finished, early-return
1507 xmlXPathFreeObject (xpathObj);
1508 xmlXPathFreeContext (xpathCtx);
1515 // versions 1.* or 2.* of statistics XML
1518 xpathObj = xmlXPathEvalExpression (BAD_CAST "/isc/bind/statistics", xpathCtx);
1519 if (xpathObj == NULL)
1521 ERROR ("bind plugin: Cannot find the <statistics> tag.");
1522 xmlXPathFreeContext (xpathCtx);
1526 else if (xpathObj->nodesetval == NULL)
1528 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
1529 xmlXPathFreeObject (xpathObj);
1530 xmlXPathFreeContext (xpathCtx);
1535 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++)
1539 int parsed_version = 0;
1541 node = xpathObj->nodesetval->nodeTab[i];
1542 assert (node != NULL);
1544 attr_version = (char *) xmlGetProp (node, BAD_CAST "version");
1545 if (attr_version == NULL)
1547 NOTICE ("bind plugin: Found <statistics> tag doesn't have a "
1548 "`version' attribute.");
1551 DEBUG ("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1553 /* At the time this plugin was written, version "1.0" was used by
1554 * BIND 9.5.0, version "2.0" was used by BIND 9.5.1 and 9.6.0. We assume
1555 * that "1.*" and "2.*" don't introduce structural changes, so we just
1556 * check for the first two characters here. */
1557 if (strncmp ("1.", attr_version, strlen ("1.")) == 0)
1559 else if (strncmp ("2.", attr_version, strlen ("2.")) == 0)
1563 /* TODO: Use the complaint mechanism here. */
1564 NOTICE ("bind plugin: Found <statistics> tag with version `%s'. "
1565 "Unfortunately I have no clue how to parse that. "
1566 "Please open a bug report for this.", attr_version);
1567 xmlFree (attr_version);
1571 ret = bind_xml_stats (parsed_version,
1572 doc, xpathCtx, node);
1574 xmlFree (attr_version);
1575 /* One <statistics> node ought to be enough. */
1579 xmlXPathFreeObject (xpathObj);
1580 xmlXPathFreeContext (xpathCtx);
1584 } /* }}} int bind_xml */
1586 static int bind_config_set_bool (const char *name, int *var, /* {{{ */
1589 if ((ci->values_num != 1) || ( ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1591 WARNING ("bind plugin: The `%s' option needs "
1592 "exactly one boolean argument.", name);
1596 if (ci->values[0].value.boolean)
1601 } /* }}} int bind_config_set_bool */
1603 static int bind_config_add_view_zone (cb_view_t *view, /* {{{ */
1608 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1610 WARNING ("bind plugin: The `Zone' option needs "
1611 "exactly one string argument.");
1615 tmp = (char **) realloc (view->zones,
1616 sizeof (char *) * (view->zones_num + 1));
1619 ERROR ("bind plugin: realloc failed.");
1624 view->zones[view->zones_num] = strdup (ci->values[0].value.string);
1625 if (view->zones[view->zones_num] == NULL)
1627 ERROR ("bind plugin: strdup failed.");
1633 } /* }}} int bind_config_add_view_zone */
1635 static int bind_config_add_view (oconfig_item_t *ci) /* {{{ */
1640 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1642 WARNING ("bind plugin: `View' blocks need exactly one string argument.");
1646 tmp = (cb_view_t *) realloc (views, sizeof (*views) * (views_num + 1));
1649 ERROR ("bind plugin: realloc failed.");
1653 tmp = views + views_num;
1655 memset (tmp, 0, sizeof (*tmp));
1657 tmp->resolver_stats = 1;
1658 tmp->cacherrsets = 1;
1662 tmp->name = strdup (ci->values[0].value.string);
1663 if (tmp->name == NULL)
1665 ERROR ("bind plugin: strdup failed.");
1670 for (i = 0; i < ci->children_num; i++)
1672 oconfig_item_t *child = ci->children + i;
1674 if (strcasecmp ("QTypes", child->key) == 0)
1675 bind_config_set_bool ("QTypes", &tmp->qtypes, child);
1676 else if (strcasecmp ("ResolverStats", child->key) == 0)
1677 bind_config_set_bool ("ResolverStats", &tmp->resolver_stats, child);
1678 else if (strcasecmp ("CacheRRSets", child->key) == 0)
1679 bind_config_set_bool ("CacheRRSets", &tmp->cacherrsets, child);
1680 else if (strcasecmp ("Zone", child->key) == 0)
1681 bind_config_add_view_zone (tmp, child);
1684 WARNING ("bind plugin: Unknown configuration option "
1685 "`%s' in view `%s' will be ignored.", child->key, tmp->name);
1687 } /* for (i = 0; i < ci->children_num; i++) */
1691 } /* }}} int bind_config_add_view */
1693 static int bind_config (oconfig_item_t *ci) /* {{{ */
1697 for (i = 0; i < ci->children_num; i++)
1699 oconfig_item_t *child = ci->children + i;
1701 if (strcasecmp ("Url", child->key) == 0) {
1702 if ((child->values_num != 1) || (child->values[0].type != OCONFIG_TYPE_STRING))
1704 WARNING ("bind plugin: The `Url' option needs "
1705 "exactly one string argument.");
1709 url = strdup (child->values[0].value.string);
1710 } else if (strcasecmp ("OpCodes", child->key) == 0)
1711 bind_config_set_bool ("OpCodes", &global_opcodes, child);
1712 else if (strcasecmp ("QTypes", child->key) == 0)
1713 bind_config_set_bool ("QTypes", &global_qtypes, child);
1714 else if (strcasecmp ("ServerStats", child->key) == 0)
1715 bind_config_set_bool ("ServerStats", &global_server_stats, child);
1716 else if (strcasecmp ("ZoneMaintStats", child->key) == 0)
1717 bind_config_set_bool ("ZoneMaintStats", &global_zone_maint_stats, child);
1718 else if (strcasecmp ("ResolverStats", child->key) == 0)
1719 bind_config_set_bool ("ResolverStats", &global_resolver_stats, child);
1720 else if (strcasecmp ("MemoryStats", child->key) == 0)
1721 bind_config_set_bool ("MemoryStats", &global_memory_stats, child);
1722 else if (strcasecmp ("View", child->key) == 0)
1723 bind_config_add_view (child);
1724 else if (strcasecmp ("ParseTime", child->key) == 0)
1725 cf_util_get_boolean (child, &config_parse_time);
1728 WARNING ("bind plugin: Unknown configuration option "
1729 "`%s' will be ignored.", child->key);
1734 } /* }}} int bind_config */
1736 static int bind_init (void) /* {{{ */
1741 curl = curl_easy_init ();
1744 ERROR ("bind plugin: bind_init: curl_easy_init failed.");
1748 curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1L);
1749 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
1750 curl_easy_setopt (curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
1751 curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, bind_curl_error);
1752 curl_easy_setopt (curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
1753 curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L);
1754 curl_easy_setopt (curl, CURLOPT_MAXREDIRS, 50L);
1757 } /* }}} int bind_init */
1759 static int bind_read (void) /* {{{ */
1765 ERROR ("bind plugin: I don't have a CURL object.");
1769 bind_buffer_fill = 0;
1770 if (curl_easy_perform (curl) != CURLE_OK)
1772 ERROR ("bind plugin: curl_easy_perform failed: %s",
1777 status = bind_xml (bind_buffer);
1782 } /* }}} int bind_read */
1784 static int bind_shutdown (void) /* {{{ */
1788 curl_easy_cleanup (curl);
1793 } /* }}} int bind_shutdown */
1795 void module_register (void)
1797 plugin_register_complex_config ("bind", bind_config);
1798 plugin_register_init ("bind", bind_init);
1799 plugin_register_read ("bind", bind_read);
1800 plugin_register_shutdown ("bind", bind_shutdown);
1801 } /* void module_register */
1803 /* vim: set sw=2 sts=2 ts=8 et fdm=marker : */