diff options
author | Miloslav Trmač <mitr@redhat.com> | 2012-08-11 08:21:43 +0200 |
---|---|---|
committer | Miloslav Trmač <mitr@redhat.com> | 2012-08-28 10:26:42 +0200 |
commit | ee8e701cddaac8e786f388beff89b57f84a1a346 (patch) | |
tree | 0ea887eaf0453b0315b47e7ade9ad19f10c892ad | |
parent | 30a43cc865f3d7247ec0356566e57b9252e2e6c1 (diff) | |
download | rsyslog-ee8e701cddaac8e786f388beff89b57f84a1a346.tar.gz rsyslog-ee8e701cddaac8e786f388beff89b57f84a1a346.tar.xz rsyslog-ee8e701cddaac8e786f388beff89b57f84a1a346.zip |
Send fields specified by a template to mongodb.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-rw-r--r-- | plugins/ommongodb/ommongodb.c | 43 | ||||
-rw-r--r-- | runtime/rsyslog.h | 1 |
2 files changed, 24 insertions, 20 deletions
diff --git a/plugins/ommongodb/ommongodb.c b/plugins/ommongodb/ommongodb.c index 8873d5ac..874ee63c 100644 --- a/plugins/ommongodb/ommongodb.c +++ b/plugins/ommongodb/ommongodb.c @@ -302,6 +302,7 @@ static rsRetVal writeMongoDB_fields(struct templateField *fields, instanceData *pData) { bson *doc = NULL; + char *fieldStr = NULL; size_t i; DEFiRet; @@ -310,39 +311,41 @@ writeMongoDB_fields(struct templateField *fields, instanceData *pData) 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); + doc = bson_new(); + if(doc == NULL) { + reportMongoError(pData); + dbgprintf("ommongodb: error creating BSON doc\n"); + ABORT_FINALIZE(RS_RET_SUSPENDED); } - 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) { + for(i = 0; fields[i].fieldName != NULL && doc != NULL; i++) { + CHKmalloc(fieldStr = es_str2cstr(fields[i].fieldName, NULL)); + if (!bson_validate_key(fieldStr, FALSE, TRUE)) { + dbgprintf("ommongodb: field name \"%s\" is invalid\n", + fieldStr); + } else if (!bson_append_string(doc, fieldStr, + (const gchar *)fields[i].value, -1)) { + reportMongoError(pData); + dbgprintf("ommongodb: error creating BSON doc\n"); + ABORT_FINALIZE(RS_RET_SUSPENDED); + } + free(fieldStr); + fieldStr = NULL; + } + if(!bson_finish(doc)) { 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: + free(fieldStr); if(doc != NULL) bson_free(doc); RETiRet; diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h index 8d91f0e7..16ddb594 100644 --- a/runtime/rsyslog.h +++ b/runtime/rsyslog.h @@ -381,6 +381,7 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth RS_RET_MODULE_ALREADY_IN_CONF = -2221, /**< module already in current configuration */ RS_RET_PARAM_NOT_PERMITTED = -2222, /**< legacy parameter no longer permitted (usally already set by v2) */ RS_RET_NO_FIELD_PASSING = -2223, /**< output module interface parameter passing mode "FIELDS" is not available but required */ + RS_RET_INVALID_FIELD_NAME = -2224, /**< field name is invalid */ /* RainerScript error messages (range 1000.. 1999) */ RS_RET_SYSVAR_NOT_FOUND = 1001, /**< system variable could not be found (maybe misspelled) */ |