[syslog-ng] [PATCH 2/3] afmongodb: Support type hints
Balazs Scheidler
bazsi77 at gmail.com
Sat Nov 17 21:51:01 CET 2012
----- Original message -----
> Since we have type hints available, lets use them! This adds support
> for 32- and 64-bit integers, datetime and boolean types (along with
> the already existing string type, of course) for the mongodb
> destination.
>
> Signed-off-by: Gergely Nagy <algernon at balabit.hu>
> ---
> modules/afmongodb/afmongodb.c | 46
> ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45
> insertions(+), 1 deletion(-)
>
> diff --git a/modules/afmongodb/afmongodb.c
> b/modules/afmongodb/afmongodb.c index 5230d8f..ea9c002 100644
> --- a/modules/afmongodb/afmongodb.c
> +++ b/modules/afmongodb/afmongodb.c
> @@ -22,6 +22,7 @@
> */
>
> #include <time.h>
> +#include <stdlib.h>
>
> #include "afmongodb.h"
> #include "afmongodb-parser.h"
> @@ -369,7 +370,50 @@ afmongodb_vp_process_value(const gchar *name, const
> gchar *prefix, else
> o = (bson *)user_data;
>
> - bson_append_string (o, name, value, -1);
> + switch (type)
> + {
> + case TEMPLATE_TYPE_BOOLEAN:
> + {
> + if (value[0] == 'T' || value[0] == 't' || value[0] == '1')
> + bson_append_boolean (o, name, TRUE);
> + else
> + bson_append_boolean (o, name, FALSE);
> + break;
> + }
> + case TEMPLATE_TYPE_INT32:
> + {
> + gchar *endptr;
> + gint32 i = (gint32)strtoul(value, &endptr, 10);
> +
> + if (endptr[0] == '\0')
> + bson_append_int32 (o, name, i);
> +
> + break;
> + }
are you sure it's a good idea to drop data for invalid formats? i'd have added as strings in this case. this applies to all cases.
> + case TEMPLATE_TYPE_INT64:
> + {
> + gchar *endptr;
> + gint64 i = (gint64)strtoul(value, &endptr, 10);
strtoll?
> +
> + if (endptr[0] == '\0')
> + bson_append_int64 (o, name, i);
> +
> + break;
> + }
> + case TEMPLATE_TYPE_DATETIME:
> + {
> + gchar *endptr;
> + gint64 i = (gint64)strtoul(value, &endptr, 10) * 1000;
> +
> + if (endptr[0] == '\0')
> + bson_append_utc_datetime (o, name, i);
> +
> + break;
> + }
we might need to support a format with broken-down timestamp. an iso stamp might easily be formatted using a template, and the log message may carry such date in its payload.
> + default:
> + bson_append_string (o, name, value, -1);
> + break;
> + }
>
> return FALSE;
> }
> --
> 1.7.10.4
>
>
> ______________________________________________________________________________
> Member info: https://lists.balabit.hu/mailman/listinfo/syslog-ng
> Documentation:
> http://www.balabit.com/support/documentation/?product=syslog-ng FAQ:
> http://www.balabit.com/wiki/syslog-ng-faq
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.balabit.hu/pipermail/syslog-ng/attachments/20121117/9472d984/attachment.htm
More information about the syslog-ng
mailing list