1f08c3bdfSopenharmony_ci#! /bin/sh
2f08c3bdfSopenharmony_ci
3f08c3bdfSopenharmony_ci#  Copyright (c) International Business Machines  Corp., 2002
4f08c3bdfSopenharmony_ci#
5f08c3bdfSopenharmony_ci#  This program is free software;  you can redistribute it and/or modify
6f08c3bdfSopenharmony_ci#  it under the terms of the GNU General Public License as published by
7f08c3bdfSopenharmony_ci#  the Free Software Foundation; either version 2 of the License, or
8f08c3bdfSopenharmony_ci#  (at your option) any later version.
9f08c3bdfSopenharmony_ci#
10f08c3bdfSopenharmony_ci#  This program is distributed in the hope that it will be useful,
11f08c3bdfSopenharmony_ci#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
12f08c3bdfSopenharmony_ci#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13f08c3bdfSopenharmony_ci#  the GNU General Public License for more details.
14f08c3bdfSopenharmony_ci#
15f08c3bdfSopenharmony_ci#  You should have received a copy of the GNU General Public License
16f08c3bdfSopenharmony_ci#  along with this program;  if not, write to the Free Software
17f08c3bdfSopenharmony_ci#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18f08c3bdfSopenharmony_ci
19f08c3bdfSopenharmony_ci# 12/05/02  Port to bash -Robbie Williamson <robbiew@us.ibm.com>
20f08c3bdfSopenharmony_ci# 02/05/03  Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
21f08c3bdfSopenharmony_ci#		   fixed bugs.
22f08c3bdfSopenharmony_ci# 07/26/05  Michael Reed  <mreedltp@vnet.ibm.com>
23f08c3bdfSopenharmony_ci#		   Made changes to account for the replacement of syslogd
24f08c3bdfSopenharmony_ci#		   with syslog-ng
25f08c3bdfSopenharmony_ci#
26f08c3bdfSopenharmony_ci##################################################################
27f08c3bdfSopenharmony_ci# case 8: Test all the facilities at a particular level.	 #
28f08c3bdfSopenharmony_ci#								 #
29f08c3bdfSopenharmony_ci# Facilities available are: LOG_KERN, LOG_USER, LOG_MAIL	 #
30f08c3bdfSopenharmony_ci# LOG_DAEMON, LOG_AUTH, LOG_LPR.				 #
31f08c3bdfSopenharmony_ci# Don't know how to send kernel messages from syslog()   	 #
32f08c3bdfSopenharmony_ci#								 #
33f08c3bdfSopenharmony_ci# o Create seperate entries in config file for each facility.	 #
34f08c3bdfSopenharmony_ci# o Send the message and grep for the entry in log file.	 #
35f08c3bdfSopenharmony_ci##################################################################
36f08c3bdfSopenharmony_ci
37f08c3bdfSopenharmony_ci. syslog-lib.sh || exit 1
38f08c3bdfSopenharmony_ci
39f08c3bdfSopenharmony_cisyslog_case8()
40f08c3bdfSopenharmony_ci{
41f08c3bdfSopenharmony_ci	local facility_no=1
42f08c3bdfSopenharmony_ci	local facilities="user mail daemon auth lpr"
43f08c3bdfSopenharmony_ci
44f08c3bdfSopenharmony_ci	tst_resm TINFO "testing all the facilities"
45f08c3bdfSopenharmony_ci
46f08c3bdfSopenharmony_ci	for facility in $facilities; do
47f08c3bdfSopenharmony_ci
48f08c3bdfSopenharmony_ci		tst_resm TINFO "Doing facility: $facility..."
49f08c3bdfSopenharmony_ci
50f08c3bdfSopenharmony_ci		# Create the configuration file specific to this facility
51f08c3bdfSopenharmony_ci		# Level is fixed at info.
52f08c3bdfSopenharmony_ci		case "$CONFIG_FILE" in
53f08c3bdfSopenharmony_ci		/etc/syslog.conf|/etc/rsyslog.conf)
54f08c3bdfSopenharmony_ci			echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
55f08c3bdfSopenharmony_ci			echo "$facility.info	/var/log/messages" >> $CONFIG_FILE
56f08c3bdfSopenharmony_ci			echo "$facility.info	/var/log/maillog" >> $CONFIG_FILE
57f08c3bdfSopenharmony_ci			;;
58f08c3bdfSopenharmony_ci
59f08c3bdfSopenharmony_ci		/etc/syslog-ng/syslog-ng.conf)
60f08c3bdfSopenharmony_ci			echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
61f08c3bdfSopenharmony_ci			echo "filter f_syslog-$facility { level(info) and facility($facility); };" >> $CONFIG_FILE
62f08c3bdfSopenharmony_ci			echo "destination syslog-messages { file(\"/var/log/messages\"); };" >> $CONFIG_FILE
63f08c3bdfSopenharmony_ci			echo "destination syslog-mail { file(\"/var/log/maillog\");};" >> $CONFIG_FILE
64f08c3bdfSopenharmony_ci			echo "log { source(src); filter(f_syslog-$facility); destination(syslog-mail); };"  >> $CONFIG_FILE
65f08c3bdfSopenharmony_ci			echo "log { source(src); filter(f_syslog-$facility); destination(syslog-messages); };"  >> $CONFIG_FILE
66f08c3bdfSopenharmony_ci			;;
67f08c3bdfSopenharmony_ci
68f08c3bdfSopenharmony_ci		esac
69f08c3bdfSopenharmony_ci
70f08c3bdfSopenharmony_ci		restart_syslog_daemon
71f08c3bdfSopenharmony_ci
72f08c3bdfSopenharmony_ci		if [ -e /var/log/messages ]; then
73f08c3bdfSopenharmony_ci			oldvalue=`grep -c "syslogtst: $facility info test." /var/log/messages`
74f08c3bdfSopenharmony_ci		else
75f08c3bdfSopenharmony_ci			oldvalue=0
76f08c3bdfSopenharmony_ci		fi
77f08c3bdfSopenharmony_ci
78f08c3bdfSopenharmony_ci		if [ -e /var/log/maillog ]; then
79f08c3bdfSopenharmony_ci			old_mail_check=`grep -c "syslogtst: $facility info test." /var/log/maillog`
80f08c3bdfSopenharmony_ci		else
81f08c3bdfSopenharmony_ci			old_mail_check=0
82f08c3bdfSopenharmony_ci		fi
83f08c3bdfSopenharmony_ci
84f08c3bdfSopenharmony_ci		# syslogtst has to be called with one more
85f08c3bdfSopenharmony_ci				# additional facility argument(1-6)
86f08c3bdfSopenharmony_ci		if ! syslogtst 8 $facility_no 2>/dev/null; then
87f08c3bdfSopenharmony_ci			status_flag=1
88f08c3bdfSopenharmony_ci			return
89f08c3bdfSopenharmony_ci		fi
90f08c3bdfSopenharmony_ci		sleep 2
91f08c3bdfSopenharmony_ci		# check if /var/log/maillog script exists
92f08c3bdfSopenharmony_ci		for logf in messages maillog
93f08c3bdfSopenharmony_ci		do
94f08c3bdfSopenharmony_ci			if [ ! -e /var/log/$logf ]; then
95f08c3bdfSopenharmony_ci				tst_resm TBROK "/var/log/$logf no such log file"
96f08c3bdfSopenharmony_ci				cleanup 1
97f08c3bdfSopenharmony_ci			fi
98f08c3bdfSopenharmony_ci		done
99f08c3bdfSopenharmony_ci
100f08c3bdfSopenharmony_ci		new_mail_check=`grep -c "syslogtst: $facility info test." /var/log/maillog`
101f08c3bdfSopenharmony_ci		newvalue=`grep -c "syslogtst: $facility info test." /var/log/messages`
102f08c3bdfSopenharmony_ci		diff=$(( $newvalue - $oldvalue ))
103f08c3bdfSopenharmony_ci		mail_check=$(( $new_mail_check - $old_mail_check ))
104f08c3bdfSopenharmony_ci
105f08c3bdfSopenharmony_ci		if [ $facility = "mail" ]; then
106f08c3bdfSopenharmony_ci			if [ $mail_check -ne 1 ]; then
107f08c3bdfSopenharmony_ci				tst_resm TFAIL " Facility $facility failed"
108f08c3bdfSopenharmony_ci				status_flag=1
109f08c3bdfSopenharmony_ci			elif [ $mail_check -eq 1 ]; then
110f08c3bdfSopenharmony_ci				tst_resm TPASS " Facility $facility passed"
111f08c3bdfSopenharmony_ci			fi
112f08c3bdfSopenharmony_ci		elif [ $diff -ne 1 ]; then
113f08c3bdfSopenharmony_ci			tst_resm TFAIL " Facility $facility failed"
114f08c3bdfSopenharmony_ci			status_flag=1
115f08c3bdfSopenharmony_ci		else
116f08c3bdfSopenharmony_ci			tst_resm TPASS " Facility $facility passed"
117f08c3bdfSopenharmony_ci		fi
118f08c3bdfSopenharmony_ci		# Increment the facility_no for next...
119f08c3bdfSopenharmony_ci		: $(( facility_no += 1 ))
120f08c3bdfSopenharmony_ci	done
121f08c3bdfSopenharmony_ci}
122f08c3bdfSopenharmony_ci
123f08c3bdfSopenharmony_citst_resm TINFO " Test all the facilities at a particular level."
124f08c3bdfSopenharmony_citst_resm TINFO " Facilities available are: LOG_KERN, LOG_USER, LOG_MAIL"
125f08c3bdfSopenharmony_citst_resm TINFO " LOG_DAEMON, LOG_AUTH, LOG_LPR."
126f08c3bdfSopenharmony_citst_resm TINFO " Don't know how to send kernel messages from syslog()"
127f08c3bdfSopenharmony_citst_resm TINFO " o Create seperate entries in config file for each facility."
128f08c3bdfSopenharmony_citst_resm TINFO " o Send the message and grep for the entry in log file."
129f08c3bdfSopenharmony_ci
130f08c3bdfSopenharmony_cisetup
131f08c3bdfSopenharmony_cisyslog_case8
132f08c3bdfSopenharmony_cicleanup ${status_flag:=0}
133