Hi, As of now mmnormalize supports only raw-msg or msg via the boolean flag 'useRawMsg'. This patch allows using template="template_name" with mmnormalize just like a few other actions(such as omfwd, omelasticsearch etc) do.
It expects a param called 'template' following the convention in other action-types. And when both useRawMsg and template params are set, it prints a warning that template will be ignored and uses raw-message instead. The patch is called 0003... because its the 3rd patch in my local-repo. But since it doesn't have any files common with previous patches, it should apply just fine on any recent commit. Please let me know if the patch looks good for merging, I'll update the documentation. -- Regards, Janmejay http://codehunk.wordpress.com
From 3e538c6d1cb7e61099c3ac7c211547a4351cfb9b Mon Sep 17 00:00:00 2001 From: Janmejay Singh <[email protected]> Date: Mon, 13 Oct 2014 22:29:39 +0530 Subject: [PATCH 3/3] adds the choice of template for mmnormalize action --- plugins/mmnormalize/mmnormalize.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/plugins/mmnormalize/mmnormalize.c b/plugins/mmnormalize/mmnormalize.c index ba2e730..039c5d0 100644 --- a/plugins/mmnormalize/mmnormalize.c +++ b/plugins/mmnormalize/mmnormalize.c @@ -45,6 +45,7 @@ #include "errmsg.h" #include "cfsysline.h" #include "dirty.h" +#include "unicode-helper.h" MODULE_TYPE_OUTPUT MODULE_TYPE_NOKEEP @@ -64,6 +65,7 @@ typedef struct _instanceData { uchar *rulebase; /**< name of rulebase to use */ ln_ctx ctxln; /**< context to be used for liblognorm */ char *pszPath; /**< path of normalized data */ + uchar *tmplName; /**< name of template to use */ } instanceData; typedef struct wrkrInstanceData { @@ -81,7 +83,8 @@ static configSettings_t cs; static struct cnfparamdescr actpdescr[] = { { "rulebase", eCmdHdlrGetWord, 1 }, { "path", eCmdHdlrGetWord, 0 }, - { "userawmsg", eCmdHdlrBinary, 0 } + { "userawmsg", eCmdHdlrBinary, 0 }, + { "template", eCmdHdlrGetWord, 0 } }; static struct cnfparamblk actpblk = { CNFPARAMBLK_VERSION, @@ -174,7 +177,8 @@ BEGINfreeInstance CODESTARTfreeInstance free(pData->rulebase); ln_exitCtx(pData->ctxln); - free(pData->pszPath); + free(pData->pszPath); + free(pData->tmplName); ENDfreeInstance @@ -186,6 +190,10 @@ ENDfreeWrkrInstance BEGINdbgPrintInstInfo CODESTARTdbgPrintInstInfo dbgprintf("mmnormalize\n"); + dbgprintf("\ttemplate='%s'\n", pData->tmplName); + dbgprintf("\trulebase='%s'\n", pData->rulebase); + dbgprintf("\tpath='%s'\n", pData->pszPath); + dbgprintf("\tbUseRawMsg='%d'\n", pData->bUseRawMsg); ENDdbgPrintInstInfo @@ -203,7 +211,10 @@ CODESTARTdoAction pMsg = (msg_t*) ppString[0]; if(pWrkrData->pData->bUseRawMsg) { getRawMsg(pMsg, &buf, &len); - } else { + } else if (pWrkrData->pData->tmplName) { + buf = ppString[1]; + len = ustrlen(buf); + } else { buf = getMSG(pMsg); len = getMSGLen(pMsg); } @@ -260,6 +271,8 @@ CODESTARTnewActInst pData->rulebase = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); } else if(!strcmp(actpblk.descr[i].name, "userawmsg")) { pData->bUseRawMsg = (int) pvals[i].val.d.n; + } else if(!strcmp(actpblk.descr[i].name, "template")) { + pData->tmplName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); } else if(!strcmp(actpblk.descr[i].name, "path")) { cstr = es_str2cstr(pvals[i].val.d.estr, NULL); if (strlen(cstr) < 2) { @@ -282,8 +295,20 @@ CODESTARTnewActInst "param '%s'\n", actpblk.descr[i].name); } } - CODE_STD_STRING_REQUESTnewActInst(1) + + if(pData->bUseRawMsg) { + errmsg.LogError(0, RS_RET_CONFIG_ERROR, + "mmnormalize: 'template' param can't be used with 'useRawMsg'. " + "Ignoring 'template', will use raw message."); + free(pData->tmplName); + pData->tmplName = NULL; + } + + CODE_STD_STRING_REQUESTnewActInst(pData->tmplName ? 2 : 1) CHKiRet(OMSRsetEntry(*ppOMSR, 0, NULL, OMSR_TPL_AS_MSG)); + if (pData->tmplName) { + CHKiRet(OMSRsetEntry(*ppOMSR, 1, ustrdup(pData->tmplName), OMSR_NO_RQD_TPL_OPTS)); + } iRet = buildInstance(pData); CODE_STD_FINALIZERnewActInst @@ -369,7 +394,7 @@ BEGINmodInit() rsRetVal localRet; rsRetVal (*pomsrGetSupportedTplOpts)(unsigned long *pOpts); unsigned long opts; - int bMsgPassingSupported; + int bMsgPassingSupported; CODESTARTmodInit INITLegCnfVars *ipIFVersProvided = CURR_MOD_IF_VERSION; -- 2.0.4
_______________________________________________ rsyslog mailing list http://lists.adiscon.net/mailman/listinfo/rsyslog http://www.rsyslog.com/professional-services/ What's up with rsyslog? Follow https://twitter.com/rgerhards NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad of sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you DON'T LIKE THAT.

