Skip to content

Commit

Permalink
Merge branch 'improve-dotests.sh-output' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
jubois committed Jan 18, 2019
2 parents ae4cc7d + 48efa6d commit e9a933c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions contrib/logtesting/dotests.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
#!/bin/sh

hostname=$(hostname)
hostname=`hostname`
hostname melancia

trap "hostname $hostname" INT TERM EXIT
cleanup() {
hostname $hostname
rm -f ./tmpres
}

trap "cleanup" INT TERM EXIT
exitcode=0

if diff --help 2>&1 | grep -q -- --color; then
diff_cmd='diff --color'
else
diff_cmd='diff'
fi

echo "Starting log unit tests (must be run as root and on a system with OSSEC installed)."
echo "(it will make sure the current rules are working as they should)."
rm -f ./tmpres
for i in ./*/log; do
idir=`dirname $i`

rm -f ./tmpres || exit "Unable to remove tmpres.";
cat $i | /var/ossec/bin/ossec-logtest 2>&1|grep -v ossec-testrule |grep -A 500 "Phase 1:" > ./tmpres
cat $i | /var/ossec/bin/ossec-logtest 2>&1|grep -av ossec-testrule |grep -aA 500 "Phase 1:" > ./tmpres

if [ ! -f $idir/res ]; then
echo "** Creating entry for $i - Not set yet."
Expand All @@ -30,8 +41,8 @@ for i in ./*/log; do
echo
echo
echo "**ERROR: Unit testing failed. Output for the test $i failed."
echo "== DIFF OUTPUT (reference | new): =="
diff -Nay $idir/res tmpres
echo "== DIFF OUTPUT: =="
$diff_cmd -Na -U `wc -l $idir/res` tmpres
rm -f tmpres
fi

Expand Down

0 comments on commit e9a933c

Please sign in to comment.