| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | # added 2023-04-20 by Théo Bertin, released under ASL 2.0 |
| 3 | ## Uncomment for debugging |
| 4 | # export RS_REDIR=-d |
| 5 | |
| 6 | . ${srcdir:=.}/diag.sh init |
| 7 | |
| 8 | start_redis |
| 9 | |
| 10 | generate_conf |
| 11 | add_conf ' |
| 12 | global(localhostname="server") |
| 13 | module(load="../contrib/omhiredis/.libs/omhiredis") |
| 14 | template(name="outfmt" type="string" string="%msg%") |
| 15 | |
| 16 | local4.* { |
| 17 | action(type="omhiredis" |
| 18 | name="omhiredis-stream-outfield" |
| 19 | server="127.0.0.1" |
| 20 | serverport="'$REDIS_RANDOM_PORT'" |
| 21 | mode="stream" |
| 22 | key="outStream" |
| 23 | stream.outField="custom_field" |
| 24 | template="outfmt") |
| 25 | stop |
| 26 | } |
| 27 | |
| 28 | action(type="omfile" file="'$RSYSLOG_DYNNAME.othermsg'" template="outfmt") |
| 29 | ' |
| 30 | |
| 31 | startup |
| 32 | |
| 33 | # Inject 2 messages |
| 34 | injectmsg 1 2 |
| 35 | |
| 36 | shutdown_when_empty |
| 37 | wait_shutdown |
| 38 | |
| 39 | # Should get '2' |
| 40 | redis_command "XLEN outStream" >> $RSYSLOG_OUT_LOG |
| 41 | # Should get 2 entries |
| 42 | redis_command "XREAD COUNT 3 STREAMS outStream 0" >> $RSYSLOG_OUT_LOG |
| 43 | |
| 44 | # Cannot check for full reply as it includes entries' unix timestamp |
| 45 | content_count_check "outStream" 1 $RSYSLOG_OUT_LOG |
| 46 | content_count_check " msgnum:00000001:" 1 $RSYSLOG_OUT_LOG |
| 47 | content_count_check " msgnum:00000002:" 1 $RSYSLOG_OUT_LOG |
| 48 | # 2 data should be inserted in the 'custom_field' field inside every message |
| 49 | content_count_check "custom_field" 2 $RSYSLOG_OUT_LOG |
| 50 | content_count_check "msg" 2 $RSYSLOG_OUT_LOG |
| 51 | content_count_check "msgnum" 2 $RSYSLOG_OUT_LOG |
| 52 | |
| 53 | content_check "omhiredis[omhiredis-stream-outfield]: trying connect to '127.0.0.1'" ${RSYSLOG_DYNNAME}.started |
| 54 | |
| 55 | stop_redis |
| 56 | |
| 57 | # Removes generated configuration file, log and pid files |
| 58 | cleanup_redis |
| 59 | |
| 60 | exit_test |