syslog01 3.5 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. # 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. # case1: Test whether messages are logged to the specified file #
  26. # in the configuration file. #
  27. # #
  28. # Send messages to syslogd at some level and facility #
  29. # and grep for those messages. #
  30. # #
  31. # syslog.conf should contain: #
  32. # *.crit /usr/adm/critical #
  33. # mail.info /usr/spool/adm/syslog #
  34. ##################################################################
  35. . syslog-lib.sh || exit 1
  36. syslog_case1()
  37. {
  38. tst_resm TINFO "testing whether messages are logged into log file"
  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 "*.crit /var/log/messages" >> $CONFIG_FILE
  44. echo "mail.info $MAILLOG" >> $CONFIG_FILE
  45. ;;
  46. /etc/syslog-ng/syslog-ng.conf)
  47. echo "source src{ internal(); unix-dgram(\"/dev/log\"); \
  48. udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
  49. echo " " >> $CONFIG_FILE
  50. echo " " >> $CONFIG_FILE
  51. echo "# Added for syslog testcase" >> $CONFIG_FILE
  52. echo "filter f_syslog { level(crit);};" >> $CONFIG_FILE
  53. echo "filter f_syslogMail { level(info) and facility(mail); };" >> $CONFIG_FILE
  54. echo "destination syslog-messages { file(\"/var/log/messages\");};" >> $CONFIG_FILE
  55. echo "log { source(src); filter(f_syslog); destination(syslog-messages); };" >> $CONFIG_FILE
  56. echo "destination syslog-mail { file(\"$MAILLOG\");};" >> $CONFIG_FILE
  57. echo "log { source(src); filter(f_syslogMail); destination(syslog-mail); };" >> $CONFIG_FILE
  58. ;;
  59. esac
  60. restart_syslog_daemon
  61. # Grepping pattern has to be changed whenever the executable name
  62. # changes, ex: syslogtst executable.
  63. # This check is neccessary for syslog-ng because $MAILLOG is
  64. # only created after syslogtst
  65. if [ -e "$MAILLOG" ]; then
  66. oldvalue1=`grep -c "syslogtst: mail info test" $MAILLOG`
  67. else
  68. oldvalue1=0
  69. fi
  70. # Call syslogtst executable with case number as argument
  71. if syslogtst 1 2>/dev/null; then
  72. sleep 2
  73. if [ ! -e $MAILLOG ]; then
  74. tst_resm TBROK "$MAILLOG no such log file"
  75. cleanup 1
  76. fi
  77. newvalue1=`grep -c "syslogtst: mail info test" $MAILLOG`
  78. if [ "x$(( $newvalue1 - $oldvalue1 ))" != "x1" ]; then
  79. status_flag=1
  80. fi
  81. else
  82. status_flag=1
  83. fi
  84. }
  85. export TST_TOTAL=1
  86. export TST_COUNT=1
  87. export TCID=syslog01
  88. tst_resm TINFO "Send messages to syslogd at some level "
  89. tst_resm TINFO "and facility and grep for those messages."
  90. setup
  91. syslog_case1
  92. cleanup ${status_flag:=0}