From 52b6b6f2211718101e43de05e5292f555e8198a8 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 14 Feb 2008 15:43:50 +0000 Subject: - added new facility and severity syntaxes to cfsysline handler - implemented $InputFileFacility config directive - implemented $InputFileSeverity config directive --- cfsysline.c | 124 ++++++++++++++++++++++++++++++++++++++++-------- cfsysline.h | 2 + doc/imfile.html | 19 +++++++- plugins/imfile/imfile.c | 20 ++++---- srUtils.c | 8 ++-- srUtils.h | 10 ++-- syslogd.c | 1 - 7 files changed, 143 insertions(+), 41 deletions(-) diff --git a/cfsysline.c b/cfsysline.c index 0cc6c134..7249188e 100644 --- a/cfsysline.c +++ b/cfsysline.c @@ -438,7 +438,40 @@ finalize_it: } -/* Parse and a word config line option. A word is a consequitive +/* parse a whitespace-delimited word from the provided string. This is a + * helper function for a number of syntaxes. The parsed value is returned + * in ppStrB (which must be provided by caller). + * rgerhards, 2008-02-14 + */ +static rsRetVal +getWord(uchar **pp, rsCStrObj **ppStrB) +{ + DEFiRet; + uchar *p; + + ASSERT(pp != NULL); + ASSERT(*pp != NULL); + ASSERT(*ppStrB != NULL); + + if((*ppStrB = rsCStrConstruct()) == NULL) + ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); + + /* parse out the word */ + p = *pp; + + while(*p && !isspace((int) *p)) { + CHKiRet(rsCStrAppendChar(*ppStrB, *p++)); + } + CHKiRet(rsCStrFinish(*ppStrB)); + + *pp = p; + +finalize_it: + RETiRet; +} + + +/* Parse and a word config line option. A word is a consequtive * sequence of non-whitespace characters. pVal must be * a pointer to a string which is to receive the option * value. The returned string must be freed by the caller. @@ -455,23 +488,12 @@ static rsRetVal doGetWord(uchar **pp, rsRetVal (*pSetHdlr)(void*, uchar*), void { DEFiRet; rsCStrObj *pStrB; - uchar *p; uchar *pNewVal; - assert(pp != NULL); - assert(*pp != NULL); - - if((pStrB = rsCStrConstruct()) == NULL) - return RS_RET_OUT_OF_MEMORY; - - /* parse out the word */ - p = *pp; - - while(*p && !isspace((int) *p)) { - CHKiRet(rsCStrAppendChar(pStrB, *p++)); - } - CHKiRet(rsCStrFinish(pStrB)); + ASSERT(pp != NULL); + ASSERT(*pp != NULL); + CHKiRet(getWord(pp, &pStrB)); CHKiRet(rsCStrConvSzStrAndDestruct(pStrB, &pNewVal, 0)); pStrB = NULL; @@ -486,7 +508,6 @@ static rsRetVal doGetWord(uchar **pp, rsRetVal (*pSetHdlr)(void*, uchar*), void CHKiRet(pSetHdlr(pVal, pNewVal)); } - *pp = p; skipWhiteSpace(pp); /* skip over any whitespace */ finalize_it: @@ -499,6 +520,66 @@ finalize_it: } +/* parse a syslog name from the string. This is the generic code that is + * called by the facility/severity functions. Note that we do not check the + * validity of numerical values, something that should probably change over + * time (TODO). -- rgerhards, 2008-02-14 + */ +static rsRetVal +doSyslogName(uchar **pp, rsRetVal (*pSetHdlr)(void*, int), void *pVal, syslogName_t *pNameTable) +{ + DEFiRet; + rsCStrObj *pStrB; + int iNewVal; + + ASSERT(pp != NULL); + ASSERT(*pp != NULL); + + CHKiRet(getWord(pp, &pStrB)); /* get word */ + iNewVal = decodeSyslogName(rsCStrGetSzStr(pStrB), pNameTable); + + if(pSetHdlr == NULL) { + /* we should set value directly to var */ + *((int*)pVal) = iNewVal; /* set new one */ + } else { + /* we set value via a set function */ + CHKiRet(pSetHdlr(pVal, iNewVal)); + } + + skipWhiteSpace(pp); /* skip over any whitespace */ + +finalize_it: + if(pStrB != NULL) + rsCStrDestruct(pStrB); + + RETiRet; +} + + +/* Implements the facility syntax. + * rgerhards, 2008-02-14 + */ +static rsRetVal +doFacility(uchar **pp, rsRetVal (*pSetHdlr)(void*, int), void *pVal) +{ + DEFiRet; + iRet = doSyslogName(pp, pSetHdlr, pVal, syslogFacNames); + RETiRet; +} + + +/* Implements the severity syntax. + * rgerhards, 2008-02-14 + */ +static rsRetVal +doSeverity(uchar **pp, rsRetVal (*pSetHdlr)(void*, int), void *pVal) +{ + DEFiRet; + iRet = doSyslogName(pp, pSetHdlr, pVal, syslogPriNames); + RETiRet; +} + + /* --------------- END functions for handling canned syntaxes --------------- */ /* destructor for cslCmdHdlr @@ -507,7 +588,7 @@ finalize_it: */ static rsRetVal cslchDestruct(void *pThis) { - assert(pThis != NULL); + ASSERT(pThis != NULL); free(pThis); return RS_RET_OK; @@ -607,6 +688,12 @@ static rsRetVal cslchCallHdlr(cslCmdHdlr_t *pThis, uchar **ppConfLine) case eCmdHdlrGetChar: pHdlr = doGetChar; break; + case eCmdHdlrFacility: + pHdlr = doFacility; + break; + case eCmdHdlrSeverity: + pHdlr = doSeverity; + break; case eCmdHdlrGetWord: pHdlr = doGetWord; break; @@ -892,6 +979,5 @@ void dbgPrintCfSysLineHandlers(void) ENDfunc } -/* - * vi:set ai: +/* vim:set ai: */ diff --git a/cfsysline.h b/cfsysline.h index 2aa54595..2eec18ab 100644 --- a/cfsysline.h +++ b/cfsysline.h @@ -37,6 +37,8 @@ typedef enum cslCmdHdlrType { eCmdHdlrInt, eCmdHdlrSize, eCmdHdlrGetChar, + eCmdHdlrFacility, + eCmdHdlrSeverity, eCmdHdlrGetWord } ecslCmdHdrlType; diff --git a/doc/imfile.html b/doc/imfile.html index 15ace7c1..3cc8308d 100644 --- a/doc/imfile.html +++ b/doc/imfile.html @@ -54,6 +54,16 @@ $WorkDirectory). Be careful to use unique names for different files being monitored. If there are duplicates, all sorts of "interesting" things may happen. Rsyslog currently does not check if a name is specified multiple times. +
  • $InputFileFacility +facility
    +The syslog facility to be assigned to lines read. Can be specified in +textual form (e.g. "local0", "local1", ...) or as numbers (e.g. 128 for +"local0"). Textual form is suggested. Default  is "local0".
  • +
  • $InputFileSeverity
    +The +syslog severity to be assigned to lines read. Can be specified in +textual form (e.g. "info", "warning", ...) or as numbers (e.g. 4 for +"info"). Textual form is suggested. Default is "notice".
  • $InputRunFileMonitor
    This activates the current monitor. It has no parameters. If you forget this @@ -61,7 +71,8 @@ directive, no file monitoring will take place.
  • $InputFilePollInterval seconds
    This is a global setting. It specifies how often files are to be polled -for new data. The time specified is in seconds. The default value is 10 seconds. Please note that future +for new data. The time specified is in seconds. The default value is 10 +seconds. Please note that future releases of imfile may support per-file polling intervals, but currently this is not the case. If multiple $InputFilePollInterval statements are present in rsyslog.conf, only the last one is used.
    @@ -83,7 +94,9 @@ the source needs to be patched. See define MAX_INPUT_FILES in imfile.c

    The following sample monitors two files. If you need just one, remove the second one. If you need more, add them according to the sample ;). This code must be placed in /etc/rsyslog.conf (or wherever -your distro puts rsyslog's config files).
    +your distro puts rsyslog's config files). Note that only commands +actually needed need to be specified. The second file uses less +commands and uses defaults instead.