Debian Codegraph @

debian/tests/logcheck

raw symbols SCIP
1 #!/bin/bash
2
3 set -eu
4
5 trap cleanup EXIT
6
7 # remove temporary files that were created by the test suite
8 cleanup() {
9 echo "Removing temporary files"
10 rm -rf \
11 /etc/rsyslog.d/rsyslog-logcheck.conf \
12 /etc/logcheck/ignore.d.server/local-rsyslog \
13 /tmp/logcheck.state \
14 /tmp/logcheck.logfiles \
15 /tmp/test-rsyslog-journal.log \
16 /tmp/test-rsyslog-unmatched \
17 /var/log/test-rsyslog-syslog.log
18 }
19
20 echo "* Checking logcheck rules"
21 # tell rsyslog to output to a file other than /var/log/syslog to isolate
22 # rsyslog messages. nb that rsyslog.service is hardened so this file
23 # cannot be in /tmp (#1053898)
24 cat > /etc/rsyslog.d/rsyslog-logcheck.conf <<EOF
25 :programname, contains, "rsyslog" /var/log/test-rsyslog-syslog.log
26 EOF
27
28 : > /var/log/test-rsyslog-syslog.log
29
30 if ! dmesg --since '1s ago' 2>/dev/null; then
31 # /proc/kmesg is not available (eg: running in debusine):
32 # rsyslog will produce additional error messages that the
33 # usual logcheck rules won't match
34 for msg in "imklog: cannot open kernel log" "activation of module imklog failed"; do
35 echo "rsyslogd(\[[0-9]+\])?: $msg" >> /etc/logcheck/ignore.d.server/local-rsyslog
36 done
37 fi
38
39 echo "** Starting and stopping rsyslog"
40 # if rsyslog is already running then merely doing 'start+stop'
41 # will not reload the new config
42 systemctl stop rsyslog 2>&1 #(redirect stderr becuase systemd tells us that syslog.socket will restart rsyslog)
43 systemctl start rsyslog
44 systemctl stop rsyslog 2>&1
45 echo "** rsyslog generated the following lines in syslog:"
46 cat /var/log/test-rsyslog-syslog.log
47 if [ ! -s /var/log/test-rsyslog-syslog.log ]; then
48 echo >&2 "ERROR: rsyslog produced no syslog entries (in /var/log/test-rsyslog-syslog.log) at all"
49 echo "/var/log/syslog contained:"
50 cat /var/log/syslog
51 fi
52
53 echo "** rsyslog generated the following lines in the systemd journal:"
54 journalctl --since=-5min _COMM=rsyslogd \
55 | tee /tmp/test-rsyslog-journal.log
56 if [ ! -s /tmp/test-rsyslog-journal.log ]; then
57 echo >&2 "ERROR: rsyslog produced no journal entries at all"
58 fi
59
60
61 echo "** Running logcheck"
62 # check both syslog and journal lines with logcheck
63 # no need to change config, but set -o and hide state and logfiles-list-directory
64 cat > /tmp/logcheck.logfiles <<EOF
65 /tmp/test-rsyslog-journal.log
66 /var/log/test-rsyslog-syslog.log
67 EOF
68
69 mkdir /tmp/logcheck.state
70 chown logcheck:logcheck /tmp/logcheck.state
71 chmod 0750 /tmp/logcheck.state
72 # nb: su is used because logcheck refuses to run as root
73 # nb: add '-d' option to logcheck if you need to debug
74 su -s /bin/bash -c "/usr/sbin/logcheck -L /tmp/logcheck.logfiles -S /tmp/logcheck.state -D /dev/null -o" logcheck \
75 | tee /tmp/test-rsyslog-unmatched
76
77 # result should be empty
78 if [ -s /tmp/test-rsyslog-unmatched ]; then
79 echo >&2 "* FAIL: unmatched lines - logcheck rules may need updating"
80 else
81 echo "* OK: no unmatched lines"
82 fi
83 cat /tmp/test-rsyslog-unmatched
84