Internet Connection Monitoring.
Set-up the script defined here: viewtopic.php?f=28&t=11970
This provides me with ping time and current upload and download speed.
Ping Devices:
For every device I wanted to measure I made a Custom Sensor, value ms (milliseconds)
Created a standard script:
Ping.sh
Code: Select all
host=$1
count=$2
idx=$3
name=$4
domoticz=127.0.0.1
value=`ping -c $count $host | awk -F '/' 'END {print $5}'`
echo "$4 $value"
curl "$domoticz:8080/json.htm?type=command¶m=udevice&idx=$idx&nvalue=0&sval$
In the Vars section I put all the devices I wanted to check.
syntax is “IP-address #of pings VirtualSwitch Description”
There is some logging in /home/pi/domoticz/scripts/pingall.log, used for troubleshooting
pingall.sh
Code: Select all
echo start >> /home/pi/domoticz/scripts/pingall.log
date >> /home/pi/domoticz/scripts/pingall.log
vars=(
"192.168.0.1 3 773 Ziggo"
"192.168.1.254 3 774 Linksys"
"192.168.1.253 3 775 Synology"
"192.168.1.175 3 776 ESX"
"192.168.1.13 3 778 Exchange"
"192.168.1.12 3 779 DC"
"192.168.1.14 3 780 Mailcleaner"
"192.168.1.133 3 782 Resol"
"192.168.1.199 3 783 Synology2"
"192.168.1.119 3 784 RP-AC52"
)
echo $vars >> /home/pi/domoticz/scripts/pingall.log
for v in "${vars[@]}";
do
echo $v >> /home/pi/domoticz/scripts/pingall.log
/home/pi/domoticz/scripts/ping.sh $v >> /home/pi/domoticz/scripts/pingall.log;
done
#date >> /home/pi/domoticz/scripts/pingall.log
echo done >> /home/pi/domoticz/scripts/pingall.log
To check if applications are functioning I decided to check if the TCP ports are open. I use nmap for this. If it’s not available, you can install it via apt:
sudo apt-get install nmap
Created a standard script:
nmap.sh
Code: Select all
host=$1
port=$2
idx=$3
name=$4
domoticz=127.0.0.1
value=
value=`nmap $host -p $port | grep closed`
echo "$4 $value"
if [ -n "$value" ]
then echo "port closed"
curl "$domoticz:8080/json.htm?type=command¶m=switchlight&idx=$idx&switchcmd=Off"
##echo "$domoticz:8080/json.htm?type=command¶m=switchlight&idx=$idx&&switchcmd=Off"
else echo "port open"
curl "$domoticz:8080/json.htm?type=command¶m=switchlight&idx=$idx&switchcmd=On"
fi
In the Vars section I put all the devices and Ports I wanted to check.
syntax is “IP-address Port# VirtualSwitch Description”
Description is not used, only for my own reference.
There is some logging in /home/pi/domoticz/scripts/nmapall.log, used for troubleshooting
nmapall.sh
Code: Select all
echo start >> /home/pi/domoticz/scripts/nmapall.log
date >> /home/pi/domoticz/scripts/nmapall.log
vars=(
"192.168.0.1 80 786 Ziggo HTTP"
"192.168.0.1 443 787 Ziggo HTTPS"
"192.168.0.1 2602 788 Ziggo RIPD"
"192.168.1.254 5000 790 Linksys UPNP"
"192.168.1.254 5000 789 Linksys HTTP"
"192.168.1.253 22 791 Synology SSH"
"192.168.1.253 25 792 Synology SMTP"
"192.168.1.253 53 785 Synology DNS"
"192.168.1.253 80 793 Synology HTTP"
"192.168.1.253 443 794 Synology HTTPS"
"192.168.1.253 5000 795 Synology DSM"
"192.168.1.253 5001 796 Synology DSM-s"
"192.168.1.175 22 798 ESX SSH"
"192.168.1.175 443 797 ESX HTTPS"
"192.168.1.13 25 799 Exchange SMTP"
"192.168.1.13 80 800 Exchange HTTP"
"192.168.1.13 443 801 Exchange HTTPS"
"192.168.1.13 3389 802 Exchange RDP"
"192.168.1.12 53 803 DC DNS"
"192.168.1.12 389 804 DC LDAP"
"192.168.1.12 88 805 DC Kerb"
"192.168.1.12 139 806 DC Netbios"
"192.168.1.14 22 807 Mailcleaner SSH"
"192.168.1.14 25 808 Mailcleaner SMTP"
"192.168.1.14 80 809 Mailcleaner HTTP"
"192.168.1.133 80 810 Resol HTTP"
"192.168.1.199 22 811 Synology2 SSH"
"192.168.1.199 80 812 Synology2 HTTP"
"192.168.1.199 443 813 Synology2 HTTPS"
"192.168.1.199 139 814 Synology2 NetBios"
"192.168.1.199 548 815 Synology2 AFP"
"192.168.1.199 5000 816 Synology2 DSM"
"192.168.1.199 5001 817 Synology2 DSM-s"
"192.168.1.119 80 818 RP-AC52 HTTP"
)
for v in "${vars[@]}";
do
echo $v >> /home/pi/domoticz/scripts/nmapall.log
/home/pi/domoticz/scripts/nmap.sh $v >> /home/pi/domoticz/scripts/nmapall.log;
done
#date >> /home/pi/domoticz/scripts/pingall.log
echo done >> /home/pi/domoticz/scripts/nmapall.log
Scheduled the scripts via crontab:
Code: Select all
55 * * * * /home/pi/domoticz/scripts/speedtest.sh
*/2 * * * * bash -l /home/pi/domoticz/scripts/pingall.sh
*/10 * * * * bash -l /home/pi/domoticz/scripts/nmapall.sh
I created a nice image for the the floorplan, added the created Switches and Sensors. Also the Standard Motherboard Monitors for my Pi and now I have the following overview of my network:
I can use the logging to see when there was anything wrong with a device, like this example when my Linksys router was acting up. Let me know what you think and if you have any suggestions!