mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-20 02:40:42 +01:00
Merge branch 'pull-mongo-extended-json' of https://github.com/Baqend/rsyslog into merge-706
This commit is contained in:
commit
64f1efdc15
@ -337,6 +337,7 @@ getDefaultBSON(msg_t *pMsg)
|
||||
|
||||
static bson *BSONFromJSONArray(struct json_object *json);
|
||||
static bson *BSONFromJSONObject(struct json_object *json);
|
||||
static gboolean BSONAppendExtendedJSON(bson *doc, const gchar *name, struct json_object *json);
|
||||
|
||||
/* Append a BSON variant of json to doc using name. Return TRUE on success */
|
||||
static gboolean
|
||||
@ -365,6 +366,10 @@ BSONAppendJSONObject(bson *doc, const gchar *name, struct json_object *json)
|
||||
return bson_append_int64(doc, name, i);
|
||||
}
|
||||
case json_type_object: {
|
||||
|
||||
if (BSONAppendExtendedJSON(doc, name, json) == TRUE)
|
||||
return TRUE;
|
||||
|
||||
bson *sub;
|
||||
gboolean ok;
|
||||
|
||||
@ -395,6 +400,34 @@ BSONAppendJSONObject(bson *doc, const gchar *name, struct json_object *json)
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
BSONAppendExtendedJSON(bson *doc, const gchar *name, struct json_object *json)
|
||||
{
|
||||
struct lh_entry *entry;
|
||||
|
||||
entry = json_object_get_object(json)->head;
|
||||
if (entry) {
|
||||
char *key;
|
||||
key = (char*)entry->k;
|
||||
if (strcmp(key, "$date") == 0) {
|
||||
struct tm tm;
|
||||
gint64 ts;
|
||||
struct json_object *val;
|
||||
|
||||
val = (struct json_object*)entry->v;
|
||||
|
||||
DBGPRINTF("ommongodb: extended json date detected %s", json_object_get_string(val));
|
||||
|
||||
tm.tm_isdst = -1;
|
||||
strptime(json_object_get_string(val), "%Y-%m-%dT%H:%M:%S%z", &tm);
|
||||
ts = 1000 * (gint64) mktime(&tm);
|
||||
return bson_append_utc_datetime(doc, name, ts);
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Return a BSON variant of json, which must be a json_type_array */
|
||||
static bson *
|
||||
BSONFromJSONArray(struct json_object *json)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user