2012-10-09 10:59:38 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# -*- sh -*-
|
|
|
|
|
|
|
|
: << =cut
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
openvpn_as_time -Indicate the medium time of the logged users.
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
Require jsonpipe software:
|
|
|
|
https://github.com/dvxhouse/jsonpipe
|
|
|
|
|
|
|
|
[openvpn_*]
|
|
|
|
user root
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
Ricardo Fraile <rfrail3@yahoo.es>
|
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
GPLv2
|
|
|
|
|
|
|
|
=head1 MAGICK MARKERS
|
|
|
|
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
. $MUNIN_LIBDIR/plugins/plugin.sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
2018-08-02 02:03:42 +02:00
|
|
|
echo yes
|
2012-10-09 10:59:38 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
SUM=0
|
|
|
|
NOW=`date +%s`
|
|
|
|
# Script folder
|
|
|
|
D_BIN="/usr/local/openvpn_as/scripts"
|
|
|
|
|
|
|
|
# List with users time
|
|
|
|
LIST1=`$D_BIN/sacli VPNStatus | tr '/' - | jsonpipe | grep "/openvpn_[0-9]/client_list/[0-9]/6" | tr -d '"' | awk '{print $2} '`
|
|
|
|
# Count users listed
|
|
|
|
TOTU=`$D_BIN/sacli VPNStatus | tr '/' - | jsonpipe | grep "/openvpn_[0-9]/client_list/[0-9]/6" | tr -d '"' | awk '{print $2} ' | wc -l`
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
|
|
|
|
|
|
|
echo 'graph_title OpenVPN Users medium time'
|
|
|
|
echo 'graph_args --base 1000 -l 0 '
|
|
|
|
echo 'graph_vlabel Time in minutes'
|
|
|
|
echo 'graph_scale no'
|
2017-02-23 17:08:02 +01:00
|
|
|
echo 'graph_category network'
|
2012-10-09 10:59:38 +02:00
|
|
|
echo 'graph_info Indicate the medium time of the logged users.'
|
|
|
|
|
|
|
|
echo "time.label Users"
|
|
|
|
echo "time.type GAUGE"
|
|
|
|
echo "time.min 0"
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2012-10-09 10:59:38 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Sum all times (times are the time request minus epoch date at now)
|
|
|
|
for i in $LIST1; do
|
|
|
|
SUM=`expr $SUM + $((NOW - $i))`
|
|
|
|
done
|
|
|
|
|
|
|
|
# If TOTU is 0, change to 1 for avoid problem in the division
|
2014-10-04 22:23:52 +02:00
|
|
|
if [ "$TOTU" = "0" ]; then
|
2012-10-09 10:59:38 +02:00
|
|
|
TOTU=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Total is total time between number of users between 60 for give it in minutes
|
|
|
|
echo "time.value $(($(($SUM / $TOTU)) / 60))"
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2012-10-09 10:59:38 +02:00
|
|
|
|