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 ​
 +and ''/​etc/​hosts''​ must contain a line like
 +<code - /​etc/​hosts>​
 + ​ myserver.sub.example.com myserver
 +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
 +Choose //internet site; mail is sent and received directly using SMTP// when configuring Exim.
 +Test in Shell
 +<code bash>
 +mail samuel.hess@netmodule.com
 +Subject: Test
 +Some Body Text
 +Ctrl + D to send
 +===== 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>​
 +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.
 +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