Centos – Email alert when OpenVPN disconnects

centosopenvpnsyslog

I am running OpenVPN client on my dedicated server to connect the server to a private network. Last week, the service (i.e. OpenVPN) disconnected itself and we did not realise until our customers started to ring us. I don't know the reason why it disconnected, Now I want to set up email alert as soon as the OpenVPN disconnects. How can I do that ? Can anyone help please.

By the way, the server is running CentOS 6.8

Thank you.

Best Answer

I have successfully set up one myself with these three steps

  1. Follow this or find your own guide to configure the script for email notification

  2. Open /etc/openvpn/server.conf and append the following lines

    script-security 2
    client-disconnect /path/to/script
    
  3. Finally chmod 755 /path/to/script


Edit: Sorry, I misread your question. Add the two lines below to client.conf. This method is preferable over cronjob as it is almost instantaneous and doesn't flood you with mail

    script-security 2
    down /path/to/script