- status = mongo_connect(node->conn,node->opts->host, node->opts->port);
- if (status!=MONGO_OK) {
- ERROR ("write_mongodb plugin: Connecting to host \"%s\" (port %i) failed.",
+ bson_finish (ret);
+
+ sfree (rates);
+ return (ret);
+} /* }}} bson *wm_create_bson */
+
+static int wm_write (const data_set_t *ds, /* {{{ */
+ const value_list_t *vl,
+ user_data_t *ud)
+{
+ wm_node_t *node = ud->data;
+ char collection_name[512];
+ bson *bson_record;
+ int status;
+
+ ssnprintf (collection_name, sizeof (collection_name), "collectd.%s",
+ vl->plugin);
+
+ bson_record = wm_create_bson (ds, vl, node->store_rates);
+ if (bson_record == NULL)
+ return (ENOMEM);
+
+ pthread_mutex_lock (&node->lock);
+
+ if (!mongo_is_connected (node->conn))
+ {
+ INFO ("write_mongodb plugin: Connecting to [%s]:%i",
+ (node->host != NULL) ? node->host : "localhost",
+ (node->port != 0) ? node->port : MONGO_DEFAULT_PORT);
+ status = mongo_connect (node->conn, node->host, node->port);
+ if (status != MONGO_OK) {
+ ERROR ("write_mongodb plugin: Connecting to [%s]:%i failed.",