2012-10-09 10:59:38 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# -*- sh -*-
|
|
|
|
|
|
|
|
: << =cut
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
openvpn_as_time -Indicate user logged time.
|
|
|
|
|
|
|
|
=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
|
|
|
|
COUNT=1
|
|
|
|
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} '`
|
|
|
|
# List with users names
|
|
|
|
LIST2=`$D_BIN/sacli VPNStatus | tr '/' - | jsonpipe | grep "/openvpn_[0-9]/client_list/[0-9]/0" | tr -d '"' | awk '{print $2} '`
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
|
|
|
|
|
|
|
echo 'graph_title OpenVPN User logged 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 user logged time.'
|
|
|
|
|
|
|
|
# If none, print 0
|
|
|
|
if [ -z $LIST1 ]; then
|
|
|
|
LIST1=$NOW
|
|
|
|
LIST2="none"
|
|
|
|
fi
|
|
|
|
|
|
|
|
for i in $LIST1; do
|
|
|
|
NAME=`echo $LIST2 | cut -d " " -f $COUNT`
|
|
|
|
echo "$NAME.label User $NAME"
|
|
|
|
echo "$NAME.type GAUGE"
|
|
|
|
echo "$NAME.min 0"
|
|
|
|
COUNT=$((COUNT + 1))
|
|
|
|
done
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2012-10-09 10:59:38 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If none, print 0
|
|
|
|
if [ -z $LIST1 ]; then
|
|
|
|
LIST1=$NOW
|
|
|
|
LIST2="none"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Print values
|
|
|
|
for i in $LIST1; do
|
|
|
|
NAME=`echo $LIST2 | cut -d " " -f $COUNT`
|
|
|
|
echo "$NAME.value $(($((NOW - $i)) / 60))"
|
|
|
|
COUNT=$((COUNT + 1))
|
|
|
|
done
|