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