1 #! /bin/sh 2 # OpenLDAP: pkg/ldap/tests/scripts/test056-monitor,v 1.2.2.7 2010/04/19 19:14:36 quanah Exp 3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4 ## 5 ## Copyright 1998-2010 The OpenLDAP Foundation. 6 ## All rights reserved. 7 ## 8 ## Redistribution and use in source and binary forms, with or without 9 ## modification, are permitted only as authorized by the OpenLDAP 10 ## Public License. 11 ## 12 ## A copy of this license is available in the file LICENSE in the 13 ## top-level directory of the distribution or, alternatively, at 14 ## <http://www.OpenLDAP.org/license.html>. 15 16 echo "running defines.sh" 17 . $SRCDIR/scripts/defines.sh 18 19 if test $MONITORDB = "no" ; then 20 echo "Monitor backend not available, test skipped" 21 exit 0 22 fi 23 24 mkdir -p $TESTDIR $DBDIR1 25 26 echo "Starting slapd on TCP/IP port $PORT..." 27 . $CONFFILTER $BACKEND $MONITORDB < $SCHEMACONF > $CONF1 28 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 & 29 PID=$! 30 if test $WAIT != 0 ; then 31 echo PID $PID 32 read foo 33 fi 34 KILLPIDS="$PID" 35 36 sleep 1 37 38 echo "Using ldapsearch to check that slapd is running..." 39 for i in 0 1 2 3 4 5; do 40 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \ 41 'objectclass=*' > /dev/null 2>&1 42 RC=$? 43 if test $RC = 0 ; then 44 break 45 fi 46 echo "Waiting 5 seconds for slapd to start..." 47 sleep 5 48 done 49 50 echo "Using ldapsearch to read connection monitor entries..." 51 $LDAPSEARCH -S "" -b "$CONNECTIONSMONITORDN" -h $LOCALHOST -p $PORT1 \ 52 'objectclass=*' \ 53 structuralObjectClass entryDN \ 54 monitorConnectionProtocol monitorConnectionOpsReceived \ 55 monitorConnectionOpsExecuting monitorConnectionOpsPending \ 56 monitorConnectionOpsCompleted monitorConnectionGet \ 57 monitorConnectionRead monitorConnectionWrite \ 58 monitorConnectionMask monitorConnectionAuthzDN \ 59 monitorConnectionListener monitorConnectionLocalAddress \ 60 > $SEARCHOUT 2>&1 61 RC=$? 62 63 if test $RC != 0 ; then 64 echo "ldapsearch failed ($RC)!" 65 test $KILLSERVERS != no && kill -HUP $KILLPIDS 66 exit $RC 67 fi 68 69 # Compare results, ignoring possible difference of IPv4/IPv6 localhost address 70 localrewrite='s/=127\.0\.0\.1:/=LOCAL:/; s/=\[::1\]:/=LOCAL:/' 71 echo "Filtering ldapsearch results..." 72 sed -e "$localrewrite" < $SEARCHOUT | $LDIFFILTER > $SEARCHFLT 73 echo "Filtering expected data..." 74 . $CONFFILTER < $MONITOROUT1 | sed -e "$localrewrite" | $LDIFFILTER > $LDIFFLT 75 echo "Comparing filter output..." 76 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT 77 78 if test $? != 0 ; then 79 echo "comparison failed - connection monitor output is not correct" 80 test $KILLSERVERS != no && kill -HUP $KILLPIDS 81 exit 1 82 fi 83 84 echo "Using ldapsearch to read database monitor entries..." 85 $LDAPSEARCH -S "" -b "$DATABASESMONITORDN" -h $LOCALHOST -p $PORT1 \ 86 'objectclass=*' \ 87 structuralObjectClass entryDN namingContexts readOnly \ 88 monitorIsShadow monitorContext \ 89 olmBDBEntryCache olmBDBDNCache olmBDBIDLCache \ 90 > $SEARCHOUT 2>&1 91 RC=$? 92 93 if test $RC != 0 ; then 94 echo "ldapsearch failed ($RC)!" 95 test $KILLSERVERS != no && kill -HUP $KILLPIDS 96 exit $RC 97 fi 98 99 echo "Filtering ldapsearch results..." 100 $LDIFFILTER -b monitor < $SEARCHOUT > $SEARCHFLT 101 102 TMPMONITOROUT2=$MONITOROUT2 103 case $BACKEND in 104 bdb|hdb) 105 ;; 106 *) 107 TMPMONITOROUT2=$TESTDIR/monitor2.out 108 grep -v "olmBDB" $MONITOROUT2 > $TMPMONITOROUT2 109 ;; 110 esac 111 112 echo "Comparing filter output..." 113 $CMP $SEARCHFLT $TMPMONITOROUT2 > $CMPOUT 114 115 if test $? != 0 ; then 116 echo "comparison failed - database monitor output is not correct" 117 test $KILLSERVERS != no && kill -HUP $KILLPIDS 118 exit 1 119 fi 120 121 echo "Using ldapsearch to read statistics monitor entries..." 122 $LDAPSEARCH -S "" -b "$STATISTICSMONITORDN" -h $LOCALHOST -p $PORT1 \ 123 '(|(cn=Entries)(cn=PDU)(cn=Referrals))' \ 124 structuralObjectClass monitorCounter entryDN \ 125 > $SEARCHOUT 2>&1 126 RC=$? 127 128 if test $RC != 0 ; then 129 echo "ldapsearch failed ($RC)!" 130 test $KILLSERVERS != no && kill -HUP $KILLPIDS 131 exit $RC 132 fi 133 134 echo "Filtering ldapsearch results..." 135 $LDIFFILTER -b monitor < $SEARCHOUT > $SEARCHFLT 136 137 echo "Comparing filter output..." 138 $CMP $SEARCHFLT $MONITOROUT3 > $CMPOUT 139 140 if test $? != 0 ; then 141 echo "comparison failed - statistics monitor output is not correct" 142 test $KILLSERVERS != no && kill -HUP $KILLPIDS 143 exit 1 144 fi 145 146 echo "Using ldapsearch to read operation monitor entries..." 147 $LDAPSEARCH -S "" -b "$OPERATIONSMONITORDN" -h $LOCALHOST -p $PORT1 \ 148 'objectclass=*' \ 149 structuralObjectClass monitorOpInitiated monitorOpCompleted entryDN \ 150 > $SEARCHOUT 2>&1 151 RC=$? 152 153 if test $RC != 0 ; then 154 echo "ldapsearch failed ($RC)!" 155 test $KILLSERVERS != no && kill -HUP $KILLPIDS 156 exit $RC 157 fi 158 159 echo "Filtering ldapsearch results..." 160 $LDIFFILTER -b monitor < $SEARCHOUT > $SEARCHFLT 161 162 echo "Comparing filter output..." 163 $CMP $SEARCHFLT $MONITOROUT4 > $CMPOUT 164 165 if test $? != 0 ; then 166 echo "comparison failed - operations monitor output is not correct" 167 test $KILLSERVERS != no && kill -HUP $KILLPIDS 168 exit 1 169 fi 170 171 test $KILLSERVERS != no && kill -HUP $KILLPIDS 172 173 echo ">>>>> Test succeeded" 174 175 test $KILLSERVERS != no && wait 176 177 exit 0 178 179