[syslog-ng] [PATCH (3.4) 2/2] tfuuid: New template function to generate UUIDs.

Gergely Nagy algernon at balabit.hu
Fri Feb 3 13:46:02 CET 2012


This patch adds a new template function: $(uuid), which can be used to
generate Universally Unique IDentifiers.

The use case for this is to add an UUID to each message as soon as
they're received, so that they can be identified later, accross
destinations. This allows me to pre-generate an ID for messages going
into mongodb, and send those messages to a different destination too,
with the same ID included.

Use it like this:

rewrite r_add_uuid { set("$(uuid)" value("uuid")); };
log { source(s_network); rewrite(r_add_uuid);
      destination(d_mongo); destination(d_program); };

Signed-off-by: Gergely Nagy <algernon at balabit.hu>
---
 modules/Makefile.am        |    2 +-
 modules/tfuuid/Makefile.am |    9 +++++++
 modules/tfuuid/tfuuid.c    |   57 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 1 deletions(-)
 create mode 100644 modules/tfuuid/Makefile.am
 create mode 100644 modules/tfuuid/tfuuid.c

diff --git a/modules/Makefile.am b/modules/Makefile.am
index 0d0594b..72c005f 100644
--- a/modules/Makefile.am
+++ b/modules/Makefile.am
@@ -1 +1 @@
-SUBDIRS = afsocket afsql afstreams affile afprog afuser afmongodb csvparser confgen syslogformat pacctformat basicfuncs dbparser tfjson jsonparser dummy
+SUBDIRS = afsocket afsql afstreams affile afprog afuser afmongodb csvparser confgen syslogformat pacctformat basicfuncs dbparser tfjson tfuuid jsonparser dummy
diff --git a/modules/tfuuid/Makefile.am b/modules/tfuuid/Makefile.am
new file mode 100644
index 0000000..47cbeb4
--- /dev/null
+++ b/modules/tfuuid/Makefile.am
@@ -0,0 +1,9 @@
+moduledir = @moduledir@
+export top_srcdir
+
+AM_CPPFLAGS = -I$(top_srcdir)/lib -I../../lib
+module_LTLIBRARIES = libtfuuid.la
+
+libtfuuid_la_SOURCES = tfuuid.c
+libtfuuid_la_LIBADD = $(MODULE_DEPS_LIBS) ../../lib/libsyslog-ng-crypto.la
+libtfuuid_la_LDFLAGS = $(MODULE_LDFLAGS)
diff --git a/modules/tfuuid/tfuuid.c b/modules/tfuuid/tfuuid.c
new file mode 100644
index 0000000..64643f5
--- /dev/null
+++ b/modules/tfuuid/tfuuid.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2012 BalaBit IT Ltd, Budapest, Hungary
+ * Copyright (c) 2012 Gergely Nagy <algernon at balabit.hu>
+ *
+ * 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 library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "plugin.h"
+#include "templates.h"
+#include "cfg.h"
+#include "uuid.h"
+
+#include "config.h"
+
+static void
+tf_uuid(LogMessage *msg, gint argc, GString *argv[], GString *result)
+{
+  char uuid_str[37];
+
+  uuid_gen_random(uuid_str, sizeof(uuid_str));
+  g_string_append (result, uuid_str);
+}
+
+TEMPLATE_FUNCTION_SIMPLE(tf_uuid);
+
+static Plugin tfuuid_plugins[] =
+  {
+    TEMPLATE_FUNCTION_PLUGIN(tf_uuid, "uuid"),
+  };
+
+gboolean
+tfuuid_module_init(GlobalConfig *cfg, CfgArgs *args)
+{
+  plugin_register(cfg, tfuuid_plugins, G_N_ELEMENTS(tfuuid_plugins));
+  return TRUE;
+}
+
+const ModuleInfo module_info =
+{
+  .canonical_name = "tfuuid",
+  .version = VERSION,
+  .description = "The tfuuid module provides a template function to generate UUIDs.",
+  .core_revision = SOURCE_REVISION,
+  .plugins = tfuuid_plugins,
+  .plugins_len = G_N_ELEMENTS(tfuuid_plugins),
+};
-- 
1.7.8.3




More information about the syslog-ng mailing list