wifi_auth 1.96 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#!/bin/sh
# -*- sh -*-

mktempfile () {
    #cmd=`echo $MUNIN_MKTEMP | sed s/\\$1/$1/`
    #$cmd
    touch /tmp/$1
    echo /tmp/$1
}

11
FREERADIUS_LOG=${freeradiuslog:-/var/log/wifi/global.log}
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
LOGTAIL=${logtail:-/usr/sbin/logtail}
MUNIN_PLUGSTATE=${MUNIN_PLUGSTATE:-/var/lib/munin/plugin-state/}
STATEFILE=$MUNIN_PLUGSTATE/wifi_auth.offset

if [ "$1" = "autoconf" ]; then
        if [ -f "${FREERADIUS_LOG}" -a -n "${LOGTAIL}" -a -x "${LOGTAIL}" ] ; then
		echo yes
		exit 0
	else
		echo no
		exit 0
	fi
fi

# Try tailing a random file to check how arguments are passed
ARGS=0
`$LOGTAIL /etc/hosts 2>/dev/null >/dev/null`
if [ $? = 66 ]; then
    if [ ! -n "$logtail" ]; then
	ARGS=1
    fi
fi

if [ "$1" = "config" ]; then
	echo 'graph_title Authentifications WiFi'
	echo 'graph_vlabel Auth'
	echo 'graph_category wifi'
    echo 'failures.label Échecs'
    echo 'failures.draw AREASTACK'
    echo 'failures.colour FF0000'
    echo 'success.label Succès'
    echo 'success.draw AREASTACK'
    echo 'success.colour 00FF00'
45 46 47 48 49 50
    echo 'peap.label Authentifications PEAP'
    echo 'ttls.label Authentifications TTLS'
    echo 'peap.draw LINE1'
    echo 'peap.colour 000000'
    echo 'ttls.draw LINE2'
    echo 'ttls.colour F6FF00'
51 52 53 54 55 56 57 58 59 60 61
	exit 0
fi

success=U
failures=U

TEMP_FILE=$(mktempfile munin-radius-wifi.XXXXXX)

if [ -n "$TEMP_FILE" -a -f "$TEMP_FILE" ]
then
	if [ $ARGS != 0 ]; then
62
	    $LOGTAIL -f ${FREERADIUS_LOG} -o ${STATEFILE} > ${TEMP_FILE}
63
	else
64
	    $LOGTAIL ${FREERADIUS_LOG} ${STATEFILE} > ${TEMP_FILE}
65 66 67
	fi
    success=$(grep -c 'Login OK' ${TEMP_FILE})
    failures=$(grep -c 'Login incorrect' ${TEMP_FILE})
68 69
    peap=$(grep -c 'authenticated - EAP type: 25' ${TEMP_FILE})
    ttls=$(grep -c 'authenticated - EAP type: 21' ${TEMP_FILE})
70 71 72 73 74 75

	/bin/rm -f $TEMP_FILE
fi

echo "success.value ${success}"
echo "failures.value ${failures}"
76 77 78 79 80
# NB: chaque authentification réussie en TTLS ou PEAP produit deux "succès"
# (inner et outer-tunnels)
echo "peap.value ${peap}"
echo "ttls.value ${ttls}"

81