Permalink
Browse files

redis: New destination driver

Based on the work of Tihamer Petrovics during the Google Summer of Code
2013, this driver implements a new destination driver that allows
syslog-ng to send events to a Redis key-value sture.

destination d_redis {
 redis(
  host("localhost")
  port(6369)

  command("HINCRBY", "hosts", "$HOST", "1")
 );
};

The driver requires the hiredis library, and will try to detect it
during configure-time.

Signed-off-by: Tihamer Petrovics <tihameri@gmail.com>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
  • Loading branch information...
1 parent 79418b5 commit ecef67b81616e48a93594ad606c0995b88854a4f @algernon algernon committed Sep 20, 2013
View
@@ -198,6 +198,14 @@ AC_ARG_WITH(libesmtp,
AC_HELP_STRING([--with-libesmtp=DIR],
[use libesmtp library from (prefix) directory DIR]),,)
+AC_ARG_ENABLE(redis,
+ [ --disable-redis Disable REDIS support (default: auto)]
+ ,,enable_redis="auto")
+
+AC_ARG_WITH(libhiredis,
+ AC_HELP_STRING([--with-libhiredis=DIR],
+ [use libhiredis library from (prefix) directory DIR]),,)
+
AC_ARG_ENABLE(systemd,
[ --enable-systemd Enable systemd support (default: auto)]
,,enable_systemd="auto")
@@ -877,6 +885,33 @@ if test "x$enable_smtp" != "xno" && test "x$with_libesmtp" != "no"; then
enable_smtp=$libesmtp
fi
+ dnl ***************************************************************************
+dnl libhiredis headers/libraries
+dnl ***************************************************************************
+if test "x$enable_redis" != "xno" && test "x$with_redis" != "no"; then
+ hiredis="yes"
+ if test "x$with_libhiredis" != "yes" && test "x$with_libhiredis" != "x"; then
+ CFLAGS_SAVE="$CFLAGS"
+ LDFLAGS_SAVE="$LDFLAGS"
+ CFLAGS="$CFLAGS -I$with_libhiredis/include"
+ LDFLAGS="$LDFLAGS -L$with_libhiredis/lib"
+ AC_CHECK_HEADER(hiredis.h, [HIREDIS_CFLAGS="-I$with_libhiredis/include"
+ HIREDIS_LIBS="-L$with_libhiredis/lib -lhiredis"], [hiredis=no])
+ CFLAGS="$CFLAGS_SAVE"
+ LDFLAGS="$LDFLAGS_SAVE"
+ else
+ hiredis="yes"
+ PKG_CHECK_MODULES(HIREDIS, hiredis, ,
+ [PKG_CHECK_MODULES(HIREDIS, libhiredis,, [hiredis=no])])
+ fi
+
+ if test "x$enable_redis" = "xyes" && test "x$hiredis" = "xno"; then
+ AC_MSG_ERROR(libHIREDIS not found)
+ fi
+
+ enable_redis=$hiredis
+fi
+
dnl ***************************************************************************
dnl rabbitmq-c headers/libraries
dnl ***************************************************************************
@@ -1171,6 +1206,7 @@ AM_CONDITIONAL(ENABLE_AMQP, [test "$enable_amqp" = "yes"])
AM_CONDITIONAL(ENABLE_STOMP, [test "$enable_stomp" = "yes"])
AM_CONDITIONAL(ENABLE_JSON, [test "$enable_json" = "yes"])
AM_CONDITIONAL(ENABLE_GEOIP, [test "$enable_geoip" = "yes"])
+AM_CONDITIONAL(ENABLE_REDIS, [test "$enable_redis" = "yes"])
AM_CONDITIONAL(WITH_EMBEDDED_CRYPTO, [test "$with_embedded_crypto" = "yes"])
AM_CONDITIONAL(IVYKIS_INTERNAL, [test "x$IVYKIS_SUBDIRS" != "x"])
AM_CONDITIONAL(LIBMONGO_INTERNAL, [test "x$LIBMONGO_SUBDIRS" != "x"])
View
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002-2012 BalaBit IT Ltd, Budapest, Hungary
+ * Copyright (c) 2002-2013 BalaBit IT Ltd, Budapest, Hungary
* Copyright (c) 1998-2012 Balázs Scheidler
*
* This library is free software; you can redistribute it and/or
@@ -387,6 +387,7 @@ const gchar *source_names[SCS_MAX] =
"smtp",
"amqp",
"stomp",
+ "redis",
};
View
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002-2012 BalaBit IT Ltd, Budapest, Hungary
+ * Copyright (c) 2002-2013 BalaBit IT Ltd, Budapest, Hungary
* Copyright (c) 1998-2012 Balázs Scheidler
*
* This library is free software; you can redistribute it and/or
@@ -82,6 +82,7 @@ enum
SCS_SMTP = 28,
SCS_AMQP = 29,
SCS_STOMP = 30,
+ SCS_REDIS = 31,
SCS_MAX,
SCS_SOURCE_MASK = 0xff
};
View
@@ -19,13 +19,15 @@ include modules/dbparser/Makefile.am
include modules/json/Makefile.am
include modules/tfgeoip/Makefile.am
include modules/afstomp/Makefile.am
+include modules/redis/Makefile.am
SYSLOG_NG_MODULES = \
mod-afsocket mod-afstreams mod-affile mod-afprog \
mod-usertty mod-amqp mod-mongodb mod-smtp mod-json \
mod-syslogformat mod-linux-kmsg mod-pacctformat \
mod-confgen mod-system-source mod-csvparser mod-dbparser \
- mod-basicfuncs mod-cryptofuncs mod-geoip mod-afstomp
+ mod-basicfuncs mod-cryptofuncs mod-geoip mod-afstomp \
+ mod-redis
modules modules/: ${SYSLOG_NG_MODULES}
View
@@ -0,0 +1,35 @@
+if ENABLE_REDIS
+module_LTLIBRARIES += \
+ modules/redis/libredis.la
+
+modules_redis_libredis_la_CFLAGS = \
+ $(HIREDIS_CFLAGS) \
+ -I$(top_srcdir)/modules/redis \
+ -I$(top_builddir)/modules/redis
+modules_redis_libredis_la_SOURCES = \
+ modules/redis/redis-grammar.y \
+ modules/redis/redis.c \
+ modules/redis/redis.h \
+ modules/redis/redis-parser.c \
+ modules/redis/redis-parser.h
+modules_redis_libredis_la_LIBADD = \
+ $(HIREDIS_LIBS) $(MODULE_DEPS_LIBS)
+modules_redis_libredis_la_LDFLAGS = \
+ $(MODULE_LDFLAGS)
+modules_redis_libredis_la_DEPENDENCIES = \
+ $(MODULE_DEPS_LIBS)
+
+modules/redis modules/redis/ mod-redis: \
+ modules/redis/libredis.la
+else
+modules/redis modules/redis/ mod-redis:
+endif
+
+BUILT_SOURCES += \
+ modules/redis/redis-grammar.y \
+ modules/redis/redis-grammar.c \
+ modules/redis/redis-grammar.h
+EXTRA_DIST += \
+ modules/redis/redis-grammar.ym
+
+.PHONY: modules/redis/ mod-redis
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary
+ * Copyright (c) 2013 Tihamer Petrovics <tihameri@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As an additional exemption you are allowed to compile & link against the
+ * OpenSSL libraries as published by the OpenSSL project. See the file
+ * COPYING for details.
+ *
+ */
+
+%code requires {
+
+#include "redis-parser.h"
+
+}
+
+%code {
+
+#include "cfg-grammar.h"
+#include "plugin.h"
+}
+
+%name-prefix "redis_"
+%lex-param {CfgLexer *lexer}
+%parse-param {CfgLexer *lexer}
+%parse-param {LogDriver **instance}
+%parse-param {gpointer arg}
+
+/* INCLUDE_DECLS */
+
+%token KW_REDIS
+%token KW_COMMAND
+%%
+
+start
+ : LL_CONTEXT_DESTINATION KW_REDIS
+ {
+ last_driver = *instance = redis_dd_new(configuration);
+ }
+ '(' redis_options ')' { YYACCEPT; }
+;
+
+redis_options
+ : redis_option redis_options
+|
+;
+
+redis_option
+ : KW_HOST '(' string ')'
+ {
+ redis_dd_set_host(last_driver, $3);
+ free($3);
+ }
+ | KW_PORT '(' LL_NUMBER ')'
+ {
+ redis_dd_set_port(last_driver, $3);
+ }
+ | KW_COMMAND '(' string template_content ')'
+ {
+ redis_dd_set_command(last_driver, $3, $4, NULL, NULL);
+ free($3);
+ }
+ | KW_COMMAND '(' string template_content template_content ')'
+ {
+ redis_dd_set_command(last_driver, $3, $4, $5, NULL);
+ free($3);
+ }
+ | KW_COMMAND '(' string template_content template_content template_content ')'
+ {
+ redis_dd_set_command(last_driver, $3, $4, $5, $6);
+ free($3);
+ }
+ | dest_driver_option
+ | { last_template_options = redis_dd_get_template_options(last_driver); } template_option
+ ;
+
+/* INCLUDE_RULES */
+
+%%
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary
+ * Copyright (c) 2013 Tihamer Petrovics <tihameri@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As an additional exemption you are allowed to compile & link against the
+ * OpenSSL libraries as published by the OpenSSL project. See the file
+ * COPYING for details.
+ *
+ */
+
+#include "redis.h"
+#include "cfg-parser.h"
+#include "redis-grammar.h"
+
+extern int redis_debug;
+int redis_parse(CfgLexer *lexer, LogDriver **instance, gpointer arg);
+
+static CfgLexerKeyword redis_keywords[] = {
+ { "redis", KW_REDIS },
+ { "command", KW_COMMAND },
+ { NULL }
+};
+
+CfgParser redis_parser =
+{
+#if ENABLE_DEBUG
+ .debug_flag = &redis_debug,
+#endif
+ .name = "redis",
+ .keywords = redis_keywords,
+ .parse = (int (*)(CfgLexer *lexer, gpointer *instance, gpointer)) redis_parse,
+ .cleanup = (void (*)(gpointer)) log_pipe_unref,
+};
+
+CFG_PARSER_IMPLEMENT_LEXER_BINDING(redis_, LogDriver **)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary
+ * Copyright (c) 2013 Tihamer Petrovics <tihameri@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As an additional exemption you are allowed to compile & link against the
+ * OpenSSL libraries as published by the OpenSSL project. See the file
+ * COPYING for details.
+ *
+ */
+
+#ifndef REDIS_PARSER_H_INCLUDED
+#define REDIS_PARSER_H_INCLUDED
+
+#include "cfg-parser.h"
+#include "cfg-lexer.h"
+#include "redis.h"
+
+extern CfgParser redis_parser;
+
+CFG_PARSER_DECLARE_LEXER_BINDING(redis_, LogDriver **)
+
+#endif
Oops, something went wrong.

0 comments on commit ecef67b

Please sign in to comment.