claudineimatos / zabbix_template-openvpn-autodiscovery

Simple Zabbix template to auto discovery OpenVPN connections
10 stars 8 forks source link

Monitor openvpn without sock file #3

Open roberdaniel opened 3 years ago

roberdaniel commented 3 years ago

Hi all I'm trying to deploy this script but in many places it refers to sock file but in my deploy Openvpn did not use any sock file. So how to proceed? Regards

huntastikus commented 3 years ago

Same here, please share if you find an answer :(

safaribaer commented 3 years ago

I learned a lot from this template but I do not use it. I also do not know how the autodiscovery works. I do not need it because I only monitor the servers and configure everything manually. I allways have a Zabbix Agent on the server. Here is what I use: Create file and make it executable /usr/local/bin/openvpn_get_status.sh

#!/bin/bash
echo "state" | /usr/bin/socat tcp4:127.0.0.1:5555 stdio 2>/dev/null |grep -q CONNECTED,SUCCESS && echo 1 || echo 0

Create file and make it executable /usr/local/bin/openvpn_get_clients.sh

#!/bin/bash
echo "load-stats" | /usr/bin/socat tcp4:127.0.0.1:5555 stdio 2>/dev/null | grep SUCCESS | cut -d= -f 2 |   cut -d, -f 1 || echo 0

Tell sudo to allow this commands without password. file /etc/sudoers.d/zabbix

zabbix ALL=(ALL) NOPASSWD: /usr/local/bin/openvpn_get_status.sh
zabbix ALL=(ALL) NOPASSWD: /usr/local/bin/openvpn_get_clients.sh

Append this to /etc/zabbix/zabbix_agentd.conf :

UserParameter=openvpn.server.status[*],/usr/local/bin/openvpn_get_status.sh
UserParameter=openvpn.server.clients[*],/usr/local/bin/openvpn_get_clients.sh

Restart Zabbix Agent....

Test from your Zabbix server:

zabbix_get -s $ip_of_your_server -k openvpn.server.status
1
zabbix_get -s $ip_of_your_server -k openvpn.server.clients
29

OpenVPN server configuration file contains:

management 127.0.0.1 5555

In Zabbix I create an item for OpenVPN in the server with these parameters: Type: Zabbix agent Key: openvpn.server.clients[x]

I know that [x] is not really needed.

hth