syslog02 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. # case2: Test if messages of all levels are logged.
  26. # For each level, a separate configuration file is
  27. # created and that will be used as syslog.conf file.
  28. ##################################################################
  29. # Number of levels.
  30. export TST_TOTAL=8
  31. . syslog-lib.sh || exit 1
  32. syslog_case2()
  33. {
  34. level_no=0
  35. levels="emerg alert crit err warning notice info debug"
  36. tst_resm TINFO "testing whether messages are logged into log file"
  37. for level in $levels
  38. do
  39. tst_resm TINFO "Doing level: $level..."
  40. case "$CONFIG_FILE" in
  41. /etc/syslog.conf)
  42. # Create the configuration file specific to this level
  43. echo "mail.$level $MAILLOG" >> $CONFIG_FILE
  44. ;;
  45. /etc/rsyslog.conf)
  46. # Create the configuration file specific to this level
  47. echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
  48. echo "mail.$level $MAILLOG" >> $CONFIG_FILE
  49. ;;
  50. /etc/syslog-ng/syslog-ng.conf)
  51. echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
  52. echo "filter f_syslog_$level { level($level) and facility(mail); };" >> $CONFIG_FILE
  53. echo "destination syslog-$level { file(\"$MAILLOG\"); };" >> $CONFIG_FILE
  54. echo "log { source(src); filter(f_syslog_$level); destination(syslog-$level); };" >> $CONFIG_FILE;;
  55. esac
  56. restart_syslog_daemon
  57. # Grepping pattern has to be changed whenever the executable name
  58. # changes, ex: syslogtst executable.
  59. # This check is neccessary for syslog-ng because $MAILLOG is
  60. # only created after syslogtst
  61. if [ -e "$MAILLOG" ]; then
  62. oldvalue=`grep -c "syslogtst: mail $level test\." $MAILLOG`
  63. else
  64. oldvalue=0
  65. fi
  66. # syslogtst has to be called with additional level argument(0-7)
  67. if ! syslogtst 2 $level_no 2>/dev/null; then
  68. cleanup 1
  69. fi
  70. sleep 2
  71. # check if $MAILLOG script exists
  72. if [ ! -e "$MAILLOG" ]; then
  73. tst_resm TBROK "$MAILLOG no such log file"
  74. cleanup 1
  75. fi
  76. newvalue=`grep -c "syslogtst: mail $level test" $MAILLOG`
  77. diff=$(( $newvalue - $oldvalue ))
  78. if [ $diff -eq 0 ]; then
  79. tst_resm TFAIL "***** Level $level failed *****"
  80. status_flag=1
  81. elif [ $diff -ge 1 ]; then
  82. tst_resm TPASS "***** Level $level passed *****"
  83. fi
  84. # Increment the level_no for next level...
  85. : $(( level_no += 1 ))
  86. incr_tst_count
  87. done
  88. }
  89. tst_resm TINFO "Test if messages of all levels are logged."
  90. tst_resm TINFO "For each level, a separate configuration file is"
  91. tst_resm TINFO "created and that will be used as syslog.conf file."
  92. setup
  93. syslog_case2
  94. cleanup ${status_flag:=0}