587403d07727341fcb23e10ae1c9ba92ffa2f0e9
1 /**
2 * collectd - src/bind.c
3 * Copyright (C) 2009 Bruno Prémont
4 * Copyright (C) 2009 Florian Forster
5 *
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.
9 *
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.
14 *
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
18 *
19 * Authors:
20 * Bruno Prémont <bonbons at linux-vserver.org>
21 * Florian Forster <octo at verplant.org>
22 **/
25 #include "collectd.h"
26 #include "common.h"
27 #include "plugin.h"
28 #include "configfile.h"
30 #include <curl/curl.h>
31 #include <libxml/parser.h>
32 #include <libxml/xpath.h>
34 #ifndef BIND_DEFAULT_URL
35 # define BIND_DEFAULT_URL "http://localhost:8053/"
36 #endif
38 /*
39 * Some types used for the callback functions. `translation_table_ptr_t' and
40 * `list_info_ptr_t' are passed to the callbacks in the `void *user_data'
41 * pointer.
42 */
43 typedef int (*list_callback_t) (const char *name, value_t value,
44 time_t current_time, void *user_data);
46 struct cb_view_s
47 {
48 char *name;
50 int qtypes;
51 int resolver_stats;
52 int cacherrsets;
54 char **zones;
55 size_t zones_num;
56 };
57 typedef struct cb_view_s cb_view_t;
59 struct translation_info_s
60 {
61 const char *xml_name;
62 const char *type;
63 const char *type_instance;
64 };
65 typedef struct translation_info_s translation_info_t;
67 struct translation_table_ptr_s
68 {
69 const translation_info_t *table;
70 size_t table_length;
71 const char *plugin_instance;
72 };
73 typedef struct translation_table_ptr_s translation_table_ptr_t;
75 struct list_info_ptr_s
76 {
77 const char *plugin_instance;
78 const char *type;
79 };
80 typedef struct list_info_ptr_s list_info_ptr_t;
82 static char *url = NULL;
83 static int global_opcodes = 1;
84 static int global_qtypes = 1;
85 static int global_server_stats = 1;
86 static int global_zone_maint_stats = 1;
87 static int global_resolver_stats = 0;
88 static int global_memory_stats = 1;
90 static cb_view_t *views = NULL;
91 static size_t views_num = 0;
93 static CURL *curl = NULL;
95 static char *bind_buffer = NULL;
96 static size_t bind_buffer_size = 0;
97 static size_t bind_buffer_fill = 0;
98 static char bind_curl_error[CURL_ERROR_SIZE];
100 /* Translation table for the `nsstats' values. */
101 static const translation_info_t nsstats_translation_table[] = /* {{{ */
102 {
103 /* Requests */
104 { "Requestv4", "dns_request", "IPv4" },
105 { "Requestv6", "dns_request", "IPv6" },
106 { "ReqEdns0", "dns_request", "EDNS0" },
107 { "ReqBadEDNSVer", "dns_request", "BadEDNSVer" },
108 { "ReqTSIG", "dns_request", "TSIG" },
109 { "ReqSIG0", "dns_request", "SIG0" },
110 { "ReqBadSIG", "dns_request", "BadSIG" },
111 { "ReqTCP", "dns_request", "TCP" },
112 /* Rejects */
113 { "AuthQryRej", "dns_reject", "authorative" },
114 { "RecQryRej", "dns_reject", "recursive" },
115 { "XfrRej", "dns_reject", "transfer" },
116 { "UpdateRej", "dns_reject", "update" },
117 /* Responses */
118 { "Response", "dns_response", "normal" },
119 { "TruncatedResp", "dns_response", "truncated" },
120 { "RespEDNS0", "dns_response", "EDNS0" },
121 { "RespTSIG", "dns_response", "TSIG" },
122 { "RespSIG0", "dns_response", "SIG0" },
123 /* Queries */
124 { "QryAuthAns", "dns_query", "authorative" },
125 { "QryNoauthAns", "dns_query", "nonauth" },
126 { "QryReferral", "dns_query", "referral" },
127 { "QryRecursion", "dns_query", "recursion" },
128 { "QryDuplicate", "dns_query", "dupliate" },
129 { "QryDropped", "dns_query", "dropped" },
130 { "QryFailure", "dns_query", "failure" },
131 /* Response codes */
132 { "QrySuccess", "dns_rcode", "tx-NOERROR" },
133 { "QryNxrrset", "dns_rcode", "tx-NXRRSET" },
134 { "QrySERVFAIL", "dns_rcode", "tx-SERVFAIL" },
135 { "QryFORMERR", "dns_rcode", "tx-FORMERR" },
136 { "QryNXDOMAIN", "dns_rcode", "tx-NXDOMAIN" }
137 #if 0
138 { "XfrReqDone", "type", "type_instance" },
139 { "UpdateReqFwd", "type", "type_instance" },
140 { "UpdateRespFwd", "type", "type_instance" },
141 { "UpdateFwdFail", "type", "type_instance" },
142 { "UpdateDone", "type", "type_instance" },
143 { "UpdateFail", "type", "type_instance" },
144 { "UpdateBadPrereq", "type", "type_instance" },
145 #endif
146 };
147 static int nsstats_translation_table_length =
148 STATIC_ARRAY_SIZE (nsstats_translation_table);
149 /* }}} */
151 /* Translation table for the `zonestats' values. */
152 static const translation_info_t zonestats_translation_table[] = /* {{{ */
153 {
154 /* Notify's */
155 { "NotifyOutv4", "dns_notify", "tx-IPv4" },
156 { "NotifyOutv6", "dns_notify", "tx-IPv6" },
157 { "NotifyInv4", "dns_notify", "rx-IPv4" },
158 { "NotifyInv6", "dns_notify", "rx-IPv6" },
159 { "NotifyRej", "dns_notify", "rejected" },
160 /* SOA/AXFS/IXFS requests */
161 { "SOAOutv4", "dns_opcode", "SOA-IPv4" },
162 { "SOAOutv6", "dns_opcode", "SOA-IPv6" },
163 { "AXFRReqv4", "dns_opcode", "AXFR-IPv4" },
164 { "AXFRReqv6", "dns_opcode", "AXFR-IPv6" },
165 { "IXFRReqv4", "dns_opcode", "IXFR-IPv4" },
166 { "IXFRReqv6", "dns_opcode", "IXFR-IPv6" },
167 /* Domain transfers */
168 { "XfrSuccess", "dns_transfer", "success" },
169 { "XfrFail", "dns_transfer", "failure" }
170 };
171 static int zonestats_translation_table_length =
172 STATIC_ARRAY_SIZE (zonestats_translation_table);
173 /* }}} */
175 /* Translation table for the `resstats' values. */
176 static const translation_info_t resstats_translation_table[] = /* {{{ */
177 {
178 /* Generic resolver information */
179 { "Queryv4", "dns_query", "IPv4" },
180 { "Queryv6", "dns_query", "IPv6" },
181 { "Responsev4", "dns_response", "IPv4" },
182 { "Responsev6", "dns_response", "IPv6" },
183 /* Received response codes */
184 { "NXDOMAIN", "dns_rcode", "rx-NXDOMAIN" },
185 { "SERVFAIL", "dns_rcode", "rx-SERVFAIL" },
186 { "FORMERR", "dns_rcode", "rx-FORMERR" },
187 { "OtherError", "dns_rcode", "rx-OTHER" },
188 { "EDNS0Fail", "dns_rcode", "rx-EDNS0Fail"},
189 /* Received responses */
190 { "Mismatch", "dns_response", "mismatch" },
191 { "Truncated", "dns_response", "truncated" },
192 { "Lame", "dns_response", "lame" },
193 { "Retry", "dns_query", "retry" },
194 #if 0
195 { "GlueFetchv4", "type", "type_instance" },
196 { "GlueFetchv6", "type", "type_instance" },
197 { "GlueFetchv4Fail", "type", "type_instance" },
198 { "GlueFetchv6Fail", "type", "type_instance" },
199 #endif
200 /* DNSSEC information */
201 { "ValAttempt", "dns_resolver", "DNSSEC-attempt" },
202 { "ValOk", "dns_resolver", "DNSSEC-okay" },
203 { "ValNegOk", "dns_resolver", "DNSSEC-negokay" },
204 { "ValFail", "dns_resolver", "DNSSEC-fail" }
205 };
206 static int resstats_translation_table_length =
207 STATIC_ARRAY_SIZE (resstats_translation_table);
208 /* }}} */
210 /* Translation table for the `memory/summary' values. */
211 static const translation_info_t memsummary_translation_table[] = /* {{{ */
212 {
213 { "TotalUse", "memory", "TotalUse" },
214 { "InUse", "memory", "InUse" },
215 { "BlockSize", "memory", "BlockSize" },
216 { "ContextSize", "memory", "ContextSize" },
217 { "Lost", "memory", "Lost" }
218 };
219 static int memsummary_translation_table_length =
220 STATIC_ARRAY_SIZE (memsummary_translation_table);
221 /* }}} */
223 static void remove_special (char *buffer, size_t buffer_size) /* {{{ */
224 {
225 size_t i;
227 for (i = 0; i < buffer_size; i++)
228 {
229 if (buffer[i] == 0)
230 return;
231 if ((!isalnum ((int) buffer[i])) && (buffer[i] != '-'))
232 buffer[i] = '_';
233 }
234 } /* }}} void remove_special */
236 static void submit (time_t ts, const char *plugin_instance, /* {{{ */
237 const char *type, const char *type_instance, value_t value)
238 {
239 value_t values[1];
240 value_list_t vl = VALUE_LIST_INIT;
242 values[0] = value;
244 vl.values = values;
245 vl.values_len = 1;
246 vl.time = ts;
247 sstrncpy(vl.host, hostname_g, sizeof(vl.host));
248 sstrncpy(vl.plugin, "bind", sizeof(vl.plugin));
249 if (plugin_instance) {
250 sstrncpy(vl.plugin_instance, plugin_instance,
251 sizeof(vl.plugin_instance));
252 remove_special (vl.plugin_instance, sizeof (vl.plugin_instance));
253 }
254 sstrncpy(vl.type, type, sizeof(vl.type));
255 if (type_instance) {
256 sstrncpy(vl.type_instance, type_instance,
257 sizeof(vl.type_instance));
258 remove_special (vl.plugin_instance, sizeof (vl.plugin_instance));
259 }
260 plugin_dispatch_values(&vl);
261 } /* }}} void submit */
263 static size_t bind_curl_callback (void *buf, size_t size, /* {{{ */
264 size_t nmemb, void __attribute__((unused)) *stream)
265 {
266 size_t len = size * nmemb;
268 if (len <= 0)
269 return (len);
271 if ((bind_buffer_fill + len) >= bind_buffer_size)
272 {
273 char *temp;
275 temp = realloc(bind_buffer, bind_buffer_fill + len + 1);
276 if (temp == NULL)
277 {
278 ERROR ("bind plugin: realloc failed.");
279 return (0);
280 }
281 bind_buffer = temp;
282 bind_buffer_size = bind_buffer_fill + len + 1;
283 }
285 memcpy (bind_buffer + bind_buffer_fill, (char *) buf, len);
286 bind_buffer_fill += len;
287 bind_buffer[bind_buffer_fill] = 0;
289 return (len);
290 } /* }}} size_t bind_curl_callback */
292 /*
293 * Callback, that's called with a translation table.
294 * (Plugin instance is fixed, type and type instance come from lookup table.)
295 */
296 static int bind_xml_table_callback (const char *name, value_t value, /* {{{ */
297 time_t current_time, void *user_data)
298 {
299 translation_table_ptr_t *table = (translation_table_ptr_t *) user_data;
300 size_t i;
302 if (table == NULL)
303 return (-1);
305 for (i = 0; i < table->table_length; i++)
306 {
307 if (strcmp (table->table[i].xml_name, name) != 0)
308 continue;
310 submit (current_time,
311 table->plugin_instance,
312 table->table[i].type,
313 table->table[i].type_instance,
314 value);
315 break;
316 }
318 return (0);
319 } /* }}} int bind_xml_table_callback */
321 /*
322 * Callback, that's used for lists.
323 * (Plugin instance and type are fixed, xml name is used as type instance.)
324 */
325 static int bind_xml_list_callback (const char *name, /* {{{ */
326 value_t value, time_t current_time, void *user_data)
327 {
328 list_info_ptr_t *list_info = (list_info_ptr_t *) user_data;
330 if (list_info == NULL)
331 return (-1);
333 submit (current_time,
334 list_info->plugin_instance,
335 list_info->type,
336 /* type instance = */ name,
337 value);
339 return (0);
340 } /* }}} int bind_xml_list_callback */
342 static int bind_xml_read_counter (xmlDoc *doc, xmlNode *node, /* {{{ */
343 counter_t *ret_value)
344 {
345 char *str_ptr, *end_ptr;
346 long long int value;
348 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
349 if (str_ptr == NULL)
350 {
351 ERROR ("bind plugin: bind_xml_read_counter: xmlNodeListGetString failed.");
352 return (-1);
353 }
355 errno = 0;
356 value = strtoll (str_ptr, &end_ptr, 10);
357 xmlFree(str_ptr);
358 if (str_ptr == end_ptr || errno)
359 {
360 if (errno && (value < 0))
361 ERROR ("bind plugin: bind_xml_read_counter: strtoll failed with underflow.");
362 else if (errno && (value > 0))
363 ERROR ("bind plugin: bind_xml_read_counter: strtoll failed with overflow.");
364 else
365 ERROR ("bind plugin: bind_xml_read_counter: strtoll failed.");
366 return (-1);
367 }
369 *ret_value = value;
370 return (0);
371 } /* }}} int bind_xml_read_counter */
373 static int bind_xml_read_gauge (xmlDoc *doc, xmlNode *node, /* {{{ */
374 gauge_t *ret_value)
375 {
376 char *str_ptr, *end_ptr;
377 double value;
379 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
380 if (str_ptr == NULL)
381 {
382 ERROR ("bind plugin: bind_xml_read_gauge: xmlNodeListGetString failed.");
383 return (-1);
384 }
386 errno = 0;
387 value = strtod (str_ptr, &end_ptr);
388 xmlFree(str_ptr);
389 if (str_ptr == end_ptr || errno)
390 {
391 if (errno && (value < 0))
392 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed with underflow.");
393 else if (errno && (value > 0))
394 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed with overflow.");
395 else
396 ERROR ("bind plugin: bind_xml_read_gauge: strtod failed.");
397 return (-1);
398 }
400 *ret_value = (gauge_t) value;
401 return (0);
402 } /* }}} int bind_xml_read_gauge */
404 static int bind_xml_read_timestamp (const char *xpath_expression, /* {{{ */
405 xmlDoc *doc, xmlXPathContext *xpathCtx, time_t *ret_value)
406 {
407 xmlXPathObject *xpathObj = NULL;
408 xmlNode *node;
409 char *str_ptr;
410 char *tmp;
411 struct tm tm;
413 xpathObj = xmlXPathEvalExpression (BAD_CAST xpath_expression, xpathCtx);
414 if (xpathObj == NULL)
415 {
416 ERROR ("bind plugin: Unable to evaluate XPath expression `%s'.",
417 xpath_expression);
418 return (-1);
419 }
421 if ((xpathObj->nodesetval == NULL) || (xpathObj->nodesetval->nodeNr < 1))
422 {
423 xmlXPathFreeObject (xpathObj);
424 return (-1);
425 }
427 if (xpathObj->nodesetval->nodeNr != 1)
428 {
429 NOTICE ("bind plugin: Evaluating the XPath expression `%s' returned "
430 "%i nodes. Only handling the first one.",
431 xpath_expression, xpathObj->nodesetval->nodeNr);
432 }
434 node = xpathObj->nodesetval->nodeTab[0];
436 if (node->xmlChildrenNode == NULL)
437 {
438 ERROR ("bind plugin: bind_xml_read_timestamp: "
439 "node->xmlChildrenNode == NULL");
440 xmlXPathFreeObject (xpathObj);
441 return (-1);
442 }
444 str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
445 if (str_ptr == NULL)
446 {
447 ERROR ("bind plugin: bind_xml_read_timestamp: xmlNodeListGetString failed.");
448 xmlXPathFreeObject (xpathObj);
449 return (-1);
450 }
452 memset (&tm, 0, sizeof(tm));
453 tmp = strptime (str_ptr, "%Y-%m-%dT%T", &tm);
454 xmlFree(str_ptr);
455 if (tmp == NULL)
456 {
457 ERROR ("bind plugin: bind_xml_read_timestamp: strptime failed.");
458 xmlXPathFreeObject (xpathObj);
459 return (-1);
460 }
462 *ret_value = timegm(&tm);
464 xmlXPathFreeObject (xpathObj);
465 return (0);
466 } /* }}} int bind_xml_read_timestamp */
468 /*
469 * bind_parse_generic_name_value
470 *
471 * Reads statistics in the form:
472 * <foo>
473 * <name>QUERY</name>
474 * <counter>123</counter>
475 * </foo>
476 */
477 static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ */
478 list_callback_t list_callback,
479 void *user_data,
480 xmlDoc *doc, xmlXPathContext *xpathCtx,
481 time_t current_time, int ds_type)
482 {
483 xmlXPathObject *xpathObj = NULL;
484 int num_entries;
485 int i;
487 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
488 if (xpathObj == NULL)
489 {
490 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
491 xpath_expression);
492 return (-1);
493 }
495 num_entries = 0;
496 /* Iterate over all matching nodes. */
497 for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
498 {
499 xmlNode *name_node = NULL;
500 xmlNode *counter = NULL;
501 xmlNode *parent;
502 xmlNode *child;
504 parent = xpathObj->nodesetval->nodeTab[i];
505 DEBUG ("bind plugin: bind_parse_generic_name_value: parent->name = %s;",
506 (char *) parent->name);
508 /* Iterate over all child nodes. */
509 for (child = parent->xmlChildrenNode;
510 child != NULL;
511 child = child->next)
512 {
513 if (child->type != XML_ELEMENT_NODE)
514 continue;
516 if (xmlStrcmp (BAD_CAST "name", child->name) == 0)
517 name_node = child;
518 else if (xmlStrcmp (BAD_CAST "counter", child->name) == 0)
519 counter = child;
520 }
522 if ((name_node != NULL) && (counter != NULL))
523 {
524 char *name = (char *) xmlNodeListGetString (doc,
525 name_node->xmlChildrenNode, 1);
526 value_t value;
527 int status;
529 if (ds_type == DS_TYPE_GAUGE)
530 status = bind_xml_read_gauge (doc, counter, &value.gauge);
531 else
532 status = bind_xml_read_counter (doc, counter, &value.counter);
533 if (status != 0)
534 continue;
536 status = (*list_callback) (name, value, current_time, user_data);
537 if (status == 0)
538 num_entries++;
540 xmlFree (name);
541 }
542 }
544 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
545 num_entries, (num_entries == 1) ? "entry" : "entries",
546 xpath_expression);
548 xmlXPathFreeObject(xpathObj);
550 return (0);
551 } /* }}} int bind_parse_generic_name_value */
553 /*
554 * bind_parse_generic_value_list
555 *
556 * Reads statistics in the form:
557 * <foo>
558 * <name0>123</name0>
559 * <name1>234</name1>
560 * <name2>345</name2>
561 * :
562 * </foo>
563 */
564 static int bind_parse_generic_value_list (const char *xpath_expression, /* {{{ */
565 list_callback_t list_callback,
566 void *user_data,
567 xmlDoc *doc, xmlXPathContext *xpathCtx,
568 time_t current_time, int ds_type)
569 {
570 xmlXPathObject *xpathObj = NULL;
571 int num_entries;
572 int i;
574 xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
575 if (xpathObj == NULL)
576 {
577 ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
578 xpath_expression);
579 return (-1);
580 }
582 num_entries = 0;
583 /* Iterate over all matching nodes. */
584 for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
585 {
586 xmlNode *child;
588 /* Iterate over all child nodes. */
589 for (child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
590 child != NULL;
591 child = child->next)
592 {
593 char *node_name;
594 value_t value;
595 int status;
597 if (child->type != XML_ELEMENT_NODE)
598 continue;
600 node_name = (char *) child->name;
602 if (ds_type == DS_TYPE_GAUGE)
603 status = bind_xml_read_gauge (doc, child, &value.gauge);
604 else
605 status = bind_xml_read_counter (doc, child, &value.counter);
606 if (status != 0)
607 continue;
609 status = (*list_callback) (node_name, value, current_time, user_data);
610 if (status == 0)
611 num_entries++;
612 }
613 }
615 DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
616 num_entries, (num_entries == 1) ? "entry" : "entries",
617 xpath_expression);
619 xmlXPathFreeObject(xpathObj);
621 return (0);
622 } /* }}} int bind_parse_generic_value_list */
624 static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */
625 xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view,
626 time_t current_time)
627 {
628 xmlXPathObject *path_obj;
629 char *zone_name = NULL;
630 int i;
631 size_t j;
633 path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
634 if (path_obj == NULL)
635 {
636 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
637 return (-1);
638 }
640 for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
641 {
642 zone_name = (char *) xmlNodeListGetString (doc,
643 path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
644 if (zone_name != NULL)
645 break;
646 }
648 if (zone_name == NULL)
649 {
650 ERROR ("bind plugin: Could not determine zone name.");
651 xmlXPathFreeObject (path_obj);
652 return (-1);
653 }
655 for (j = 0; j < view->zones_num; j++)
656 {
657 if (strcasecmp (zone_name, view->zones[j]) == 0)
658 break;
659 }
661 xmlFree (zone_name);
662 zone_name = NULL;
664 if (j >= views_num)
665 {
666 xmlXPathFreeObject (path_obj);
667 return (0);
668 }
670 zone_name = view->zones[j];
672 DEBUG ("bind plugin: bind_xml_stats_handle_zone: Found zone `%s'.",
673 zone_name);
675 { /* Parse the <counters> tag {{{ */
676 char plugin_instance[DATA_MAX_NAME_LEN];
677 translation_table_ptr_t table_ptr =
678 {
679 nsstats_translation_table,
680 nsstats_translation_table_length,
681 plugin_instance
682 };
684 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-zone-%s",
685 view->name, zone_name);
687 bind_parse_generic_value_list (/* xpath = */ "counters",
688 /* callback = */ bind_xml_table_callback,
689 /* user_data = */ &table_ptr,
690 doc, path_ctx, current_time, DS_TYPE_COUNTER);
691 } /* }}} */
693 xmlXPathFreeObject (path_obj);
695 return (0);
696 } /* }}} int bind_xml_stats_handle_zone */
698 static int bind_xml_stats_search_zones (int version, xmlDoc *doc, /* {{{ */
699 xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view,
700 time_t current_time)
701 {
702 xmlXPathObject *zone_nodes = NULL;
703 xmlXPathContext *zone_path_context;
704 int i;
706 zone_path_context = xmlXPathNewContext (doc);
707 if (zone_path_context == NULL)
708 {
709 ERROR ("bind plugin: xmlXPathNewContext failed.");
710 return (-1);
711 }
713 zone_nodes = xmlXPathEvalExpression (BAD_CAST "zones/zone", path_ctx);
714 if (zone_nodes == NULL)
715 {
716 ERROR ("bind plugin: Cannot find any <view> tags.");
717 xmlXPathFreeContext (zone_path_context);
718 return (-1);
719 }
721 for (i = 0; i < zone_nodes->nodesetval->nodeNr; i++)
722 {
723 xmlNode *node;
725 node = zone_nodes->nodesetval->nodeTab[i];
726 assert (node != NULL);
728 zone_path_context->node = node;
730 bind_xml_stats_handle_zone (version, doc, zone_path_context, node, view,
731 current_time);
732 }
734 xmlXPathFreeObject (zone_nodes);
735 xmlXPathFreeContext (zone_path_context);
736 return (0);
737 } /* }}} int bind_xml_stats_search_zones */
739 static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */
740 xmlXPathContext *path_ctx, xmlNode *node, time_t current_time)
741 {
742 xmlXPathObject *path_obj;
743 char *view_name = NULL;
744 cb_view_t *view;
745 int i;
746 size_t j;
748 path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
749 if (path_obj == NULL)
750 {
751 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
752 return (-1);
753 }
755 for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
756 {
757 view_name = (char *) xmlNodeListGetString (doc,
758 path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
759 if (view_name != NULL)
760 break;
761 }
763 if (view_name == NULL)
764 {
765 ERROR ("bind plugin: Could not determine view name.");
766 xmlXPathFreeObject (path_obj);
767 return (-1);
768 }
770 for (j = 0; j < views_num; j++)
771 {
772 if (strcasecmp (view_name, views[j].name) == 0)
773 break;
774 }
776 xmlFree (view_name);
777 xmlXPathFreeObject (path_obj);
779 view_name = NULL;
780 path_obj = NULL;
782 if (j >= views_num)
783 return (0);
785 view = views + j;
787 DEBUG ("bind plugin: bind_xml_stats_handle_view: Found view `%s'.",
788 view->name);
790 if (view->qtypes != 0) /* {{{ */
791 {
792 char plugin_instance[DATA_MAX_NAME_LEN];
793 list_info_ptr_t list_info =
794 {
795 plugin_instance,
796 /* type = */ "dns_qtype_gauge"
797 };
799 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-qtypes",
800 view->name);
802 bind_parse_generic_name_value (/* xpath = */ "rdtype",
803 /* callback = */ bind_xml_list_callback,
804 /* user_data = */ &list_info,
805 doc, path_ctx, current_time, DS_TYPE_COUNTER);
806 } /* }}} */
808 if (view->resolver_stats != 0) /* {{{ */
809 {
810 char plugin_instance[DATA_MAX_NAME_LEN];
811 translation_table_ptr_t table_ptr =
812 {
813 resstats_translation_table,
814 resstats_translation_table_length,
815 plugin_instance
816 };
818 ssnprintf (plugin_instance, sizeof (plugin_instance),
819 "%s-resolver_stats", view->name);
821 bind_parse_generic_name_value ("resstat",
822 /* callback = */ bind_xml_table_callback,
823 /* user_data = */ &table_ptr,
824 doc, path_ctx, current_time, DS_TYPE_COUNTER);
825 } /* }}} */
827 if (view->cacherrsets != 0) /* {{{ */
828 {
829 char plugin_instance[DATA_MAX_NAME_LEN];
830 list_info_ptr_t list_info =
831 {
832 plugin_instance,
833 /* type = */ "dns_qtype_gauge"
834 };
836 ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-cache_rr_sets",
837 view->name);
839 bind_parse_generic_name_value (/* xpath = */ "cache/rrset",
840 /* callback = */ bind_xml_list_callback,
841 /* user_data = */ &list_info,
842 doc, path_ctx, current_time, DS_TYPE_GAUGE);
843 } /* }}} */
845 if (view->zones_num > 0)
846 bind_xml_stats_search_zones (version, doc, path_ctx, node, view,
847 current_time);
849 return (0);
850 } /* }}} int bind_xml_stats_handle_view */
852 static int bind_xml_stats_search_views (int version, xmlDoc *doc, /* {{{ */
853 xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
854 {
855 xmlXPathObject *view_nodes = NULL;
856 xmlXPathContext *view_path_context;
857 int i;
859 view_path_context = xmlXPathNewContext (doc);
860 if (view_path_context == NULL)
861 {
862 ERROR ("bind plugin: xmlXPathNewContext failed.");
863 return (-1);
864 }
866 view_nodes = xmlXPathEvalExpression (BAD_CAST "views/view", xpathCtx);
867 if (view_nodes == NULL)
868 {
869 ERROR ("bind plugin: Cannot find any <view> tags.");
870 xmlXPathFreeContext (view_path_context);
871 return (-1);
872 }
874 for (i = 0; i < view_nodes->nodesetval->nodeNr; i++)
875 {
876 xmlNode *node;
878 node = view_nodes->nodesetval->nodeTab[i];
879 assert (node != NULL);
881 view_path_context->node = node;
883 bind_xml_stats_handle_view (version, doc, view_path_context, node,
884 current_time);
885 }
887 xmlXPathFreeObject (view_nodes);
888 xmlXPathFreeContext (view_path_context);
889 return (0);
890 } /* }}} int bind_xml_stats_search_views */
892 static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
893 xmlXPathContext *xpathCtx, xmlNode *statsnode)
894 {
895 time_t current_time = 0;
896 int status;
898 xpathCtx->node = statsnode;
900 /* TODO: Check `server/boot-time' to recognize server restarts. */
902 status = bind_xml_read_timestamp ("server/current-time",
903 doc, xpathCtx, ¤t_time);
904 if (status != 0)
905 {
906 ERROR ("bind plugin: Reading `server/current-time' failed.");
907 return (-1);
908 }
909 DEBUG ("bind plugin: Current server time is %i.", (int) current_time);
911 /* XPath: server/requests/opcode
912 * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
913 * Layout:
914 * <opcode>
915 * <name>A</name>
916 * <counter>1</counter>
917 * </opcode>
918 * :
919 */
920 if (global_opcodes != 0)
921 {
922 list_info_ptr_t list_info =
923 {
924 /* plugin instance = */ "global-opcodes",
925 /* type = */ "dns_opcode"
926 };
928 bind_parse_generic_name_value (/* xpath = */ "server/requests/opcode",
929 /* callback = */ bind_xml_list_callback,
930 /* user_data = */ &list_info,
931 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
932 }
934 /* XPath: server/queries-in/rdtype
935 * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
936 * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
937 * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
938 * Layout:
939 * <rdtype>
940 * <name>A</name>
941 * <counter>1</counter>
942 * </rdtype>
943 * :
944 */
945 if (global_qtypes != 0)
946 {
947 list_info_ptr_t list_info =
948 {
949 /* plugin instance = */ "global-qtypes",
950 /* type = */ "dns_qtype"
951 };
953 bind_parse_generic_name_value (/* xpath = */ "server/queries-in/rdtype",
954 /* callback = */ bind_xml_list_callback,
955 /* user_data = */ &list_info,
956 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
957 }
959 /* XPath: server/nsstats, server/nsstat
960 * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
961 * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
962 * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
963 * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
964 * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
965 * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
966 * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
967 * UpdateBadPrereq
968 * Layout v1:
969 * <nsstats>
970 * <Requestv4>1</Requestv4>
971 * <Requestv6>0</Requestv6>
972 * :
973 * </nsstats>
974 * Layout v2:
975 * <nsstat>
976 * <name>Requestv4</name>
977 * <counter>1</counter>
978 * </nsstat>
979 * <nsstat>
980 * <name>Requestv6</name>
981 * <counter>0</counter>
982 * </nsstat>
983 * :
984 */
985 if (global_server_stats)
986 {
987 translation_table_ptr_t table_ptr =
988 {
989 nsstats_translation_table,
990 nsstats_translation_table_length,
991 /* plugin_instance = */ "global-server_stats"
992 };
994 if (version == 1)
995 {
996 bind_parse_generic_value_list ("server/nsstats",
997 /* callback = */ bind_xml_table_callback,
998 /* user_data = */ &table_ptr,
999 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1000 }
1001 else
1002 {
1003 bind_parse_generic_name_value ("server/nsstat",
1004 /* callback = */ bind_xml_table_callback,
1005 /* user_data = */ &table_ptr,
1006 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1007 }
1008 }
1010 /* XPath: server/zonestats, server/zonestat
1011 * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
1012 * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
1013 * XfrSuccess, XfrFail
1014 * Layout v1:
1015 * <zonestats>
1016 * <NotifyOutv4>0</NotifyOutv4>
1017 * <NotifyOutv6>0</NotifyOutv6>
1018 * :
1019 * </zonestats>
1020 * Layout v2:
1021 * <zonestat>
1022 * <name>NotifyOutv4</name>
1023 * <counter>0</counter>
1024 * </zonestat>
1025 * <zonestat>
1026 * <name>NotifyOutv6</name>
1027 * <counter>0</counter>
1028 * </zonestat>
1029 * :
1030 */
1031 if (global_zone_maint_stats)
1032 {
1033 translation_table_ptr_t table_ptr =
1034 {
1035 zonestats_translation_table,
1036 zonestats_translation_table_length,
1037 /* plugin_instance = */ "global-zone_maint_stats"
1038 };
1040 if (version == 1)
1041 {
1042 bind_parse_generic_value_list ("server/zonestats",
1043 /* callback = */ bind_xml_table_callback,
1044 /* user_data = */ &table_ptr,
1045 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1046 }
1047 else
1048 {
1049 bind_parse_generic_name_value ("server/zonestat",
1050 /* callback = */ bind_xml_table_callback,
1051 /* user_data = */ &table_ptr,
1052 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1053 }
1054 }
1056 /* XPath: server/resstats
1057 * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
1058 * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
1059 * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
1060 * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
1061 * Layout v1:
1062 * <resstats>
1063 * <Queryv4>0</Queryv4>
1064 * <Queryv6>0</Queryv6>
1065 * :
1066 * </resstats>
1067 * Layout v2:
1068 * <resstat>
1069 * <name>Queryv4</name>
1070 * <counter>0</counter>
1071 * </resstat>
1072 * <resstat>
1073 * <name>Queryv6</name>
1074 * <counter>0</counter>
1075 * </resstat>
1076 * :
1077 */
1078 if (global_resolver_stats != 0)
1079 {
1080 translation_table_ptr_t table_ptr =
1081 {
1082 resstats_translation_table,
1083 resstats_translation_table_length,
1084 /* plugin_instance = */ "global-resolver_stats"
1085 };
1087 if (version == 1)
1088 {
1089 bind_parse_generic_value_list ("server/resstats",
1090 /* callback = */ bind_xml_table_callback,
1091 /* user_data = */ &table_ptr,
1092 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1093 }
1094 else
1095 {
1096 bind_parse_generic_name_value ("server/resstat",
1097 /* callback = */ bind_xml_table_callback,
1098 /* user_data = */ &table_ptr,
1099 doc, xpathCtx, current_time, DS_TYPE_COUNTER);
1100 }
1101 }
1103 /* XPath: memory/summary
1104 * Variables: TotalUse, InUse, BlockSize, ContextSize, Lost
1105 * Layout: v2:
1106 * <summary>
1107 * <TotalUse>6587096</TotalUse>
1108 * <InUse>1345424</InUse>
1109 * <BlockSize>5505024</BlockSize>
1110 * <ContextSize>3732456</ContextSize>
1111 * <Lost>0</Lost>
1112 * </summary>
1113 */
1114 if (global_memory_stats != 0)
1115 {
1116 translation_table_ptr_t table_ptr =
1117 {
1118 memsummary_translation_table,
1119 memsummary_translation_table_length,
1120 /* plugin_instance = */ "global-memory_stats"
1121 };
1123 bind_parse_generic_value_list ("memory/summary",
1124 /* callback = */ bind_xml_table_callback,
1125 /* user_data = */ &table_ptr,
1126 doc, xpathCtx, current_time, DS_TYPE_GAUGE);
1127 }
1129 if (views_num > 0)
1130 bind_xml_stats_search_views (version, doc, xpathCtx, statsnode,
1131 current_time);
1133 return 0;
1134 } /* }}} int bind_xml_stats */
1136 static int bind_xml (const char *data) /* {{{ */
1137 {
1138 xmlDoc *doc = NULL;
1139 xmlXPathContext *xpathCtx = NULL;
1140 xmlXPathObject *xpathObj = NULL;
1141 int ret = -1;
1142 int i;
1144 doc = xmlParseMemory (data, strlen (data));
1145 if (doc == NULL)
1146 {
1147 ERROR ("bind plugin: xmlParseMemory failed.");
1148 return (-1);
1149 }
1151 xpathCtx = xmlXPathNewContext (doc);
1152 if (xpathCtx == NULL)
1153 {
1154 ERROR ("bind plugin: xmlXPathNewContext failed.");
1155 xmlFreeDoc (doc);
1156 return (-1);
1157 }
1159 xpathObj = xmlXPathEvalExpression (BAD_CAST "/isc/bind/statistics", xpathCtx);
1160 if (xpathObj == NULL)
1161 {
1162 ERROR ("bind plugin: Cannot find the <statistics> tag.");
1163 xmlXPathFreeContext (xpathCtx);
1164 xmlFreeDoc (doc);
1165 return (-1);
1166 }
1167 else if (xpathObj->nodesetval == NULL)
1168 {
1169 ERROR ("bind plugin: xmlXPathEvalExpression failed.");
1170 xmlXPathFreeObject (xpathObj);
1171 xmlXPathFreeContext (xpathCtx);
1172 xmlFreeDoc (doc);
1173 return (-1);
1174 }
1176 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++)
1177 {
1178 xmlNode *node;
1179 char *attr_version;
1180 int parsed_version = 0;
1182 node = xpathObj->nodesetval->nodeTab[i];
1183 assert (node != NULL);
1185 attr_version = (char *) xmlGetProp (node, BAD_CAST "version");
1186 if (attr_version == NULL)
1187 {
1188 NOTICE ("bind plugin: Found <statistics> tag doesn't have a "
1189 "`version' attribute.");
1190 continue;
1191 }
1192 DEBUG ("bind plugin: Found: <statistics version=\"%s\">", attr_version);
1194 /* At the time this plugin was written, version "1.0" was used by
1195 * BIND 9.5.0, version "2.0" was used by BIND 9.5.1 and 9.6.0. We assume
1196 * that "1.*" and "2.*" don't introduce structural changes, so we just
1197 * check for the first two characters here. */
1198 if (strncmp ("1.", attr_version, strlen ("1.")) == 0)
1199 parsed_version = 1;
1200 else if (strncmp ("2.", attr_version, strlen ("2.")) == 0)
1201 parsed_version = 2;
1202 else
1203 {
1204 /* TODO: Use the complaint mechanism here. */
1205 NOTICE ("bind plugin: Found <statistics> tag with version `%s'. "
1206 "Unfortunately I have no clue how to parse that. "
1207 "Please open a bug report for this.", attr_version);
1208 xmlFree (attr_version);
1209 continue;
1210 }
1212 ret = bind_xml_stats (parsed_version,
1213 doc, xpathCtx, node);
1215 xmlFree (attr_version);
1216 /* One <statistics> node ought to be enough. */
1217 break;
1218 }
1220 xmlXPathFreeObject (xpathObj);
1221 xmlXPathFreeContext (xpathCtx);
1222 xmlFreeDoc (doc);
1224 return (ret);
1225 } /* }}} int bind_xml */
1227 static int bind_config_set_bool (const char *name, int *var, /* {{{ */
1228 oconfig_item_t *ci)
1229 {
1230 if ((ci->values_num != 1) || ( ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1231 {
1232 WARNING ("bind plugin: The `%s' option needs "
1233 "exactly one boolean argument.", name);
1234 return (-1);
1235 }
1237 if (ci->values[0].value.boolean)
1238 *var = 1;
1239 else
1240 *var = 0;
1241 return 0;
1242 } /* }}} int bind_config_set_bool */
1244 static int bind_config_add_view_zone (cb_view_t *view, /* {{{ */
1245 oconfig_item_t *ci)
1246 {
1247 char **tmp;
1249 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1250 {
1251 WARNING ("bind plugin: The `Zone' option needs "
1252 "exactly one string argument.");
1253 return (-1);
1254 }
1256 tmp = (char **) realloc (view->zones,
1257 sizeof (char *) * (view->zones_num + 1));
1258 if (tmp == NULL)
1259 {
1260 ERROR ("bind plugin: realloc failed.");
1261 return (-1);
1262 }
1263 view->zones = tmp;
1265 view->zones[view->zones_num] = strdup (ci->values[0].value.string);
1266 if (view->zones[view->zones_num] == NULL)
1267 {
1268 ERROR ("bind plugin: strdup failed.");
1269 return (-1);
1270 }
1271 view->zones_num++;
1273 return (0);
1274 } /* }}} int bind_config_add_view_zone */
1276 static int bind_config_add_view (oconfig_item_t *ci) /* {{{ */
1277 {
1278 cb_view_t *tmp;
1279 int i;
1281 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1282 {
1283 WARNING ("bind plugin: `View' blocks need exactly one string argument.");
1284 return (-1);
1285 }
1287 tmp = (cb_view_t *) realloc (views, sizeof (*views) * (views_num + 1));
1288 if (tmp == NULL)
1289 {
1290 ERROR ("bind plugin: realloc failed.");
1291 return (-1);
1292 }
1293 views = tmp;
1294 tmp = views + views_num;
1296 memset (tmp, 0, sizeof (*tmp));
1297 tmp->qtypes = 1;
1298 tmp->resolver_stats = 1;
1299 tmp->cacherrsets = 1;
1300 tmp->zones = NULL;
1301 tmp->zones_num = 0;
1303 tmp->name = strdup (ci->values[0].value.string);
1304 if (tmp->name == NULL)
1305 {
1306 ERROR ("bind plugin: strdup failed.");
1307 free (tmp);
1308 return (-1);
1309 }
1311 for (i = 0; i < ci->children_num; i++)
1312 {
1313 oconfig_item_t *child = ci->children + i;
1315 if (strcasecmp ("QTypes", child->key) == 0)
1316 bind_config_set_bool ("QTypes", &tmp->qtypes, child);
1317 else if (strcasecmp ("ResolverStats", child->key) == 0)
1318 bind_config_set_bool ("ResolverStats", &tmp->resolver_stats, child);
1319 else if (strcasecmp ("CacheRRSets", child->key) == 0)
1320 bind_config_set_bool ("CacheRRSets", &tmp->cacherrsets, child);
1321 else if (strcasecmp ("Zone", child->key) == 0)
1322 bind_config_add_view_zone (tmp, child);
1323 else
1324 {
1325 WARNING ("bind plugin: Unknown configuration option "
1326 "`%s' in view `%s' will be ignored.", child->key, tmp->name);
1327 }
1328 } /* for (i = 0; i < ci->children_num; i++) */
1330 views_num++;
1331 return (0);
1332 } /* }}} int bind_config_add_view */
1334 static int bind_config (oconfig_item_t *ci) /* {{{ */
1335 {
1336 int i;
1338 for (i = 0; i < ci->children_num; i++)
1339 {
1340 oconfig_item_t *child = ci->children + i;
1342 if (strcasecmp ("Url", child->key) == 0) {
1343 if ((child->values_num != 1) || (child->values[0].type != OCONFIG_TYPE_STRING))
1344 {
1345 WARNING ("bind plugin: The `Url' option needs "
1346 "exactly one string argument.");
1347 return (-1);
1348 }
1350 url = strdup (child->values[0].value.string);
1351 } else if (strcasecmp ("OpCodes", child->key) == 0)
1352 bind_config_set_bool ("OpCodes", &global_opcodes, child);
1353 else if (strcasecmp ("QTypes", child->key) == 0)
1354 bind_config_set_bool ("QTypes", &global_qtypes, child);
1355 else if (strcasecmp ("ServerStats", child->key) == 0)
1356 bind_config_set_bool ("ServerStats", &global_server_stats, child);
1357 else if (strcasecmp ("ZoneMaintStats", child->key) == 0)
1358 bind_config_set_bool ("ZoneMaintStats", &global_zone_maint_stats, child);
1359 else if (strcasecmp ("ResolverStats", child->key) == 0)
1360 bind_config_set_bool ("ResolverStats", &global_resolver_stats, child);
1361 else if (strcasecmp ("MemoryStats", child->key) == 0)
1362 bind_config_set_bool ("MemoryStats", &global_memory_stats, child);
1363 else if (strcasecmp ("View", child->key) == 0)
1364 bind_config_add_view (child);
1365 else
1366 {
1367 WARNING ("bind plugin: Unknown configuration option "
1368 "`%s' will be ignored.", child->key);
1369 }
1370 }
1372 return (0);
1373 } /* }}} int bind_config */
1375 static int bind_init (void) /* {{{ */
1376 {
1377 if (curl != NULL)
1378 return (0);
1380 curl = curl_easy_init ();
1381 if (curl == NULL)
1382 {
1383 ERROR ("bind plugin: bind_init: curl_easy_init failed.");
1384 return (-1);
1385 }
1387 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
1388 curl_easy_setopt (curl, CURLOPT_USERAGENT, PACKAGE_NAME"/"PACKAGE_VERSION);
1389 curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, bind_curl_error);
1390 curl_easy_setopt (curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
1392 return (0);
1393 } /* }}} int bind_init */
1395 static int bind_read (void) /* {{{ */
1396 {
1397 int status;
1399 if (curl == NULL)
1400 {
1401 ERROR ("bind plugin: I don't have a CURL object.");
1402 return (-1);
1403 }
1405 bind_buffer_fill = 0;
1406 if (curl_easy_perform (curl) != 0)
1407 {
1408 ERROR ("bind plugin: curl_easy_perform failed: %s",
1409 bind_curl_error);
1410 return (-1);
1411 }
1413 status = bind_xml (bind_buffer);
1414 if (status != 0)
1415 return (-1);
1416 else
1417 return (0);
1418 } /* }}} int bind_read */
1420 static int bind_shutdown (void) /* {{{ */
1421 {
1422 if (curl != NULL)
1423 {
1424 curl_easy_cleanup (curl);
1425 curl = NULL;
1426 }
1428 return (0);
1429 } /* }}} int bind_shutdown */
1431 void module_register (void)
1432 {
1433 plugin_register_complex_config ("bind", bind_config);
1434 plugin_register_init ("bind", bind_init);
1435 plugin_register_read ("bind", bind_read);
1436 plugin_register_shutdown ("bind", bind_shutdown);
1437 } /* void module_register */
1439 /* vim: set sw=2 sts=2 ts=8 et fdm=marker : */