1#! /bin/sh
2
3#  Copyright (c) International Business Machines  Corp., 2002
4#
5#  This program is free software;  you can redistribute it and/or modify
6#  it under the terms of the GNU General Public License as published by
7#  the Free Software Foundation; either version 2 of the License, or
8#  (at your option) any later version.
9#
10#  This program is distributed in the hope that it will be useful,
11#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
12#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13#  the GNU General Public License for more details.
14#
15#  You should have received a copy of the GNU General Public License
16#  along with this program;  if not, write to the Free Software
17#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19# 12/05/02  Port to bash -Robbie Williamson <robbiew@us.ibm.com>
20# 02/05/03  Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
21#		   fixed bugs.
22# 07/26/05  Michael Reed  <mreedltp@vnet.ibm.com>
23#		   Made changes to account for the replacement of syslogd
24#		   with syslog-ng
25#
26##################################################################
27# case2: Test if messages of all levels are logged.
28#	For each level, a separate configuration file is
29#	created and that will be used as syslog.conf file.
30##################################################################
31
32# Number of levels.
33export TST_TOTAL=8
34
35. syslog-lib.sh || exit 1
36
37syslog_case2()
38{
39	level_no=0
40	levels="emerg alert crit err warning notice info debug"
41	tst_resm TINFO "testing whether messages are logged into log file"
42
43	for level in $levels
44	do
45		tst_resm TINFO "Doing level: $level..."
46
47		case "$CONFIG_FILE" in
48		/etc/syslog.conf)
49			# Create the configuration file specific to this level
50			echo "mail.$level	$MAILLOG" >> $CONFIG_FILE
51			;;
52
53		/etc/rsyslog.conf)
54			# Create the configuration file specific to this level
55			echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
56			echo "mail.$level	$MAILLOG" >> $CONFIG_FILE
57			;;
58
59		/etc/syslog-ng/syslog-ng.conf)
60			echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
61			echo "filter f_syslog_$level { level($level) and facility(mail); };"  >> $CONFIG_FILE
62			echo "destination syslog-$level { file(\"$MAILLOG\"); };"  >> $CONFIG_FILE
63			echo "log { source(src); filter(f_syslog_$level); destination(syslog-$level); };"  >> $CONFIG_FILE;;
64		esac
65
66		restart_syslog_daemon
67
68		# Grepping pattern has to be changed whenever the executable name
69		# changes, ex: syslogtst executable.
70		# This check is neccessary for syslog-ng because $MAILLOG is
71		# only created after syslogtst
72		if [ -e "$MAILLOG" ]; then
73			oldvalue=`grep -c "syslogtst: mail $level test\." $MAILLOG`
74		else
75			oldvalue=0
76		fi
77
78		# syslogtst has to be called with additional level argument(0-7)
79		if ! syslogtst 2 $level_no 2>/dev/null; then
80			cleanup 1
81		fi
82		sleep 2
83
84		# check if $MAILLOG script exists
85		if [ ! -e "$MAILLOG" ]; then
86			tst_resm TBROK "$MAILLOG no such log file"
87			cleanup 1
88		fi
89
90		newvalue=`grep -c "syslogtst: mail $level test" $MAILLOG`
91		diff=$(( $newvalue - $oldvalue ))
92		if [ $diff -eq 0 ]; then
93			tst_resm TFAIL "***** Level $level failed *****"
94			status_flag=1
95		elif [ $diff -ge 1 ]; then
96			tst_resm TPASS "***** Level $level passed *****"
97		fi
98		# Increment the level_no for next level...
99		: $(( level_no += 1 ))
100
101		incr_tst_count
102	done
103}
104
105tst_resm TINFO "Test if messages of all levels are logged."
106tst_resm TINFO "For each level, a separate configuration file is"
107tst_resm TINFO "created and that will be used as syslog.conf file."
108
109setup
110syslog_case2
111cleanup ${status_flag:=0}
112