<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="generator" content="Osso Notes">
<title></title></head>
<body>
<p>----- Original message -----
<br>> Since we have type hints available, lets use them! This adds support
<br>> for 32- and 64-bit integers, datetime and boolean types (along with
<br>> the already existing string type, of course) for the mongodb
<br>> destination.
<br>>
<br>> Signed-off-by: Gergely Nagy <<a href="mailto:algernon@balabit.hu">algernon@balabit.hu</a>>
<br>> ---
<br>>  modules/afmongodb/afmongodb.c |  46
<br>> ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45
<br>> insertions(+), 1 deletion(-)
<br>>
<br>> diff --git a/modules/afmongodb/afmongodb.c
<br>> b/modules/afmongodb/afmongodb.c index 5230d8f..ea9c002 100644
<br>> --- a/modules/afmongodb/afmongodb.c
<br>> +++ b/modules/afmongodb/afmongodb.c
<br>> @@ -22,6 +22,7 @@
<br>>  */
<br>>  
<br>>  #include <time.h>
<br>> +#include <stdlib.h>
<br>>  
<br>>  #include "afmongodb.h"
<br>>  #include "afmongodb-parser.h"
<br>> @@ -369,7 +370,50 @@ afmongodb_vp_process_value(const gchar *name, const
<br>> gchar *prefix,  else
<br>>  o = (bson *)user_data;
<br>>  
<br>> -  bson_append_string (o, name, value, -1);
<br>> +  switch (type)
<br>> +  {
<br>> +  case TEMPLATE_TYPE_BOOLEAN:
<br>> +  {
<br>> +  if (value[0] == 'T' || value[0] == 't' || value[0] == '1')
<br>> +  bson_append_boolean (o, name, TRUE);
<br>> +  else
<br>> +  bson_append_boolean (o, name, FALSE);
<br>> +  break;
<br>> +  }
<br>> +  case TEMPLATE_TYPE_INT32:
<br>> +  {
<br>> +  gchar *endptr;
<br>> +  gint32 i = (gint32)strtoul(value, &endptr, 10);
<br>> +
<br>> +  if (endptr[0] == '\0')
<br>> +  bson_append_int32 (o, name, i);
<br>> +
<br>> +  break;
<br>> +  }
<br>
<br>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.
<br>
<br>> +  case TEMPLATE_TYPE_INT64:
<br>> +  {
<br>> +  gchar *endptr;
<br>> +  gint64 i = (gint64)strtoul(value, &endptr, 10);
<br>
<br>strtoll?
<br>
<br>> +
<br>> +  if (endptr[0] == '\0')
<br>> +  bson_append_int64 (o, name, i);
<br>> +
<br>> +  break;
<br>> +  }
<br>> +  case TEMPLATE_TYPE_DATETIME:
<br>> +  {
<br>> +  gchar *endptr;
<br>> +  gint64 i = (gint64)strtoul(value, &endptr, 10) * 1000;
<br>> +
<br>> +  if (endptr[0] == '\0')
<br>> +  bson_append_utc_datetime (o, name, i);
<br>> +
<br>> +  break;
<br>> +  }
<br>
<br>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.
<br>
<br>> +  default:
<br>> +  bson_append_string (o, name, value, -1);
<br>> +  break;
<br>> +  }
<br>>  
<br>>  return FALSE;
<br>>  }
<br>> --
<br>> 1.7.10.4
<br>>
<br>>
<br>> ______________________________________________________________________________
<br>> Member info: <a href="https://lists.balabit.hu/mailman/listinfo/syslog-ng">https://lists.balabit.hu/mailman/listinfo/syslog-ng</a>
<br>> Documentation:
<br>> <a href="http://www.balabit.com/support/documentation/?product=syslog-ng">http://www.balabit.com/support/documentation/?product=syslog-ng</a> FAQ:
<br>> <a href="http://www.balabit.com/wiki/syslog-ng-faq">http://www.balabit.com/wiki/syslog-ng-faq</a>
<br>>
<br><br></p>
</body>
</html>