summaryrefslogtreecommitdiffstats
path: root/plugins/ommongodb/ommongodb.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/ommongodb/ommongodb.c')
-rw-r--r--plugins/ommongodb/ommongodb.c81
1 files changed, 77 insertions, 4 deletions
diff --git a/plugins/ommongodb/ommongodb.c b/plugins/ommongodb/ommongodb.c
index 00afcf68..8873d5ac 100644
--- a/plugins/ommongodb/ommongodb.c
+++ b/plugins/ommongodb/ommongodb.c
@@ -297,6 +297,57 @@ finalize_it:
RETiRet;
}
+/* write to mongodb based on a field template. */
+static rsRetVal
+writeMongoDB_fields(struct templateField *fields, instanceData *pData)
+{
+ bson *doc = NULL;
+ size_t i;
+ DEFiRet;
+
+ /* see if we are ready to proceed */
+ if(pData->conn == NULL) {
+ CHKiRet(initMongoDB(pData, 0));
+ }
+
+ dbgprintf("+++start+++\n");
+ for(i = 0; fields[i].fieldName != NULL; i++) {
+ dbgprintf("%.*s: %s\n", (int)es_strlen(fields[i].fieldName),
+ es_getBufAddr(fields[i].fieldName), fields[i].value);
+ }
+ dbgprintf("---end---\n");
+#if 0
+ doc = bson_build(BSON_TYPE_STRING, "sys", sys, sys_len,
+ BSON_TYPE_UTC_DATETIME, "time", ts_gen,
+ BSON_TYPE_UTC_DATETIME, "time_rcvd", ts_rcv,
+ BSON_TYPE_STRING, "msg", msg, msg_len,
+ BSON_TYPE_INT32, "syslog_fac", facil,
+ BSON_TYPE_INT32, "syslog_sever", severity,
+ BSON_TYPE_STRING, "syslog_tag", tag, tag_len,
+ BSON_TYPE_STRING, "procid", procid, procid_len,
+ BSON_TYPE_STRING, "pid", pid, pid_len,
+ BSON_TYPE_STRING, "level", getLumberjackLevel(pMsg->iSeverity), -1,
+ BSON_TYPE_NONE);
+
+ if(doc == NULL) {
+ reportMongoError(pData);
+ dbgprintf("ommongodb: error creating BSON doc\n");
+ ABORT_FINALIZE(RS_RET_SUSPENDED);
+ }
+ bson_finish(doc);
+ if(!mongo_sync_cmd_insert(pData->conn, (char*)pData->dbNcoll, doc, NULL)) {
+ reportMongoError(pData);
+ dbgprintf("ommongodb: insert error\n");
+ ABORT_FINALIZE(RS_RET_SUSPENDED);
+ }
+#endif
+
+finalize_it:
+ if(doc != NULL)
+ bson_free(doc);
+ RETiRet;
+}
+
BEGINtryResume
CODESTARTtryResume
if(pData->conn == NULL) {
@@ -308,6 +359,9 @@ BEGINdoAction
CODESTARTdoAction
if(pData->tplName == NULL) {
iRet = writeMongoDB_msg((msg_t*)ppString[0], pData);
+ } else {
+ iRet = writeMongoDB_fields((struct templateField *)ppString[0],
+ pData);
}
ENDdoAction
@@ -363,12 +417,9 @@ CODESTARTnewActInst
if(pData->tplName == NULL) {
CHKiRet(OMSRsetEntry(*ppOMSR, 0, NULL, OMSR_TPL_AS_MSG));
} else {
- errmsg.LogError(0, RS_RET_LEGA_ACT_NOT_SUPPORTED,
- "ommongodb: templates are not supported in this version");
- ABORT_FINALIZE(RS_RET_ERR);
CHKiRet(OMSRsetEntry(*ppOMSR, 0,
(uchar*) strdup((char*) pData->tplName),
- OMSR_TPL_AS_ARRAY));
+ OMSR_TPL_AS_FIELDS));
}
if(pData->db == NULL)
@@ -420,9 +471,31 @@ CODEqueryEtryPt_STD_CONF2_OMOD_QUERIES
ENDqueryEtryPt
BEGINmodInit()
+ rsRetVal localRet;
+ rsRetVal (*pomsrGetSupportedTplOpts)(unsigned long *pOpts);
+ unsigned long opts;
+ int bFieldPassingSupported;
CODESTARTmodInit
*ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
CODEmodInit_QueryRegCFSLineHdlr
+ /* check if the rsyslog core supports parameter passing code */
+ bFieldPassingSupported = 0;
+ localRet = pHostQueryEtryPt((uchar*)"OMSRgetSupportedTplOpts",
+ &pomsrGetSupportedTplOpts);
+ if(localRet == RS_RET_OK) {
+ /* found entry point, so let's see if core supports msg passing */
+ CHKiRet((*pomsrGetSupportedTplOpts)(&opts));
+ if(opts & OMSR_TPL_AS_FIELDS)
+ bFieldPassingSupported = 1;
+ } else if(localRet != RS_RET_ENTRY_POINT_NOT_FOUND) {
+ ABORT_FINALIZE(localRet); /* Something else went wrong, not acceptable */
+ }
+ if(!bFieldPassingSupported) {
+ DBGPRINTF("ommongodb: field-passing is not supported by rsyslog core, "
+ "can not continue.\n");
+ ABORT_FINALIZE(RS_RET_NO_FIELD_PASSING);
+ }
+
CHKiRet(objUse(errmsg, CORE_COMPONENT));
CHKiRet(objUse(datetime, CORE_COMPONENT));
INITChkCoreFeature(bCoreSupportsBatching, CORE_FEATURE_BATCHING);