summaryrefslogtreecommitdiffstats
path: root/tests/imfile-logrotate-multiple.sh
blob: e63a308559e53b2f8a16a65e8d08a32a3d39e808 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
# This is part of the rsyslog testbench, licensed under ASL 2.0
. $srcdir/diag.sh check-inotify-only
. ${srcdir:=.}/diag.sh init
check_command_available logrotate

export IMFILEROTATES="10"
export TESTMESSAGES=10000
export TESTMESSAGESFULL=$((IMFILEROTATES * TESTMESSAGES-1))

generate_conf
add_conf '
global(
	workDirectory="'$RSYSLOG_DYNNAME'.spool"
	/* Filter out busy debug output */
	debug.whitelist="off"
	debug.files=["omfile.c", "queue.c", "rainerscript.c", "ratelimit.c", "ruleset.c", "main Q", "msg.c", "../action.c"]
	)

module(load="../plugins/imfile/.libs/imfile" mode="inotify")

input(type="imfile" File="./'$RSYSLOG_DYNNAME'.input"
	Tag="file:" Severity="error" Facility="local7" addMetadata="on")

$template outfmt,"%msg:F,58:2%\n"
if $msg contains "msgnum:" then
 action(
   type="omfile"
   file=`echo $RSYSLOG_OUT_LOG`
   template="outfmt"
 )
'

# Write logrotate config file
echo '"./'$RSYSLOG_DYNNAME'.input"
{
	create
	daily
	missingok
	rotate 14
	notifempty
	compress
	delaycompress
}' > $RSYSLOG_DYNNAME.logrotate


display_file() {
	printf '\nFILE %s content:\n' $1
	cat -n $1
}

startup

TESTMESSAGESSTART=0
for i in $(seq 1 $IMFILEROTATES);
do
	#printf 'PRESS ENTER TO CONTINUE\n'
	#read
	printf '\n\nNEW RUN:\n'

	./inputfilegen -m $TESTMESSAGES -i $TESTMESSAGESSTART > $RSYSLOG_DYNNAME.input

	ls -li $RSYSLOG_DYNNAME.input*
	echo ls ${RSYSLOG_DYNNAME}.spool:
	ls -li ${RSYSLOG_DYNNAME}.spool
	echo STATE FILE CONTENT:
	shopt -s extglob
	for filename in "$RSYSLOG_DYNNAME.spool"/imfile-state:*; do display_file $filename; done

	# Wait until testmessages are processed by imfile!
	msgcount=$((i * TESTMESSAGES-1))
	# echo "TESTMESSAGESSTART: $TESTMESSAGESSTART - TotalMsgCount: $msgcount"
	wait_file_lines $RSYSLOG_OUT_LOG $msgcount $RETRIES

	# Logrotate on logfile
	logrotate --state $RSYSLOG_DYNNAME.logrotate.state -f $RSYSLOG_DYNNAME.logrotate

	TESTMESSAGESSTART=$((TESTMESSAGESSTART+TESTMESSAGES))
done


shutdown_when_empty
wait_shutdown
seq_check 0 $TESTMESSAGESFULL
exit_test