[PATCH] [0/1] Allow mongodb destination to use Unix sockets
As promised this is actually the second part of the previous patch, but since the other one was for a different repo I decided to keep them seperate. Yet, this one depends on the former. This patch is also for syslog-ng-3.4, master branch. Like I mentioned, I already used Unix sockets successfully, though I must add that this was with a modified version of the path for syslog-ng-3.3, because I had trouble getting 3.4 to work at all. I will take another look at this tomorrow, but maybe you can give some feedback already? Conrad Hoffmann (1): Allow Unix sockets for MongoDB connection. modules/afmongodb/afmongodb-grammar.ym | 2 ++ modules/afmongodb/afmongodb-parser.c | 1 + modules/afmongodb/afmongodb.c | 25 +++++++++++++++++++++---- modules/afmongodb/afmongodb.h | 1 + 4 files changed, 25 insertions(+), 4 deletions(-) -- 1.7.11.4
Signed-off-by: Conrad Hoffmann <ch@bitfehler.net> --- modules/afmongodb/afmongodb-grammar.ym | 2 ++ modules/afmongodb/afmongodb-parser.c | 1 + modules/afmongodb/afmongodb.c | 25 +++++++++++++++++++++---- modules/afmongodb/afmongodb.h | 1 + 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/modules/afmongodb/afmongodb-grammar.ym b/modules/afmongodb/afmongodb-grammar.ym index 71dd46d..c5d97c4 100644 --- a/modules/afmongodb/afmongodb-grammar.ym +++ b/modules/afmongodb/afmongodb-grammar.ym @@ -50,6 +50,7 @@ extern ValuePairsTransformSet *last_vp_transset; %token KW_MONGODB %token KW_COLLECTION +%token KW_PATH %token KW_SERVERS %token KW_SAFE_MODE @@ -77,6 +78,7 @@ afmongodb_option | KW_SAFE_MODE '(' yesno ')' { afmongodb_dd_set_safe_mode(last_driver, $3); } | KW_HOST '(' string ')' { afmongodb_dd_set_host(last_driver, $3); free($3); } | KW_PORT '(' LL_NUMBER ')' { afmongodb_dd_set_port(last_driver, $3); } + | KW_PATH '(' string ')' { afmongodb_dd_set_path(last_driver, $3); free($3); } | value_pair_option { afmongodb_dd_set_value_pairs(last_driver, $1); } | dest_driver_option ; diff --git a/modules/afmongodb/afmongodb-parser.c b/modules/afmongodb/afmongodb-parser.c index 9d72878..8aa55c1 100644 --- a/modules/afmongodb/afmongodb-parser.c +++ b/modules/afmongodb/afmongodb-parser.c @@ -38,6 +38,7 @@ static CfgLexerKeyword afmongodb_keywords[] = { { "safe_mode", KW_SAFE_MODE }, { "host", KW_HOST }, { "port", KW_PORT }, + { "path", KW_PATH }, { NULL } }; diff --git a/modules/afmongodb/afmongodb.c b/modules/afmongodb/afmongodb.c index 5af34c9..f714a16 100644 --- a/modules/afmongodb/afmongodb.c +++ b/modules/afmongodb/afmongodb.c @@ -52,6 +52,7 @@ typedef struct GList *servers; gchar *host; gint port; + gchar *path; gboolean safe_mode; @@ -129,6 +130,15 @@ afmongodb_dd_set_port(LogDriver *d, gint port) } void +afmongodb_dd_set_path(LogDriver *d, const gchar *path) +{ + MongoDBDestDriver *self = (MongoDBDestDriver *)d; + + g_free(self->path); + self->path = g_strdup(path); +} + +void afmongodb_dd_set_servers(LogDriver *d, GList *servers) { MongoDBDestDriver *self = (MongoDBDestDriver *)d; @@ -221,7 +231,14 @@ afmongodb_dd_connect(MongoDBDestDriver *self, gboolean reconnect) if (reconnect && self->conn) return TRUE; - self->conn = mongo_sync_connect(self->host, self->port, FALSE); + if (self->path) + { + self->conn = mongo_sync_unix_connect(self->path, FALSE); + } + else + { + self->conn = mongo_sync_connect(self->host, self->port, FALSE); + } if (!self->conn) { msg_error ("Error connecting to MongoDB", NULL); @@ -467,7 +484,7 @@ afmongodb_dd_init(LogPipe *s) value_pairs_add_scope(self->vp, "nv-pairs"); } - if (self->host) + if (self->host && !self->path) { gchar *srv = g_strdup_printf ("%s:%d", self->host, (self->port) ? self->port : 27017); @@ -477,8 +494,8 @@ afmongodb_dd_init(LogPipe *s) self->host = NULL; self->port = 27017; - if (!mongo_util_parse_addr(g_list_nth_data(self->servers, 0), &self->host, - &self->port)) + if (!self->path && !mongo_util_parse_addr(g_list_nth_data(self->servers, 0), + &self->host, &self->port)) { msg_error("Cannot parse the primary host", evt_tag_str("primary", g_list_nth_data(self->servers, 0)), diff --git a/modules/afmongodb/afmongodb.h b/modules/afmongodb/afmongodb.h index e1f4b57..14c1653 100644 --- a/modules/afmongodb/afmongodb.h +++ b/modules/afmongodb/afmongodb.h @@ -32,6 +32,7 @@ LogDriver *afmongodb_dd_new(void); void afmongodb_dd_set_servers(LogDriver *d, GList *servers); void afmongodb_dd_set_host(LogDriver *d, const gchar *host); void afmongodb_dd_set_port(LogDriver *d, gint port); +void afmongodb_dd_set_path(LogDriver *d, const gchar *path); void afmongodb_dd_set_database(LogDriver *d, const gchar *database); void afmongodb_dd_set_collection(LogDriver *d, const gchar *collection); void afmongodb_dd_set_user(LogDriver *d, const gchar *user); -- 1.7.11.4
Hi, This looks good to me, but again, I'd wait for Algernon's OK, especially on the libmongo-client part. On Sun, 2012-08-12 at 04:06 +0200, Conrad Hoffmann wrote:
Signed-off-by: Conrad Hoffmann <ch@bitfehler.net> --- modules/afmongodb/afmongodb-grammar.ym | 2 ++ modules/afmongodb/afmongodb-parser.c | 1 + modules/afmongodb/afmongodb.c | 25 +++++++++++++++++++++---- modules/afmongodb/afmongodb.h | 1 + 4 files changed, 25 insertions(+), 4 deletions(-)
-- Bazsi
Conrad Hoffmann <ch@bitfehler.net> writes:
I will take another look at this tomorrow, but maybe you can give some feedback already?
One thing that I'm missing - at least, on a first glance - is handling the case where path() is specified in the config along with servers(), host() or port(). Since one can do only one of these, having path() with any of the others should produce an error, I believe. -- |8]
On 08/12/2012 09:23 PM, Gergely Nagy wrote:
One thing that I'm missing - at least, on a first glance - is handling the case where path() is specified in the config along with servers(), host() or port(). Since one can do only one of these, having path() with any of the others should produce an error, I believe.
Yeah, I admit I didn't spent too much time on that issue :) Last night I mainly wanted to get it to work and didn't really check if there are any possibile "misconfigurations" - I will take another look at this and try out some configs and then send you an updated patch. Probably not before Wednesday, though. Anyways, thanks for the feedback!
participants (3)
-
Balazs Scheidler
-
Conrad Hoffmann
-
Gergely Nagy