Imported Upstream version 2.7
[ossec-hids.git] / contrib / logtesting / dotests.sh
1 #!/bin/sh
2
3 echo "Starting log unit tests (must be run as root and on a system with OSSEC installed)."
4 echo "(it will make sure the current rules aree working as they should)."
5 rm -f ./tmpres
6 for i in ./*/log; do
7     idir=`dirname $i`
8
9     rm -f ./tmpres || exit "Unable to remove tmpres.";
10     cat $i | /var/ossec/bin/ossec-logtest 2>&1|grep -v ossec-testrule |grep -A 500 "Phase 1:" > ./tmpres
11
12     if [ ! -f $idir/res ]; then
13         echo "** Creating entry for $i - Not set yet."
14         cat ./tmpres > $idir/res
15         rm -f tmpres
16         continue;
17     fi
18     MD1=`md5sum ./tmpres | cut -d " " -f 1`
19     MD2=`md5sum $idir/res | cut -d " " -f 1`
20
21     if [ ! $MD1 = $MD2 ]; then
22         echo "**ERROR: Unit testing failed. Output for the test $i failed."
23         echo "== OLD OUTPUT: =="
24         cat $idir/res
25         echo "== NEW OUTPUT: =="
26         cat tmpres
27         echo "** ERROR: Exiting."
28         rm -f tmpres
29         exit 0;
30     fi
31
32 done
33
34 echo ""
35 echo "Log unit tests completed. Everything seems ok (nothing changed since last test regarding the outputs)."