From 9b273d1930cc6ccaada911d77db4c47e019119d2 Mon Sep 17 00:00:00 2001
From: Rainer Gerhards
Date: Mon, 30 Sep 2013 11:17:52 +0200
Subject: omfwd: new action parameter "maxErrorMessages" added
---
ChangeLog | 1 +
doc/omfwd.html | 30 +++++++++++++++++++++---------
runtime/rsyslog.h | 2 ++
tools/omfwd.c | 32 ++++++++++++++++++++++++++------
4 files changed, 50 insertions(+), 15 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4f7d6614..dbf15813 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
---------------------------------------------------------------------------
Version 7.5.4 [devel] 2013-09-??
+- omfwd: new action parameter "maxErrorMessages" added
- omfile: new module parameters to set action defaults added
* dirCreateMode
* fileCreateMode
diff --git a/doc/omfwd.html b/doc/omfwd.html
index 554c98ac..848ecdd3 100644
--- a/doc/omfwd.html
+++ b/doc/omfwd.html
@@ -20,14 +20,14 @@ If you prefer, you can also
a specific version of the rsyslog documentation.
-Global Configuration Directives:
+Module Parameters:
- Template [templateName]
sets a non-standard default template for this module.
-Action specific Configuration Directives:
+Action Parameters:
This documentation is part of the
rsyslog project.
-Copyright © 2008 by Rainer Gerhards and
+Copyright © 2008-2013 by Rainer Gerhards and
Adiscon. Released under the GNU GPL
version 3 or higher.
diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h
index 743296b5..fffcfbf4 100644
--- a/runtime/rsyslog.h
+++ b/runtime/rsyslog.h
@@ -424,6 +424,8 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth
RS_RET_QUEUE_CRY_DISK_ONLY = -2351,/**< crypto provider only supported for disk-associated queues */
RS_RET_NO_DATA = -2352,/**< file has no data; more a state than a real error */
RS_RET_RELP_AUTH_FAIL = -2353,/**< RELP peer authentication failed */
+ RS_RET_ERR_UDPSEND = -2354,/**< sending msg via UDP failed */
+ RS_RET_LAST_ERRREPORT = -2355,/**< module does not emit more error messages as limit is reached */
/* RainerScript error messages (range 1000.. 1999) */
RS_RET_SYSVAR_NOT_FOUND = 1001, /**< system variable could not be found (maybe misspelled) */
diff --git a/tools/omfwd.c b/tools/omfwd.c
index 3c8221c3..6e5cf809 100644
--- a/tools/omfwd.c
+++ b/tools/omfwd.c
@@ -109,6 +109,7 @@ typedef struct _instanceData {
z_stream zstrm; /* zip stream to use for tcp compression */
uchar sndBuf[16*1024]; /* this is intensionally fixed -- see no good reason to make configurable */
unsigned offsSndBuf; /* next free spot in send buffer */
+ int errsToReport; /* (remaining) number of errors to report */
} instanceData;
/* config data */
@@ -144,6 +145,7 @@ static struct cnfparamdescr actpdescr[] = {
{ "ziplevel", eCmdHdlrInt, 0 },
{ "compression.mode", eCmdHdlrGetWord, 0 },
{ "compression.stream.flushontxend", eCmdHdlrBinary, 0 },
+ { "maxerrormessages", eCmdHdlrInt, 0 },
{ "rebindinterval", eCmdHdlrInt, 0 },
{ "streamdriver", eCmdHdlrGetWord, 0 },
{ "streamdrivermode", eCmdHdlrInt, 0 },
@@ -329,6 +331,7 @@ ENDfreeCnf
BEGINcreateInstance
CODESTARTcreateInstance
pData->offsSndBuf = 0;
+ pData->errsToReport = 5;
ENDcreateInstance
@@ -372,7 +375,9 @@ static rsRetVal UDPSend(instanceData *pData, char *msg, size_t len)
struct addrinfo *r;
int i;
unsigned lsent = 0;
- int bSendSuccess;
+ sbool bSendSuccess;
+ int lasterrno;
+ char errStr[1024];
if(pData->iRebindInterval && (pData->nXmit++ % pData->iRebindInterval == 0)) {
dbgprintf("omfwd dropping UDP 'connection' (as configured)\n");
@@ -400,18 +405,30 @@ static rsRetVal UDPSend(instanceData *pData, char *msg, size_t len)
bSendSuccess = RSTRUE;
break;
} else {
- int eno = errno;
- char errStr[1024];
- dbgprintf("sendto() error: %d = %s.\n",
- eno, rs_strerror_r(eno, errStr, sizeof(errStr)));
+ lasterrno = errno;
+ DBGPRINTF("sendto() error: %d = %s.\n",
+ lasterrno,
+ rs_strerror_r(lasterrno, errStr, sizeof(errStr)));
}
}
if (lsent == len && !send_to_all)
break;
}
/* finished looping */
- if (bSendSuccess == RSFALSE) {
+ if(bSendSuccess == RSFALSE) {
dbgprintf("error forwarding via udp, suspending\n");
+ if(pData->errsToReport > 0) {
+ rs_strerror_r(lasterrno, errStr, sizeof(errStr));
+ errmsg.LogError(0, RS_RET_ERR_UDPSEND, "omfwd: error sending "
+ "via udp: %s", errStr);
+ if(pData->errsToReport == 1) {
+ errmsg.LogError(0, RS_RET_LAST_ERRREPORT, "omfwd: "
+ "max number of error message emitted "
+ "- further messages will be "
+ "suppressed");
+ }
+ --pData->errsToReport;
+ }
iRet = RS_RET_SUSPENDED;
}
}
@@ -866,6 +883,7 @@ setInstParamDefaults(instanceData *pData)
pData->compressionLevel = 9;
pData->strmCompFlushOnTxEnd = 1;
pData->compressionMode = COMPRESS_NEVER;
+ pData->errsToReport = 5;
}
BEGINnewActInst
@@ -984,6 +1002,8 @@ CODESTARTnewActInst
errmsg.LogError(0, NO_ERRCODE, "Compression requested, but rsyslogd is not compiled "
"with compression support - request ignored.");
# endif /* #ifdef USE_NETZIP */
+ } else if(!strcmp(actpblk.descr[i].name, "maxerrormessages")) {
+ pData->errsToReport = (int) pvals[i].val.d.n;
} else if(!strcmp(actpblk.descr[i].name, "resendlastmsgonreconnect")) {
pData->bResendLastOnRecon = (int) pvals[i].val.d.n;
} else if(!strcmp(actpblk.descr[i].name, "template")) {
--
cgit v1.2.3