• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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#  02/05/03  Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
20#			fixed bugs.
21#  07/26/05  Michael Reed  <mreedltp@vnet.ibm.com>
22#			Made changes to account for the replacement of syslogd
23#			with syslog-ng
24#
25##################################################################
26# case1: Test whether messages are logged to the specified file  #
27# in the configuration file.					 #
28#								 #
29# Send messages to syslogd at some level and facility	 	 #
30# and grep for those messages.					 #
31#								 #
32# syslog.conf should contain:					 #
33# *.crit		/usr/adm/critical			 #
34# mail.info		/usr/spool/adm/syslog			 #
35##################################################################
36
37. syslog-lib.sh || exit 1
38
39syslog_case1()
40{
41	tst_resm TINFO "testing whether messages are logged into log file"
42
43	# Create the configuration file specific to this test case.
44
45	case "$CONFIG_FILE" in
46	/etc/syslog.conf|/etc/rsyslog.conf)
47		echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
48		echo "*.crit		/var/log/messages" >> $CONFIG_FILE
49		echo "mail.info	$MAILLOG" >> $CONFIG_FILE
50		;;
51
52	/etc/syslog-ng/syslog-ng.conf)
53		echo "source src{ internal(); unix-dgram(\"/dev/log\"); \
54		      udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
55		echo " " >> $CONFIG_FILE
56		echo " " >> $CONFIG_FILE
57		echo "# Added for syslog testcase"  >> $CONFIG_FILE
58		echo "filter f_syslog	 { level(crit);};" >> $CONFIG_FILE
59		echo "filter f_syslogMail { level(info)	and facility(mail); };" >> $CONFIG_FILE
60		echo "destination syslog-messages { file(\"/var/log/messages\");};" >> $CONFIG_FILE
61		echo "log { source(src); filter(f_syslog); destination(syslog-messages); };" >> $CONFIG_FILE
62		echo "destination syslog-mail { file(\"$MAILLOG\");};" >> $CONFIG_FILE
63		echo "log { source(src); filter(f_syslogMail); destination(syslog-mail); };"  >> $CONFIG_FILE
64		;;
65	esac
66
67	restart_syslog_daemon
68
69	# Grepping pattern has to be changed whenever the executable name
70	# changes, ex: syslogtst executable.
71	# This check is neccessary for syslog-ng because $MAILLOG is
72	# only created after syslogtst
73	if [ -e "$MAILLOG" ]; then
74		oldvalue1=`grep -c "syslogtst: mail info test" $MAILLOG`
75	else
76		oldvalue1=0
77	fi
78
79	# Call syslogtst executable with case number as argument
80	if syslogtst 1 2>/dev/null; then
81
82		sleep 2
83
84		if [ ! -e $MAILLOG ]; then
85			tst_resm TBROK "$MAILLOG no such log file"
86			cleanup 1
87		fi
88
89		newvalue1=`grep -c "syslogtst: mail info test" $MAILLOG`
90		if [ "x$(( $newvalue1 - $oldvalue1 ))" != "x1" ]; then
91			status_flag=1
92		fi
93	else
94		status_flag=1
95	fi
96
97}
98
99export TST_TOTAL=1
100export TST_COUNT=1
101export TCID=syslog01
102
103tst_resm TINFO "Send messages to syslogd at some level "
104tst_resm TINFO "and facility and grep for those messages."
105
106setup
107syslog_case1
108cleanup ${status_flag:=0}
109