omhiredis: Allow to define a name to instance and use it in logs

This commit is contained in:
frikilax 2025-12-04 16:18:07 +01:00 committed by Théo Bertin
parent f48844e53b
commit e981d7dbdb
No known key found for this signature in database
17 changed files with 215 additions and 137 deletions

View File

@ -48,6 +48,8 @@
#include "errmsg.h"
#include "cfsysline.h"
#include "unicode-helper.h"
#include "parserif.h"
#include "action.h"
MODULE_TYPE_OUTPUT;
MODULE_TYPE_NOKEEP;
@ -109,6 +111,8 @@ typedef struct _instanceData {
char *sni; /* TLS Server Name Indication */
#endif
action_t *pAction;
} instanceData;
typedef struct wrkrInstanceData {
@ -150,6 +154,7 @@ static struct cnfparamdescr actpdescr[] = {
{"client_key", eCmdHdlrGetWord, 0},
{"sni", eCmdHdlrGetWord, 0},
#endif
{"name", eCmdHdlrGetWord, 0},
};
static struct cnfparamblk actpblk = {CNFPARAMBLK_VERSION, sizeof(actpdescr) / sizeof(struct cnfparamdescr), actpdescr};
@ -158,6 +163,11 @@ BEGINcreateInstance
CODESTARTcreateInstance;
ENDcreateInstance
BEGINsetActionInfo
CODESTARTsetActionInfo;
pData->pAction = pAction;
ENDsetActionInfo
BEGINcreateWrkrInstance
CODESTARTcreateWrkrInstance;
pWrkrData->conn = NULL; /* Connect later */
@ -240,10 +250,12 @@ static rsRetVal initHiredis(wrkrInstanceData_t *pWrkrData, int bSilent) {
struct timeval timeout = {1, 500000}; /* 1.5 seconds */
if (udsAddr) {
DBGPRINTF("omhiredis: trying connect to UDS socket '%s'\n", server);
LogMsg(0, RS_RET_OK, LOG_INFO, "omhiredis[%s]: trying connect to UDS socket '%s'",
actionGetName(pWrkrData->pData->pAction), server);
pWrkrData->conn = redisConnectUnixWithTimeout(server, timeout);
} else {
DBGPRINTF("omhiredis: trying connect to '%s' at port %d\n", server, pWrkrData->pData->port);
LogMsg(0, RS_RET_OK, LOG_INFO, "omhiredis[%s]: trying connect to '%s' at port %d",
actionGetName(pWrkrData->pData->pAction), server, pWrkrData->pData->port);
pWrkrData->conn = redisConnectWithTimeout(server, pWrkrData->pData->port, timeout);
}
@ -251,13 +263,13 @@ static rsRetVal initHiredis(wrkrInstanceData_t *pWrkrData, int bSilent) {
if (!bSilent) {
const char *err_str = pWrkrData->conn == NULL ? "could not allocate context!" : pWrkrData->conn->errstr;
if (udsAddr) {
LogError(0, RS_RET_REDIS_ERROR, "omhiredis: can not connect to redis UDS socket '%s' -> %s", server,
err_str);
LogError(0, RS_RET_REDIS_ERROR, "omhiredis[%s]: can not connect to redis UDS socket '%s' -> %s",
actionGetName(pWrkrData->pData->pAction), server, err_str);
} else {
LogError(0, RS_RET_REDIS_ERROR,
"omhiredis: can not connect to redis server '%s', "
"omhiredis[%s]: can not connect to redis server '%s', "
"port %d -> %s",
server, pWrkrData->pData->port, err_str);
actionGetName(pWrkrData->pData->pAction), server, pWrkrData->pData->port, err_str);
}
}
ABORT_FINALIZE(RS_RET_SUSPENDED);
@ -269,13 +281,17 @@ static rsRetVal initHiredis(wrkrInstanceData_t *pWrkrData, int bSilent) {
pWrkrData->pData->client_cert, pWrkrData->pData->client_key,
pWrkrData->pData->sni, &pWrkrData->ssl_error);
if (!pWrkrData->ssl_conn || pWrkrData->ssl_error != REDIS_SSL_CTX_NONE) {
LogError(0, NO_ERRCODE, "omhiredis: SSL Context error: %s", redisSSLContextGetError(pWrkrData->ssl_error));
if (!bSilent) LogError(0, RS_RET_SUSPENDED, "[TLS] can not initialize redis handle");
LogError(0, NO_ERRCODE, "omhiredis[%s]: SSL Context error: %s", actionGetName(pWrkrData->pData->pAction),
redisSSLContextGetError(pWrkrData->ssl_error));
if (!bSilent) LogError(0, RS_RET_SUSPENDED, "omhiredis[%s]: can not initialize TLS context");
ABORT_FINALIZE(RS_RET_SUSPENDED);
}
if (redisInitiateSSLWithContext(pWrkrData->conn, pWrkrData->ssl_conn) != REDIS_OK) {
LogError(0, NO_ERRCODE, "omhiredis: %s", pWrkrData->conn->errstr);
if (!bSilent) LogError(0, RS_RET_SUSPENDED, "[TLS] can not initialize redis handle");
LogError(0, NO_ERRCODE, "omhiredis[%s]: %s", actionGetName(pWrkrData->pData->pAction),
pWrkrData->conn->errstr);
if (!bSilent)
LogError(0, RS_RET_SUSPENDED, "omhiredis[%s]: [TLS] can not initialize redis handle",
actionGetName(pWrkrData->pData->pAction));
ABORT_FINALIZE(RS_RET_SUSPENDED);
}
}
@ -287,7 +303,8 @@ static rsRetVal initHiredis(wrkrInstanceData_t *pWrkrData, int bSilent) {
DBGPRINTF("omhiredis: could not get reply from AUTH command\n");
ABORT_FINALIZE(RS_RET_SUSPENDED);
} else if (reply->type == REDIS_REPLY_ERROR) {
LogError(0, NO_ERRCODE, "omhiredis: error while authenticating: %s", reply->str);
LogError(0, NO_ERRCODE, "omhiredis[%s]: error while authenticating: %s",
actionGetName(pWrkrData->pData->pAction), reply->str);
ABORT_FINALIZE(RS_RET_ERR);
}
}
@ -315,20 +332,21 @@ static rsRetVal isMaster(wrkrInstanceData_t *pWrkrData) {
reply = redisCommand(pWrkrData->conn, "ROLE");
if (reply == NULL) {
DBGPRINTF("omhiredis: could not get reply from ROLE command\n");
LogMsg(0, RS_RET_OK, LOG_WARNING, "omhiredis[%s]: could not get reply from ROLE command",
actionGetName(pWrkrData->pData->pAction));
ABORT_FINALIZE(RS_RET_SUSPENDED);
} else if (reply->type == REDIS_REPLY_ERROR) {
LogMsg(0, RS_RET_REDIS_ERROR, LOG_WARNING,
"omhiredis: got an error while querying role -> "
"%s\n",
reply->str);
LogMsg(0, RS_RET_REDIS_ERROR, LOG_WARNING, "omhiredis[%s]: got an error while querying role -> %s",
actionGetName(pWrkrData->pData->pAction), reply->str);
ABORT_FINALIZE(RS_RET_SUSPENDED);
} else if (reply->type != REDIS_REPLY_ARRAY || reply->element[0]->type != REDIS_REPLY_STRING) {
LogMsg(0, RS_RET_REDIS_ERROR, LOG_ERR, "omhiredis: did not get a proper reply from ROLE command");
LogMsg(0, RS_RET_REDIS_ERROR, LOG_ERR, "omhiredis[%s]: did not get a proper reply from ROLE command",
actionGetName(pWrkrData->pData->pAction));
ABORT_FINALIZE(RS_RET_SUSPENDED);
} else {
if (strncmp(reply->element[0]->str, "master", 6)) {
LogMsg(0, RS_RET_OK, LOG_WARNING, "omhiredis: current connected node is not a master");
LogMsg(0, RS_RET_OK, LOG_WARNING, "omhiredis[%s]: current connected node is not a master",
actionGetName(pWrkrData->pData->pAction));
ABORT_FINALIZE(RS_RET_SUSPENDED);
}
}
@ -394,7 +412,7 @@ static rsRetVal writeHiredis(uchar *key, uchar *message, wrkrInstanceData_t *pWr
}
if (rc == REDIS_ERR) {
LogError(0, NO_ERRCODE, "omhiredis: %s", pWrkrData->conn->errstr);
LogError(0, NO_ERRCODE, "omhiredis[%s]: %s", actionGetName(pWrkrData->pData->pAction), pWrkrData->conn->errstr);
dbgprintf("omhiredis: %s\n", pWrkrData->conn->errstr);
ABORT_FINALIZE(RS_RET_ERR);
} else {
@ -410,7 +428,7 @@ static rsRetVal ackHiredisStreamIndex(wrkrInstanceData_t *pWrkrData, uchar *key,
DEFiRet;
if (REDIS_ERR == redisAppendCommand(pWrkrData->conn, "XACK %s %s %s", key, group, index)) {
LogError(0, NO_ERRCODE, "omhiredis: %s", pWrkrData->conn->errstr);
LogError(0, NO_ERRCODE, "omhiredis[%s]: %s", actionGetName(pWrkrData->pData->pAction), pWrkrData->conn->errstr);
DBGPRINTF("omhiredis: %s\n", pWrkrData->conn->errstr);
ABORT_FINALIZE(RS_RET_ERR);
} else {
@ -425,7 +443,7 @@ static rsRetVal delHiredisStreamIndex(wrkrInstanceData_t *pWrkrData, uchar *key,
DEFiRet;
if (REDIS_ERR == redisAppendCommand(pWrkrData->conn, "XDEL %s %s", key, index)) {
LogError(0, NO_ERRCODE, "omhiredis: %s", pWrkrData->conn->errstr);
LogError(0, NO_ERRCODE, "omhiredis[%s]: %s", actionGetName(pWrkrData->pData->pAction), pWrkrData->conn->errstr);
DBGPRINTF("omhiredis: %s\n", pWrkrData->conn->errstr);
ABORT_FINALIZE(RS_RET_ERR);
} else {
@ -500,12 +518,14 @@ BEGINendTransaction
for (i = 0; i < pWrkrData->count; i++) {
if (REDIS_OK != redisGetReply(pWrkrData->conn, (void *)&reply) || pWrkrData->conn->err) {
dbgprintf("omhiredis: %s\n", pWrkrData->conn->errstr);
LogError(0, RS_RET_REDIS_ERROR, "Error while processing replies: %s", pWrkrData->conn->errstr);
LogError(0, RS_RET_REDIS_ERROR, "omhiredis[%s]: Error while processing replies: %s",
actionGetName(pWrkrData->pData->pAction), pWrkrData->conn->errstr);
closeHiredis(pWrkrData);
ABORT_FINALIZE(RS_RET_SUSPENDED);
} else {
if (reply->type == REDIS_REPLY_ERROR) {
LogError(0, RS_RET_REDIS_ERROR, "Received error from redis -> %s", reply->str);
LogError(0, RS_RET_REDIS_ERROR, "omhiredis[%s]: Received error from redis -> %s",
actionGetName(pWrkrData->pData->pAction), reply->str);
closeHiredis(pWrkrData);
freeReplyObject(reply);
ABORT_FINALIZE(RS_RET_SUSPENDED);
@ -551,6 +571,7 @@ static void setInstParamDefaults(instanceData *pData) {
pData->client_key = NULL;
pData->sni = NULL;
#endif
pData->pAction = NULL;
}
/* here is where the work to set up a new instance
@ -650,134 +671,122 @@ BEGINnewActInst
dbgprintf("omhiredis: checking config sanity\n");
#ifdef HIREDIS_SSL
if ((pData->client_cert == NULL) ^ (pData->client_key == NULL)) {
parser_errmsg("omhiredis: \"client_cert\" and \"client_key\" must be specified together!");
ABORT_FINALIZE(RS_RET_PARAM_ERROR);
}
#endif
if (!pData->modeDescription) {
dbgprintf("omhiredis: no mode specified, setting it to 'template'\n");
parser_warnmsg("omhiredis: no mode specified, setting it to 'template'\n");
pData->mode = OMHIREDIS_MODE_TEMPLATE;
}
if (pData->mode == OMHIREDIS_MODE_STREAM && !pData->streamOutField) {
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: no stream.outField set, "
"using 'msg' as default");
parser_warnmsg("omhiredis: no stream.outField set, using 'msg' as default");
pData->streamOutField = ustrdup("msg");
}
if (pData->server != NULL && pData->socketPath != NULL) {
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: both 'server' and 'socketpath' are set; 'socketpath' will be ignored");
parser_warnmsg("omhiredis: both 'server' and 'socketpath' are set; 'socketpath' will be ignored");
free(pData->socketPath);
pData->socketPath = NULL;
}
if (pData->tplName == NULL) {
if (pData->mode == OMHIREDIS_MODE_TEMPLATE) {
LogError(0, RS_RET_CONF_PARSE_ERROR, "omhiredis: selected mode requires a template");
parser_errmsg("omhiredis: selected mode requires a template");
ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
} else {
CHKmalloc(pData->tplName = ustrdup("RSYSLOG_ForwardFormat"));
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: no template set, "
"using RSYSLOG_ForwardFormat as default");
parser_warnmsg("omhiredis: no template set, using RSYSLOG_ForwardFormat as default");
}
}
if (pData->mode != OMHIREDIS_MODE_TEMPLATE && pData->key == NULL) {
LogError(0, RS_RET_CONF_PARSE_ERROR, "omhiredis: mode %s requires a key", pData->modeDescription);
parser_errmsg("omhiredis: mode %s requires a key", pData->modeDescription);
ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
}
if (pData->expiration && pData->mode != OMHIREDIS_MODE_SET) {
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: expiration set but mode is not "
"'set', expiration will be ignored");
parser_warnmsg("omhiredis: expiration set but mode is not 'set', expiration will be ignored");
}
if (pData->mode != OMHIREDIS_MODE_STREAM) {
if (pData->streamOutField) {
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: stream.outField set "
"but mode is not 'stream', field will be ignored");
parser_warnmsg("omhiredis: stream.outField set but mode is not 'stream', field will be ignored");
}
if (pData->streamAck) {
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: stream.ack set "
"but mode is not 'stream', XACK will be ignored");
parser_warnmsg("omhiredis: stream.ack set but mode is not 'stream', XACK will be ignored");
}
if (pData->streamDel) {
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: stream.del set "
"but mode is not 'stream', XDEL will be ignored");
parser_warnmsg("omhiredis: stream.del set but mode is not 'stream', XDEL will be ignored");
}
if (pData->streamCapacityLimit) {
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: stream.capacityLimit set "
"but mode is not 'stream', stream trimming will be ignored");
parser_warnmsg(
"omhiredis: stream.capacityLimit set "
"but mode is not 'stream', stream trimming will be ignored");
}
if (pData->streamKeyAck) {
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: stream.keyAck set "
"but mode is not 'stream', parameter will be ignored");
parser_warnmsg(
"omhiredis: stream.keyAck set "
"but mode is not 'stream', parameter will be ignored");
}
if (pData->streamDynaKeyAck) {
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: stream.dynaKeyAck set "
"but mode is not 'stream', parameter will be ignored");
parser_warnmsg(
"omhiredis: stream.dynaKeyAck set "
"but mode is not 'stream', parameter will be ignored");
}
if (pData->streamGroupAck) {
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: stream.groupAck set "
"but mode is not 'stream', parameter will be ignored");
parser_warnmsg(
"omhiredis: stream.groupAck set "
"but mode is not 'stream', parameter will be ignored");
}
if (pData->streamDynaGroupAck) {
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: stream.dynaGroupAck set "
"but mode is not 'stream', parameter will be ignored");
parser_warnmsg(
"omhiredis: stream.dynaGroupAck set "
"but mode is not 'stream', parameter will be ignored");
}
if (pData->streamIndexAck) {
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: stream.indexAck set "
"but mode is not 'stream', parameter will be ignored");
parser_warnmsg(
"omhiredis: stream.indexAck set "
"but mode is not 'stream', parameter will be ignored");
}
if (pData->streamDynaIndexAck) {
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: stream.dynaIndexAck set "
"but mode is not 'stream', parameter will be ignored");
parser_warnmsg(
"omhiredis: stream.dynaIndexAck set "
"but mode is not 'stream', parameter will be ignored");
}
} else {
if (pData->streamAck) {
if (!pData->streamKeyAck || !pData->streamGroupAck || !pData->streamIndexAck) {
LogError(0, RS_RET_CONF_PARSE_ERROR,
"omhiredis: 'stream.ack' is set but one of "
"'stream.keyAck', 'stream.groupAck' or 'stream.indexAck' is missing");
parser_errmsg(
"omhiredis: 'stream.ack' is set but one of "
"'stream.keyAck', 'stream.groupAck' or 'stream.indexAck' is missing");
ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
}
}
if (pData->streamDel) {
if (!pData->streamKeyAck || !pData->streamIndexAck) {
LogError(0, RS_RET_CONF_PARSE_ERROR,
"omhiredis: 'stream.del' is set but one of "
"'stream.keyAck' or 'stream.indexAck' is missing");
parser_errmsg(
"omhiredis: 'stream.del' is set but one of "
"'stream.keyAck' or 'stream.indexAck' is missing");
ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
}
}
}
if (pData->streamDynaKeyAck && pData->streamKeyAck == NULL) {
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: 'stream.dynaKeyAck' set "
"but 'stream.keyAck' is empty, disabling");
parser_warnmsg("omhiredis: 'stream.dynaKeyAck' set but 'stream.keyAck' is empty, disabling");
pData->streamDynaKeyAck = 0;
}
if (pData->streamDynaGroupAck && pData->streamGroupAck == NULL) {
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: 'stream.dynaGroupAck' set "
"but 'stream.groupAck' is empty, disabling");
parser_warnmsg("omhiredis: 'stream.dynaGroupAck' set but 'stream.groupAck' is empty, disabling");
pData->streamDynaGroupAck = 0;
}
if (pData->streamDynaIndexAck && pData->streamIndexAck == NULL) {
LogError(0, RS_RET_CONF_PARSE_WARNING,
"omhiredis: 'stream.dynaGroupAck' set "
"but 'stream.indexAck' is empty, disabling");
parser_warnmsg("omhiredis: 'stream.dynaIndexAck' set but 'stream.indexAck' is empty, disabling");
pData->streamDynaIndexAck = 0;
}
@ -850,6 +859,7 @@ ENDmodExit
* with the rsyslog core engine */
BEGINqueryEtryPt
CODESTARTqueryEtryPt;
CODEqueryEtryPt_SetActionInfo_IF_OMOD_QUERIES;
CODEqueryEtryPt_STD_OMOD_QUERIES;
CODEqueryEtryPt_STD_OMOD8_QUERIES;
CODEqueryEtryPt_STD_CONF2_OMOD_QUERIES;

View File

@ -17,6 +17,7 @@ template(name="dynakey" type="string" string="%$!dynaKey%")
local4.* {
set $!dynaKey = "myDynaKey";
action(type="omhiredis"
name="omhiredis-dynakey"
server="127.0.0.1"
serverport="'$REDIS_RANDOM_PORT'"
mode="set"
@ -44,13 +45,13 @@ wait_shutdown
redis_command "GET myDynaKey" >> $RSYSLOG_OUT_LOG
# The first get is before inserting, the second is after
export EXPECTED="/usr/bin/redis-cli
/usr/bin/redis-cli
export EXPECTED="
msgnum:00000001:"
cmp_exact $RSYSLOG_OUT_LOG
content_check "omhiredis[omhiredis-dynakey]: trying connect to '127.0.0.1'" ${RSYSLOG_DYNNAME}.started
stop_redis
# Removes generated configuration file, log and pid files

42
tests/omhiredis-name-blank.sh Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/env bash
# added 2025-12-04 by Théo Bertin, released under ASL 2.0
## Uncomment for debugging
# export RS_REDIR=-d
. ${srcdir:=.}/diag.sh init
start_redis
generate_conf
add_conf '
global(localhostname="server")
module(load="../contrib/omhiredis/.libs/omhiredis")
template(name="outfmt" type="string" string="%msg%")
local4.* {
action(type="omhiredis"
server="127.0.0.1"
serverport="'$REDIS_RANDOM_PORT'"
mode="queue"
key="myKey"
template="outfmt")
stop
}
'
startup
injectmsg 1 1
shutdown_when_empty
wait_shutdown
content_check "omhiredis[action-1-../contrib/omhiredis/.libs/omhiredis]:" ${RSYSLOG_DYNNAME}.started
check_not_present "omhiredis:" ${RSYSLOG_DYNNAME}.started
stop_redis
# Removes generated configuration file, log and pid files
cleanup_redis
exit_test

View File

@ -15,6 +15,7 @@ template(name="outfmt" type="string" string="%msg%")
local4.* {
action(type="omhiredis"
name="omhiredis-publish"
server="127.0.0.1"
serverport="'$REDIS_RANDOM_PORT'"
mode="publish"
@ -36,8 +37,7 @@ shutdown_when_empty
wait_shutdown
# The SUBSCRIBE command gets the result of the subscribing and the 3 subsequent messages published by omhiredis
export EXPECTED="/usr/bin/redis-cli
subscribe
export EXPECTED="subscribe
myChannel
1
message
@ -52,6 +52,8 @@ myChannel
cmp_exact $RSYSLOG_OUT_LOG
content_check "omhiredis[omhiredis-publish]: trying connect to '127.0.0.1'" ${RSYSLOG_DYNNAME}.started
stop_redis
# Removes generated configuration file, log and pid files

View File

@ -15,6 +15,7 @@ template(name="outfmt" type="string" string="%msg%")
local4.* {
action(type="omhiredis"
name="omhiredis-queue-rpush"
server="127.0.0.1"
serverport="'$REDIS_RANDOM_PORT'"
mode="queue"
@ -39,9 +40,7 @@ redis_command "LLEN myKey" > $RSYSLOG_OUT_LOG
redis_command "LPOP myKey 6" >> $RSYSLOG_OUT_LOG
# Messages should be retrieved in order (as they were inserted using RPUSH)
export EXPECTED="/usr/bin/redis-cli
5
/usr/bin/redis-cli
export EXPECTED="5
msgnum:00000001:
msgnum:00000002:
msgnum:00000003:
@ -50,6 +49,8 @@ export EXPECTED="/usr/bin/redis-cli
cmp_exact $RSYSLOG_OUT_LOG
content_check "omhiredis[omhiredis-queue-rpush]: trying connect to '127.0.0.1'" ${RSYSLOG_DYNNAME}.started
stop_redis
# Removes generated configuration file, log and pid files

View File

@ -15,6 +15,7 @@ template(name="outfmt" type="string" string="%msg%")
local4.* {
action(type="omhiredis"
name="omhiredis-queue"
server="127.0.0.1"
serverport="'$REDIS_RANDOM_PORT'"
mode="queue"
@ -38,9 +39,7 @@ redis_command "LLEN myKey" > $RSYSLOG_OUT_LOG
redis_command "LPOP myKey 11" >> $RSYSLOG_OUT_LOG
# Messages should be retrieved in reverse order (as they were inserted using LPUSH)
export EXPECTED="/usr/bin/redis-cli
10
/usr/bin/redis-cli
export EXPECTED="10
msgnum:00000010:
msgnum:00000009:
msgnum:00000008:
@ -54,6 +53,8 @@ export EXPECTED="/usr/bin/redis-cli
cmp_exact $RSYSLOG_OUT_LOG
content_check "omhiredis[omhiredis-queue]: trying connect to '127.0.0.1'" ${RSYSLOG_DYNNAME}.started
stop_redis
# Removes generated configuration file, log and pid files

View File

@ -15,6 +15,7 @@ template(name="outfmt" type="string" string="%msg%")
local4.* {
action(type="omhiredis"
name="omhiredis-set"
server="127.0.0.1"
serverport="'$REDIS_RANDOM_PORT'"
mode="set"
@ -26,8 +27,8 @@ local4.* {
action(type="omfile" file="'$RSYSLOG_DYNNAME.othermsg'" template="outfmt")
'
# Should get nothing
redis_command "GET outKey" > $RSYSLOG_OUT_LOG
# Should get 'none'
redis_command "TYPE outKey" > $RSYSLOG_OUT_LOG
startup
@ -37,17 +38,21 @@ injectmsg 1 1
shutdown_when_empty
wait_shutdown
# Should get 'string'
redis_command "TYPE outKey" >> $RSYSLOG_OUT_LOG
# Should get ' msgnum:00000001:'
redis_command "GET outKey" >> $RSYSLOG_OUT_LOG
# The first get is before inserting, the second is after
export EXPECTED="/usr/bin/redis-cli
/usr/bin/redis-cli
export EXPECTED="none
string
msgnum:00000001:"
cmp_exact $RSYSLOG_OUT_LOG
content_check "omhiredis[omhiredis-set]: trying connect to '127.0.0.1'" ${RSYSLOG_DYNNAME}.started
stop_redis
# Removes generated configuration file, log and pid files

View File

@ -16,6 +16,7 @@ template(name="outfmt" type="string" string="%msg%")
local4.* {
action(type="omhiredis"
name="omhiredis-setex"
server="127.0.0.1"
serverport="'$REDIS_RANDOM_PORT'"
mode="set"
@ -28,8 +29,8 @@ local4.* {
action(type="omfile" file="'$RSYSLOG_DYNNAME.othermsg'" template="outfmt")
'
# Should get nothing
redis_command "GET outKey" > $RSYSLOG_OUT_LOG
# Should get 'none'
redis_command "TYPE outKey" > $RSYSLOG_OUT_LOG
startup
@ -47,8 +48,8 @@ redis_command "GET outKey" >> $RSYSLOG_OUT_LOG
sleep $EXPIRATION
# Should get nothing
redis_command "GET outKey" >> $RSYSLOG_OUT_LOG
# Should get 'none'
redis_command "TYPE outKey" >> $RSYSLOG_OUT_LOG
if [ $ttl -lt 0 ] || [ $ttl -gt $EXPIRATION ]; then
echo "ERROR: expiration is not in [0:$EXPIRATION] -> $ttl"
@ -58,15 +59,14 @@ fi
# The first get is before inserting
# The third is while the key is still valid
# The fourth is after the key expired
export EXPECTED="/usr/bin/redis-cli
/usr/bin/redis-cli
export EXPECTED="none
msgnum:00000001:
/usr/bin/redis-cli
"
none"
cmp_exact $RSYSLOG_OUT_LOG
content_check "omhiredis[omhiredis-setex]: trying connect to '127.0.0.1'" ${RSYSLOG_DYNNAME}.started
stop_redis
# Removes generated configuration file, log and pid files

View File

@ -15,6 +15,7 @@ template(name="outfmt" type="string" string="%msg%")
local4.* {
action(type="omhiredis"
name="omhiredis-stream-ack"
server="127.0.0.1"
serverport="'$REDIS_RANDOM_PORT'"
mode="stream"
@ -51,16 +52,12 @@ redis_command "XINFO GROUPS inStream" >> $RSYSLOG_OUT_LOG
# 4. show group infos -> pending shows 1 pending entry
# 4.2. start Rsyslog and send message -> omhiredis acknowledges index 1-0 on group 'group' for stream 'inStream'
# 5. show group infos again -> pending now shows 0 pending entries
export EXPECTED="/usr/bin/redis-cli
OK
/usr/bin/redis-cli
export EXPECTED="OK
1-0
/usr/bin/redis-cli
inStream
1-0
key
value
/usr/bin/redis-cli
name
group
consumers
@ -73,7 +70,6 @@ entries-read
1
lag
0
/usr/bin/redis-cli
name
group
consumers
@ -89,6 +85,9 @@ lag
cmp_exact $RSYSLOG_OUT_LOG
content_check "omhiredis: no stream.outField set, using 'msg' as default" ${RSYSLOG_DYNNAME}.started
content_check "omhiredis[omhiredis-stream-ack]: trying connect to '127.0.0.1'" ${RSYSLOG_DYNNAME}.started
stop_redis
# Removes generated configuration file, log and pid files

View File

@ -15,6 +15,7 @@ template(name="outfmt" type="string" string="%msg%")
local4.* {
action(type="omhiredis"
name="omhiredis-stream-capped"
server="127.0.0.1"
serverport="'$REDIS_RANDOM_PORT'"
mode="stream"
@ -45,6 +46,9 @@ if [ ! "${count}" -le 500 ]; then
error_exit 1
fi
content_check "omhiredis: no stream.outField set, using 'msg' as default" ${RSYSLOG_DYNNAME}.started
content_check "omhiredis[omhiredis-stream-capped]: trying connect to '127.0.0.1'" ${RSYSLOG_DYNNAME}.started
stop_redis
# Removes generated configuration file, log and pid files

View File

@ -15,6 +15,7 @@ template(name="outfmt" type="string" string="%msg%")
local4.* {
action(type="omhiredis"
name="omhiredis-stream-del"
server="127.0.0.1"
serverport="'$REDIS_RANDOM_PORT'"
mode="stream"
@ -48,20 +49,19 @@ redis_command "XLEN inStream" >> $RSYSLOG_OUT_LOG
# 4. show stream length -> should be 1
# 4.2. start Rsyslog and send message -> omhiredis deletes index 1-0 on stream 'inStream'
# 5. show stream length again -> should be 0
export EXPECTED="/usr/bin/redis-cli
1-0
/usr/bin/redis-cli
export EXPECTED="1-0
inStream
1-0
key
value
/usr/bin/redis-cli
1
/usr/bin/redis-cli
0"
cmp_exact $RSYSLOG_OUT_LOG
content_check "omhiredis: no stream.outField set, using 'msg' as default " ${RSYSLOG_DYNNAME}.started
content_check "omhiredis[omhiredis-stream-del]: trying connect to '127.0.0.1'" ${RSYSLOG_DYNNAME}.started
stop_redis
# Removes generated configuration file, log and pid files

View File

@ -22,6 +22,7 @@ local4.* {
set $.redis!group = "myGroup";
set $.redis!index = "2-0";
action(type="omhiredis"
name="omhiredis-stream-dynack"
server="127.0.0.1"
serverport="'$REDIS_RANDOM_PORT'"
mode="stream"
@ -61,16 +62,12 @@ redis_command "XINFO GROUPS inputStream" >> $RSYSLOG_OUT_LOG
# 4. show group infos -> pending shows 1 pending entry
# 4.2. start Rsyslog and send message -> omhiredis acknowledges index 2-0 on group 'myGroup' for stream 'inputStream'
# 5. show group infos again -> pending now shows 0 pending entries
export EXPECTED="/usr/bin/redis-cli
OK
/usr/bin/redis-cli
export EXPECTED="OK
2-0
/usr/bin/redis-cli
inputStream
2-0
key
value
/usr/bin/redis-cli
name
myGroup
consumers
@ -83,7 +80,6 @@ entries-read
1
lag
0
/usr/bin/redis-cli
name
myGroup
consumers
@ -99,6 +95,9 @@ lag
cmp_exact $RSYSLOG_OUT_LOG
content_check "omhiredis: no stream.outField set, using 'msg' as default" ${RSYSLOG_DYNNAME}.started
content_check "omhiredis[omhiredis-stream-dynack]: trying connect to '127.0.0.1'" ${RSYSLOG_DYNNAME}.started
stop_redis
# Removes generated configuration file, log and pid files

View File

@ -15,6 +15,7 @@ template(name="outfmt" type="string" string="%msg%")
local4.* {
action(type="omhiredis"
name="omhiredis-stream-outfield"
server="127.0.0.1"
serverport="'$REDIS_RANDOM_PORT'"
mode="stream"
@ -49,6 +50,8 @@ content_count_check "custom_field" 2 $RSYSLOG_OUT_LOG
content_count_check "msg" 2 $RSYSLOG_OUT_LOG
content_count_check "msgnum" 2 $RSYSLOG_OUT_LOG
content_check "omhiredis[omhiredis-stream-outfield]: trying connect to '127.0.0.1'" ${RSYSLOG_DYNNAME}.started
stop_redis
# Removes generated configuration file, log and pid files

View File

@ -15,6 +15,7 @@ template(name="outfmt" type="string" string="%msg%")
local4.* {
action(type="omhiredis"
name="omhiredis-stream"
server="127.0.0.1"
serverport="'$REDIS_RANDOM_PORT'"
mode="stream"
@ -55,6 +56,9 @@ content_count_check " msgnum:00000002:" 1 $RSYSLOG_OUT_LOG
content_count_check "msg" 4 $RSYSLOG_OUT_LOG
content_count_check "msgnum" 2 $RSYSLOG_OUT_LOG
content_check "omhiredis: no stream.outField set, using 'msg' as default" ${RSYSLOG_DYNNAME}.started
content_check "omhiredis[omhiredis-stream]: trying connect to '127.0.0.1'" ${RSYSLOG_DYNNAME}.started
stop_redis
# Removes generated configuration file, log and pid files

View File

@ -16,6 +16,7 @@ template(name="redis_command" type="string" string="INCRBY counter 3")
local4.* {
action(type="omhiredis"
name="omhiredis-template"
server="127.0.0.1"
serverport="'$REDIS_RANDOM_PORT'"
mode="template"
@ -26,14 +27,17 @@ local4.* {
action(type="omfile" file="'$RSYSLOG_DYNNAME.othermsg'" template="outfmt")
'
# Should get nothing
redis_command "GET counter" > $RSYSLOG_OUT_LOG
# Should get 'none'
redis_command "TYPE counter" > $RSYSLOG_OUT_LOG
startup
# Inject 3 messages
injectmsg 1 3
# Should get 'string'
redis_command "TYPE counter" >> $RSYSLOG_OUT_LOG
shutdown_when_empty
wait_shutdown
@ -41,13 +45,14 @@ wait_shutdown
redis_command "GET counter" >> $RSYSLOG_OUT_LOG
# The first get is before inserting, the second is after
export EXPECTED="/usr/bin/redis-cli
/usr/bin/redis-cli
export EXPECTED="none
string
9"
cmp_exact $RSYSLOG_OUT_LOG
content_check "omhiredis[omhiredis-template]: trying connect to '127.0.0.1'" ${RSYSLOG_DYNNAME}.started
stop_redis
# Removes generated configuration file, log and pid files

View File

@ -19,6 +19,7 @@ template(name="outfmt" type="string" string="%msg%")
local4.* {
action(type="omhiredis"
name="omhiredis-withpass"
server="127.0.0.1"
serverport="'$REDIS_RANDOM_PORT'"
serverpassword="'${REDIS_PASSWORD}'"
@ -32,7 +33,7 @@ action(type="omfile" file="'$RSYSLOG_DYNNAME.othermsg'" template="outfmt")
'
# Client MUST authentiate here!
redis_command "AUTH ${REDIS_PASSWORD} \n GET outKey" > $RSYSLOG_OUT_LOG
redis_command "AUTH ${REDIS_PASSWORD} \n TYPE outKey" > $RSYSLOG_OUT_LOG
startup
@ -46,15 +47,15 @@ wait_shutdown
redis_command "AUTH ${REDIS_PASSWORD} \n GET outKey" >> $RSYSLOG_OUT_LOG
# the "OK" replies are for authentication of the redis cli client
export EXPECTED="/usr/bin/redis-cli
OK
/usr/bin/redis-cli
export EXPECTED="OK
none
OK
msgnum:00000001:"
cmp_exact $RSYSLOG_OUT_LOG
content_check "omhiredis[omhiredis-withpass]: trying connect to '127.0.0.1'" ${RSYSLOG_DYNNAME}.started
stop_redis
# Removes generated configuration file, log and pid files

View File

@ -19,6 +19,7 @@ template(name="outfmt" type="string" string="%msg%")
local4.* {
action(type="omhiredis"
name="omhiredis-wrongpass"
server="127.0.0.1"
serverport="'$REDIS_RANDOM_PORT'"
serverpassword="ThatsNotMyPassword"
@ -27,8 +28,6 @@ local4.* {
template="outfmt")
stop
}
action(type="omfile" file="'$RSYSLOG_OUT_LOG'" template="outfmt")
'
startup
@ -39,7 +38,9 @@ injectmsg 1 1
shutdown_when_empty
wait_shutdown
content_check "error while authenticating: WRONGPASS invalid username-password pair or user is disabled." $RSYSLOG_OUT_LOG
content_check "omhiredis[omhiredis-wrongpass]: trying connect to '127.0.0.1'" ${RSYSLOG_DYNNAME}.started
content_check "omhiredis[omhiredis-wrongpass]: error while authenticating: WRONGPASS invalid username-password pair or user is disabled." ${RSYSLOG_DYNNAME}.started
stop_redis