summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3665b5d)
raw | patch | inline | side by side (parent: 3665b5d)
author | Florian Forster <octo@collectd.org> | |
Sat, 23 Mar 2013 17:07:03 +0000 (18:07 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Sat, 23 Mar 2013 17:07:03 +0000 (18:07 +0100) |
Fixes Github issue #282.
src/collectd.conf.in | patch | blob | history | |
src/collectd.conf.pod | patch | blob | history | |
src/write_mongodb.c | patch | blob | history |
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index fc8d3f277d0eb7ac8d949553ad7be0db191641a0..5af15684092acb486b57d90023f7203da1a9abaa 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
# Port "27017"
# Timeout 1000
# StoreRates false
+# Database "auth_db"
+# User "auth_user"
+# Password "auth_passwd"
# </Node>
#</Plugin>
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 7dbb2c547ba62e21ad4dbf121512831cfead3b75..8606d3e05533ff123f606e30ea7ef1f514c8857b 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
B<false> counter values are stored as is, i.e. as an increasing integer
number.
+=item B<Database> I<Database>
+
+=item B<User> I<User>
+
+=item B<Password> I<Password>
+
+Sets the information used when authenticating to a I<MongoDB> database. The
+fields are optional (in which case no authentication is attempted), but if you
+want to use authentication all three fields must be set.
+
=back
=head2 Plugin C<write_http>
diff --git a/src/write_mongodb.c b/src/write_mongodb.c
index c7b768205cdf2ca59e0938b8b5a955d3deb0e78a..30e261c9eee919e582f1d4da06ff52aced103a56 100644 (file)
--- a/src/write_mongodb.c
+++ b/src/write_mongodb.c
/**
* collectd - src/write_mongodb.c
- * Copyright (C) 2010-2012 Florian Forster
+ * Copyright (C) 2010-2013 Florian Forster
* Copyright (C) 2010 Akkarit Sangpetch
* Copyright (C) 2012 Chris Lundquist
*
* DEALINGS IN THE SOFTWARE.
*
* Authors:
- * Florian Forster <ff at octo.it>
+ * Florian Forster <octo at collectd.org>
* Akkarit Sangpetch <asangpet at andrew.cmu.edu>
* Chris Lundquist <clundquist at bluebox.net>
**/
int port;
int timeout;
+ /* Authentication information */
+ char *db;
+ char *user;
+ char *passwd;
+
_Bool store_rates;
mongo conn[1];
return (-1);
}
+ if ((node->db != NULL) && (node->user != NULL) && (node->passwd != NULL))
+ {
+ status = mongo_cmd_authenticate (node->conn,
+ node->db, node->user, node->passwd);
+ if (status != MONGO_OK)
+ {
+ ERROR ("write_mongodb plugin: Authenticating to [%s]%i for database "
+ "\"%s\" as user \"%s\" failed.",
+ (node->host != NULL) ? node->host : "localhost",
+ (node->port != 0) ? node->port : MONGO_DEFAULT_PORT,
+ node->db, node->user);
+ mongo_destroy (node->conn);
+ pthread_mutex_unlock (&node->lock);
+ return (-1);
+ }
+ }
+
if (node->timeout > 0) {
status = mongo_set_op_timeout (node->conn, node->timeout);
if (status != MONGO_OK) {
status = mongo_insert (node->conn, collection_name, bson_record);
#endif
- if(status != MONGO_OK)
+ if (status != MONGO_OK)
{
ERROR ( "write_mongodb plugin: error inserting record: %d", node->conn->err);
if (node->conn->err != MONGO_BSON_INVALID)
ERROR ("write_mongodb plugin: %s", node->conn->errstr);
- else if (bson_record->err)
- ERROR ("write_mongodb plugin: %s", bson_record->errstr);
+ else
+ ERROR ("write_mongodb plugin: Invalid BSON structure, error = %#x",
+ (unsigned int) bson_record->err);
/* Disconnect except on data errors. */
if ((node->conn->err != MONGO_BSON_INVALID)
status = cf_util_get_int (child, &node->timeout);
else if (strcasecmp ("StoreRates", child->key) == 0)
status = cf_util_get_boolean (child, &node->store_rates);
+ else if (strcasecmp ("Database", child->key) == 0)
+ status = cf_util_get_string (child, &node->db);
+ else if (strcasecmp ("User", child->key) == 0)
+ status = cf_util_get_string (child, &node->user);
+ else if (strcasecmp ("Password", child->key) == 0)
+ status = cf_util_get_string (child, &node->passwd);
else
WARNING ("write_mongodb plugin: Ignoring unknown config option \"%s\".",
child->key);
break;
} /* for (i = 0; i < ci->children_num; i++) */
+ if ((node->db != NULL) || (node->user != NULL) || (node->passwd != NULL))
+ {
+ if ((node->db == NULL) || (node->user == NULL) || (node->passwd == NULL))
+ {
+ WARNING ("write_mongodb plugin: Authentication requires the "
+ "\"Database\", \"User\" and \"Password\" options to be specified, "
+ "but at last one of them is missing. Authentication will NOT be "
+ "used.");
+ sfree (node->db);
+ sfree (node->user);
+ sfree (node->passwd);
+ }
+ }
+
if (status == 0)
{
char cb_name[DATA_MAX_NAME_LEN];