2d40853919f296cc16a3504d09f4f4162aefccf6
[ossec-hids.git] / debian / ossec-hids / usr / share / doc / ossec-hids / contrib / logtesting / dotests.sh
1 #!/bin/sh
2
3 hostname=`hostname`
4 hostname melancia
5
6 cleanup() {
7     hostname $hostname
8     rm -f ./tmpres
9 }
10
11 trap "cleanup" INT TERM EXIT
12 exitcode=0
13
14 if diff --help 2>&1 | grep -q -- --color; then
15     diff_cmd='diff --color'
16 else
17     diff_cmd='diff'
18 fi
19
20 echo "Starting log unit tests (must be run as root and on a system with OSSEC installed)."
21 echo "(it will make sure the current rules are working as they should)."
22 rm -f ./tmpres
23 for i in ./*/log; do
24     idir=`dirname $i`
25
26     rm -f ./tmpres || exit "Unable to remove tmpres.";
27     cat $i | /var/ossec/bin/ossec-logtest 2>&1|grep -av ossec-testrule |grep -aA 500 "Phase 1:" > ./tmpres
28
29     if [ ! -f $idir/res ]; then
30         echo "** Creating entry for $i - Not set yet."
31         cat ./tmpres > $idir/res
32         rm -f tmpres
33         continue;
34     fi
35     MD1=`md5sum ./tmpres | cut -d " " -f 1`
36     MD2=`md5sum $idir/res | cut -d " " -f 1`
37
38     if [ ! $MD1 = $MD2 ]; then
39         exitcode=1
40         echo
41         echo
42         echo
43         echo "**ERROR: Unit testing failed. Output for the test $i failed."
44         echo "== DIFF OUTPUT: =="
45         $diff_cmd -Na -U `wc -l $idir/res` tmpres
46         rm -f tmpres
47     fi
48
49 done
50
51 echo ""
52 if [ $exitcode -eq 0 ]; then
53     echo "Log unit tests completed. Everything seems ok (nothing changed since last test regarding the outputs)."
54 else
55     echo "Log unit tests completed. Some tests failed."
56 fi
57 exit $exitcode