3
* This module is a testing aid. It is not meant to be used in production. I have
4
* initially written it to introduce delays of custom length to action processing.
5
* This is needed for development of new message queueing methods. However, I think
6
* there are other uses for this module. For example, I can envision that it is a good
7
* thing to have an output module that requests a retry on every "n"th invocation
8
* and such things. I implement only what I need. But should further testing needs
9
* arise, it makes much sense to add them here.
11
* This module will become part of the CVS and the rsyslog project because I think
12
* it is a generally useful debugging, testing and development aid for everyone
13
* involved with rsyslog.
15
* CURRENT SUPPORTED COMMANDS:
17
* :omtesting:sleep <seconds> <milliseconds>
19
* Must be specified exactly as above. Keep in mind milliseconds are a millionth
22
* NOTE: read comments in module-template.h to understand how this file
25
* Copyright 2007 Rainer Gerhards and Adiscon GmbH.
27
* This file is part of rsyslog.
29
* Rsyslog is free software: you can redistribute it and/or modify
30
* it under the terms of the GNU General Public License as published by
31
* the Free Software Foundation, either version 3 of the License, or
32
* (at your option) any later version.
34
* Rsyslog is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37
* GNU General Public License for more details.
39
* You should have received a copy of the GNU General Public License
40
* along with Rsyslog. If not, see <http://www.gnu.org/licenses/>.
42
* A copy of the GPL can be found in the file "COPYING" in this distribution.
53
#include "syslogd-types.h"
54
#include "module-template.h"
58
/* internal structures
62
typedef struct _instanceData {
64
int iWaitUSeconds; /* milli-seconds (one million of a second, just to make sure...) */
68
CODESTARTcreateInstance
69
pData->iWaitSeconds = 1;
70
pData->iWaitUSeconds = 0;
75
CODESTARTdbgPrintInstInfo
76
dbgprintf("Action delays rule by %d second(s) and %d millisecond(s)\n",
77
pData->iWaitSeconds, pData->iWaitUSeconds);
82
BEGINisCompatibleWithFeature
83
CODESTARTisCompatibleWithFeature
84
/* we are not compatible with repeated msg reduction feature, so do not allow it */
85
ENDisCompatibleWithFeature
94
struct timeval tvSelectTimeout;
96
dbgprintf("sleep(%d, %d)\n", pData->iWaitSeconds, pData->iWaitUSeconds);
97
tvSelectTimeout.tv_sec = pData->iWaitSeconds;
98
tvSelectTimeout.tv_usec = pData->iWaitUSeconds; /* milli seconds */
99
select(0, NULL, NULL, NULL, &tvSelectTimeout);
100
//dbgprintf(":omtesting: end doAction(), iRet %d\n", iRet);
105
CODESTARTfreeInstance
106
/* we do not have instance data, so we do not need to
107
* do anything here. -- rgerhards, 2007-07-25
112
BEGINparseSelectorAct
115
CODESTARTparseSelectorAct
116
CODE_STD_STRING_REQUESTparseSelectorAct(0)
117
/* code here is quick and dirty - if you like, clean it up. But keep
118
* in mind it is just a testing aid ;) -- rgerhards, 2007-12-31
120
if(!strncmp((char*) p, ":omtesting:", sizeof(":omtesting:") - 1)) {
121
p += sizeof(":omtesting:") - 1; /* eat indicator sequence (-1 because of '\0'!) */
123
ABORT_FINALIZE(RS_RET_CONFLINE_UNPROCESSED);
126
/* ok, if we reach this point, we have something for us */
127
if((iRet = createInstance(&pData)) != RS_RET_OK)
131
for(i = 0 ; *p && !isspace((char) *p) && ((unsigned) i < sizeof(szBuf) - 1) ; ++i) {
132
szBuf[i] = (uchar) *p++;
138
if(!strcmp((char*) szBuf, "sleep")) {
140
for(i = 0 ; *p && !isspace(*p) && ((unsigned) i < sizeof(szBuf) - 1) ; ++i) {
146
pData->iWaitSeconds = atoi((char*) szBuf);
147
/* parse milliseconds */
148
for(i = 0 ; *p && !isspace(*p) && ((unsigned) i < sizeof(szBuf) - 1) ; ++i) {
154
pData->iWaitUSeconds = atoi((char*) szBuf);
156
/* once there are other modes, here is the spot to add it! */
158
dbgprintf("invalid mode '%s', doing 'sleep 1 0' - fix your config\n", szBuf);
161
CODE_STD_FINALIZERparseSelectorAct
172
CODEqueryEtryPt_STD_OMOD_QUERIES
178
*ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
179
CODEmodInit_QueryRegCFSLineHdlr