mongodb plugin: Fix build issues with version 0.4 of libmongoc.
[collectd.git] / src / write_mongodb.c
index cb4161c..704ac07 100644 (file)
@@ -1,6 +1,8 @@
 /**
  * collectd - src/write_mongodb.c
- * Copyright (C) 2010  Florian Forster, Akkarit Sangpetch
+ * Copyright (C) 2010  Florian Forster
+ * Copyright (C) 2010  Akkarit Sangpetch
+ * Copyright (C) 2012  Chris Lundquist
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -22,7 +24,8 @@
  *
  * Authors:
  *   Florian Forster <ff at octo.it>
- *   Akkarit Sangpetch <asangpet@andrew.cmu.edu>
+ *   Akkarit Sangpetch <asangpet at andrew.cmu.edu>
+ *   Chris Lundquist <clundquist at bluebox.net>
  **/
 
 #include "collectd.h"
 #endif
 #include <mongo.h>
 
-/*
-struct mongo_options
-{
-  char *host;
-  int port;
-  int timeout;
-};
-typedef struct mongo_options mongo_options;
-*/
-
 struct wm_node_s
 {
   char name[DATA_MAX_NAME_LEN];
@@ -60,7 +53,6 @@ struct wm_node_s
   int connected;
 
   mongo conn[1];
-/*  mongo_options opts[1]; */
   pthread_mutex_t lock;
 };
 typedef struct wm_node_s wm_node_t;
@@ -81,7 +73,7 @@ static int wm_write (const data_set_t *ds, /* {{{ */
   ssnprintf(collection_name, sizeof (collection_name), "collectd.%s", vl->plugin);
 
   bson_init(&record);
-  bson_append_time_t(&record,"ts",vl->time);
+  bson_append_time_t(&record,"ts",CDTIME_T_TO_TIME_T(vl->time));
   bson_append_string(&record,"h",vl->host);
   bson_append_string(&record,"i",vl->plugin_instance);
   bson_append_string(&record,"t",vl->type);
@@ -106,13 +98,6 @@ static int wm_write (const data_set_t *ds, /* {{{ */
 
   if (node->connected == 0)
   {
-/*
-    sstrncpy(node->opts->host, node->host,
-        sizeof (node->opts->host));
-    node->opts->port = node->port;
-*/
-
- /*   status = mongo_connect(node->conn,node->opts->host, node->opts->port);*/
     status = mongo_connect(node->conn, node->host, node->port);
     if (status != MONGO_OK) {
       ERROR ("write_mongodb plugin: Connecting to host \"%s\" (port %i) failed.",
@@ -137,17 +122,12 @@ static int wm_write (const data_set_t *ds, /* {{{ */
   if(status != MONGO_OK)
   {
     ERROR ( "write_mongodb plugin: error inserting record: %d", node->conn->err);
-    if(node->conn->err == MONGO_BSON_INVALID)
-    {
-      ERROR (node->conn->errstr);
-    } else if ( record.err)
-    {
-      ERROR (record.errstr);
-    }
-
+    if (node->conn->err == MONGO_BSON_INVALID)
+      ERROR ("write_mongodb plugin: %s", node->conn->errstr);
+    else if (record.err)
+      ERROR ("write_mongodb plugin: %s", record.errstr);
   }
 
-
   pthread_mutex_unlock (&node->lock);
 
   return (0);