diff --git a/plugins/openvpn/openvpn_as_mtime b/plugins/openvpn/openvpn_as_mtime new file mode 100755 index 00000000..c92720f6 --- /dev/null +++ b/plugins/openvpn/openvpn_as_mtime @@ -0,0 +1,82 @@ +#!/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 + +=head1 LICENSE + +GPLv2 + +=head1 MAGICK MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +. $MUNIN_LIBDIR/plugins/plugin.sh + + + + +if [ "$1" = "autoconf" ]; then + echo yes + 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' + echo 'graph_category OpenVPN' + echo 'graph_info Indicate the medium time of the logged users.' + + echo "time.label Users" + echo "time.type GAUGE" + echo "time.min 0" + + 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 +if [[ $TOTU -eq 0 ]]; then + TOTU=1 +fi + +# Total is total time between number of users between 60 for give it in minutes +echo "time.value $(($(($SUM / $TOTU)) / 60))" + + diff --git a/plugins/openvpn/openvpn_as_traffic b/plugins/openvpn/openvpn_as_traffic new file mode 100755 index 00000000..61e4de2f --- /dev/null +++ b/plugins/openvpn/openvpn_as_traffic @@ -0,0 +1,89 @@ +#!/bin/bash +# -*- bash -*- + +: << =cut + +=head1 NAME + +openvpn_as_traffic -OpenVPN traffic + +=head1 CONFIGURATION + +Require jsonpipe software: +https://github.com/dvxhouse/jsonpipe + +[openvpn_as*] + user root + +=head1 AUTHOR + +Ricardo Fraile + +=head1 LICENSE + +GPLv2 + +=head1 MAGICK MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +. $MUNIN_LIBDIR/plugins/plugin.sh + + +# Script folder +D_BIN="/usr/local/openvpn_as/scripts" +SUM1=0 +SUM2=0 +NOW=`date +%s` + +if [ "$1" = "autoconf" ]; then + echo yes + exit 0 +fi + +if [ "$1" = "config" ]; then + + echo "graph_title OpenVPN traffic" + echo 'graph_args --base 1000' + echo 'graph_vlabel Bytes in (-) / out (+)' + echo 'graph_category OpenVPN' + echo "graph_info OpenVPN traffic" + + + echo "down.label Bytes" + echo "down.type DERIVE" + echo "down.graph no" + echo "down.cdef down,8,*" + echo "down.min 0" + + echo "up.label Bytes" + echo "up.type DERIVE" + echo "up.negative down" + echo "up.cdef up,8,*" + echo "up.info Bytes" + echo "up.min 0" + exit 0 +fi + +# List users values, bytes sent +LIST1=`$D_BIN/sacli VPNStatus | tr '/' - | jsonpipe | grep "/openvpn_[0-9]/client_list/[0-9]/4" | tr -d '"' | awk '{print $2} '` + +# Sum list +for i in $LIST1; do + SUM1=`expr $SUM1 + $i` +done + +# List users values, bytes received +LIST2=`$D_BIN/sacli VPNStatus | tr '/' - | jsonpipe | grep "/openvpn_[0-9]/client_list/[0-9]/3" | tr -d '"' | awk '{print $2} '` + +# Sum list +for i in $LIST2; do + SUM2=`expr $SUM2 + $i` +done + + +echo "down.value $SUM1" +echo "up.value $SUM2" diff --git a/plugins/openvpn/openvpn_as_ttime b/plugins/openvpn/openvpn_as_ttime new file mode 100755 index 00000000..dfbd1757 --- /dev/null +++ b/plugins/openvpn/openvpn_as_ttime @@ -0,0 +1,91 @@ +#!/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 + +=head1 LICENSE + +GPLv2 + +=head1 MAGICK MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +. $MUNIN_LIBDIR/plugins/plugin.sh + + + + +if [ "$1" = "autoconf" ]; then + echo yes + 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' + echo 'graph_category OpenVPN' + 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 + + 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 diff --git a/plugins/openvpn/openvpn_as_users b/plugins/openvpn/openvpn_as_users new file mode 100755 index 00000000..640a48b6 --- /dev/null +++ b/plugins/openvpn/openvpn_as_users @@ -0,0 +1,80 @@ +#!/bin/sh +# -*- sh -*- + +: << =cut + +=head1 NAME + +openvpn_as_users -Indicate the number of users and the license limit + +=head1 CONFIGURATION + +[openvpn_*] +user root + +=head1 AUTHOR + +Ricardo Fraile + +=head1 LICENSE + +GPLv2 + +=head1 MAGICK MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +. $MUNIN_LIBDIR/plugins/plugin.sh + + + + +if [ "$1" = "autoconf" ]; then + echo yes + exit 0 +fi + +# Script folder +D_BIN="/usr/local/openvpn_as/scripts" +# Number of clients +VAL1=`$D_BIN/sacli VPNSummary | grep clients | awk '{print $2}'` +# Limit of clients by license +VAL2=`$D_BIN/liman info | grep -o "[0-9]*"` +# Warn value +WARN=80 + +if [ "$1" = "config" ]; then + + echo 'graph_title OpenVPN Users' + echo 'graph_args --base 1000 -l 0 ' + echo 'graph_vlabel Users' + echo 'graph_scale no' + echo 'graph_category OpenVPN' + echo 'graph_info Indicate the number of vpn users and the license limit.' + + echo "users.label Users" + echo "users.type GAUGE" + echo "users.draw AREA" + echo "users.min 0" + + echo "users.warning $((VAL2 * $WARN / 100))" + echo "users.critical $VAL2" + + + echo "limit.label Limit" + echo "limit.type GAUGE" + echo "limit.min 0" + + + exit 0 +fi + + + +echo "users.value $VAL1" +echo "limit.value $VAL2" + +