-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathopenvpn_usercount
executable file
·73 lines (62 loc) · 2.03 KB
/
openvpn_usercount
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
##
## Munin plugin to return how many OpenVPN sessions are currently connected to
## an OpenVPN server.
##
## The 'openvpn_usercount' config stanza for munin-node looks like:
##
### [openvpn_usercount]
### user root
### env.statusfile "/var/log/openvpn-status.log"
##
## You can watch mutiple OpenVPN networks by aliasing openvpn_usercount script
## to "openvpn_usercount_network.vpn" where "network.vpn" is the OpenVPN
## network name.
##
### [openvpn_usercount_network.vpn]
### user root
### env.statusfile "/var/log/openvpn/network.vpn/openvpn-status.log"
##
## Original Author: Jeffrey Forman ( https://github.com/jforman )
## Enhanced by : Pierre-Yves Landuré for Biapy ( https://github.com/biapy )
##
# Compute statusfile option.
OPENVPN_STATUS_FILE="/var/log/openvpn-status.log"
if [ -n "${statusfile}" ]; then
OPENVPN_STATUS_FILE="${statusfile}"
fi
# Check for status log existance.
if [ ! -e "${OPENVPN_STATUS_FILE}" ]; then
echo "Error: OpenVPN status file '${OPENVPN_STATUS_FILE}' does not exist"
exit 1
fi
# Detect VPN network name from script name.
NETWORK_NAME="$(command basename "${0}" \
| command sed -e 's/openvpn_usercount[_]\{0,1\}//')"
if [ -n "${NETWORK_NAME}" ]; then
NETWORK_NAME=" (${NETWORK_NAME})"
fi
case "${1}" in
"config" )
# Display munin-node plugin configuration.
echo "graph_title OpenVPN Users${NETWORK_NAME}
graph_vlabel User Count
graph_category openvpn
user.label Logged In Users"
exit 0
;;
* )
# Default action.
# This compute the number of connected clients for all
# status-version values.
CLIENT_LIST_START="$(command grep --max-count=1 --line-number \
"Connected Since" "${OPENVPN_STATUS_FILE}" \
| command cut --delimiter=":" --field="1")"
CLIENT_LIST_END="$(command grep --max-count=1 --line-number \
"ROUTING[ _]TABLE" "${OPENVPN_STATUS_FILE}" \
| command cut --delimiter=":" --field="1")"
USER_COUNT=$((${CLIENT_LIST_END} - ${CLIENT_LIST_START} - 1))
echo "user.value ${USER_COUNT}"
exit 0;
;;
esac