syslog10 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #
  18. # 12/05/02 Port to bash -Robbie Williamson <robbiew@us.ibm.com>
  19. # 02/05/03 Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
  20. # fixed bugs.
  21. # 07/26/05 Michael Reed <mreedltp@vnet.ibm.com>
  22. # Made changes to account for the replacement of syslogd
  23. # with syslog-ng
  24. #
  25. ##################################################################
  26. # case 10: Test setlogmask() with LOG_MASK macro. #
  27. # #
  28. # o Use setlogmask() with LOG_MASK macro to set an #
  29. # individual priority level. #
  30. # o Send the message of above prority and expect it to #
  31. # be logged. #
  32. # o Send message which is below the priority level to #
  33. # the one set above, which should not be logged. #
  34. ##################################################################
  35. . syslog-lib.sh || exit 1
  36. syslog_case10()
  37. {
  38. tst_resm TINFO "syslog: Testing setlogmask() with LOG_MASK macro..."
  39. # Create the configuration file specific to this test case.
  40. case "$CONFIG_FILE" in
  41. /etc/syslog.conf|/etc/rsyslog.conf)
  42. echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
  43. echo "user.debug /var/log/messages" >> $CONFIG_FILE
  44. ;;
  45. /etc/syslog-ng/syslog-ng.conf)
  46. echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
  47. echo "filter f_syslog_debug{ facility(user); };" >> $CONFIG_FILE
  48. echo "destination syslog_messages { file(\"/var/log/messages\");};" >> $CONFIG_FILE
  49. echo "log { source(src); filter(f_syslog_debug); destination(syslog_messages); };" >> $CONFIG_FILE
  50. ;;
  51. esac
  52. restart_syslog_daemon
  53. if [ -e /var/log/messages ]; then
  54. allow1=`grep -c "syslogtst:10 error level is logged" /var/log/messages`
  55. donot_allow1=`grep -c "syslogtst:10 warning level not to be logged" /var/log/messages`
  56. else
  57. allow1=0
  58. donot_allow1=0
  59. fi
  60. if ! syslogtst 10 2>/dev/null; then
  61. status_flag=1
  62. return
  63. fi
  64. sleep 2
  65. # check if /var/log/messages script exists
  66. if [ ! -e /var/log/messages ]; then
  67. tst_resm TBROK "/var/log/messages no such log file"
  68. cleanup 1
  69. fi
  70. allow2=`grep -c "syslogtst:10 error level is logged" /var/log/messages`
  71. donot_allow2=`grep -c "syslogtst:10 warning level not to be logged" /var/log/messages`
  72. diff1=$(( $allow2 - $allow1 ))
  73. if [ $diff1 -ne 1 ]; then
  74. tst_resm TFAIL "Expected message was not logged...."
  75. status_flag=1
  76. return
  77. fi
  78. diff2=$(( $donot_allow2 - $donot_allow1 ))
  79. if [ $diff2 -ne 0 ]; then
  80. tst_resm TFAIL "Unexpected message was logged..."
  81. status_flag=1
  82. fi
  83. }
  84. tst_resm TINFO " Test setlogmask() with LOG_MASK macro."
  85. tst_resm TINFO " o Use setlogmask() with LOG_MASK macro to set an"
  86. tst_resm TINFO " individual priority level."
  87. tst_resm TINFO " o Send the message of above prority and expect it to be"
  88. tst_resm TINFO " logged."
  89. tst_resm TINFO " o Send message which is at other priority level to"
  90. tst_resm TINFO " the one set above, which should not be logged."
  91. setup
  92. syslog_case10
  93. cleanup ${status_flag:=0}