[syslog-ng] [PATCH] [1/1] Allow Unix sockets for MongoDB connection.
Conrad Hoffmann
ch at bitfehler.net
Sun Aug 12 04:06:14 CEST 2012
Signed-off-by: Conrad Hoffmann <ch at 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
More information about the syslog-ng
mailing list