syslog08 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 8: Test all the facilities at a particular level. #
  26. # #
  27. # Facilities available are: LOG_KERN, LOG_USER, LOG_MAIL #
  28. # LOG_DAEMON, LOG_AUTH, LOG_LPR. #
  29. # Don't know how to send kernel messages from syslog() #
  30. # #
  31. # o Create seperate entries in config file for each facility. #
  32. # o Send the message and grep for the entry in log file. #
  33. ##################################################################
  34. . syslog-lib.sh || exit 1
  35. syslog_case8()
  36. {
  37. local facility_no=1
  38. local facilities="user mail daemon auth lpr"
  39. tst_resm TINFO "testing all the facilities"
  40. for facility in $facilities; do
  41. tst_resm TINFO "Doing facility: $facility..."
  42. # Create the configuration file specific to this facility
  43. # Level is fixed at info.
  44. case "$CONFIG_FILE" in
  45. /etc/syslog.conf|/etc/rsyslog.conf)
  46. echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
  47. echo "$facility.info /var/log/messages" >> $CONFIG_FILE
  48. echo "$facility.info /var/log/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-$facility { level(info) and facility($facility); };" >> $CONFIG_FILE
  53. echo "destination syslog-messages { file(\"/var/log/messages\"); };" >> $CONFIG_FILE
  54. echo "destination syslog-mail { file(\"/var/log/maillog\");};" >> $CONFIG_FILE
  55. echo "log { source(src); filter(f_syslog-$facility); destination(syslog-mail); };" >> $CONFIG_FILE
  56. echo "log { source(src); filter(f_syslog-$facility); destination(syslog-messages); };" >> $CONFIG_FILE
  57. ;;
  58. esac
  59. restart_syslog_daemon
  60. if [ -e /var/log/messages ]; then
  61. oldvalue=`grep -c "syslogtst: $facility info test." /var/log/messages`
  62. else
  63. oldvalue=0
  64. fi
  65. if [ -e /var/log/maillog ]; then
  66. old_mail_check=`grep -c "syslogtst: $facility info test." /var/log/maillog`
  67. else
  68. old_mail_check=0
  69. fi
  70. # syslogtst has to be called with one more
  71. # additional facility argument(1-6)
  72. if ! syslogtst 8 $facility_no 2>/dev/null; then
  73. status_flag=1
  74. return
  75. fi
  76. sleep 2
  77. # check if /var/log/maillog script exists
  78. for logf in messages maillog
  79. do
  80. if [ ! -e /var/log/$logf ]; then
  81. tst_resm TBROK "/var/log/$logf no such log file"
  82. cleanup 1
  83. fi
  84. done
  85. new_mail_check=`grep -c "syslogtst: $facility info test." /var/log/maillog`
  86. newvalue=`grep -c "syslogtst: $facility info test." /var/log/messages`
  87. diff=$(( $newvalue - $oldvalue ))
  88. mail_check=$(( $new_mail_check - $old_mail_check ))
  89. if [ $facility = "mail" ]; then
  90. if [ $mail_check -ne 1 ]; then
  91. tst_resm TFAIL " Facility $facility failed"
  92. status_flag=1
  93. elif [ $mail_check -eq 1 ]; then
  94. tst_resm TPASS " Facility $facility passed"
  95. fi
  96. elif [ $diff -ne 1 ]; then
  97. tst_resm TFAIL " Facility $facility failed"
  98. status_flag=1
  99. else
  100. tst_resm TPASS " Facility $facility passed"
  101. fi
  102. # Increment the facility_no for next...
  103. : $(( facility_no += 1 ))
  104. done
  105. }
  106. tst_resm TINFO " Test all the facilities at a particular level."
  107. tst_resm TINFO " Facilities available are: LOG_KERN, LOG_USER, LOG_MAIL"
  108. tst_resm TINFO " LOG_DAEMON, LOG_AUTH, LOG_LPR."
  109. tst_resm TINFO " Don't know how to send kernel messages from syslog()"
  110. tst_resm TINFO " o Create seperate entries in config file for each facility."
  111. tst_resm TINFO " o Send the message and grep for the entry in log file."
  112. setup
  113. syslog_case8
  114. cleanup ${status_flag:=0}