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 */
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)
250 value_list_t vl = VALUE_LIST_INIT;
254 if (config_parse_time)
255 vl.time = TIME_T_TO_CDTIME_T (ts);
256 sstrncpy(vl.plugin, "bind", sizeof(vl.plugin));
257 if (plugin_instance) {
258 sstrncpy(vl.plugin_instance, plugin_instance,
259 sizeof(vl.plugin_instance));
260 replace_special (vl.plugin_instance, sizeof (vl.plugin_instance));
262 sstrncpy(vl.type, type, sizeof(vl.type));
264 sstrncpy(vl.type_instance, type_instance,
265 sizeof(vl.type_instance));
266 replace_special (vl.type_instance, sizeof (vl.type_instance));
268 plugin_dispatch_values(&vl);
269 } /* }}} void submit */
271 static size_t bind_curl_callback (void *buf, size_t size, /* {{{ */
272 size_t nmemb, void __attribute__((unused)) *stream)
274 size_t len = size * nmemb;
279 if ((bind_buffer_fill + len) >= bind_buffer_size)
283 temp = realloc (bind_buffer, bind_buffer_fill + len + 1);
286 ERROR ("bind plugin: realloc failed.");
290 bind_buffer_size = bind_buffer_fill + len + 1;
293 memcpy (bind_buffer + bind_buffer_fill, (char *) buf, len);
294 bind_buffer_fill += len;
295 bind_buffer[bind_buffer_fill] = 0;
298 } /* }}} size_t bind_curl_callback */
301 * Callback, that's called with a translation table.
302 * (Plugin instance is fixed, type and type instance come from lookup table.)
304 static int bind_xml_table_callback (const char *name, value_t value, /* {{{ */
305 time_t current_time, void *user_data)
307 translation_table_ptr_t *table = (translation_table_ptr_t *) user_data;
312 for (size_t i = 0; i < table->table_length; i++)
314 if (strcmp (table->table[i].xml_name, name) != 0)
317 submit (current_time,
318 table->plugin_instance,
319 table->table[i].type,
320 table->table[i].type_instance,
326 } /* }}} int bind_xml_table_callback */
329 * Callback, that's used for lists.
330 * (Plugin instance and type are fixed, xml name is used as type instance.)
332 static int bind_xml_list_callback (const char *name, /* {{{ */
333 value_t value, time_t current_time, void *user_data)
335 list_info_ptr_t *list_info = (list_info_ptr_t *) user_data;
337 if (list_info == NULL)
340 submit (current_time,
341 list_info->plugin_instance,
343 /* type instance = */ name,
347 } /* }}} int bind_xml_list_callback */
349 static int bind_xml_read_derive (xmlDoc *doc, xmlNode *node, /* {{{ */
356 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
359 ERROR ("bind plugin: bind_xml_read_derive: xmlNodeListGetString failed.");
363 status = parse_value (str_ptr, &value, DS_TYPE_DERIVE);
366 ERROR ("bind plugin: Parsing string \"%s\" to derive value failed.",
373 *ret_value = value.derive;
375 } /* }}} int bind_xml_read_derive */
377 static int bind_xml_read_gauge (xmlDoc *doc, xmlNode *node, /* {{{ */
380 char *str_ptr, *end_ptr;
383 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
386 ERROR ("bind plugin: bind_xml_read_gauge: xmlNodeListGetString failed.");
391 value = strtod (str_ptr, &end_ptr);
393 if (str_ptr == end_ptr || errno)
395 if (errno && (value < 0))
396 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed with underflow.");
397 else if (errno && (value > 0))
398 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed with overflow.");
400 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed.");
404 *ret_value = (gauge_t) value;
406 } /* }}} int bind_xml_read_gauge */
408 static int bind_xml_read_timestamp (const char *xpath_expression, /* {{{ */
409 xmlDoc *doc, xmlXPathContext *xpathCtx, time_t *ret_value)
411 xmlXPathObject *xpathObj = NULL;
415 struct tm tm = { 0 };
417 xpathObj = xmlXPathEvalExpression (BAD_CAST xpath_expression, xpathCtx);
418 if (xpathObj == NULL)
420 ERROR ("bind plugin: Unable to evaluate XPath expression `%s'.",
425 if ((xpathObj->nodesetval == NULL) || (xpathObj->nodesetval->nodeNr < 1))
427 xmlXPathFreeObject (xpathObj);
431 if (xpathObj->nodesetval->nodeNr != 1)
433 NOTICE ("bind plugin: Evaluating the XPath expression `%s' returned "
434 "%i nodes. Only handling the first one.",
435 xpath_expression, xpathObj->nodesetval->nodeNr);
438 node = xpathObj->nodesetval->nodeTab[0];
440 if (node->xmlChildrenNode == NULL)
442 ERROR ("bind plugin: bind_xml_read_timestamp: "
443 "node->xmlChildrenNode == NULL");
444 xmlXPathFreeObject (xpathObj);
448 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
451 ERROR ("bind plugin: bind_xml_read_timestamp: xmlNodeListGetString failed.");
452 xmlXPathFreeObject (xpathObj);
456 tmp = strptime (str_ptr, "%Y-%m-%dT%T", &tm);
460 ERROR ("bind plugin: bind_xml_read_timestamp: strptime failed.");
461 xmlXPathFreeObject (xpathObj);
465 *ret_value = mktime(&tm);
467 xmlXPathFreeObject (xpathObj);
469 } /* }}} int bind_xml_read_timestamp */
472 * bind_parse_generic_name_value
474 * Reads statistics in the form:
477 * <counter>123</counter>
480 static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ */
481 list_callback_t list_callback,
483 xmlDoc *doc, xmlXPathContext *xpathCtx,
484 time_t current_time, int ds_type)
486 xmlXPathObject *xpathObj = NULL;
489 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
490 if (xpathObj == NULL)
492 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
498 /* Iterate over all matching nodes. */
499 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
501 xmlNode *name_node = NULL;
502 xmlNode *counter = NULL;
505 parent = xpathObj->nodesetval->nodeTab[i];
506 DEBUG ("bind plugin: bind_parse_generic_name_value: parent->name = %s;",
507 (char *) parent->name);
509 /* Iterate over all child nodes. */
510 for (xmlNode *child = parent->xmlChildrenNode;
514 if (child->type != XML_ELEMENT_NODE)
517 if (xmlStrcmp (BAD_CAST "name", child->name) == 0)
519 else if (xmlStrcmp (BAD_CAST "counter", child->name) == 0)
523 if ((name_node != NULL) && (counter != NULL))
525 char *name = (char *) xmlNodeListGetString (doc,
526 name_node->xmlChildrenNode, 1);
530 if (ds_type == DS_TYPE_GAUGE)
531 status = bind_xml_read_gauge (doc, counter, &value.gauge);
533 status = bind_xml_read_derive (doc, counter, &value.derive);
537 status = (*list_callback) (name, value, current_time, user_data);
545 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
546 num_entries, (num_entries == 1) ? "entry" : "entries",
549 xmlXPathFreeObject(xpathObj);
552 } /* }}} int bind_parse_generic_name_value */
555 * bind_parse_generic_value_list
557 * Reads statistics in the form:
565 static int bind_parse_generic_value_list (const char *xpath_expression, /* {{{ */
566 list_callback_t list_callback,
568 xmlDoc *doc, xmlXPathContext *xpathCtx,
569 time_t current_time, int ds_type)
571 xmlXPathObject *xpathObj = NULL;
574 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
575 if (xpathObj == NULL)
577 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
583 /* Iterate over all matching nodes. */
584 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
586 /* Iterate over all child nodes. */
587 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
595 if (child->type != XML_ELEMENT_NODE)
598 node_name = (char *) child->name;
600 if (ds_type == DS_TYPE_GAUGE)
601 status = bind_xml_read_gauge (doc, child, &value.gauge);
603 status = bind_xml_read_derive (doc, child, &value.derive);
607 status = (*list_callback) (node_name, value, current_time, user_data);
613 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
614 num_entries, (num_entries == 1) ? "entry" : "entries",
617 xmlXPathFreeObject(xpathObj);
620 } /* }}} int bind_parse_generic_value_list */
623 * bind_parse_generic_name_attr_value_list
625 * Reads statistics in the form:
627 * <counter name="name0">123</counter>
628 * <counter name="name1">234</counter>
629 * <counter name="name2">345</counter>
633 static int bind_parse_generic_name_attr_value_list (const char *xpath_expression, /* {{{ */
634 list_callback_t list_callback,
636 xmlDoc *doc, xmlXPathContext *xpathCtx,
637 time_t current_time, int ds_type)
639 xmlXPathObject *xpathObj = NULL;
642 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
643 if (xpathObj == NULL)
645 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
651 /* Iterate over all matching nodes. */
652 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
654 /* Iterate over all child nodes. */
655 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
659 if (child->type != XML_ELEMENT_NODE)
662 if (strncmp ("counter", (char *) child->name, strlen ("counter")) != 0)
669 attr_name = (char *) xmlGetProp (child, BAD_CAST "name");
670 if (attr_name == NULL)
672 DEBUG ("bind plugin: found <counter> without name.");
675 if (ds_type == DS_TYPE_GAUGE)
676 status = bind_xml_read_gauge (doc, child, &value.gauge);
678 status = bind_xml_read_derive (doc, child, &value.derive);
682 status = (*list_callback) (attr_name, value, current_time, user_data);
688 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
689 num_entries, (num_entries == 1) ? "entry" : "entries",
692 xmlXPathFreeObject(xpathObj);
695 } /* }}} int bind_parse_generic_name_attr_value_list */
697 static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */
698 xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view,
701 xmlXPathObject *path_obj;
702 char *zone_name = NULL;
707 char *n = (char *) xmlGetProp (node, BAD_CAST "name");
708 char *c = (char *) xmlGetProp (node, BAD_CAST "rdataclass");
711 zone_name = (char *) xmlMalloc(strlen(n) + strlen(c) + 2);
712 snprintf(zone_name, strlen(n) + strlen(c) + 2, "%s/%s", n, c);
719 path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
720 if (path_obj == NULL)
722 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
726 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
728 zone_name = (char *) xmlNodeListGetString (doc,
729 path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
730 if (zone_name != NULL)
733 xmlXPathFreeObject (path_obj);
736 if (zone_name == NULL)
738 ERROR ("bind plugin: Could not determine zone name.");
742 for (j = 0; j < view->zones_num; j++)
744 if (strcasecmp (zone_name, view->zones[j]) == 0)
751 if (j >= view->zones_num)
754 zone_name = view->zones[j];
756 DEBUG ("bind plugin: bind_xml_stats_handle_zone: Found zone `%s'.",
759 { /* Parse the <counters> tag {{{ */
760 char plugin_instance[DATA_MAX_NAME_LEN];
761 translation_table_ptr_t table_ptr =
763 nsstats_translation_table,
764 nsstats_translation_table_length,
768 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-zone-%s",
769 view->name, zone_name);
773 list_info_ptr_t list_info =
776 /* type = */ "dns_qtype"
778 bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='rcode']",
779 /* callback = */ bind_xml_table_callback,
780 /* user_data = */ &table_ptr,
781 doc, path_ctx, current_time, DS_TYPE_COUNTER);
782 bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='qtype']",
783 /* callback = */ bind_xml_list_callback,
784 /* user_data = */ &list_info,
785 doc, path_ctx, current_time, DS_TYPE_COUNTER);
789 bind_parse_generic_value_list (/* xpath = */ "counters",
790 /* callback = */ bind_xml_table_callback,
791 /* user_data = */ &table_ptr,
792 doc, path_ctx, current_time, DS_TYPE_COUNTER);
797 } /* }}} int bind_xml_stats_handle_zone */
799 static int bind_xml_stats_search_zones (int version, xmlDoc *doc, /* {{{ */
800 xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view,
803 xmlXPathObject *zone_nodes = NULL;
804 xmlXPathContext *zone_path_context;
806 zone_path_context = xmlXPathNewContext (doc);
807 if (zone_path_context == NULL)
809 ERROR ("bind plugin: xmlXPathNewContext failed.");
813 zone_nodes = xmlXPathEvalExpression (BAD_CAST "zones/zone", path_ctx);
814 if (zone_nodes == NULL)
816 ERROR ("bind plugin: Cannot find any <view> tags.");
817 xmlXPathFreeContext (zone_path_context);
821 for (int i = 0; i < zone_nodes->nodesetval->nodeNr; i++)
823 node = zone_nodes->nodesetval->nodeTab[i];
824 assert (node != NULL);
826 zone_path_context->node = node;
828 bind_xml_stats_handle_zone (version, doc, zone_path_context, node, view,
832 xmlXPathFreeObject (zone_nodes);
833 xmlXPathFreeContext (zone_path_context);
835 } /* }}} int bind_xml_stats_search_zones */
837 static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */
838 xmlXPathContext *path_ctx, xmlNode *node, time_t current_time)
840 char *view_name = NULL;
846 view_name = (char*) xmlGetProp(node, BAD_CAST "name");
848 if (view_name == NULL)
850 ERROR ("bind plugin: Could not determine view name.");
854 for (j = 0; j < views_num; j++)
856 if (strcasecmp (view_name, views[j].name) == 0)
865 xmlXPathObject *path_obj;
866 path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
867 if (path_obj == NULL)
869 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
873 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
875 view_name = (char *) xmlNodeListGetString (doc,
876 path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
877 if (view_name != NULL)
881 if (view_name == NULL)
883 ERROR ("bind plugin: Could not determine view name.");
884 xmlXPathFreeObject (path_obj);
888 for (j = 0; j < views_num; j++)
890 if (strcasecmp (view_name, views[j].name) == 0)
895 xmlXPathFreeObject (path_obj);
907 DEBUG ("bind plugin: bind_xml_stats_handle_view: Found view `%s'.",
910 if (view->qtypes != 0) /* {{{ */
912 char plugin_instance[DATA_MAX_NAME_LEN];
913 list_info_ptr_t list_info =
916 /* type = */ "dns_qtype"
919 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-qtypes",
923 bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='resqtype']",
924 /* callback = */ bind_xml_list_callback,
925 /* user_data = */ &list_info,
926 doc, path_ctx, current_time, DS_TYPE_COUNTER);
930 bind_parse_generic_name_value (/* xpath = */ "rdtype",
931 /* callback = */ bind_xml_list_callback,
932 /* user_data = */ &list_info,
933 doc, path_ctx, current_time, DS_TYPE_COUNTER);
937 if (view->resolver_stats != 0) /* {{{ */
939 char plugin_instance[DATA_MAX_NAME_LEN];
940 translation_table_ptr_t table_ptr =
942 resstats_translation_table,
943 resstats_translation_table_length,
947 ssnprintf (plugin_instance, sizeof (plugin_instance),
948 "%s-resolver_stats", view->name);
951 bind_parse_generic_name_attr_value_list ("counters[@type='resstats']",
952 /* callback = */ bind_xml_table_callback,
953 /* user_data = */ &table_ptr,
954 doc, path_ctx, current_time, DS_TYPE_COUNTER);
958 bind_parse_generic_name_value ("resstat",
959 /* callback = */ bind_xml_table_callback,
960 /* user_data = */ &table_ptr,
961 doc, path_ctx, current_time, DS_TYPE_COUNTER);
965 /* Record types in the cache */
966 if (view->cacherrsets != 0) /* {{{ */
968 char plugin_instance[DATA_MAX_NAME_LEN];
969 list_info_ptr_t list_info =
972 /* type = */ "dns_qtype_cached"
975 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-cache_rr_sets",
978 bind_parse_generic_name_value (/* xpath = */ "cache/rrset",
979 /* callback = */ bind_xml_list_callback,
980 /* user_data = */ &list_info,
981 doc, path_ctx, current_time, DS_TYPE_GAUGE);
984 if (view->zones_num > 0)
985 bind_xml_stats_search_zones (version, doc, path_ctx, node, view,
989 } /* }}} int bind_xml_stats_handle_view */
991 static int bind_xml_stats_search_views (int version, xmlDoc *doc, /* {{{ */
992 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
994 xmlXPathObject *view_nodes = NULL;
995 xmlXPathContext *view_path_context;
997 view_path_context = xmlXPathNewContext (doc);
998 if (view_path_context == NULL)
1000 ERROR ("bind plugin: xmlXPathNewContext failed.");
1004 view_nodes = xmlXPathEvalExpression (BAD_CAST "views/view", xpathCtx);
1005 if (view_nodes == NULL)
1007 ERROR ("bind plugin: Cannot find any <view> tags.");
1008 xmlXPathFreeContext (view_path_context);
1012 for (int i = 0; i < view_nodes->nodesetval->nodeNr; i++)
1016 node = view_nodes->nodesetval->nodeTab[i];
1017 assert (node != NULL);
1019 view_path_context->node = node;
1021 bind_xml_stats_handle_view (version, doc, view_path_context, node,
1025 xmlXPathFreeObject (view_nodes);
1026 xmlXPathFreeContext (view_path_context);
1028 } /* }}} int bind_xml_stats_search_views */
1030 static void bind_xml_stats_v3 (xmlDoc *doc, /* {{{ */
1031 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
1033 /* XPath: server/counters[@type='opcode']
1034 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1036 * <counters type="opcode">
1037 * <counter name="A">1</counter>
1041 if (global_opcodes != 0)
1043 list_info_ptr_t list_info =
1045 /* plugin instance = */ "global-opcodes",
1046 /* type = */ "dns_opcode"
1048 bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='opcode']",
1049 /* callback = */ bind_xml_list_callback,
1050 /* user_data = */ &list_info,
1051 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1054 /* XPath: server/counters[@type='qtype']
1055 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1056 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1057 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1059 * <counters type="opcode">
1060 * <counter name="A">1</counter>
1064 if (global_qtypes != 0)
1066 list_info_ptr_t list_info =
1068 /* plugin instance = */ "global-qtypes",
1069 /* type = */ "dns_qtype"
1072 bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='qtype']",
1073 /* callback = */ bind_xml_list_callback,
1074 /* user_data = */ &list_info,
1075 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1078 /* XPath: server/counters[@type='nsstat']
1079 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1080 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1081 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1082 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1083 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1084 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1085 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1088 * <counters type="nsstat"
1089 * <counter name="Requestv4">1</counter>
1090 * <counter name="Requestv6">0</counter>
1094 if (global_server_stats)
1096 translation_table_ptr_t table_ptr =
1098 nsstats_translation_table,
1099 nsstats_translation_table_length,
1100 /* plugin_instance = */ "global-server_stats"
1103 bind_parse_generic_name_attr_value_list ("server/counters[@type='nsstat']",
1104 /* callback = */ bind_xml_table_callback,
1105 /* user_data = */ &table_ptr,
1106 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1109 /* XPath: server/zonestats, server/zonestat, server/counters[@type='zonestat']
1110 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1111 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1112 * XfrSuccess, XfrFail
1114 * <counters type="zonestat"
1115 * <counter name="NotifyOutv4">0</counter>
1116 * <counter name="NotifyOutv6">0</counter>
1120 if (global_zone_maint_stats)
1122 translation_table_ptr_t table_ptr =
1124 zonestats_translation_table,
1125 zonestats_translation_table_length,
1126 /* plugin_instance = */ "global-zone_maint_stats"
1129 bind_parse_generic_name_attr_value_list ("server/counters[@type='zonestat']",
1130 /* callback = */ bind_xml_table_callback,
1131 /* user_data = */ &table_ptr,
1132 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1135 /* XPath: server/resstats, server/counters[@type='resstat']
1136 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1137 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1138 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1139 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1141 * <counters type="resstat"
1142 * <counter name="Queryv4">0</counter>
1143 * <counter name="Queryv6">0</counter>
1147 if (global_resolver_stats != 0)
1149 translation_table_ptr_t table_ptr =
1151 resstats_translation_table,
1152 resstats_translation_table_length,
1153 /* plugin_instance = */ "global-resolver_stats"
1156 bind_parse_generic_name_attr_value_list ("server/counters[@type='resstat']",
1157 /* callback = */ bind_xml_table_callback,
1158 /* user_data = */ &table_ptr,
1159 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1161 } /* }}} bind_xml_stats_v3 */
1163 static void bind_xml_stats_v1_v2 (int version, xmlDoc *doc, /* {{{ */
1164 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
1166 /* XPath: server/requests/opcode, server/counters[@type='opcode']
1167 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1171 * <counter>1</counter>
1175 if (global_opcodes != 0)
1177 list_info_ptr_t list_info =
1179 /* plugin instance = */ "global-opcodes",
1180 /* type = */ "dns_opcode"
1183 bind_parse_generic_name_value (/* xpath = */ "server/requests/opcode",
1184 /* callback = */ bind_xml_list_callback,
1185 /* user_data = */ &list_info,
1186 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1189 /* XPath: server/queries-in/rdtype, server/counters[@type='qtype']
1190 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1191 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1192 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1196 * <counter>1</counter>
1200 if (global_qtypes != 0)
1202 list_info_ptr_t list_info =
1204 /* plugin instance = */ "global-qtypes",
1205 /* type = */ "dns_qtype"
1208 bind_parse_generic_name_value (/* xpath = */ "server/queries-in/rdtype",
1209 /* callback = */ bind_xml_list_callback,
1210 /* user_data = */ &list_info,
1211 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1214 /* XPath: server/nsstats, server/nsstat, server/counters[@type='nsstat']
1215 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1216 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1217 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1218 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1219 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1220 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1221 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1225 * <Requestv4>1</Requestv4>
1226 * <Requestv6>0</Requestv6>
1231 * <name>Requestv4</name>
1232 * <counter>1</counter>
1235 * <name>Requestv6</name>
1236 * <counter>0</counter>
1240 if (global_server_stats)
1242 translation_table_ptr_t table_ptr =
1244 nsstats_translation_table,
1245 nsstats_translation_table_length,
1246 /* plugin_instance = */ "global-server_stats"
1251 bind_parse_generic_value_list ("server/nsstats",
1252 /* callback = */ bind_xml_table_callback,
1253 /* user_data = */ &table_ptr,
1254 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1258 bind_parse_generic_name_value ("server/nsstat",
1259 /* callback = */ bind_xml_table_callback,
1260 /* user_data = */ &table_ptr,
1261 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1265 /* XPath: server/zonestats, server/zonestat, server/counters[@type='zonestat']
1266 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1267 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1268 * XfrSuccess, XfrFail
1271 * <NotifyOutv4>0</NotifyOutv4>
1272 * <NotifyOutv6>0</NotifyOutv6>
1277 * <name>NotifyOutv4</name>
1278 * <counter>0</counter>
1281 * <name>NotifyOutv6</name>
1282 * <counter>0</counter>
1286 if (global_zone_maint_stats)
1288 translation_table_ptr_t table_ptr =
1290 zonestats_translation_table,
1291 zonestats_translation_table_length,
1292 /* plugin_instance = */ "global-zone_maint_stats"
1297 bind_parse_generic_value_list ("server/zonestats",
1298 /* callback = */ bind_xml_table_callback,
1299 /* user_data = */ &table_ptr,
1300 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1304 bind_parse_generic_name_value ("server/zonestat",
1305 /* callback = */ bind_xml_table_callback,
1306 /* user_data = */ &table_ptr,
1307 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1311 /* XPath: server/resstats, server/counters[@type='resstat']
1312 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1313 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1314 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1315 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1318 * <Queryv4>0</Queryv4>
1319 * <Queryv6>0</Queryv6>
1324 * <name>Queryv4</name>
1325 * <counter>0</counter>
1328 * <name>Queryv6</name>
1329 * <counter>0</counter>
1333 if (global_resolver_stats != 0)
1335 translation_table_ptr_t table_ptr =
1337 resstats_translation_table,
1338 resstats_translation_table_length,
1339 /* plugin_instance = */ "global-resolver_stats"
1344 bind_parse_generic_value_list ("server/resstats",
1345 /* callback = */ bind_xml_table_callback,
1346 /* user_data = */ &table_ptr,
1347 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1351 bind_parse_generic_name_value ("server/resstat",
1352 /* callback = */ bind_xml_table_callback,
1353 /* user_data = */ &table_ptr,
1354 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1357 } /* }}} bind_xml_stats_v1_v2 */
1359 static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
1360 xmlXPathContext *xpathCtx, xmlNode *statsnode)
1362 time_t current_time = 0;
1365 xpathCtx->node = statsnode;
1367 /* TODO: Check `server/boot-time' to recognize server restarts. */
1369 status = bind_xml_read_timestamp ("server/current-time",
1370 doc, xpathCtx, ¤t_time);
1373 ERROR ("bind plugin: Reading `server/current-time' failed.");
1376 DEBUG ("bind plugin: Current server time is %i.", (int) current_time);
1380 bind_xml_stats_v3(doc, xpathCtx, statsnode, current_time);
1384 bind_xml_stats_v1_v2(version, doc, xpathCtx, statsnode, current_time);
1387 /* XPath: memory/summary
1388 * Variables: TotalUse, InUse, BlockSize, ContextSize, Lost
1389 * Layout: v2 and v3:
1391 * <TotalUse>6587096</TotalUse>
1392 * <InUse>1345424</InUse>
1393 * <BlockSize>5505024</BlockSize>
1394 * <ContextSize>3732456</ContextSize>
1398 if (global_memory_stats != 0)
1400 translation_table_ptr_t table_ptr =
1402 memsummary_translation_table,
1403 memsummary_translation_table_length,
1404 /* plugin_instance = */ "global-memory_stats"
1407 bind_parse_generic_value_list ("memory/summary",
1408 /* callback = */ bind_xml_table_callback,
1409 /* user_data = */ &table_ptr,
1410 doc, xpathCtx, current_time, DS_TYPE_GAUGE);
1414 bind_xml_stats_search_views (version, doc, xpathCtx, statsnode,
1418 } /* }}} int bind_xml_stats */
1420 static int bind_xml (const char *data) /* {{{ */
1423 xmlXPathContext *xpathCtx = NULL;
1424 xmlXPathObject *xpathObj = NULL;
1427 doc = xmlParseMemory (data, strlen (data));
1430 ERROR ("bind plugin: xmlParseMemory failed.");
1434 xpathCtx = xmlXPathNewContext (doc);
1435 if (xpathCtx == NULL)
1437 ERROR ("bind plugin: xmlXPathNewContext failed.");
1443 // version 3.* of statistics XML (since BIND9.9)
1446 xpathObj = xmlXPathEvalExpression (BAD_CAST "/statistics", xpathCtx);
1447 if (xpathObj == NULL || xpathObj->nodesetval == NULL || xpathObj->nodesetval->nodeNr == 0)
1449 DEBUG ("bind plugin: Statistics appears not to be v3");
1450 // we will fallback to v1 or v2 detection
1451 if (xpathObj != NULL) { xmlXPathFreeObject (xpathObj); }
1455 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++)
1460 node = xpathObj->nodesetval->nodeTab[i];
1461 assert (node != NULL);
1463 attr_version = (char *) xmlGetProp (node, BAD_CAST "version");
1464 if (attr_version == NULL)
1466 NOTICE ("bind plugin: Found <statistics> tag doesn't have a "
1467 "`version' attribute.");
1470 DEBUG ("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1472 if (strncmp ("3.", attr_version, strlen ("3.")) != 0)
1474 /* TODO: Use the complaint mechanism here. */
1475 NOTICE ("bind plugin: Found <statistics> tag with version `%s'. "
1476 "Unfortunately I have no clue how to parse that. "
1477 "Please open a bug report for this.", attr_version);
1478 xmlFree (attr_version);
1481 ret = bind_xml_stats (3, doc, xpathCtx, node);
1483 xmlFree (attr_version);
1484 /* One <statistics> node ought to be enough. */
1488 // we are finished, early-return
1489 xmlXPathFreeObject (xpathObj);
1490 xmlXPathFreeContext (xpathCtx);
1497 // versions 1.* or 2.* of statistics XML
1500 xpathObj = xmlXPathEvalExpression (BAD_CAST "/isc/bind/statistics", xpathCtx);
1501 if (xpathObj == NULL)
1503 ERROR ("bind plugin: Cannot find the <statistics> tag.");
1504 xmlXPathFreeContext (xpathCtx);
1508 else if (xpathObj->nodesetval == NULL)
1510 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
1511 xmlXPathFreeObject (xpathObj);
1512 xmlXPathFreeContext (xpathCtx);
1517 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++)
1521 int parsed_version = 0;
1523 node = xpathObj->nodesetval->nodeTab[i];
1524 assert (node != NULL);
1526 attr_version = (char *) xmlGetProp (node, BAD_CAST "version");
1527 if (attr_version == NULL)
1529 NOTICE ("bind plugin: Found <statistics> tag doesn't have a "
1530 "`version' attribute.");
1533 DEBUG ("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1535 /* At the time this plugin was written, version "1.0" was used by
1536 * BIND 9.5.0, version "2.0" was used by BIND 9.5.1 and 9.6.0. We assume
1537 * that "1.*" and "2.*" don't introduce structural changes, so we just
1538 * check for the first two characters here. */
1539 if (strncmp ("1.", attr_version, strlen ("1.")) == 0)
1541 else if (strncmp ("2.", attr_version, strlen ("2.")) == 0)
1545 /* TODO: Use the complaint mechanism here. */
1546 NOTICE ("bind plugin: Found <statistics> tag with version `%s'. "
1547 "Unfortunately I have no clue how to parse that. "
1548 "Please open a bug report for this.", attr_version);
1549 xmlFree (attr_version);
1553 ret = bind_xml_stats (parsed_version,
1554 doc, xpathCtx, node);
1556 xmlFree (attr_version);
1557 /* One <statistics> node ought to be enough. */
1561 xmlXPathFreeObject (xpathObj);
1562 xmlXPathFreeContext (xpathCtx);
1566 } /* }}} int bind_xml */
1568 static int bind_config_set_bool (const char *name, int *var, /* {{{ */
1571 if ((ci->values_num != 1) || ( ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1573 WARNING ("bind plugin: The `%s' option needs "
1574 "exactly one boolean argument.", name);
1578 if (ci->values[0].value.boolean)
1583 } /* }}} int bind_config_set_bool */
1585 static int bind_config_add_view_zone (cb_view_t *view, /* {{{ */
1590 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1592 WARNING ("bind plugin: The `Zone' option needs "
1593 "exactly one string argument.");
1597 tmp = realloc (view->zones,
1598 sizeof (char *) * (view->zones_num + 1));
1601 ERROR ("bind plugin: realloc failed.");
1606 view->zones[view->zones_num] = strdup (ci->values[0].value.string);
1607 if (view->zones[view->zones_num] == NULL)
1609 ERROR ("bind plugin: strdup failed.");
1615 } /* }}} int bind_config_add_view_zone */
1617 static int bind_config_add_view (oconfig_item_t *ci) /* {{{ */
1621 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1623 WARNING ("bind plugin: `View' blocks need exactly one string argument.");
1627 tmp = realloc (views, sizeof (*views) * (views_num + 1));
1630 ERROR ("bind plugin: realloc failed.");
1634 tmp = views + views_num;
1636 memset (tmp, 0, sizeof (*tmp));
1638 tmp->resolver_stats = 1;
1639 tmp->cacherrsets = 1;
1643 tmp->name = strdup (ci->values[0].value.string);
1644 if (tmp->name == NULL)
1646 ERROR ("bind plugin: strdup failed.");
1651 for (int i = 0; i < ci->children_num; i++)
1653 oconfig_item_t *child = ci->children + i;
1655 if (strcasecmp ("QTypes", child->key) == 0)
1656 bind_config_set_bool ("QTypes", &tmp->qtypes, child);
1657 else if (strcasecmp ("ResolverStats", child->key) == 0)
1658 bind_config_set_bool ("ResolverStats", &tmp->resolver_stats, child);
1659 else if (strcasecmp ("CacheRRSets", child->key) == 0)
1660 bind_config_set_bool ("CacheRRSets", &tmp->cacherrsets, child);
1661 else if (strcasecmp ("Zone", child->key) == 0)
1662 bind_config_add_view_zone (tmp, child);
1665 WARNING ("bind plugin: Unknown configuration option "
1666 "`%s' in view `%s' will be ignored.", child->key, tmp->name);
1668 } /* for (i = 0; i < ci->children_num; i++) */
1672 } /* }}} int bind_config_add_view */
1674 static int bind_config (oconfig_item_t *ci) /* {{{ */
1676 for (int i = 0; i < ci->children_num; i++)
1678 oconfig_item_t *child = ci->children + i;
1680 if (strcasecmp ("Url", child->key) == 0) {
1681 if ((child->values_num != 1) || (child->values[0].type != OCONFIG_TYPE_STRING))
1683 WARNING ("bind plugin: The `Url' option needs "
1684 "exactly one string argument.");
1689 url = strdup (child->values[0].value.string);
1690 } else if (strcasecmp ("OpCodes", child->key) == 0)
1691 bind_config_set_bool ("OpCodes", &global_opcodes, child);
1692 else if (strcasecmp ("QTypes", child->key) == 0)
1693 bind_config_set_bool ("QTypes", &global_qtypes, child);
1694 else if (strcasecmp ("ServerStats", child->key) == 0)
1695 bind_config_set_bool ("ServerStats", &global_server_stats, child);
1696 else if (strcasecmp ("ZoneMaintStats", child->key) == 0)
1697 bind_config_set_bool ("ZoneMaintStats", &global_zone_maint_stats, child);
1698 else if (strcasecmp ("ResolverStats", child->key) == 0)
1699 bind_config_set_bool ("ResolverStats", &global_resolver_stats, child);
1700 else if (strcasecmp ("MemoryStats", child->key) == 0)
1701 bind_config_set_bool ("MemoryStats", &global_memory_stats, child);
1702 else if (strcasecmp ("View", child->key) == 0)
1703 bind_config_add_view (child);
1704 else if (strcasecmp ("ParseTime", child->key) == 0)
1705 cf_util_get_boolean (child, &config_parse_time);
1706 else if (strcasecmp ("Timeout", child->key) == 0)
1707 cf_util_get_int (child, &timeout);
1710 WARNING ("bind plugin: Unknown configuration option "
1711 "`%s' will be ignored.", child->key);
1716 } /* }}} int bind_config */
1718 static int bind_init (void) /* {{{ */
1723 curl = curl_easy_init ();
1726 ERROR ("bind plugin: bind_init: curl_easy_init failed.");
1730 curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1L);
1731 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
1732 curl_easy_setopt (curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
1733 curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, bind_curl_error);
1734 curl_easy_setopt (curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
1735 curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L);
1736 curl_easy_setopt (curl, CURLOPT_MAXREDIRS, 50L);
1737 #ifdef HAVE_CURLOPT_TIMEOUT_MS
1738 curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, (timeout >= 0) ?
1739 (long) timeout : (long) CDTIME_T_TO_MS(plugin_get_interval()));
1744 } /* }}} int bind_init */
1746 static int bind_read (void) /* {{{ */
1752 ERROR ("bind plugin: I don't have a CURL object.");
1756 bind_buffer_fill = 0;
1757 if (curl_easy_perform (curl) != CURLE_OK)
1759 ERROR ("bind plugin: curl_easy_perform failed: %s",
1764 status = bind_xml (bind_buffer);
1769 } /* }}} int bind_read */
1771 static int bind_shutdown (void) /* {{{ */
1775 curl_easy_cleanup (curl);
1780 } /* }}} int bind_shutdown */
1782 void module_register (void)
1784 plugin_register_complex_config ("bind", bind_config);
1785 plugin_register_init ("bind", bind_init);
1786 plugin_register_read ("bind", bind_read);
1787 plugin_register_shutdown ("bind", bind_shutdown);
1788 } /* void module_register */
1790 /* vim: set sw=2 sts=2 ts=8 et fdm=marker : */