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 7: Test the priorities....                                #
28f08c3bdfSopenharmony_ci#                                                                #
29f08c3bdfSopenharmony_ci#         o Add lowest prority level i.e debug level entry to    #
30f08c3bdfSopenharmony_ci#           configuration file.                                  #
31f08c3bdfSopenharmony_ci#           o For syslog-ng the priority is set to all           #
32f08c3bdfSopenharmony_ci#             because of the format of syslog-ng.conf            #
33f08c3bdfSopenharmony_ci#             The format of the tests is the same, all levels of #
34f08c3bdfSopenharmony_ci#             debug and above are logged                         #
35f08c3bdfSopenharmony_ci#         o Send syslog messages at all levels and see whether   #
36f08c3bdfSopenharmony_ci#           higher level messages are logged.                    #
37f08c3bdfSopenharmony_ci##################################################################
38f08c3bdfSopenharmony_ci
39f08c3bdfSopenharmony_ci. syslog-lib.sh || exit 1
40f08c3bdfSopenharmony_ci
41f08c3bdfSopenharmony_cisyslog_case7()
42f08c3bdfSopenharmony_ci{
43f08c3bdfSopenharmony_ci	tst_resm TINFO "testing syslog priorities ..."
44f08c3bdfSopenharmony_ci
45f08c3bdfSopenharmony_ci	# Adds some clarification of log message when syslog-ng is used
46f08c3bdfSopenharmony_ci	if [ $CONFIG_FILE = /etc/syslog.conf ]; then
47f08c3bdfSopenharmony_ci		explanation="Higher"
48f08c3bdfSopenharmony_ci	else
49f08c3bdfSopenharmony_ci		explanation="All"
50f08c3bdfSopenharmony_ci	fi
51f08c3bdfSopenharmony_ci
52f08c3bdfSopenharmony_ci	tst_resm TINFO " o Send syslog messages at all levels and see whether"
53f08c3bdfSopenharmony_ci	tst_resm TINFO "   $explanation level messages are logged."
54f08c3bdfSopenharmony_ci
55f08c3bdfSopenharmony_ci	# Create the configuration file specific to this test case.
56f08c3bdfSopenharmony_ci	case "$CONFIG_FILE" in
57f08c3bdfSopenharmony_ci	/etc/syslog.conf|/etc/rsyslog.conf)
58f08c3bdfSopenharmony_ci	        echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
59f08c3bdfSopenharmony_ci	        echo "user.debug /var/log/messages" >> $CONFIG_FILE
60f08c3bdfSopenharmony_ci		;;
61f08c3bdfSopenharmony_ci
62f08c3bdfSopenharmony_ci	/etc/syslog-ng/syslog-ng.conf)
63f08c3bdfSopenharmony_ci		echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
64f08c3bdfSopenharmony_ci		echo " " >> $CONFIG_FILE
65f08c3bdfSopenharmony_ci		echo " " >> $CONFIG_FILE
66f08c3bdfSopenharmony_ci		echo "# Added for syslog testcase" >> $CONFIG_FILE
67f08c3bdfSopenharmony_ci		echo "filter f_syslog_messages {facility(user); };" >> $CONFIG_FILE
68f08c3bdfSopenharmony_ci		echo "destination syslog-messages { file(\"/var/log/messages\");};" >> $CONFIG_FILE
69f08c3bdfSopenharmony_ci		echo "log { source(src); filter(f_syslog_messages); destination(syslog-messages); };" >> $CONFIG_FILE
70f08c3bdfSopenharmony_ci		;;
71f08c3bdfSopenharmony_ci	esac
72f08c3bdfSopenharmony_ci
73f08c3bdfSopenharmony_ci	restart_syslog_daemon
74f08c3bdfSopenharmony_ci
75f08c3bdfSopenharmony_ci	if [ -e /var/log/messages ]; then
76f08c3bdfSopenharmony_ci		emerg_old=`grep -c "syslogtst: emergency log" /var/log/messages`
77f08c3bdfSopenharmony_ci		alert_old=`grep -c "syslogtst: alert log" /var/log/messages`
78f08c3bdfSopenharmony_ci		crit_old=`grep -c "syslogtst: critical log" /var/log/messages`
79f08c3bdfSopenharmony_ci		err_old=`grep -c "syslogtst: error log" /var/log/messages`
80f08c3bdfSopenharmony_ci		warning_old=`grep -c "syslogtst: warning log" /var/log/messages`
81f08c3bdfSopenharmony_ci		notice_old=`grep -c "syslogtst: notice log" /var/log/messages`
82f08c3bdfSopenharmony_ci		info_old=`grep -c "syslogtst: info log" /var/log/messages`
83f08c3bdfSopenharmony_ci		debug_old=`grep -c "syslogtst: debug log" /var/log/messages`
84f08c3bdfSopenharmony_ci	else
85f08c3bdfSopenharmony_ci		emerg_old=0
86f08c3bdfSopenharmony_ci		alert_old=0
87f08c3bdfSopenharmony_ci		crit_old=0
88f08c3bdfSopenharmony_ci		err_old=0
89f08c3bdfSopenharmony_ci		notice_old=0
90f08c3bdfSopenharmony_ci		warning_old=0
91f08c3bdfSopenharmony_ci		notice_old=0
92f08c3bdfSopenharmony_ci		info_old=0
93f08c3bdfSopenharmony_ci		debug_old=0
94f08c3bdfSopenharmony_ci	fi
95f08c3bdfSopenharmony_ci
96f08c3bdfSopenharmony_ci	# Call syslogtst. It will send the messages of all levels.
97f08c3bdfSopenharmony_ci	if ! syslogtst 7 2>/dev/null; then
98f08c3bdfSopenharmony_ci		cleanup 1
99f08c3bdfSopenharmony_ci	fi
100f08c3bdfSopenharmony_ci	sleep 2
101f08c3bdfSopenharmony_ci
102f08c3bdfSopenharmony_ci	emerg_new=`grep -c "syslogtst: emergency log" /var/log/messages`
103f08c3bdfSopenharmony_ci	alert_new=`grep -c "syslogtst: alert log" /var/log/messages`
104f08c3bdfSopenharmony_ci	crit_new=`grep -c "syslogtst: critical log" /var/log/messages`
105f08c3bdfSopenharmony_ci	err_new=`grep -c "syslogtst: error log" /var/log/messages`
106f08c3bdfSopenharmony_ci	warning_new=`grep -c "syslogtst: warning log" /var/log/messages`
107f08c3bdfSopenharmony_ci	notice_new=`grep -c "syslogtst: notice log" /var/log/messages`
108f08c3bdfSopenharmony_ci	info_new=`grep -c "syslogtst: info log" /var/log/messages`
109f08c3bdfSopenharmony_ci	debug_new=`grep -c "syslogtst: debug log" /var/log/messages`
110f08c3bdfSopenharmony_ci
111f08c3bdfSopenharmony_ci	emerg=$(( $emerg_new - $emerg_old ))
112f08c3bdfSopenharmony_ci	alert=$(( $alert_new - $alert_old ))
113f08c3bdfSopenharmony_ci	crit=$(( $crit_new - $crit_old ))
114f08c3bdfSopenharmony_ci	err=$(( $err_new - $err_old ))
115f08c3bdfSopenharmony_ci	warning=$(( $warning_new - $warning_old ))
116f08c3bdfSopenharmony_ci	notice=$(( $notice_new - $notice_old ))
117f08c3bdfSopenharmony_ci	info=$(( $info_new - $info_old ))
118f08c3bdfSopenharmony_ci
119f08c3bdfSopenharmony_ci	if [ $emerg -ne 1 -o $alert -ne 1 -o $crit -ne 1 -o $err -ne 1 -o \
120f08c3bdfSopenharmony_ci	     $warning -ne 1 -o $notice -ne 1 -o $info -ne 1 -o \
121f08c3bdfSopenharmony_ci	     $info -ne 1 ]; then
122f08c3bdfSopenharmony_ci		status_flag=1
123f08c3bdfSopenharmony_ci	fi
124f08c3bdfSopenharmony_ci}
125f08c3bdfSopenharmony_ci
126f08c3bdfSopenharmony_cisetup
127f08c3bdfSopenharmony_cisyslog_case7
128f08c3bdfSopenharmony_cicleanup ${status_flag:=0}
129