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)
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;
316 for (size_t 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.",
377 *ret_value = value.derive;
379 } /* }}} int bind_xml_read_derive */
381 static int bind_xml_read_gauge (xmlDoc *doc, xmlNode *node, /* {{{ */
384 char *str_ptr, *end_ptr;
387 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
390 ERROR ("bind plugin: bind_xml_read_gauge: xmlNodeListGetString failed.");
395 value = strtod (str_ptr, &end_ptr);
397 if (str_ptr == end_ptr || errno)
399 if (errno && (value < 0))
400 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed with underflow.");
401 else if (errno && (value > 0))
402 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed with overflow.");
404 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed.");
408 *ret_value = (gauge_t) value;
410 } /* }}} int bind_xml_read_gauge */
412 static int bind_xml_read_timestamp (const char *xpath_expression, /* {{{ */
413 xmlDoc *doc, xmlXPathContext *xpathCtx, time_t *ret_value)
415 xmlXPathObject *xpathObj = NULL;
419 struct tm tm = { 0 };
421 xpathObj = xmlXPathEvalExpression (BAD_CAST xpath_expression, xpathCtx);
422 if (xpathObj == NULL)
424 ERROR ("bind plugin: Unable to evaluate XPath expression `%s'.",
429 if ((xpathObj->nodesetval == NULL) || (xpathObj->nodesetval->nodeNr < 1))
431 xmlXPathFreeObject (xpathObj);
435 if (xpathObj->nodesetval->nodeNr != 1)
437 NOTICE ("bind plugin: Evaluating the XPath expression `%s' returned "
438 "%i nodes. Only handling the first one.",
439 xpath_expression, xpathObj->nodesetval->nodeNr);
442 node = xpathObj->nodesetval->nodeTab[0];
444 if (node->xmlChildrenNode == NULL)
446 ERROR ("bind plugin: bind_xml_read_timestamp: "
447 "node->xmlChildrenNode == NULL");
448 xmlXPathFreeObject (xpathObj);
452 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
455 ERROR ("bind plugin: bind_xml_read_timestamp: xmlNodeListGetString failed.");
456 xmlXPathFreeObject (xpathObj);
460 tmp = strptime (str_ptr, "%Y-%m-%dT%T", &tm);
464 ERROR ("bind plugin: bind_xml_read_timestamp: strptime failed.");
465 xmlXPathFreeObject (xpathObj);
469 *ret_value = mktime(&tm);
471 xmlXPathFreeObject (xpathObj);
473 } /* }}} int bind_xml_read_timestamp */
476 * bind_parse_generic_name_value
478 * Reads statistics in the form:
481 * <counter>123</counter>
484 static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ */
485 list_callback_t list_callback,
487 xmlDoc *doc, xmlXPathContext *xpathCtx,
488 time_t current_time, int ds_type)
490 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 (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
505 xmlNode *name_node = NULL;
506 xmlNode *counter = NULL;
509 parent = xpathObj->nodesetval->nodeTab[i];
510 DEBUG ("bind plugin: bind_parse_generic_name_value: parent->name = %s;",
511 (char *) parent->name);
513 /* Iterate over all child nodes. */
514 for (xmlNode *child = parent->xmlChildrenNode;
518 if (child->type != XML_ELEMENT_NODE)
521 if (xmlStrcmp (BAD_CAST "name", child->name) == 0)
523 else if (xmlStrcmp (BAD_CAST "counter", child->name) == 0)
527 if ((name_node != NULL) && (counter != NULL))
529 char *name = (char *) xmlNodeListGetString (doc,
530 name_node->xmlChildrenNode, 1);
534 if (ds_type == DS_TYPE_GAUGE)
535 status = bind_xml_read_gauge (doc, counter, &value.gauge);
537 status = bind_xml_read_derive (doc, counter, &value.derive);
541 status = (*list_callback) (name, value, current_time, user_data);
549 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
550 num_entries, (num_entries == 1) ? "entry" : "entries",
553 xmlXPathFreeObject(xpathObj);
556 } /* }}} int bind_parse_generic_name_value */
559 * bind_parse_generic_value_list
561 * Reads statistics in the form:
569 static int bind_parse_generic_value_list (const char *xpath_expression, /* {{{ */
570 list_callback_t list_callback,
572 xmlDoc *doc, xmlXPathContext *xpathCtx,
573 time_t current_time, int ds_type)
575 xmlXPathObject *xpathObj = NULL;
578 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
579 if (xpathObj == NULL)
581 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
587 /* Iterate over all matching nodes. */
588 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
590 /* Iterate over all child nodes. */
591 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
599 if (child->type != XML_ELEMENT_NODE)
602 node_name = (char *) child->name;
604 if (ds_type == DS_TYPE_GAUGE)
605 status = bind_xml_read_gauge (doc, child, &value.gauge);
607 status = bind_xml_read_derive (doc, child, &value.derive);
611 status = (*list_callback) (node_name, value, current_time, user_data);
617 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
618 num_entries, (num_entries == 1) ? "entry" : "entries",
621 xmlXPathFreeObject(xpathObj);
624 } /* }}} int bind_parse_generic_value_list */
627 * bind_parse_generic_name_attr_value_list
629 * Reads statistics in the form:
631 * <counter name="name0">123</counter>
632 * <counter name="name1">234</counter>
633 * <counter name="name2">345</counter>
637 static int bind_parse_generic_name_attr_value_list (const char *xpath_expression, /* {{{ */
638 list_callback_t list_callback,
640 xmlDoc *doc, xmlXPathContext *xpathCtx,
641 time_t current_time, int ds_type)
643 xmlXPathObject *xpathObj = NULL;
646 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
647 if (xpathObj == NULL)
649 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
655 /* Iterate over all matching nodes. */
656 for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
658 /* Iterate over all child nodes. */
659 for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
663 if (child->type != XML_ELEMENT_NODE)
666 if (strncmp ("counter", (char *) child->name, strlen ("counter")) != 0)
673 attr_name = (char *) xmlGetProp (child, BAD_CAST "name");
674 if (attr_name == NULL)
676 DEBUG ("bind plugin: found <counter> without name.");
679 if (ds_type == DS_TYPE_GAUGE)
680 status = bind_xml_read_gauge (doc, child, &value.gauge);
682 status = bind_xml_read_derive (doc, child, &value.derive);
686 status = (*list_callback) (attr_name, value, current_time, user_data);
692 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
693 num_entries, (num_entries == 1) ? "entry" : "entries",
696 xmlXPathFreeObject(xpathObj);
699 } /* }}} int bind_parse_generic_name_attr_value_list */
701 static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */
702 xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view,
705 xmlXPathObject *path_obj;
706 char *zone_name = NULL;
711 char *n = (char *) xmlGetProp (node, BAD_CAST "name");
712 char *c = (char *) xmlGetProp (node, BAD_CAST "rdataclass");
715 zone_name = (char *) xmlMalloc(strlen(n) + strlen(c) + 2);
716 snprintf(zone_name, strlen(n) + strlen(c) + 2, "%s/%s", n, c);
723 path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
724 if (path_obj == NULL)
726 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
730 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
732 zone_name = (char *) xmlNodeListGetString (doc,
733 path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
734 if (zone_name != NULL)
737 xmlXPathFreeObject (path_obj);
740 if (zone_name == NULL)
742 ERROR ("bind plugin: Could not determine zone name.");
746 for (j = 0; j < view->zones_num; j++)
748 if (strcasecmp (zone_name, view->zones[j]) == 0)
755 if (j >= view->zones_num)
758 zone_name = view->zones[j];
760 DEBUG ("bind plugin: bind_xml_stats_handle_zone: Found zone `%s'.",
763 { /* Parse the <counters> tag {{{ */
764 char plugin_instance[DATA_MAX_NAME_LEN];
765 translation_table_ptr_t table_ptr =
767 nsstats_translation_table,
768 nsstats_translation_table_length,
772 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-zone-%s",
773 view->name, zone_name);
777 list_info_ptr_t list_info =
780 /* type = */ "dns_qtype"
782 bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='rcode']",
783 /* callback = */ bind_xml_table_callback,
784 /* user_data = */ &table_ptr,
785 doc, path_ctx, current_time, DS_TYPE_COUNTER);
786 bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='qtype']",
787 /* callback = */ bind_xml_list_callback,
788 /* user_data = */ &list_info,
789 doc, path_ctx, current_time, DS_TYPE_COUNTER);
793 bind_parse_generic_value_list (/* xpath = */ "counters",
794 /* callback = */ bind_xml_table_callback,
795 /* user_data = */ &table_ptr,
796 doc, path_ctx, current_time, DS_TYPE_COUNTER);
801 } /* }}} int bind_xml_stats_handle_zone */
803 static int bind_xml_stats_search_zones (int version, xmlDoc *doc, /* {{{ */
804 xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view,
807 xmlXPathObject *zone_nodes = NULL;
808 xmlXPathContext *zone_path_context;
810 zone_path_context = xmlXPathNewContext (doc);
811 if (zone_path_context == NULL)
813 ERROR ("bind plugin: xmlXPathNewContext failed.");
817 zone_nodes = xmlXPathEvalExpression (BAD_CAST "zones/zone", path_ctx);
818 if (zone_nodes == NULL)
820 ERROR ("bind plugin: Cannot find any <view> tags.");
821 xmlXPathFreeContext (zone_path_context);
825 for (int i = 0; i < zone_nodes->nodesetval->nodeNr; i++)
827 node = zone_nodes->nodesetval->nodeTab[i];
828 assert (node != NULL);
830 zone_path_context->node = node;
832 bind_xml_stats_handle_zone (version, doc, zone_path_context, node, view,
836 xmlXPathFreeObject (zone_nodes);
837 xmlXPathFreeContext (zone_path_context);
839 } /* }}} int bind_xml_stats_search_zones */
841 static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */
842 xmlXPathContext *path_ctx, xmlNode *node, time_t current_time)
844 char *view_name = NULL;
850 view_name = (char*) xmlGetProp(node, BAD_CAST "name");
852 if (view_name == NULL)
854 ERROR ("bind plugin: Could not determine view name.");
858 for (j = 0; j < views_num; j++)
860 if (strcasecmp (view_name, views[j].name) == 0)
869 xmlXPathObject *path_obj;
870 path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
871 if (path_obj == NULL)
873 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
877 for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
879 view_name = (char *) xmlNodeListGetString (doc,
880 path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
881 if (view_name != NULL)
885 if (view_name == NULL)
887 ERROR ("bind plugin: Could not determine view name.");
888 xmlXPathFreeObject (path_obj);
892 for (j = 0; j < views_num; j++)
894 if (strcasecmp (view_name, views[j].name) == 0)
899 xmlXPathFreeObject (path_obj);
911 DEBUG ("bind plugin: bind_xml_stats_handle_view: Found view `%s'.",
914 if (view->qtypes != 0) /* {{{ */
916 char plugin_instance[DATA_MAX_NAME_LEN];
917 list_info_ptr_t list_info =
920 /* type = */ "dns_qtype"
923 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-qtypes",
927 bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='resqtype']",
928 /* callback = */ bind_xml_list_callback,
929 /* user_data = */ &list_info,
930 doc, path_ctx, current_time, DS_TYPE_COUNTER);
934 bind_parse_generic_name_value (/* xpath = */ "rdtype",
935 /* callback = */ bind_xml_list_callback,
936 /* user_data = */ &list_info,
937 doc, path_ctx, current_time, DS_TYPE_COUNTER);
941 if (view->resolver_stats != 0) /* {{{ */
943 char plugin_instance[DATA_MAX_NAME_LEN];
944 translation_table_ptr_t table_ptr =
946 resstats_translation_table,
947 resstats_translation_table_length,
951 ssnprintf (plugin_instance, sizeof (plugin_instance),
952 "%s-resolver_stats", view->name);
955 bind_parse_generic_name_attr_value_list ("counters[@type='resstats']",
956 /* callback = */ bind_xml_table_callback,
957 /* user_data = */ &table_ptr,
958 doc, path_ctx, current_time, DS_TYPE_COUNTER);
962 bind_parse_generic_name_value ("resstat",
963 /* callback = */ bind_xml_table_callback,
964 /* user_data = */ &table_ptr,
965 doc, path_ctx, current_time, DS_TYPE_COUNTER);
969 /* Record types in the cache */
970 if (view->cacherrsets != 0) /* {{{ */
972 char plugin_instance[DATA_MAX_NAME_LEN];
973 list_info_ptr_t list_info =
976 /* type = */ "dns_qtype_cached"
979 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-cache_rr_sets",
982 bind_parse_generic_name_value (/* xpath = */ "cache/rrset",
983 /* callback = */ bind_xml_list_callback,
984 /* user_data = */ &list_info,
985 doc, path_ctx, current_time, DS_TYPE_GAUGE);
988 if (view->zones_num > 0)
989 bind_xml_stats_search_zones (version, doc, path_ctx, node, view,
993 } /* }}} int bind_xml_stats_handle_view */
995 static int bind_xml_stats_search_views (int version, xmlDoc *doc, /* {{{ */
996 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
998 xmlXPathObject *view_nodes = NULL;
999 xmlXPathContext *view_path_context;
1001 view_path_context = xmlXPathNewContext (doc);
1002 if (view_path_context == NULL)
1004 ERROR ("bind plugin: xmlXPathNewContext failed.");
1008 view_nodes = xmlXPathEvalExpression (BAD_CAST "views/view", xpathCtx);
1009 if (view_nodes == NULL)
1011 ERROR ("bind plugin: Cannot find any <view> tags.");
1012 xmlXPathFreeContext (view_path_context);
1016 for (int i = 0; i < view_nodes->nodesetval->nodeNr; i++)
1020 node = view_nodes->nodesetval->nodeTab[i];
1021 assert (node != NULL);
1023 view_path_context->node = node;
1025 bind_xml_stats_handle_view (version, doc, view_path_context, node,
1029 xmlXPathFreeObject (view_nodes);
1030 xmlXPathFreeContext (view_path_context);
1032 } /* }}} int bind_xml_stats_search_views */
1034 static void bind_xml_stats_v3 (xmlDoc *doc, /* {{{ */
1035 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
1037 /* XPath: server/counters[@type='opcode']
1038 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1040 * <counters type="opcode">
1041 * <counter name="A">1</counter>
1045 if (global_opcodes != 0)
1047 list_info_ptr_t list_info =
1049 /* plugin instance = */ "global-opcodes",
1050 /* type = */ "dns_opcode"
1052 bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='opcode']",
1053 /* callback = */ bind_xml_list_callback,
1054 /* user_data = */ &list_info,
1055 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1058 /* XPath: server/counters[@type='qtype']
1059 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1060 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1061 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1063 * <counters type="opcode">
1064 * <counter name="A">1</counter>
1068 if (global_qtypes != 0)
1070 list_info_ptr_t list_info =
1072 /* plugin instance = */ "global-qtypes",
1073 /* type = */ "dns_qtype"
1076 bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='qtype']",
1077 /* callback = */ bind_xml_list_callback,
1078 /* user_data = */ &list_info,
1079 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1082 /* XPath: server/counters[@type='nsstat']
1083 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1084 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1085 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1086 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1087 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1088 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1089 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1092 * <counters type="nsstat"
1093 * <counter name="Requestv4">1</counter>
1094 * <counter name="Requestv6">0</counter>
1098 if (global_server_stats)
1100 translation_table_ptr_t table_ptr =
1102 nsstats_translation_table,
1103 nsstats_translation_table_length,
1104 /* plugin_instance = */ "global-server_stats"
1107 bind_parse_generic_name_attr_value_list ("server/counters[@type='nsstat']",
1108 /* callback = */ bind_xml_table_callback,
1109 /* user_data = */ &table_ptr,
1110 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1113 /* XPath: server/zonestats, server/zonestat, server/counters[@type='zonestat']
1114 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1115 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1116 * XfrSuccess, XfrFail
1118 * <counters type="zonestat"
1119 * <counter name="NotifyOutv4">0</counter>
1120 * <counter name="NotifyOutv6">0</counter>
1124 if (global_zone_maint_stats)
1126 translation_table_ptr_t table_ptr =
1128 zonestats_translation_table,
1129 zonestats_translation_table_length,
1130 /* plugin_instance = */ "global-zone_maint_stats"
1133 bind_parse_generic_name_attr_value_list ("server/counters[@type='zonestat']",
1134 /* callback = */ bind_xml_table_callback,
1135 /* user_data = */ &table_ptr,
1136 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1139 /* XPath: server/resstats, server/counters[@type='resstat']
1140 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1141 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1142 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1143 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1145 * <counters type="resstat"
1146 * <counter name="Queryv4">0</counter>
1147 * <counter name="Queryv6">0</counter>
1151 if (global_resolver_stats != 0)
1153 translation_table_ptr_t table_ptr =
1155 resstats_translation_table,
1156 resstats_translation_table_length,
1157 /* plugin_instance = */ "global-resolver_stats"
1160 bind_parse_generic_name_attr_value_list ("server/counters[@type='resstat']",
1161 /* callback = */ bind_xml_table_callback,
1162 /* user_data = */ &table_ptr,
1163 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1165 } /* }}} bind_xml_stats_v3 */
1167 static void bind_xml_stats_v1_v2 (int version, xmlDoc *doc, /* {{{ */
1168 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
1170 /* XPath: server/requests/opcode, server/counters[@type='opcode']
1171 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
1175 * <counter>1</counter>
1179 if (global_opcodes != 0)
1181 list_info_ptr_t list_info =
1183 /* plugin instance = */ "global-opcodes",
1184 /* type = */ "dns_opcode"
1187 bind_parse_generic_name_value (/* xpath = */ "server/requests/opcode",
1188 /* callback = */ bind_xml_list_callback,
1189 /* user_data = */ &list_info,
1190 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1193 /* XPath: server/queries-in/rdtype, server/counters[@type='qtype']
1194 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
1195 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
1196 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
1200 * <counter>1</counter>
1204 if (global_qtypes != 0)
1206 list_info_ptr_t list_info =
1208 /* plugin instance = */ "global-qtypes",
1209 /* type = */ "dns_qtype"
1212 bind_parse_generic_name_value (/* xpath = */ "server/queries-in/rdtype",
1213 /* callback = */ bind_xml_list_callback,
1214 /* user_data = */ &list_info,
1215 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1218 /* XPath: server/nsstats, server/nsstat, server/counters[@type='nsstat']
1219 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
1220 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
1221 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
1222 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
1223 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
1224 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
1225 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
1229 * <Requestv4>1</Requestv4>
1230 * <Requestv6>0</Requestv6>
1235 * <name>Requestv4</name>
1236 * <counter>1</counter>
1239 * <name>Requestv6</name>
1240 * <counter>0</counter>
1244 if (global_server_stats)
1246 translation_table_ptr_t table_ptr =
1248 nsstats_translation_table,
1249 nsstats_translation_table_length,
1250 /* plugin_instance = */ "global-server_stats"
1255 bind_parse_generic_value_list ("server/nsstats",
1256 /* callback = */ bind_xml_table_callback,
1257 /* user_data = */ &table_ptr,
1258 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1262 bind_parse_generic_name_value ("server/nsstat",
1263 /* callback = */ bind_xml_table_callback,
1264 /* user_data = */ &table_ptr,
1265 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1269 /* XPath: server/zonestats, server/zonestat, server/counters[@type='zonestat']
1270 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1271 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1272 * XfrSuccess, XfrFail
1275 * <NotifyOutv4>0</NotifyOutv4>
1276 * <NotifyOutv6>0</NotifyOutv6>
1281 * <name>NotifyOutv4</name>
1282 * <counter>0</counter>
1285 * <name>NotifyOutv6</name>
1286 * <counter>0</counter>
1290 if (global_zone_maint_stats)
1292 translation_table_ptr_t table_ptr =
1294 zonestats_translation_table,
1295 zonestats_translation_table_length,
1296 /* plugin_instance = */ "global-zone_maint_stats"
1301 bind_parse_generic_value_list ("server/zonestats",
1302 /* callback = */ bind_xml_table_callback,
1303 /* user_data = */ &table_ptr,
1304 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1308 bind_parse_generic_name_value ("server/zonestat",
1309 /* callback = */ bind_xml_table_callback,
1310 /* user_data = */ &table_ptr,
1311 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1315 /* XPath: server/resstats, server/counters[@type='resstat']
1316 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1317 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1318 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1319 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1322 * <Queryv4>0</Queryv4>
1323 * <Queryv6>0</Queryv6>
1328 * <name>Queryv4</name>
1329 * <counter>0</counter>
1332 * <name>Queryv6</name>
1333 * <counter>0</counter>
1337 if (global_resolver_stats != 0)
1339 translation_table_ptr_t table_ptr =
1341 resstats_translation_table,
1342 resstats_translation_table_length,
1343 /* plugin_instance = */ "global-resolver_stats"
1348 bind_parse_generic_value_list ("server/resstats",
1349 /* callback = */ bind_xml_table_callback,
1350 /* user_data = */ &table_ptr,
1351 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1355 bind_parse_generic_name_value ("server/resstat",
1356 /* callback = */ bind_xml_table_callback,
1357 /* user_data = */ &table_ptr,
1358 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1361 } /* }}} bind_xml_stats_v1_v2 */
1363 static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
1364 xmlXPathContext *xpathCtx, xmlNode *statsnode)
1366 time_t current_time = 0;
1369 xpathCtx->node = statsnode;
1371 /* TODO: Check `server/boot-time' to recognize server restarts. */
1373 status = bind_xml_read_timestamp ("server/current-time",
1374 doc, xpathCtx, ¤t_time);
1377 ERROR ("bind plugin: Reading `server/current-time' failed.");
1380 DEBUG ("bind plugin: Current server time is %i.", (int) current_time);
1384 bind_xml_stats_v3(doc, xpathCtx, statsnode, current_time);
1388 bind_xml_stats_v1_v2(version, doc, xpathCtx, statsnode, current_time);
1391 /* XPath: memory/summary
1392 * Variables: TotalUse, InUse, BlockSize, ContextSize, Lost
1393 * Layout: v2 and v3:
1395 * <TotalUse>6587096</TotalUse>
1396 * <InUse>1345424</InUse>
1397 * <BlockSize>5505024</BlockSize>
1398 * <ContextSize>3732456</ContextSize>
1402 if (global_memory_stats != 0)
1404 translation_table_ptr_t table_ptr =
1406 memsummary_translation_table,
1407 memsummary_translation_table_length,
1408 /* plugin_instance = */ "global-memory_stats"
1411 bind_parse_generic_value_list ("memory/summary",
1412 /* callback = */ bind_xml_table_callback,
1413 /* user_data = */ &table_ptr,
1414 doc, xpathCtx, current_time, DS_TYPE_GAUGE);
1418 bind_xml_stats_search_views (version, doc, xpathCtx, statsnode,
1422 } /* }}} int bind_xml_stats */
1424 static int bind_xml (const char *data) /* {{{ */
1427 xmlXPathContext *xpathCtx = NULL;
1428 xmlXPathObject *xpathObj = NULL;
1431 doc = xmlParseMemory (data, strlen (data));
1434 ERROR ("bind plugin: xmlParseMemory failed.");
1438 xpathCtx = xmlXPathNewContext (doc);
1439 if (xpathCtx == NULL)
1441 ERROR ("bind plugin: xmlXPathNewContext failed.");
1447 // version 3.* of statistics XML (since BIND9.9)
1450 xpathObj = xmlXPathEvalExpression (BAD_CAST "/statistics", xpathCtx);
1451 if (xpathObj == NULL || xpathObj->nodesetval == NULL || xpathObj->nodesetval->nodeNr == 0)
1453 DEBUG ("bind plugin: Statistics appears not to be v3");
1454 // we will fallback to v1 or v2 detection
1455 if (xpathObj != NULL) { xmlXPathFreeObject (xpathObj); }
1459 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++)
1464 node = xpathObj->nodesetval->nodeTab[i];
1465 assert (node != NULL);
1467 attr_version = (char *) xmlGetProp (node, BAD_CAST "version");
1468 if (attr_version == NULL)
1470 NOTICE ("bind plugin: Found <statistics> tag doesn't have a "
1471 "`version' attribute.");
1474 DEBUG ("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1476 if (strncmp ("3.", attr_version, strlen ("3.")) != 0)
1478 /* TODO: Use the complaint mechanism here. */
1479 NOTICE ("bind plugin: Found <statistics> tag with version `%s'. "
1480 "Unfortunately I have no clue how to parse that. "
1481 "Please open a bug report for this.", attr_version);
1482 xmlFree (attr_version);
1485 ret = bind_xml_stats (3, doc, xpathCtx, node);
1487 xmlFree (attr_version);
1488 /* One <statistics> node ought to be enough. */
1492 // we are finished, early-return
1493 xmlXPathFreeObject (xpathObj);
1494 xmlXPathFreeContext (xpathCtx);
1501 // versions 1.* or 2.* of statistics XML
1504 xpathObj = xmlXPathEvalExpression (BAD_CAST "/isc/bind/statistics", xpathCtx);
1505 if (xpathObj == NULL)
1507 ERROR ("bind plugin: Cannot find the <statistics> tag.");
1508 xmlXPathFreeContext (xpathCtx);
1512 else if (xpathObj->nodesetval == NULL)
1514 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
1515 xmlXPathFreeObject (xpathObj);
1516 xmlXPathFreeContext (xpathCtx);
1521 for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++)
1525 int parsed_version = 0;
1527 node = xpathObj->nodesetval->nodeTab[i];
1528 assert (node != NULL);
1530 attr_version = (char *) xmlGetProp (node, BAD_CAST "version");
1531 if (attr_version == NULL)
1533 NOTICE ("bind plugin: Found <statistics> tag doesn't have a "
1534 "`version' attribute.");
1537 DEBUG ("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1539 /* At the time this plugin was written, version "1.0" was used by
1540 * BIND 9.5.0, version "2.0" was used by BIND 9.5.1 and 9.6.0. We assume
1541 * that "1.*" and "2.*" don't introduce structural changes, so we just
1542 * check for the first two characters here. */
1543 if (strncmp ("1.", attr_version, strlen ("1.")) == 0)
1545 else if (strncmp ("2.", attr_version, strlen ("2.")) == 0)
1549 /* TODO: Use the complaint mechanism here. */
1550 NOTICE ("bind plugin: Found <statistics> tag with version `%s'. "
1551 "Unfortunately I have no clue how to parse that. "
1552 "Please open a bug report for this.", attr_version);
1553 xmlFree (attr_version);
1557 ret = bind_xml_stats (parsed_version,
1558 doc, xpathCtx, node);
1560 xmlFree (attr_version);
1561 /* One <statistics> node ought to be enough. */
1565 xmlXPathFreeObject (xpathObj);
1566 xmlXPathFreeContext (xpathCtx);
1570 } /* }}} int bind_xml */
1572 static int bind_config_set_bool (const char *name, int *var, /* {{{ */
1575 if ((ci->values_num != 1) || ( ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1577 WARNING ("bind plugin: The `%s' option needs "
1578 "exactly one boolean argument.", name);
1582 if (ci->values[0].value.boolean)
1587 } /* }}} int bind_config_set_bool */
1589 static int bind_config_add_view_zone (cb_view_t *view, /* {{{ */
1594 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1596 WARNING ("bind plugin: The `Zone' option needs "
1597 "exactly one string argument.");
1601 tmp = realloc (view->zones,
1602 sizeof (char *) * (view->zones_num + 1));
1605 ERROR ("bind plugin: realloc failed.");
1610 view->zones[view->zones_num] = strdup (ci->values[0].value.string);
1611 if (view->zones[view->zones_num] == NULL)
1613 ERROR ("bind plugin: strdup failed.");
1619 } /* }}} int bind_config_add_view_zone */
1621 static int bind_config_add_view (oconfig_item_t *ci) /* {{{ */
1625 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1627 WARNING ("bind plugin: `View' blocks need exactly one string argument.");
1631 tmp = realloc (views, sizeof (*views) * (views_num + 1));
1634 ERROR ("bind plugin: realloc failed.");
1638 tmp = views + views_num;
1640 memset (tmp, 0, sizeof (*tmp));
1642 tmp->resolver_stats = 1;
1643 tmp->cacherrsets = 1;
1647 tmp->name = strdup (ci->values[0].value.string);
1648 if (tmp->name == NULL)
1650 ERROR ("bind plugin: strdup failed.");
1655 for (int i = 0; i < ci->children_num; i++)
1657 oconfig_item_t *child = ci->children + i;
1659 if (strcasecmp ("QTypes", child->key) == 0)
1660 bind_config_set_bool ("QTypes", &tmp->qtypes, child);
1661 else if (strcasecmp ("ResolverStats", child->key) == 0)
1662 bind_config_set_bool ("ResolverStats", &tmp->resolver_stats, child);
1663 else if (strcasecmp ("CacheRRSets", child->key) == 0)
1664 bind_config_set_bool ("CacheRRSets", &tmp->cacherrsets, child);
1665 else if (strcasecmp ("Zone", child->key) == 0)
1666 bind_config_add_view_zone (tmp, child);
1669 WARNING ("bind plugin: Unknown configuration option "
1670 "`%s' in view `%s' will be ignored.", child->key, tmp->name);
1672 } /* for (i = 0; i < ci->children_num; i++) */
1676 } /* }}} int bind_config_add_view */
1678 static int bind_config (oconfig_item_t *ci) /* {{{ */
1680 for (int i = 0; i < ci->children_num; i++)
1682 oconfig_item_t *child = ci->children + i;
1684 if (strcasecmp ("Url", child->key) == 0) {
1685 if ((child->values_num != 1) || (child->values[0].type != OCONFIG_TYPE_STRING))
1687 WARNING ("bind plugin: The `Url' option needs "
1688 "exactly one string argument.");
1693 url = strdup (child->values[0].value.string);
1694 } else if (strcasecmp ("OpCodes", child->key) == 0)
1695 bind_config_set_bool ("OpCodes", &global_opcodes, child);
1696 else if (strcasecmp ("QTypes", child->key) == 0)
1697 bind_config_set_bool ("QTypes", &global_qtypes, child);
1698 else if (strcasecmp ("ServerStats", child->key) == 0)
1699 bind_config_set_bool ("ServerStats", &global_server_stats, child);
1700 else if (strcasecmp ("ZoneMaintStats", child->key) == 0)
1701 bind_config_set_bool ("ZoneMaintStats", &global_zone_maint_stats, child);
1702 else if (strcasecmp ("ResolverStats", child->key) == 0)
1703 bind_config_set_bool ("ResolverStats", &global_resolver_stats, child);
1704 else if (strcasecmp ("MemoryStats", child->key) == 0)
1705 bind_config_set_bool ("MemoryStats", &global_memory_stats, child);
1706 else if (strcasecmp ("View", child->key) == 0)
1707 bind_config_add_view (child);
1708 else if (strcasecmp ("ParseTime", child->key) == 0)
1709 cf_util_get_boolean (child, &config_parse_time);
1710 else if (strcasecmp ("Timeout", child->key) == 0)
1711 cf_util_get_int (child, &timeout);
1714 WARNING ("bind plugin: Unknown configuration option "
1715 "`%s' will be ignored.", child->key);
1720 } /* }}} int bind_config */
1722 static int bind_init (void) /* {{{ */
1727 curl = curl_easy_init ();
1730 ERROR ("bind plugin: bind_init: curl_easy_init failed.");
1734 curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1L);
1735 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
1736 curl_easy_setopt (curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
1737 curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, bind_curl_error);
1738 curl_easy_setopt (curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
1739 curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L);
1740 curl_easy_setopt (curl, CURLOPT_MAXREDIRS, 50L);
1741 #ifdef HAVE_CURLOPT_TIMEOUT_MS
1742 curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, (timeout >= 0) ?
1743 (long) timeout : (long) CDTIME_T_TO_MS(plugin_get_interval()));
1748 } /* }}} int bind_init */
1750 static int bind_read (void) /* {{{ */
1756 ERROR ("bind plugin: I don't have a CURL object.");
1760 bind_buffer_fill = 0;
1761 if (curl_easy_perform (curl) != CURLE_OK)
1763 ERROR ("bind plugin: curl_easy_perform failed: %s",
1768 status = bind_xml (bind_buffer);
1773 } /* }}} int bind_read */
1775 static int bind_shutdown (void) /* {{{ */
1779 curl_easy_cleanup (curl);
1784 } /* }}} int bind_shutdown */
1786 void module_register (void)
1788 plugin_register_complex_config ("bind", bind_config);
1789 plugin_register_init ("bind", bind_init);
1790 plugin_register_read ("bind", bind_read);
1791 plugin_register_shutdown ("bind", bind_shutdown);
1792 } /* void module_register */
1794 /* vim: set sw=2 sts=2 ts=8 et fdm=marker : */