syslog07 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #! /bin/sh
  2. # Copyright (c) International Business Machines Corp., 2002
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  12. # the GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. # 12/05/02 Port to bash -Robbie Williamson <robbiew@us.ibm.com>
  18. # 02/05/03 Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
  19. # fixed bugs.
  20. # 07/26/05 Michael Reed <mreedltp@vnet.ibm.com>
  21. # Made changes to account for the replacement of syslogd
  22. # with syslog-ng
  23. #
  24. ##################################################################
  25. # case 7: Test the priorities.... #
  26. # #
  27. # o Add lowest prority level i.e debug level entry to #
  28. # configuration file. #
  29. # o For syslog-ng the priority is set to all #
  30. # because of the format of syslog-ng.conf #
  31. # The format of the tests is the same, all levels of #
  32. # debug and above are logged #
  33. # o Send syslog messages at all levels and see whether #
  34. # higher level messages are logged. #
  35. ##################################################################
  36. . syslog-lib.sh || exit 1
  37. syslog_case7()
  38. {
  39. tst_resm TINFO "testing syslog priorities ..."
  40. # Adds some clarification of log message when syslog-ng is used
  41. if [ $CONFIG_FILE = /etc/syslog.conf ]; then
  42. explanation="Higher"
  43. else
  44. explanation="All"
  45. fi
  46. tst_resm TINFO " o Send syslog messages at all levels and see whether"
  47. tst_resm TINFO " $explanation level messages are logged."
  48. # Create the configuration file specific to this test case.
  49. case "$CONFIG_FILE" in
  50. /etc/syslog.conf|/etc/rsyslog.conf)
  51. echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
  52. echo "user.debug /var/log/messages" >> $CONFIG_FILE
  53. ;;
  54. /etc/syslog-ng/syslog-ng.conf)
  55. echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
  56. echo " " >> $CONFIG_FILE
  57. echo " " >> $CONFIG_FILE
  58. echo "# Added for syslog testcase" >> $CONFIG_FILE
  59. echo "filter f_syslog_messages {facility(user); };" >> $CONFIG_FILE
  60. echo "destination syslog-messages { file(\"/var/log/messages\");};" >> $CONFIG_FILE
  61. echo "log { source(src); filter(f_syslog_messages); destination(syslog-messages); };" >> $CONFIG_FILE
  62. ;;
  63. esac
  64. restart_syslog_daemon
  65. if [ -e /var/log/messages ]; then
  66. emerg_old=`grep -c "syslogtst: emergency log" /var/log/messages`
  67. alert_old=`grep -c "syslogtst: alert log" /var/log/messages`
  68. crit_old=`grep -c "syslogtst: critical log" /var/log/messages`
  69. err_old=`grep -c "syslogtst: error log" /var/log/messages`
  70. warning_old=`grep -c "syslogtst: warning log" /var/log/messages`
  71. notice_old=`grep -c "syslogtst: notice log" /var/log/messages`
  72. info_old=`grep -c "syslogtst: info log" /var/log/messages`
  73. debug_old=`grep -c "syslogtst: debug log" /var/log/messages`
  74. else
  75. emerg_old=0
  76. alert_old=0
  77. crit_old=0
  78. err_old=0
  79. notice_old=0
  80. warning_old=0
  81. notice_old=0
  82. info_old=0
  83. debug_old=0
  84. fi
  85. # Call syslogtst. It will send the messages of all levels.
  86. if ! syslogtst 7 2>/dev/null; then
  87. cleanup 1
  88. fi
  89. sleep 2
  90. emerg_new=`grep -c "syslogtst: emergency log" /var/log/messages`
  91. alert_new=`grep -c "syslogtst: alert log" /var/log/messages`
  92. crit_new=`grep -c "syslogtst: critical log" /var/log/messages`
  93. err_new=`grep -c "syslogtst: error log" /var/log/messages`
  94. warning_new=`grep -c "syslogtst: warning log" /var/log/messages`
  95. notice_new=`grep -c "syslogtst: notice log" /var/log/messages`
  96. info_new=`grep -c "syslogtst: info log" /var/log/messages`
  97. debug_new=`grep -c "syslogtst: debug log" /var/log/messages`
  98. emerg=$(( $emerg_new - $emerg_old ))
  99. alert=$(( $alert_new - $alert_old ))
  100. crit=$(( $crit_new - $crit_old ))
  101. err=$(( $err_new - $err_old ))
  102. warning=$(( $warning_new - $warning_old ))
  103. notice=$(( $notice_new - $notice_old ))
  104. info=$(( $info_new - $info_old ))
  105. if [ $emerg -ne 1 -o $alert -ne 1 -o $crit -ne 1 -o $err -ne 1 -o \
  106. $warning -ne 1 -o $notice -ne 1 -o $info -ne 1 -o \
  107. $info -ne 1 ]; then
  108. status_flag=1
  109. fi
  110. }
  111. setup
  112. syslog_case7
  113. cleanup ${status_flag:=0}