[syslog-ng] [PATCH] afmongodb: Restore compatibility with syslog-ng 3.3
Gergely Nagy
algernon at balabit.hu
Fri Mar 30 10:54:28 CEST 2012
In syslog-ng 3.3, we had the host() and port() options for the mongodb
driver, these were removed in 3.4 in favour of servers(). This patch
re-adds this two.
Using host() and port() will now prepend the specified combination to
the server list.
Signed-off-by: Gergely Nagy <algernon at balabit.hu>
---
modules/afmongodb/afmongodb-grammar.ym | 2 ++
modules/afmongodb/afmongodb-parser.c | 2 ++
modules/afmongodb/afmongodb.c | 25 +++++++++++++++++++++++++
modules/afmongodb/afmongodb.h | 2 ++
4 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/modules/afmongodb/afmongodb-grammar.ym b/modules/afmongodb/afmongodb-grammar.ym
index a21e23c..71dd46d 100644
--- a/modules/afmongodb/afmongodb-grammar.ym
+++ b/modules/afmongodb/afmongodb-grammar.ym
@@ -75,6 +75,8 @@ afmongodb_option
| KW_USERNAME '(' string ')' { afmongodb_dd_set_user(last_driver, $3); free($3); }
| KW_PASSWORD '(' string ')' { afmongodb_dd_set_password(last_driver, $3); free($3); }
| 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); }
| 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 b8c9ead..9d72878 100644
--- a/modules/afmongodb/afmongodb-parser.c
+++ b/modules/afmongodb/afmongodb-parser.c
@@ -36,6 +36,8 @@ static CfgLexerKeyword afmongodb_keywords[] = {
{ "username", KW_USERNAME },
{ "password", KW_PASSWORD },
{ "safe_mode", KW_SAFE_MODE },
+ { "host", KW_HOST },
+ { "port", KW_PORT },
{ NULL }
};
diff --git a/modules/afmongodb/afmongodb.c b/modules/afmongodb/afmongodb.c
index de78b23..9d75799 100644
--- a/modules/afmongodb/afmongodb.c
+++ b/modules/afmongodb/afmongodb.c
@@ -112,6 +112,23 @@ afmongodb_dd_set_password(LogDriver *d, const gchar *password)
}
void
+afmongodb_dd_set_host(LogDriver *d, const gchar *host)
+{
+ MongoDBDestDriver *self = (MongoDBDestDriver *)d;
+
+ g_free(self->host);
+ self->host = g_strdup(host);
+}
+
+void
+afmongodb_dd_set_port(LogDriver *d, gint port)
+{
+ MongoDBDestDriver *self = (MongoDBDestDriver *)d;
+
+ self->port = port;
+}
+
+void
afmongodb_dd_set_servers(LogDriver *d, GList *servers)
{
MongoDBDestDriver *self = (MongoDBDestDriver *)d;
@@ -450,6 +467,14 @@ afmongodb_dd_init(LogPipe *s)
value_pairs_add_scope(self->vp, "nv-pairs");
}
+ if (self->host)
+ {
+ gchar *srv = g_strdup_printf ("%s:%d", self->host,
+ (self->port) ? self->port : 27017);
+ self->servers = g_list_prepend (self->servers, srv);
+ g_free (self->host);
+ }
+
self->host = NULL;
self->port = 27017;
if (!mongo_util_parse_addr(g_list_nth_data(self->servers, 0), &self->host,
diff --git a/modules/afmongodb/afmongodb.h b/modules/afmongodb/afmongodb.h
index 9950d26..e1f4b57 100644
--- a/modules/afmongodb/afmongodb.h
+++ b/modules/afmongodb/afmongodb.h
@@ -30,6 +30,8 @@
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_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.9
More information about the syslog-ng
mailing list