summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2012-10-02 15:36:20 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2012-10-02 15:36:20 +0200
commit2ef5dd47395ea3758f408cbbfa3ef37dd33ab615 (patch)
tree88a36387817b5f1630cff5492027dcd6c73af7c5
parent0faec9628301e1fd9c57e220d2ad5485e52ced2f (diff)
downloadrsyslog-2ef5dd47395ea3758f408cbbfa3ef37dd33ab615.tar.gz
rsyslog-2ef5dd47395ea3758f408cbbfa3ef37dd33ab615.tar.bz2
rsyslog-2ef5dd47395ea3758f408cbbfa3ef37dd33ab615.zip
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.
-rw-r--r--plugins/mmjsonparse/mmjsonparse.c20
-rw-r--r--runtime/rsyslog.h1
2 files changed, 11 insertions, 10 deletions
diff --git a/plugins/mmjsonparse/mmjsonparse.c b/plugins/mmjsonparse/mmjsonparse.c
index 0fc6a11c..406fbbf9 100644
--- a/plugins/mmjsonparse/mmjsonparse.c
+++ b/plugins/mmjsonparse/mmjsonparse.c
@@ -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
diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h
index ad5e54b4..4404c475 100644
--- a/runtime/rsyslog.h
+++ b/runtime/rsyslog.h
@@ -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 */