mmjsonparse: also add MSG part of message if CEE-parsing fails

In that case, the CEE/lumberjack spec says MSG is NON-CEE and must
be treated accordingly. This means no JSON parsing happens. The case
is equal to missing CEE cookie.
Also adapted module to new interfaces provided by msg object.
This commit is contained in:
Rainer Gerhards 2012-10-02 15:36:20 +02:00
parent 0faec96283
commit 2ef5dd4739
2 changed files with 11 additions and 10 deletions

View File

@ -134,7 +134,7 @@ processJSON(instanceData *pData, msg_t *pMsg, char *buf, size_t lenBuf)
if(json == NULL
|| ((size_t)pData->tokener->char_offset < lenBuf)
|| (!json_object_is_type(json, json_type_object))) {
FINALIZE; /* just don't set property */
ABORT_FINALIZE(RS_RET_NO_CEE_MSG);
}
msgAddJSON(pMsg, (uchar*)"!", json);
@ -150,6 +150,7 @@ BEGINdoAction
uchar *buf;
int bSuccess = 0;
struct json_object *jval;
struct json_object *json;
CODESTARTdoAction
pMsg = (msg_t*) ppString[0];
/* note that we can performance-optimize the interface, but this also
@ -165,21 +166,20 @@ dbgprintf("mmjsonparse: msg is '%s'\n", buf);
if(*buf == '\0' || strncmp((char*)buf, COOKIE, LEN_COOKIE)) {
DBGPRINTF("mmjsonparse: no JSON cookie: '%s'\n", buf);
/* create json if necessary and add buf as msg */
if (!pMsg->json) {
pMsg->json = json_object_new_object();
}
jval = json_object_new_string((char*)buf);
json_object_object_add(pMsg->json, "msg", jval);
FINALIZE;
ABORT_FINALIZE(RS_RET_NO_CEE_MSG);
}
buf += LEN_COOKIE;
dbgprintf("mmjsonparse: cookie found, rest of message: '%s'\n", buf);
CHKiRet(processJSON(pData, pMsg, (char*) buf, strlen((char*)buf)));
bSuccess = 1;
finalize_it:
if(iRet == RS_RET_NO_CEE_MSG) {
/* add buf as msg */
json = json_object_new_object();
jval = json_object_new_string((char*)buf);
json_object_object_add(json, "msg", jval);
msgAddJSON(pMsg, (uchar*)"!", json);
}
MsgSetParseSuccess(pMsg, bSuccess);
ENDdoAction

View File

@ -382,6 +382,7 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth
RS_RET_PARAM_NOT_PERMITTED = -2222, /**< legacy parameter no longer permitted (usally already set by v2) */
RS_RET_NO_JSON_PASSING = -2223, /**< rsyslog core does not support JSON-passing plugin API */
RS_RET_MOD_NO_INPUT_STMT = -2224, /**< (input) module does not support input() statement */
RS_RET_NO_CEE_MSG = -2225, /**< the message being processed is NOT CEE-enhanced */
/**** up to 2300 is reserved for v6 use ****/
RS_RET_JNAME_NO_ROOT = -2301, /**< root element is missing in JSON path */