mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-11 05:00:41 +01:00
imklog: implement ruleset support
see also: https://github.com/rsyslog/rsyslog/issues/4344#issuecomment-658001854 see also: https://github.com/rsyslog/rsyslog/issues/106
This commit is contained in:
parent
b53f034d26
commit
94c4a871d0
@ -21,7 +21,7 @@
|
||||
* To test under Linux:
|
||||
* echo test1 > /dev/kmsg
|
||||
*
|
||||
* Copyright (C) 2008-2018 Adiscon GmbH
|
||||
* Copyright (C) 2008-2020 Adiscon GmbH
|
||||
*
|
||||
* This file is part of rsyslog.
|
||||
*
|
||||
@ -62,6 +62,7 @@
|
||||
#include "prop.h"
|
||||
#include "errmsg.h"
|
||||
#include "unicode-helper.h"
|
||||
#include "ruleset.h"
|
||||
|
||||
|
||||
MODULE_TYPE_INPUT
|
||||
@ -71,6 +72,7 @@ MODULE_CNFNAME("imklog")
|
||||
/* Module static data */
|
||||
DEF_IMOD_STATIC_DATA
|
||||
DEFobjCurrIf(datetime)
|
||||
DEFobjCurrIf(ruleset)
|
||||
DEFobjCurrIf(glbl)
|
||||
DEFobjCurrIf(prop)
|
||||
DEFobjCurrIf(net)
|
||||
@ -94,6 +96,7 @@ static int bLegacyCnfModGlobalsPermitted;/* are legacy module-global config para
|
||||
|
||||
/* module-global parameters */
|
||||
static struct cnfparamdescr modpdescr[] = {
|
||||
{ "ruleset", eCmdHdlrString, 0 },
|
||||
{ "logpath", eCmdHdlrGetWord, 0 },
|
||||
{ "permitnonkernelfacility", eCmdHdlrBinary, 0 },
|
||||
{ "consoleloglevel", eCmdHdlrInt, 0 },
|
||||
@ -113,6 +116,38 @@ static prop_t *pInputName = NULL;
|
||||
/* there is only one global inputName for all messages generated by this module */
|
||||
static prop_t *pLocalHostIP = NULL;
|
||||
|
||||
/** POTENTIAL COMMON CODE FOR RULESET CHECK **/
|
||||
static inline void std_mod_checkRuleset_genErrMsg(const modConfData_t *const modConf);
|
||||
static inline rsRetVal
|
||||
std_mod_checkRuleset(modConfData_t *const modConf)
|
||||
{
|
||||
ruleset_t *pRuleset;
|
||||
rsRetVal localRet;
|
||||
DEFiRet;
|
||||
|
||||
modConf->pBindRuleset = NULL; /* assume default ruleset */
|
||||
|
||||
if(modConf->pszBindRuleset == NULL)
|
||||
FINALIZE;
|
||||
|
||||
localRet = ruleset.GetRuleset(modConf->pConf, &pRuleset, modConf->pszBindRuleset);
|
||||
if(localRet == RS_RET_NOT_FOUND) {
|
||||
std_mod_checkRuleset_genErrMsg(modConf);
|
||||
}
|
||||
CHKiRet(localRet);
|
||||
modConf->pBindRuleset = pRuleset;
|
||||
|
||||
finalize_it:
|
||||
RETiRet;
|
||||
}
|
||||
/** END POTENTIAL COMMON CODE FOR RULESET CHECK **/
|
||||
static inline void
|
||||
std_mod_checkRuleset_genErrMsg(const modConfData_t *const modConf)
|
||||
{
|
||||
LogError(0, NO_ERRCODE, "imklog: ruleset '%s' not found - "
|
||||
"using default ruleset instead", modConf->pszBindRuleset);
|
||||
}
|
||||
|
||||
static void
|
||||
initConfigSettings(void)
|
||||
{
|
||||
@ -153,6 +188,7 @@ enqMsg(uchar *const __restrict__ msg,
|
||||
MsgSetFlowControlType(pMsg, eFLOWCTL_LIGHT_DELAY);
|
||||
MsgSetInputName(pMsg, pInputName);
|
||||
MsgSetRawMsgWOSize(pMsg, (char*)msg);
|
||||
MsgSetRuleset(pMsg, runModConf->pBindRuleset);
|
||||
MsgSetMSGoffs(pMsg, 0); /* we do not have a header... */
|
||||
MsgSetRcvFrom(pMsg, glbl.GetLocalHostNameProp());
|
||||
MsgSetRcvFromIP(pMsg, pLocalHostIP);
|
||||
@ -350,6 +386,8 @@ CODESTARTsetModCnf
|
||||
loadModConf->ratelimitBurst = (unsigned int) pvals[i].val.d.n;
|
||||
} else if(!strcmp(modpblk.descr[i].name, "ratelimitinterval")) {
|
||||
loadModConf->ratelimitInterval = (unsigned int) pvals[i].val.d.n;
|
||||
} else if(!strcmp(modpblk.descr[i].name, "ruleset")) {
|
||||
loadModConf->pszBindRuleset = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
|
||||
} else {
|
||||
LogMsg(0, RS_RET_INTERNAL_ERROR, LOG_WARNING,
|
||||
"imklog: RSYSLOG BUG, non-handled param '%s' in "
|
||||
@ -392,6 +430,7 @@ ENDendCnfLoad
|
||||
|
||||
BEGINcheckCnf
|
||||
CODESTARTcheckCnf
|
||||
std_mod_checkRuleset(pModConf);
|
||||
ENDcheckCnf
|
||||
|
||||
|
||||
@ -436,10 +475,12 @@ CODESTARTmodExit
|
||||
if(pInputName != NULL)
|
||||
prop.Destruct(&pInputName);
|
||||
|
||||
free(runModConf->pszBindRuleset);
|
||||
/* release objects we used */
|
||||
objRelease(glbl, CORE_COMPONENT);
|
||||
objRelease(net, CORE_COMPONENT);
|
||||
objRelease(datetime, CORE_COMPONENT);
|
||||
objRelease(ruleset, CORE_COMPONENT);
|
||||
objRelease(prop, CORE_COMPONENT);
|
||||
ENDmodExit
|
||||
|
||||
@ -472,6 +513,7 @@ CODEmodInit_QueryRegCFSLineHdlr
|
||||
CHKiRet(objUse(datetime, CORE_COMPONENT));
|
||||
CHKiRet(objUse(glbl, CORE_COMPONENT));
|
||||
CHKiRet(objUse(prop, CORE_COMPONENT));
|
||||
CHKiRet(objUse(ruleset, CORE_COMPONENT));
|
||||
CHKiRet(objUse(net, CORE_COMPONENT));
|
||||
|
||||
/* we need to create the inputName property (only once during our lifetime) */
|
||||
|
||||
@ -43,6 +43,8 @@ struct modConfData_s {
|
||||
ratelimit_t *ratelimiter;
|
||||
int ratelimitInterval;
|
||||
int ratelimitBurst;
|
||||
ruleset_t *pBindRuleset; /* ruleset to bind (use system default if unspecified) */
|
||||
uchar *pszBindRuleset;
|
||||
};
|
||||
|
||||
/* interface to "drivers"
|
||||
|
||||
25
tests/imklog_ruleset.sh
Executable file
25
tests/imklog_ruleset.sh
Executable file
@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
# added 2020-07-14 by Rainer Gerhards, released under ASL 2.0
|
||||
. ${srcdir:=.}/diag.sh init
|
||||
echo This test must be run as root with no other active syslogd
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
exit 77 # Not root, skip this test
|
||||
fi
|
||||
generate_conf
|
||||
add_conf '
|
||||
module(load="../plugins/imklog/.libs/imklog" permitnonkernelfacility="on" ruleset="klogrs")
|
||||
|
||||
template(name="outfmt" type="string" string="%msg:17:$%:%pri%\n")
|
||||
|
||||
ruleset(name="klogrs") {
|
||||
:msg, contains, "msgnum" action(type="omfile" template="outfmt" file="'$RSYSLOG_OUT_LOG'")
|
||||
}
|
||||
'
|
||||
startup
|
||||
echo "<115>Mar 10 01:00:00 172.20.245.8 tag: msgnum:1" > /dev/kmsg
|
||||
shutdown_when_empty
|
||||
wait_shutdown
|
||||
export EXPECTED='Mar 10 01:00:00 172.20.245.8 tag: msgnum:1:115'
|
||||
cmp_exact
|
||||
|
||||
exit_test
|
||||
Loading…
x
Reference in New Issue
Block a user