Saturday, November 28, 2015

OpenVPN: Use MRTG To Graph Connected Users To The VPN

This is a little and simple shell script I wrote to graph using MRTG the number of users who are connected to a VPN server.
The script is really, really simple (as this VPN setup).
It searches for a string on a log file, and then counts and graphs how many times that string appears.
The script itself (simply edit the LAN to suit your needs):

#!/bin/sh

LOG='/path/to/your.openvpn.log'
LAN='10.17.25.'

if [ `cat $LOG | egrep $LAN | wc -l` = 0 ]
then
    echo `cat $LOG | egrep $LAN | wc -l`
    echo `cat $LOG | egrep $LAN | wc -l` Logged Users
else
    echo `cat $LOG | egrep $LAN | wc -l`
    echo `cat $LOG | egrep $LAN | wc -l` Logged Users
fi

# EoF #


And then the MRTG configuration file snip:

###############################
## Users connected to the VPN
###############################
Target[local_openvpn]: `sh /path/to/script.sh`
Options[local_openvpn]: nopercent,gauge,noinfo,nobanner,noo
Title[local_openvpn]: Number of VPN Connections
MaxBytes[local_openvpn]: 100
YLegend[local_openvpn]: Users
ShortLegend[local_openvpn]:
LegendO[local_openvpn]: VPN Users:
Legend2[local_openvpn]: VPN Users

PageTop[local_openvpn]: Users Logged to The VPN
WithPeak[local_openvpn]:wmy
Legend4[local_openvpn]: Max number of users on the VPN






Labels: , , , , , ,

0 Comments:

Post a Comment

<< Home