2 * collectd - src/curl_xml.c
3 * Copyright (C) 2009,2010 Amit Gupta
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Amit Gupta <amit.gupta221 at gmail.com>
25 #include "configfile.h"
26 #include "utils_llist.h"
28 #include <libxml/parser.h>
29 #include <libxml/tree.h>
30 #include <libxml/xpath.h>
31 #include <libxml/xpathInternals.h>
33 #include <curl/curl.h>
35 #define CX_DEFAULT_HOST "localhost"
38 * Private data structures
40 struct cx_values_s /* {{{ */
42 char path[DATA_MAX_NAME_LEN];
45 typedef struct cx_values_s cx_values_t;
48 struct cx_xpath_s /* {{{ */
54 char *instance_prefix;
59 typedef struct cx_xpath_s cx_xpath_t;
62 struct cx_namespace_s /* {{{ */
67 typedef struct cx_namespace_s cx_namespace_t;
83 struct curl_slist *headers;
85 cx_namespace_t *namespaces;
86 size_t namespaces_num;
89 char curl_errbuf[CURL_ERROR_SIZE];
94 llist_t *list; /* list of xpath blocks */
96 typedef struct cx_s cx_t; /* }}} */
101 static size_t cx_curl_callback (void *buf, /* {{{ */
102 size_t size, size_t nmemb, void *user_data)
104 size_t len = size * nmemb;
110 ERROR ("curl_xml plugin: cx_curl_callback: "
111 "user_data pointer is NULL.");
118 if ((db->buffer_fill + len) >= db->buffer_size)
122 temp = (char *) realloc (db->buffer,
123 db->buffer_fill + len + 1);
126 ERROR ("curl_xml plugin: realloc failed.");
130 db->buffer_size = db->buffer_fill + len + 1;
133 memcpy (db->buffer + db->buffer_fill, (char *) buf, len);
134 db->buffer_fill += len;
135 db->buffer[db->buffer_fill] = 0;
138 } /* }}} size_t cx_curl_callback */
140 static void cx_xpath_free (cx_xpath_t *xpath) /* {{{ */
147 sfree (xpath->instance_prefix);
148 sfree (xpath->instance);
149 sfree (xpath->values);
151 } /* }}} void cx_xpath_free */
153 static void cx_list_free (llist_t *list) /* {{{ */
157 le = llist_head (list);
165 cx_xpath_free (le->value);
170 llist_destroy (list);
172 } /* }}} void cx_list_free */
174 static void cx_free (void *arg) /* {{{ */
179 DEBUG ("curl_xml plugin: cx_free (arg = %p);", arg);
186 if (db->curl != NULL)
187 curl_easy_cleanup (db->curl);
190 if (db->list != NULL)
191 cx_list_free (db->list);
194 sfree (db->instance);
200 sfree (db->credentials);
202 sfree (db->post_body);
203 curl_slist_free_all (db->headers);
205 for (i = 0; i < db->namespaces_num; i++)
207 sfree (db->namespaces[i].prefix);
208 sfree (db->namespaces[i].url);
210 sfree (db->namespaces);
213 } /* }}} void cx_free */
215 static int cx_config_append_string (const char *name, struct curl_slist **dest, /* {{{ */
218 struct curl_slist *temp = NULL;
219 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
221 WARNING ("curl_xml plugin: `%s' needs exactly one string argument.", name);
225 temp = curl_slist_append(*dest, ci->values[0].value.string);
232 } /* }}} int cx_config_append_string */
234 static int cx_check_type (const data_set_t *ds, cx_xpath_t *xpath) /* {{{ */
238 WARNING ("curl_xml plugin: DataSet `%s' not defined.", xpath->type);
242 if (ds->ds_num != xpath->values_len)
244 WARNING ("curl_xml plugin: DataSet `%s' requires %i values, but config talks about %i",
245 xpath->type, ds->ds_num, xpath->values_len);
250 } /* }}} cx_check_type */
252 static xmlXPathObjectPtr cx_evaluate_xpath (xmlXPathContextPtr xpath_ctx, /* {{{ */
255 xmlXPathObjectPtr xpath_obj;
257 /* XXX: When to free this? */
258 xpath_obj = xmlXPathEvalExpression(BAD_CAST expr, xpath_ctx);
259 if (xpath_obj == NULL)
261 WARNING ("curl_xml plugin: "
262 "Error unable to evaluate xpath expression \"%s\". Skipping...", expr);
267 } /* }}} cx_evaluate_xpath */
269 static int cx_if_not_text_node (xmlNodePtr node) /* {{{ */
271 if (node->type == XML_TEXT_NODE || node->type == XML_ATTRIBUTE_NODE ||
272 node->type == XML_ELEMENT_NODE)
275 WARNING ("curl_xml plugin: "
276 "Node \"%s\" doesn't seem to be a text node. Skipping...", node->name);
278 } /* }}} cx_if_not_text_node */
280 static int cx_handle_single_value_xpath (xmlXPathContextPtr xpath_ctx, /* {{{ */
282 const data_set_t *ds, value_list_t *vl, int index)
284 xmlXPathObjectPtr values_node_obj;
285 xmlNodeSetPtr values_node;
289 values_node_obj = cx_evaluate_xpath (xpath_ctx, BAD_CAST xpath->values[index].path);
290 if (values_node_obj == NULL)
291 return (-1); /* Error already logged. */
293 values_node = values_node_obj->nodesetval;
294 tmp_size = (values_node) ? values_node->nodeNr : 0;
298 WARNING ("curl_xml plugin: "
299 "relative xpath expression \"%s\" doesn't match any of the nodes. "
300 "Skipping...", xpath->values[index].path);
301 xmlXPathFreeObject (values_node_obj);
307 WARNING ("curl_xml plugin: "
308 "relative xpath expression \"%s\" is expected to return "
309 "only one node. Skipping...", xpath->values[index].path);
310 xmlXPathFreeObject (values_node_obj);
314 /* ignoring the element if other than textnode/attribute*/
315 if (cx_if_not_text_node(values_node->nodeTab[0]))
317 WARNING ("curl_xml plugin: "
318 "relative xpath expression \"%s\" is expected to return "
319 "only text/attribute node which is not the case. Skipping...",
320 xpath->values[index].path);
321 xmlXPathFreeObject (values_node_obj);
325 node_value = (char *) xmlNodeGetContent(values_node->nodeTab[0]);
326 switch (ds->ds[index].type)
328 case DS_TYPE_COUNTER:
329 vl->values[index].counter = (counter_t) strtoull (node_value,
330 /* endptr = */ NULL, /* base = */ 0);
333 vl->values[index].derive = (derive_t) strtoll (node_value,
334 /* endptr = */ NULL, /* base = */ 0);
336 case DS_TYPE_ABSOLUTE:
337 vl->values[index].absolute = (absolute_t) strtoull (node_value,
338 /* endptr = */ NULL, /* base = */ 0);
341 vl->values[index].gauge = (gauge_t) strtod (node_value,
342 /* endptr = */ NULL);
346 xmlXPathFreeObject (values_node_obj);
349 /* We have reached here which means that
350 * we have got something to work */
352 } /* }}} int cx_handle_single_value_xpath */
354 static int cx_handle_all_value_xpaths (xmlXPathContextPtr xpath_ctx, /* {{{ */
356 const data_set_t *ds, value_list_t *vl)
358 value_t values[xpath->values_len];
362 assert (xpath->values_len > 0);
363 assert (xpath->values_len == vl->values_len);
364 assert (xpath->values_len == ds->ds_num);
367 for (i = 0; i < xpath->values_len; i++)
369 status = cx_handle_single_value_xpath (xpath_ctx, xpath, ds, vl, i);
371 return (-1); /* An error has been printed. */
372 } /* for (i = 0; i < xpath->values_len; i++) */
374 plugin_dispatch_values (vl);
378 } /* }}} int cx_handle_all_value_xpaths */
380 static int cx_handle_instance_xpath (xmlXPathContextPtr xpath_ctx, /* {{{ */
381 cx_xpath_t *xpath, value_list_t *vl,
384 xmlXPathObjectPtr instance_node_obj = NULL;
385 xmlNodeSetPtr instance_node = NULL;
387 memset (vl->type_instance, 0, sizeof (vl->type_instance));
389 /* If the base xpath returns more than one block, the result is assumed to be
390 * a table. The `Instance' option is not optional in this case. Check for the
391 * condition and inform the user. */
392 if (is_table && (xpath->instance == NULL))
394 WARNING ("curl_xml plugin: "
395 "Base-XPath %s is a table (more than one result was returned), "
396 "but no instance-XPath has been defined.",
401 /* instance has to be an xpath expression */
402 if (xpath->instance != NULL)
406 instance_node_obj = cx_evaluate_xpath (xpath_ctx, BAD_CAST xpath->instance);
407 if (instance_node_obj == NULL)
408 return (-1); /* error is logged already */
410 instance_node = instance_node_obj->nodesetval;
411 tmp_size = (instance_node) ? instance_node->nodeNr : 0;
415 WARNING ("curl_xml plugin: "
416 "relative xpath expression for 'InstanceFrom' \"%s\" doesn't match "
417 "any of the nodes. Skipping the node.", xpath->instance);
418 xmlXPathFreeObject (instance_node_obj);
424 WARNING ("curl_xml plugin: "
425 "relative xpath expression for 'InstanceFrom' \"%s\" is expected "
426 "to return only one text node. Skipping the node.", xpath->instance);
427 xmlXPathFreeObject (instance_node_obj);
431 /* ignoring the element if other than textnode/attribute */
432 if (cx_if_not_text_node(instance_node->nodeTab[0]))
434 WARNING ("curl_xml plugin: "
435 "relative xpath expression \"%s\" is expected to return only text node "
436 "which is not the case. Skipping the node.", xpath->instance);
437 xmlXPathFreeObject (instance_node_obj);
440 } /* if (xpath->instance != NULL) */
442 if (xpath->instance_prefix != NULL)
444 if (instance_node != NULL)
446 char *node_value = (char *) xmlNodeGetContent(instance_node->nodeTab[0]);
447 ssnprintf (vl->type_instance, sizeof (vl->type_instance),"%s%s",
448 xpath->instance_prefix, node_value);
452 sstrncpy (vl->type_instance, xpath->instance_prefix,
453 sizeof (vl->type_instance));
457 /* If instance_prefix and instance_node are NULL, then
458 * don't set the type_instance */
459 if (instance_node != NULL)
461 char *node_value = (char *) xmlNodeGetContent(instance_node->nodeTab[0]);
462 sstrncpy (vl->type_instance, node_value, sizeof (vl->type_instance));
467 /* Free `instance_node_obj' this late, because `instance_node' points to
468 * somewhere inside this structure. */
469 xmlXPathFreeObject (instance_node_obj);
472 } /* }}} int cx_handle_instance_xpath */
474 static int cx_handle_base_xpath (char const *plugin_instance, /* {{{ */
476 xmlXPathContextPtr xpath_ctx, const data_set_t *ds,
477 char *base_xpath, cx_xpath_t *xpath)
482 xmlXPathObjectPtr base_node_obj = NULL;
483 xmlNodeSetPtr base_nodes = NULL;
485 value_list_t vl = VALUE_LIST_INIT;
487 base_node_obj = cx_evaluate_xpath (xpath_ctx, BAD_CAST base_xpath);
488 if (base_node_obj == NULL)
489 return -1; /* error is logged already */
491 base_nodes = base_node_obj->nodesetval;
492 total_nodes = (base_nodes) ? base_nodes->nodeNr : 0;
494 if (total_nodes == 0)
496 ERROR ("curl_xml plugin: "
497 "xpath expression \"%s\" doesn't match any of the nodes. "
498 "Skipping the xpath block...", base_xpath);
499 xmlXPathFreeObject (base_node_obj);
503 /* If base_xpath returned multiple results, then */
504 /* Instance in the xpath block is required */
505 if (total_nodes > 1 && xpath->instance == NULL)
507 ERROR ("curl_xml plugin: "
508 "InstanceFrom is must in xpath block since the base xpath expression \"%s\" "
509 "returned multiple results. Skipping the xpath block...", base_xpath);
513 /* set the values for the value_list */
514 vl.values_len = ds->ds_num;
515 sstrncpy (vl.type, xpath->type, sizeof (vl.type));
516 sstrncpy (vl.plugin, "curl_xml", sizeof (vl.plugin));
517 sstrncpy (vl.host, (host != NULL) ? host : hostname_g, sizeof (vl.host));
518 if (plugin_instance != NULL)
519 sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
521 for (i = 0; i < total_nodes; i++)
525 xpath_ctx->node = base_nodes->nodeTab[i];
527 status = cx_handle_instance_xpath (xpath_ctx, xpath, &vl,
528 /* is_table = */ (total_nodes > 1));
530 continue; /* An error has already been reported. */
532 status = cx_handle_all_value_xpaths (xpath_ctx, xpath, ds, &vl);
534 continue; /* An error has been logged. */
535 } /* for (i = 0; i < total_nodes; i++) */
537 /* free up the allocated memory */
538 xmlXPathFreeObject (base_node_obj);
541 } /* }}} cx_handle_base_xpath */
543 static int cx_handle_parsed_xml(xmlDocPtr doc, /* {{{ */
544 xmlXPathContextPtr xpath_ctx, cx_t *db)
547 const data_set_t *ds;
552 le = llist_head (db->list);
556 xpath = (cx_xpath_t *) le->value;
557 ds = plugin_get_ds (xpath->type);
559 if ( (cx_check_type(ds, xpath) == 0) &&
560 (cx_handle_base_xpath(db->instance, db->host,
561 xpath_ctx, ds, le->key, xpath) == 0) )
562 status = 0; /* we got atleast one success */
565 } /* while (le != NULL) */
568 } /* }}} cx_handle_parsed_xml */
570 static int cx_parse_stats_xml(xmlChar* xml, cx_t *db) /* {{{ */
574 xmlXPathContextPtr xpath_ctx;
578 doc = xmlParseDoc(xml);
581 ERROR ("curl_xml plugin: Failed to parse the xml document - %s", xml);
585 xpath_ctx = xmlXPathNewContext(doc);
586 if(xpath_ctx == NULL)
588 ERROR ("curl_xml plugin: Failed to create the xml context");
593 for (i = 0; i < db->namespaces_num; i++)
595 cx_namespace_t const *ns = db->namespaces + i;
596 status = xmlXPathRegisterNs (xpath_ctx,
597 BAD_CAST ns->prefix, BAD_CAST ns->url);
600 ERROR ("curl_xml plugin: "
601 "unable to register NS with prefix=\"%s\" and href=\"%s\"\n",
602 ns->prefix, ns->url);
603 xmlXPathFreeContext(xpath_ctx);
609 status = cx_handle_parsed_xml (doc, xpath_ctx, db);
611 xmlXPathFreeContext(xpath_ctx);
614 } /* }}} cx_parse_stats_xml */
616 static int cx_curl_perform (cx_t *db, CURL *curl) /* {{{ */
625 status = curl_easy_perform (curl);
626 if (status != CURLE_OK)
628 ERROR ("curl_xml plugin: curl_easy_perform failed with status %i: %s (%s)",
629 status, db->curl_errbuf, url);
633 curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
634 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &rc);
636 /* The response code is zero if a non-HTTP transport was used. */
637 if ((rc != 0) && (rc != 200))
639 ERROR ("curl_xml plugin: curl_easy_perform failed with response code %ld (%s)",
646 status = cx_parse_stats_xml(BAD_CAST ptr, db);
650 } /* }}} int cx_curl_perform */
652 static int cx_read (user_data_t *ud) /* {{{ */
656 if ((ud == NULL) || (ud->data == NULL))
658 ERROR ("curl_xml plugin: cx_read: Invalid user data.");
662 db = (cx_t *) ud->data;
664 return cx_curl_perform (db, db->curl);
665 } /* }}} int cx_read */
667 /* Configuration handling functions {{{ */
669 static int cx_config_add_values (const char *name, cx_xpath_t *xpath, /* {{{ */
674 if (ci->values_num < 1)
676 WARNING ("curl_xml plugin: `ValuesFrom' needs at least one argument.");
680 for (i = 0; i < ci->values_num; i++)
681 if (ci->values[i].type != OCONFIG_TYPE_STRING)
683 WARNING ("curl_xml plugin: `ValuesFrom' needs only string argument.");
687 sfree (xpath->values);
689 xpath->values_len = 0;
690 xpath->values = (cx_values_t *) malloc (sizeof (cx_values_t) * ci->values_num);
691 if (xpath->values == NULL)
693 xpath->values_len = ci->values_num;
695 /* populate cx_values_t structure */
696 for (i = 0; i < ci->values_num; i++)
698 xpath->values[i].path_len = sizeof (ci->values[i].value.string);
699 sstrncpy (xpath->values[i].path, ci->values[i].value.string, sizeof (xpath->values[i].path));
703 } /* }}} cx_config_add_values */
705 static int cx_config_add_xpath (cx_t *db, oconfig_item_t *ci) /* {{{ */
713 xpath = malloc (sizeof (*xpath));
716 ERROR ("curl_xml plugin: malloc failed.");
719 memset (xpath, 0, sizeof (*xpath));
721 status = cf_util_get_string (ci, &xpath->path);
724 cx_xpath_free (xpath);
728 /* error out if xpath->path is an empty string */
729 if (strlen (xpath->path) == 0)
731 ERROR ("curl_xml plugin: invalid xpath. "
732 "xpath value can't be an empty string");
733 cx_xpath_free (xpath);
738 for (i = 0; i < ci->children_num; i++)
740 oconfig_item_t *child = ci->children + i;
742 if (strcasecmp ("Type", child->key) == 0)
743 status = cf_util_get_string (child, &xpath->type);
744 else if (strcasecmp ("InstancePrefix", child->key) == 0)
745 status = cf_util_get_string (child, &xpath->instance_prefix);
746 else if (strcasecmp ("InstanceFrom", child->key) == 0)
747 status = cf_util_get_string (child, &xpath->instance);
748 else if (strcasecmp ("ValuesFrom", child->key) == 0)
749 status = cx_config_add_values ("ValuesFrom", xpath, child);
752 WARNING ("curl_xml plugin: Option `%s' not allowed here.", child->key);
758 } /* for (i = 0; i < ci->children_num; i++) */
762 cx_xpath_free (xpath);
766 if (xpath->type == NULL)
768 WARNING ("curl_xml plugin: `Type' missing in `xpath' block.");
769 cx_xpath_free (xpath);
773 if (db->list == NULL)
775 db->list = llist_create();
776 if (db->list == NULL)
778 ERROR ("curl_xml plugin: list creation failed.");
779 cx_xpath_free (xpath);
784 name = strdup (xpath->path);
787 ERROR ("curl_xml plugin: strdup failed.");
788 cx_xpath_free (xpath);
792 le = llentry_create (name, xpath);
795 ERROR ("curl_xml plugin: llentry_create failed.");
796 cx_xpath_free (xpath);
801 llist_append (db->list, le);
803 } /* }}} int cx_config_add_xpath */
805 static int cx_config_add_namespace (cx_t *db, /* {{{ */
810 if ((ci->values_num != 2)
811 || (ci->values[0].type != OCONFIG_TYPE_STRING)
812 || (ci->values[1].type != OCONFIG_TYPE_STRING))
814 WARNING ("curl_xml plugin: The `Namespace' option "
815 "needs exactly two string arguments.");
819 ns = realloc (db->namespaces, sizeof (*db->namespaces)
820 * (db->namespaces_num + 1));
823 ERROR ("curl_xml plugin: realloc failed.");
827 ns = db->namespaces + db->namespaces_num;
828 memset (ns, 0, sizeof (*ns));
830 ns->prefix = strdup (ci->values[0].value.string);
831 ns->url = strdup (ci->values[1].value.string);
833 if ((ns->prefix == NULL) || (ns->url == NULL))
837 ERROR ("curl_xml plugin: strdup failed.");
841 db->namespaces_num++;
843 } /* }}} int cx_config_add_namespace */
845 /* Initialize db->curl */
846 static int cx_init_curl (cx_t *db) /* {{{ */
848 db->curl = curl_easy_init ();
849 if (db->curl == NULL)
851 ERROR ("curl_xml plugin: curl_easy_init failed.");
855 curl_easy_setopt (db->curl, CURLOPT_NOSIGNAL, 1L);
856 curl_easy_setopt (db->curl, CURLOPT_WRITEFUNCTION, cx_curl_callback);
857 curl_easy_setopt (db->curl, CURLOPT_WRITEDATA, db);
858 curl_easy_setopt (db->curl, CURLOPT_USERAGENT,
859 PACKAGE_NAME"/"PACKAGE_VERSION);
860 curl_easy_setopt (db->curl, CURLOPT_ERRORBUFFER, db->curl_errbuf);
861 curl_easy_setopt (db->curl, CURLOPT_URL, db->url);
863 if (db->user != NULL)
865 size_t credentials_size;
867 credentials_size = strlen (db->user) + 2;
868 if (db->pass != NULL)
869 credentials_size += strlen (db->pass);
871 db->credentials = (char *) malloc (credentials_size);
872 if (db->credentials == NULL)
874 ERROR ("curl_xml plugin: malloc failed.");
878 ssnprintf (db->credentials, credentials_size, "%s:%s",
879 db->user, (db->pass == NULL) ? "" : db->pass);
880 curl_easy_setopt (db->curl, CURLOPT_USERPWD, db->credentials);
883 curl_easy_setopt (db->curl, CURLOPT_SSL_VERIFYPEER, db->verify_peer ? 1L : 0L);
884 curl_easy_setopt (db->curl, CURLOPT_SSL_VERIFYHOST,
885 db->verify_host ? 2L : 0L);
886 if (db->cacert != NULL)
887 curl_easy_setopt (db->curl, CURLOPT_CAINFO, db->cacert);
888 if (db->headers != NULL)
889 curl_easy_setopt (db->curl, CURLOPT_HTTPHEADER, db->headers);
890 if (db->post_body != NULL)
891 curl_easy_setopt (db->curl, CURLOPT_POSTFIELDS, db->post_body);
894 } /* }}} int cx_init_curl */
896 static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */
902 if ((ci->values_num != 1)
903 || (ci->values[0].type != OCONFIG_TYPE_STRING))
905 WARNING ("curl_xml plugin: The `URL' block "
906 "needs exactly one string argument.");
910 db = (cx_t *) malloc (sizeof (*db));
913 ERROR ("curl_xml plugin: malloc failed.");
916 memset (db, 0, sizeof (*db));
918 if (strcasecmp ("URL", ci->key) == 0)
920 status = cf_util_get_string (ci, &db->url);
929 ERROR ("curl_xml plugin: cx_config: "
930 "Invalid key: %s", ci->key);
935 /* Fill the `cx_t' structure.. */
936 for (i = 0; i < ci->children_num; i++)
938 oconfig_item_t *child = ci->children + i;
940 if (strcasecmp ("Instance", child->key) == 0)
941 status = cf_util_get_string (child, &db->instance);
942 else if (strcasecmp ("Host", child->key) == 0)
943 status = cf_util_get_string (child, &db->host);
944 else if (strcasecmp ("User", child->key) == 0)
945 status = cf_util_get_string (child, &db->user);
946 else if (strcasecmp ("Password", child->key) == 0)
947 status = cf_util_get_string (child, &db->pass);
948 else if (strcasecmp ("VerifyPeer", child->key) == 0)
949 status = cf_util_get_boolean (child, &db->verify_peer);
950 else if (strcasecmp ("VerifyHost", child->key) == 0)
951 status = cf_util_get_boolean (child, &db->verify_host);
952 else if (strcasecmp ("CACert", child->key) == 0)
953 status = cf_util_get_string (child, &db->cacert);
954 else if (strcasecmp ("xpath", child->key) == 0)
955 status = cx_config_add_xpath (db, child);
956 else if (strcasecmp ("Header", child->key) == 0)
957 status = cx_config_append_string ("Header", &db->headers, child);
958 else if (strcasecmp ("Post", child->key) == 0)
959 status = cf_util_get_string (child, &db->post_body);
960 else if (strcasecmp ("Namespace", child->key) == 0)
961 status = cx_config_add_namespace (db, child);
964 WARNING ("curl_xml plugin: Option `%s' not allowed here.", child->key);
974 if (db->list == NULL)
976 WARNING ("curl_xml plugin: No (valid) `Key' block "
977 "within `URL' block `%s'.", db->url);
981 status = cx_init_curl (db);
984 /* If all went well, register this database for reading */
990 if (db->instance == NULL)
991 db->instance = strdup("default");
993 DEBUG ("curl_xml plugin: Registering new read callback: %s",
996 memset (&ud, 0, sizeof (ud));
997 ud.data = (void *) db;
998 ud.free_func = cx_free;
1000 cb_name = ssnprintf_alloc ("curl_xml-%s-%s", db->instance, db->url);
1001 plugin_register_complex_read (/* group = */ "curl_xml", cb_name, cx_read,
1002 /* interval = */ NULL, &ud);
1012 } /* }}} int cx_config_add_url */
1014 /* }}} End of configuration handling functions */
1016 static int cx_config (oconfig_item_t *ci) /* {{{ */
1026 for (i = 0; i < ci->children_num; i++)
1028 oconfig_item_t *child = ci->children + i;
1030 if (strcasecmp ("URL", child->key) == 0)
1032 status = cx_config_add_url (child);
1040 WARNING ("curl_xml plugin: Option `%s' not allowed here.", child->key);
1045 if ((success == 0) && (errors > 0))
1047 ERROR ("curl_xml plugin: All statements failed.");
1052 } /* }}} int cx_config */
1054 static int cx_init (void) /* {{{ */
1056 /* Call this while collectd is still single-threaded to avoid
1057 * initialization issues in libgcrypt. */
1058 curl_global_init (CURL_GLOBAL_SSL);
1060 } /* }}} int cx_init */
1062 void module_register (void)
1064 plugin_register_complex_config ("curl_xml", cx_config);
1065 plugin_register_init ("curl_xml", cx_init);
1066 } /* void module_register */
1068 /* vim: set sw=2 sts=2 et fdm=marker : */