OpenVPN notification on connect and disconnect

  • Hello,

    Since i am working with domoticz home automation and i figured out the telegram notifications (which works really great) i would like to get a notification in telegram on connect and disconnect of my openvpn. I found already some descriptions of notifications by email:

    As i can send a notification to telegram via http-call i put the command in the /usr/local/sbin/ in the connect- and disconnect-section. But it doesn't work. The connection is established normally, but no notification.

    This is the file:

    echo $script_type > /tmp/script
    if [ "$script_type" = "client-connect" ]; then
    	if [ -f /tmp/$common_name ]; then
    		/bin/cat /tmp/$common_name > $1
    		/bin/rm /tmp/$common_name
    ${trusted_ip} vpn_client_ip: ${ifconfig_pool_remote_ip} datetime: $(date +'%Y/%m/%d %H:%M:%S') ${common_name} has connected to OpenVPN
    elif [ "$script_type" = "client-disconnect" ]; then
    	command="/sbin/pfctl -a 'openvpn/$common_name' -F rules"
    	eval $command
    	/sbin/pfctl -k $ifconfig_pool_remote_ip
    	/sbin/pfctl -K $ifconfig_pool_remote_ip
    ${trusted_ip} vpn_client_ip: ${ifconfig_pool_remote_ip} datetime: $(date +'%Y/%m/%d %H:%M:%S') ${common_name} has disconnected from OpenVPN
    exit 0

    The only change in the original script are the lines with the curl-command.
    If i enter the url in the webbrowser or also in the shell of pfsense the message is sent. Sot the url is working. Just in the sript it seems not to work.

    Once it is working i will complete the message like this:
    /usr/local/bin/curl " user_name: ${common_name} remote_pub_address: ${trusted_ip} vpn_client_ip: ${ifconfig_pool_remote_ip} datetime: $(date +'%Y/%m/%d %H:%M:%S') ${common_name} has connected to OpenVPN"

    Does anyon have an idea what can be the problem?

    Thanks very much,

  • @willi25 Finally, did you get it fixed? I'm also interested in sending notifications via telegram

Log in to reply