#!/bin/bash
#check_ap_alliedt.sh

#jeremie dieudonne
#28 mai 2011 v0.2 > ajout des �tats CRITICAL ET WARNING
#nombre d'utilisateurs connectes sur les bornes Wifi ALLIED TELESIS via SSH
#test ok avec WA-7400 et AT-TQ2403

#pr�requis :
#Ne pas oublier d'installer expect

#commands.cfg :
	##POINT D'ACCES WIFI ALLIED TELESIS
	#define command{
	#	command_name	check_users_connected_AT
	#	command_line	bash /usr/lib/nagios/plugins/check_ssh_AP_AT.sh $HOSTADDRESS$ $ARG1$ $ARG2$ $ARG3$ $ARG4$
	#}
#service :
	#define service{
	#use                             generic-service         ; Name of service template to use
	#host_name                       hostname
	#service_description             Utilisateurs connectes
	#check_command                   check_users_connected_AT!user!password!25!35
	#}
#

#USAGE :
#./check_users_AP_Allied.sh hostname user password warning critical

#sortie dans le fichier /tmp/
expect 2>&1 << EOF > /tmp/$1".txt"
spawn ssh $2@$1 -l $2 -o StrictHostKeyChecking=no
expect "$2@$1's password:"
send "$3\r"
expect "#"
send "get association\r"
expect "#"
send "\r"
expect "#"
send "exit\r"
expect "closed"
exit
EOF

nmbline=`grep -e "wlan" /tmp/$1.txt | wc -l`

if [ $nmbline -ge $5 ]
then
        echo "Critical: number of clients: $nmbline | Clients= $nmbline;25;55;0";
        rm -f /tmp/$1.txt
        exit 2;
elif [ $nmbline -ge $4 ]
then
        echo "Warning: number of clients: $nmbline | Clients= $nmbline;25;55;0";
        rm -f /tmp/$1.txt
        exit 1
else
        echo "OK: number of clients: $nmbline | Clients= $nmbline;25;55;0";
        exit 0;
fi
