mirror of
				https://github.com/mail-in-a-box/mailinabox.git
				synced 2025-11-03 19:30:54 +00:00 
			
		
		
		
	Prevent duplicate logging of mail-related output by configuring rsyslog to record only to mail.log and not also to syslog
This commit is contained in:
		
							parent
							
								
									72827f365d
								
							
						
					
					
						commit
						94f140d528
					
				@ -370,3 +370,13 @@ cp -f conf/fail2ban/filter.d/* /etc/fail2ban/filter.d/
 | 
				
			|||||||
# scripts will ensure the files exist and then fail2ban is given another
 | 
					# scripts will ensure the files exist and then fail2ban is given another
 | 
				
			||||||
# restart at the very end of setup.
 | 
					# restart at the very end of setup.
 | 
				
			||||||
restart_service fail2ban
 | 
					restart_service fail2ban
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ### Mail-related logs should be recorded in mail.log only - stop
 | 
				
			||||||
 | 
					# ### duplicate logging to syslog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cat >/etc/rsyslog.d/20-mailinabox.conf <<EOF
 | 
				
			||||||
 | 
					mail.*				-/var/log/mail.log
 | 
				
			||||||
 | 
					mail.err			/var/log/mail.err
 | 
				
			||||||
 | 
					mail.* stop
 | 
				
			||||||
 | 
					EOF
 | 
				
			||||||
 | 
					restart_service rsyslog
 | 
				
			||||||
 | 
				
			|||||||
@ -114,9 +114,7 @@ detect_syslog_error() {
 | 
				
			|||||||
		while read line; do
 | 
							while read line; do
 | 
				
			||||||
			# named[7940]: dispatch 0x7f460c02c3a0: shutting down due to TCP receive error: 199.249.112.1#53: connection reset
 | 
								# named[7940]: dispatch 0x7f460c02c3a0: shutting down due to TCP receive error: 199.249.112.1#53: connection reset
 | 
				
			||||||
			awk '
 | 
								awk '
 | 
				
			||||||
/status=(bounced|deferred|undeliverable)/  { exit 1 }
 | 
					!/nsd\[[0-9]+\]/ && /warning:/	{ exit 1 }
 | 
				
			||||||
/warning:/ && /spamhaus\.org: RBL lookup error:/ { exit 2 }
 | 
					 | 
				
			||||||
!/postfix\/qmgr/ && !/nsd\[[0-9]+\]/ && /warning:/	{ exit 1 }
 | 
					 | 
				
			||||||
/nsd\[[0-9]+\]: error: Cannot open .*nsd\.log/ { exit 2 }
 | 
					/nsd\[[0-9]+\]: error: Cannot open .*nsd\.log/ { exit 2 }
 | 
				
			||||||
/named\[[0-9]+\]:.* receive error: .*: connection reset/ { exit 2 }
 | 
					/named\[[0-9]+\]:.* receive error: .*: connection reset/ { exit 2 }
 | 
				
			||||||
/(fatal|reject|error):/	 { exit 1 }
 | 
					/(fatal|reject|error):/	 { exit 1 }
 | 
				
			||||||
@ -209,9 +207,9 @@ detect_slapd_log_error() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
detect_dovecot_log_error() {
 | 
					detect_mail_log_error() {
 | 
				
			||||||
	record
 | 
						record
 | 
				
			||||||
	record "[Detect dovecot log errors]"
 | 
						record "[Detect mail log errors]"
 | 
				
			||||||
	local count
 | 
						local count
 | 
				
			||||||
	let count="$MAIL_LOG_LINECOUNT + 1"
 | 
						let count="$MAIL_LOG_LINECOUNT + 1"
 | 
				
			||||||
	if [ ! -e /var/log/mail.log ]; then
 | 
						if [ ! -e /var/log/mail.log ]; then
 | 
				
			||||||
@ -225,10 +223,16 @@ detect_dovecot_log_error() {
 | 
				
			|||||||
		let ignored=0
 | 
							let ignored=0
 | 
				
			||||||
		while read line; do
 | 
							while read line; do
 | 
				
			||||||
			awk '
 | 
								awk '
 | 
				
			||||||
 | 
					/status=(bounced|deferred|undeliverable)/  { exit 1 }
 | 
				
			||||||
 | 
					/warning:/ && /spamhaus\.org: RBL lookup error:/ { exit 2 }
 | 
				
			||||||
 | 
					!/postfix\/qmgr/ && /warning:/	{ exit 1 }
 | 
				
			||||||
/LDAP server, reconnecting/ { exit 2 }
 | 
					/LDAP server, reconnecting/ { exit 2 }
 | 
				
			||||||
/postfix/ { exit 2 }
 | 
					/postfix/ { exit 2 }
 | 
				
			||||||
/auth failed/  { exit 1 }
 | 
					/auth failed/  { exit 1 }
 | 
				
			||||||
/ Error: /			  { exit 1 }
 | 
					/ Error: /			  { exit 1 }
 | 
				
			||||||
 | 
					/(fatal|reject|error):/	 { exit 1 }
 | 
				
			||||||
 | 
					/Error in /			{ exit 1 }
 | 
				
			||||||
 | 
					/Exception on /     { exit 1 }
 | 
				
			||||||
' \
 | 
					' \
 | 
				
			||||||
				>>$TEST_OF 2>&1 <<< "$line"
 | 
									>>$TEST_OF 2>&1 <<< "$line"
 | 
				
			||||||
			r=$?
 | 
								r=$?
 | 
				
			||||||
@ -281,8 +285,8 @@ check_logs() {
 | 
				
			|||||||
	fi
 | 
						fi
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	if array_contains mail ${types[@]}; then
 | 
						if array_contains mail ${types[@]}; then
 | 
				
			||||||
		detect_dovecot_log_error && $assert &&
 | 
							detect_mail_log_error && $assert &&
 | 
				
			||||||
			test_failure "detected errors in dovecot log"
 | 
								test_failure "detected errors in mail log"
 | 
				
			||||||
	fi
 | 
						fi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -293,8 +297,8 @@ assert_check_logs() {
 | 
				
			|||||||
grep_postfix_log() {
 | 
					grep_postfix_log() {
 | 
				
			||||||
	local msg="$1"
 | 
						local msg="$1"
 | 
				
			||||||
	local count
 | 
						local count
 | 
				
			||||||
	let count="$SYS_LOG_LINECOUNT + 1"
 | 
						let count="$MAIL_LOG_LINECOUNT + 1"
 | 
				
			||||||
	tail --lines=+$count /var/log/syslog 2>>$TEST_OF | grep -iF "$msg" >/dev/null 2>>$TEST_OF
 | 
						tail --lines=+$count /var/log/mail.log 2>>$TEST_OF | grep -iF "$msg" >/dev/null 2>>$TEST_OF
 | 
				
			||||||
	return $?
 | 
						return $?
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -328,6 +328,7 @@ EOF
 | 
				
			|||||||
			# ok
 | 
								# ok
 | 
				
			||||||
			check_logs
 | 
								check_logs
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
 | 
								test_failure "Expected postfix/lmtp to report 'User doesn't exist'"
 | 
				
			||||||
			assert_check_logs
 | 
								assert_check_logs
 | 
				
			||||||
		fi
 | 
							fi
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user