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