Last Updated: 23-JUN-2016 / 11:20 am
Recently at a network where multiple NAS were implemented with single centralized billing system(radius Manager with Free radius as backend engine) , I configured MRTG to create graphs for each NAS and added Mikrotik DUDE system to monitor various instances of the target systems, but there was no single graph to monitor overall ONLINE users of all NASES.
MRTG was configured on main Billing system, to sort this I used the following bash script and tag it with the mrtg cfg script.
SCRIPT TO PRINT ONLINE SESSIONS IN FREERADIUS
First create the script
mkdir /temp
touch /temp/online.sh
chmod +x /temp/online.sh
nano /temp/online.sh
Now paste the following code, [make sure to change the IP, ID and Password]
Note: I used this script for Radius Manager base freeradius billing system.
(http://www.netexpertise.eu/en/freeradius/graph-freeradius-sessions.html)
#!/bin/bash # Script to query online connected users in freeradius # Syed Jahanzaib / aacable at hotmail dot com # http://aacable . wordpress . com SQLUSER="root" SQLPASS="PASSWORD" SQL_DB=radius SQL_SERVER=127.0.0.1 SQL_ACCOUNTING_TABLE=radacct # acquire online users whose accnt-stop time is null so consider it online : ) SESSIONS=`mysql -u$SQLUSER -p$SQLPASS --skip-column-names -e "use radius; SELECT username FROM $SQL_ACCOUNTING_TABLE WHERE acctstoptime IS NULL;" |wc -l` echo $SESSIONS echo $SESSIONS
Save & Exit.
MRTG.CFG FILE TO GENERATE MRTG GRAPH
Now create a MRTG cfg file and tag it with your master mrtg config file or run it as individual , its up to you and your local design.
#Radius.cfg # Total Radius Users Target[Radius.users]: `/temp/online.sh` Title[Radius.users]: Central Billing System Logged in Users by ZAIB (Total) PageTop[Radius.users]: <H1> Central Billing System Logged in Users (Total)</H1> MaxBytes[Radius.users]: 1000 Colours[Radius.users]: B#8888ff,B#8888ff,B#5398ff,B#5398ff Options[Radius.users]: gauge,nopercent,noo,integer,growright LegendI[Radius.users]: Radius Logged in Users LegendO[Radius.users]: YLegend[Radius.users]: Radius Logged in Users (Total) Legend1[Radius.users]: Radius Logged in Users (Total) Legend2[Radius.users]: Unscaled[Radius.users]: ymwd
Another Script to find online users, ALL, specific user. made customized for GT @ 20-DEC2017
#!/bin/bash # Script to query online conencted users in freeradius # Syed Jahanzaib / aacable at hotmail dot com # http://aacable . wordpress . com #set -x SQLUSER="root" SQLPASS="sqlpassword" SQL_DB="radius" SQL_SERVER=127.0.0.1 SQL_ACCOUNTING_TABLE=radacct TMP="/tmp/onlineusers.txt" USR="$1" if [ -z "$USR" ]; then echo "Please use following ... ./online.sh all OR ./online.sh username" exit 1 fi mysql -u$SQLUSER -p$SQLPASS --skip-column-names -e "use $SQL_DB; SELECT username FROM $SQL_ACCOUNTING_TABLE WHERE acctstoptime IS NULL;" > $TMP TOT=`cat $TMP | wc -l` if [ "$USR" == "all" ]; then echo "TOTAL Number of online users are - $TOT" cat $TMP | sort | more exit 1 fi if [ "$USR" != "all" ]; then CHK=`cat $TMP |grep "$USR" | more` if [ -z "$CHK" ]; then echo "No User found in the SESSION list with this name ... Exiting" else echo " User Found ..." cat $TMP |grep "$USR" | more fi fi
Regard’s
Syed Jahanzaib