diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2012-03-30 09:55:45 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2012-03-30 09:55:45 +0200 |
commit | 2fbac28d3c1335e1283596b4f574fd55d8117fd6 (patch) | |
tree | 92643709a1a5cc7b27cd0dc79861564edccb5393 /plugins/ommongodb | |
parent | b88ba949f8d657034f808034321fabbd65bf8078 (diff) | |
download | rsyslog-2fbac28d3c1335e1283596b4f574fd55d8117fd6.tar.gz rsyslog-2fbac28d3c1335e1283596b4f574fd55d8117fd6.tar.xz rsyslog-2fbac28d3c1335e1283596b4f574fd55d8117fd6.zip |
ommongodb: now writes a real timestamp into mongo
Diffstat (limited to 'plugins/ommongodb')
-rw-r--r-- | plugins/ommongodb/ommongodb.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/plugins/ommongodb/ommongodb.c b/plugins/ommongodb/ommongodb.c index 5591b693..267f98a1 100644 --- a/plugins/ommongodb/ommongodb.c +++ b/plugins/ommongodb/ommongodb.c @@ -191,6 +191,17 @@ getLumberjackLevel(short severity) } +/* small helper: get integer power of 10 */ +static inline int +i10pow(int exp) +{ + int r = 1; + while(exp > 0) { + r *= 10; + exp--; + } + return r; +} /* write to mongodb in MSG passing mode, that is without a template. * In this mode, we use the standard document format, which is somewhat * aligned to cee (as described in project lumberjack). Note that this is @@ -204,7 +215,8 @@ rsRetVal writeMongoDB_msg(msg_t *pMsg, instanceData *pData) uchar *pid; short unsigned pid_free; size_t pid_len; uchar *sys; short unsigned sys_free; size_t sys_len; uchar *msg; short unsigned msg_free; size_t msg_len; - char timestamp[64]; + gint64 timestamp; + int secfrac; DEFiRet; /* see if we are ready to proceed */ @@ -216,10 +228,21 @@ rsRetVal writeMongoDB_msg(msg_t *pMsg, instanceData *pData) pid = MsgGetProp(pMsg, NULL, PROP_PROCID, NULL, &pid_len, &pid_free); sys = MsgGetProp(pMsg, NULL, PROP_HOSTNAME, NULL, &sys_len, &sys_free); msg = MsgGetProp(pMsg, NULL, PROP_MSG, NULL, &msg_len, &msg_free); - datetime.formatTimestamp3339(&pMsg->tTIMESTAMP, timestamp); + timestamp = (gint64) datetime.syslogTime2time_t(&pMsg->tTIMESTAMP) * 1000; /* ms! */ +dbgprintf("ommongodb: timestamp is %lld\n", (long long) timestamp); +dbgprintf("ommongodb: secfrac is %d, precision %d\n", pMsg->tTIMESTAMP.secfrac, pMsg->tTIMESTAMP.secfracPrecision); + if(pMsg->tTIMESTAMP.secfracPrecision > 3) { + secfrac = pMsg->tTIMESTAMP.secfrac / i10pow(pMsg->tTIMESTAMP.secfracPrecision - 3); + } else if(pMsg->tTIMESTAMP.secfracPrecision < 3) { + secfrac = pMsg->tTIMESTAMP.secfrac * i10pow(3 - pMsg->tTIMESTAMP.secfracPrecision); + } else { + secfrac = pMsg->tTIMESTAMP.secfrac; + } + timestamp += secfrac; +dbgprintf("ommongodb: normalized secfrac is %d, final timestamp %lld\n", secfrac, (long long) timestamp); doc = bson_build(BSON_TYPE_STRING, "sys", sys, sys_len, - BSON_TYPE_STRING, "time", timestamp, -1, + BSON_TYPE_UTC_DATETIME, "time", timestamp, BSON_TYPE_STRING, "msg", msg, msg_len, BSON_TYPE_STRING, "procid", procid, procid_len, BSON_TYPE_STRING, "pid", pid, pid_len, |