|
| 1 | +#!/bin/sh |
| 2 | +# Verify stop-processing block prefixes (!! ++ ::) |
| 3 | +# |
| 4 | +# A block prefixed with :: (propfilter), !! (program), or ++ (hostname) |
| 5 | +# stops further rule processing for a matching message. This test |
| 6 | +# exercises all three forms and confirms that non-matching messages |
| 7 | +# fall through to subsequent rules as expected. |
| 8 | +# |
| 9 | +. "${srcdir:-.}/lib.sh" |
| 10 | + |
| 11 | +MSG_STOP="STOPME-needle-7a3f" |
| 12 | +MSG_PASS="PASSTHRU-needle-8b2e" |
| 13 | +MSG_PROG="PROGSTOP-needle-9c1d" |
| 14 | +MSG_OTHER="OTHERPROG-needle-0d4c" |
| 15 | + |
| 16 | +LOGDIR="$DIR/log" |
| 17 | +STOPLOG="${LOGDIR}/stop.log" |
| 18 | +PROGLOG="${LOGDIR}/prog.log" |
| 19 | +CATCHALL="${LOGDIR}/all.log" |
| 20 | + |
| 21 | +# Config layout: |
| 22 | +# 1. ::propfilter stop-block → STOPLOG (stops; MSG_STOP never reaches CATCHALL) |
| 23 | +# 2. !!stopper stop-block → PROGLOG (stops; MSG_PROG from "stopper" never reaches CATCHALL) |
| 24 | +# 3. !* resets program filter so the catch-all below applies to all programs |
| 25 | +# 4. catch-all → CATCHALL (receives everything not stopped above) |
| 26 | +setup_syslogd() |
| 27 | +{ |
| 28 | + mkdir -p "$LOGDIR" |
| 29 | + cat <<-EOF >"${CONF}" |
| 30 | + ::msg, contains, "${MSG_STOP}" |
| 31 | + *.* ${STOPLOG} |
| 32 | + !!stopper |
| 33 | + *.* ${PROGLOG} |
| 34 | + !* |
| 35 | + *.* -${CATCHALL} |
| 36 | + EOF |
| 37 | + setup -m0 |
| 38 | +} |
| 39 | + |
| 40 | +# Send MSG_STOP, expect it in STOPLOG |
| 41 | +check_stop_in_stoplog() |
| 42 | +{ |
| 43 | + logger -t test -p user.notice "${MSG_STOP}" |
| 44 | + sleep 1 |
| 45 | + grep "${MSG_STOP}" "${STOPLOG}" |
| 46 | +} |
| 47 | + |
| 48 | +# MSG_STOP must NOT appear in CATCHALL (stop-processing worked) |
| 49 | +check_stop_not_in_catchall() |
| 50 | +{ |
| 51 | + grep "${MSG_STOP}" "${CATCHALL}" && return 1 |
| 52 | + return 0 |
| 53 | +} |
| 54 | + |
| 55 | +# Send MSG_PASS (no match for stop filter), expect it in CATCHALL |
| 56 | +check_pass_in_catchall() |
| 57 | +{ |
| 58 | + logger -t test -p user.notice "${MSG_PASS}" |
| 59 | + sleep 1 |
| 60 | + grep "${MSG_PASS}" "${CATCHALL}" |
| 61 | +} |
| 62 | + |
| 63 | +# MSG_PASS must NOT appear in STOPLOG |
| 64 | +check_pass_not_in_stoplog() |
| 65 | +{ |
| 66 | + grep "${MSG_PASS}" "${STOPLOG}" && return 1 |
| 67 | + return 0 |
| 68 | +} |
| 69 | + |
| 70 | +# Send MSG_PROG from tag "stopper", expect it in PROGLOG (!! stop-block) |
| 71 | +check_prog_in_proglog() |
| 72 | +{ |
| 73 | + logger -t stopper -p user.notice "${MSG_PROG}" |
| 74 | + sleep 1 |
| 75 | + grep "${MSG_PROG}" "${PROGLOG}" |
| 76 | +} |
| 77 | + |
| 78 | +# MSG_PROG from "stopper" must NOT appear in CATCHALL |
| 79 | +check_prog_not_in_catchall() |
| 80 | +{ |
| 81 | + grep "${MSG_PROG}" "${CATCHALL}" && return 1 |
| 82 | + return 0 |
| 83 | +} |
| 84 | + |
| 85 | +# Send MSG_OTHER from a different tag, expect it in CATCHALL only |
| 86 | +check_other_in_catchall() |
| 87 | +{ |
| 88 | + logger -t otherprog -p user.notice "${MSG_OTHER}" |
| 89 | + sleep 1 |
| 90 | + grep "${MSG_OTHER}" "${CATCHALL}" |
| 91 | +} |
| 92 | + |
| 93 | +# MSG_OTHER must NOT appear in PROGLOG |
| 94 | +check_other_not_in_proglog() |
| 95 | +{ |
| 96 | + grep "${MSG_OTHER}" "${PROGLOG}" && return 1 |
| 97 | + return 0 |
| 98 | +} |
| 99 | + |
| 100 | +run_step "Set up syslogd with stop-processing rules" setup_syslogd |
| 101 | + |
| 102 | +run_step "Matched msg (propfilter ::) lands in stop log" check_stop_in_stoplog |
| 103 | +run_step "Matched msg (propfilter ::) absent from catch-all" check_stop_not_in_catchall |
| 104 | +run_step "Non-matched msg reaches catch-all" check_pass_in_catchall |
| 105 | +run_step "Non-matched msg absent from stop log" check_pass_not_in_stoplog |
| 106 | + |
| 107 | +run_step "Matched msg (program !!) lands in prog log" check_prog_in_proglog |
| 108 | +run_step "Matched msg (program !!) absent from catch-all" check_prog_not_in_catchall |
| 109 | +run_step "Other-program msg reaches catch-all" check_other_in_catchall |
| 110 | +run_step "Other-program msg absent from prog log" check_other_not_in_proglog |
0 commit comments