Commit f66e3c94 authored by Vitaly Lipatov's avatar Vitaly Lipatov

check_rules.sh: improve output and error handling

- Add warning() function for non-fatal errors - Skip missing filters with warning instead of exit - Better visual separation between test runs - Change fatal to warning for partial regex matches 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: 's avatarClaude Opus 4.5 <noreply@anthropic.com>
parent 0a24ff50
#!/bin/sh #!/bin/sh
warning()
{
echo
echo "Warning: $@" >&2
}
fatal() fatal()
{ {
echo "Error: $@" >&2 echo "Error: $@" >&2
...@@ -16,13 +22,17 @@ TEST="*" ...@@ -16,13 +22,17 @@ TEST="*"
for i in test.d/$TEST ; do for i in test.d/$TEST ; do
FILTERNAME=$(basename $i) FILTERNAME=$(basename $i)
FILTER=$(pwd)/filter.d/$FILTERNAME.conf FILTER=$(pwd)/filter.d/$FILTERNAME.conf
test -r "$FILTER" || exit if [ ! -r "$FILTER" ] ; then
warning "Missed filter $FILTER"
continue
fi
echo
echo echo
echo "Testing filter $FILTER with data..." echo "================== Testing filter $FILTER with data... ====================== "
cat $i cat $i
TOTAL=$(fail2ban-regex -v $i $FILTER | grep "^Failregex:" | sed -e "s|Failregex: \([0-9]\+\) total.*|\1|g") TOTAL=$(fail2ban-regex -v $i $FILTER | grep "^Failregex:" | sed -e "s|Failregex: \([0-9]\+\) total.*|\1|g")
fail2ban-regex -v $i $FILTER #&& echo Success fail2ban-regex -v $i $FILTER #&& echo Success
TOTALTEST=$(cat $i | grep -v "^$" | grep -v "^#" | wc -l) TOTALTEST=$(cat $i | grep -v "^$" | grep -v "^#" | wc -l)
[ "$TOTAL" = "$TOTALTEST" ] || fatal "Regexped only $TOTAL tests from $TOTALTEST total! Fix rule $FILTER" [ "$TOTAL" = "$TOTALTEST" ] || warning "Regexped only $TOTAL tests from $TOTALTEST total! Fix rule $FILTER"
done done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment