Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / vpn / openvpn_as_mtime @ 17f78427

Historique | Voir | Annoter | Télécharger (1,56 ko)

1
#!/bin/sh
2
# -*- sh -*-
3

    
4
: << =cut
5

    
6
=head1 NAME
7

    
8
openvpn_as_time -Indicate the medium time of the logged users.
9

    
10
=head1 CONFIGURATION
11

    
12
Require jsonpipe software:
13
https://github.com/dvxhouse/jsonpipe
14

    
15
[openvpn_*]
16
user root
17

    
18
=head1 AUTHOR
19

    
20
Ricardo Fraile <rfrail3@yahoo.es>
21

    
22
=head1 LICENSE
23

    
24
GPLv2
25

    
26
=head1 MAGICK MARKERS
27

    
28
 #%# family=auto
29
 #%# capabilities=autoconf
30

    
31
=cut
32

    
33
. $MUNIN_LIBDIR/plugins/plugin.sh
34

    
35

    
36

    
37

    
38
if [ "$1" = "autoconf" ]; then
39
	echo yes
40
	exit 0
41
fi
42

    
43
SUM=0
44
NOW=`date +%s`
45
# Script folder
46
D_BIN="/usr/local/openvpn_as/scripts"
47

    
48
# List with users time
49
LIST1=`$D_BIN/sacli VPNStatus | tr '/' - |  jsonpipe  | grep "/openvpn_[0-9]/client_list/[0-9]/6" | tr -d '"'  | awk '{print $2} '`
50
# Count users listed
51
TOTU=`$D_BIN/sacli VPNStatus | tr '/' - |  jsonpipe  | grep "/openvpn_[0-9]/client_list/[0-9]/6" | tr -d '"'  | awk '{print $2} ' | wc -l`
52

    
53
if [ "$1" = "config" ]; then
54

    
55
	echo 'graph_title OpenVPN Users medium time'
56
	echo 'graph_args --base 1000 -l 0 '
57
	echo 'graph_vlabel Time in minutes'
58
	echo 'graph_scale no'
59
	echo 'graph_category network'
60
	echo 'graph_info Indicate the medium time of the logged users.'
61

    
62
        echo "time.label Users"
63
        echo "time.type GAUGE"
64
        echo "time.min 0"
65

    
66
	exit 0
67
fi
68

    
69
# Sum all times (times are the time request minus epoch date at now)
70
for i in $LIST1; do
71
        SUM=`expr $SUM + $((NOW - $i))`
72
done
73

    
74
# If TOTU is 0, change to 1 for avoid problem in the division
75
if [ "$TOTU" = "0" ]; then
76
        TOTU=1
77
fi
78

    
79
# Total is total time between number of users between 60 for give it in minutes
80
echo "time.value $(($(($SUM / $TOTU)) / 60))"
81

    
82