Skip to content

Instantly share code, notes, and snippets.

@gswallow
Created August 22, 2018 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gswallow/22cec9093ddb5337dac6ccb38e2b6f70 to your computer and use it in GitHub Desktop.
Save gswallow/22cec9093ddb5337dac6ccb38e2b6f70 to your computer and use it in GitHub Desktop.
Find LDAP clients from HAProxy connection logs
#!/usr/local/bin/bash
pfx=$(basename $0)
tempdir=$(mktemp -d /tmp/$pfx.$$)
for i in /var/log/messages*; do
case $i in
*.bz2 )
bunzip2 -c $i | egrep '(51|62)(:389|:636)' | awk '{print $8" "$10}' | awk -F':' '{print $1" "$3}' >> $tempdir/clients
;;
* )
cat $i | egrep '(51|62)(:389|:636)' | awk '{print $8" "$10}' | awk -F':' '{print $1" "$3}' >> $tempdir/clients
;;
esac
done
sort $tempdir/clients | uniq -c | sort -k1n | while read COUNT HOST PORT; do
res=$(host $HOST)
if [ $? -gt 0 ]; then
echo $COUNT $HOST $PORT >> $tempdir/sorted
else
hostname=$(echo $res | awk '{print $NF}')
echo $COUNT $hostname $PORT >> $tempdir/sorted
fi
done
cat $tempdir/sorted
rm $tempdir/clients $tempdir/sorted
rmdir $tempdir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment