Differences

This shows you the differences between two versions of the page.

Link to this comparison view

app-notes:cloud-router-alarms [2014/12/05 11:57] (current)
Line 1: Line 1:
 +====== Cloud Router Alarms======
 +Cloud Router shall send an alarm message via email, if one or more activated clients are offline.
 +
 +===== Prerequisites =====
 +Make sure the hostname is configured correctly. If the FQDN is myserver.sub.example.com,​ ''/​etc/​hostname''​ must contain a line like
 +<code - /​etc/​hostname>​
 +myserver ​
 +</​code>​
 +and ''/​etc/​hosts''​ must contain a line like
 +<code - /​etc/​hosts>​
 +1.2.3.4 ​ myserver.sub.example.com myserver
 +</​code>​
 +Check correct configuration with ''​hostname''​ and ''​hostname -f''​
 +
 +Further, we need a Mail Transfer Agent (MTA) such as Exim 4 ((https://​packages.debian.org/​en/​wheezy/​exim4-daemon-light)) installed on our machine. For convenience reasons we will also install mailutils ((https://​packages.debian.org/​en/​wheezy/​mailutils)) so we can just call ''​mail''​ from the command line.
 +<code bash>
 +apt-get install exim4-daemon-light (or just default-mta)
 +dpkg-reconfigure exim4-config
 +apt-get install mailutils
 +</​code>​
 +
 +Choose //internet site; mail is sent and received directly using SMTP// when configuring Exim.
 +
 +Test in Shell
 +<code bash>
 +mail samuel.hess@netmodule.com
 +Cc:
 +Subject: Test
 +Some Body Text
 +Ctrl + D to send
 +</​code>​
 +
 +
 +
 +===== Implementation =====
 +
 +Cloud Router stores the current connections status for OpenVPN clients under ''/​tmp/​vpnportal/​openvpn_clients''​
 +Make a file called ''​activated''​ with the activated clients
 +<code - activated>​
 +OPENVPN_CLIENT_1
 +OPENVPN_CLIENT_2
 +OPENVPN_CLIENT_3
 +OPENVPN_CLIENT_4
 +OPENVPN_CLIENT_5
 +OPENVPN_CLIENT_6
 +OPENVPN_CLIENT_7
 +OPENVPN_CLIENT_8
 +OPENVPN_CLIENT_9
 +OPENVPN_CLIENT_10
 +</​code>​
 +
 +Run a script like this:
 +<code bash surveyor.sh>​
 +# This script checks every $interval if the activated clients are online. ​
 +# If one or more activated clients are offline, an e-mail alarm is sent.
 +activatedClients=/​tmp/​vpnportal/​openvpn_clients/​activated
 +connectedClients=/​tmp/​vpnportal/​openvpn_clients/​connected
 +interval=60
 +recipient=alarms@netmodule.com
 +
 +while true; do
 +    while read client
 +    do
 +        grep -q $client $connectedClients
 +        if [ $? -eq 0 ]
 +        then
 +            echo "​$client is connected"​ > /dev/null
 +        else
 +            echo "​$client is offline"​
 +            echo "​$client is offline"​ >> message2
 +        fi
 +    done < $activatedClients
 +    if [ -f message2 ]
 +    then
 +        echo "​sending alarm message"​
 +        echo "This alarm message is coming from $(hostname -f) since one or more activated clients are offline:"​ > message1
 +        cat message1 message2 | mail -s "Cloud Router Alarm: Client(s) offline"​ recipient
 +        rm message*
 +    fi
 +    sleep $interval
 +done
 +</​code>​