Page 1 of 1

Network Infrastructure Monitoring

Posted: Tuesday 20 September 2016 10:08
by MarceldeJongNL
I was looking to manage my home network and to be notified for any outages. I have been looking at tools like OpenNMS, Cacti etc but I found them all to be quite complex for my needs. So I decided to try and use my Domoticz set for this purpose and have build the following config:


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&param=udevice&idx=$idx&nvalue=0&sval$
Create a scheduled script:

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
Check open ports:

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&param=switchlight&idx=$idx&switchcmd=Off"
##echo "$domoticz:8080/json.htm?type=command&param=switchlight&idx=$idx&&switchcmd=Off"
else echo "port open"
curl "$domoticz:8080/json.htm?type=command&param=switchlight&idx=$idx&switchcmd=On"
fi
Created a scheduled script:
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:
marceldejong_kls39.jpg
marceldejong_kls39.jpg (105 KiB) Viewed 10686 times

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.
chart.jpeg
chart.jpeg (32.89 KiB) Viewed 10686 times
Let me know what you think and if you have any suggestions!

Re: Networking Infrastructure Monitoring

Posted: Tuesday 20 September 2016 12:42
by emme
:o :o :o
will do the same as soon as I can!!! :lol: :lol: :lol:

Re: Networking Infrastructure Monitoring

Posted: Tuesday 20 September 2016 13:44
by zeputt
:shock: Nice!
Looks really good and a breeze to administrate if you know your way around in Domoticz.
I will have to make a setup for my own net - thanks for sharing!!

Re: Networking Infrastructure Monitoring

Posted: Wednesday 21 September 2016 8:46
by MarceldeJongNL
Thanks, if you make something nice, please share!

Re: Network Infrastructure Monitoring

Posted: Sunday 16 October 2016 13:03
by franzelare
sweet!

this is added to my todo list!
likely with the addition to send out alarm emails to me when times are outside normal values 3 sigma limits or so...

Re: Network Infrastructure Monitoring

Posted: Monday 17 October 2016 10:34
by franzelare
MarceldeJongNL wrote: Ping Devices:
For every device I wanted to measure I made a Custom Sensor, value ms (milliseconds)
what kind of sensor did you use? or how did you create it?
because if i use a counter, the values are all noted in full numbers and the ms from the ping are not correctly displayed in domoticz

Re: Network Infrastructure Monitoring

Posted: Monday 17 October 2016 11:06
by franzelare
fixed it by using a counter and multiply the ping result with 1000 to convert to ms before sending it to domoticz

Re: Network Infrastructure Monitoring

Posted: Wednesday 19 October 2016 7:31
by MarceldeJongNL
franzelare wrote: what kind of sensor did you use? or how did you create it?
because if i use a counter, the values are all noted in full numbers and the ms from the ping are not correctly displayed in domoticz
I just use a "custom" sensor, and label it "ms"
My values are noted in *.*** ms

Re: Network Infrastructure Monitoring

Posted: Sunday 23 October 2016 14:47
by Derik
Great stuff!!!
Real you all make my days to sort.....
This one is on my bucket list..

What do you have for other options whit this option

Re: Network Infrastructure Monitoring

Posted: Wednesday 26 October 2016 8:44
by MarceldeJongNL
Found a little issue with nmap.sh.
If a host is down, nmap will report that instead of using the word closed. So I changed the grep to:

Code: Select all

value=`nmap $host -p $port -Pn | grep 'closed\|down\|filtered'`
so now the light icons for the ports go out if the host is down

Also changed ping.sh to

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"
 if [ $value = ""]; then
               value=99999
            fi
curl "$domoticz:8080/json.htm?type=command&param=udevice&idx=$idx&nvalue=0&svalue=$value


This will set the ping counter to 99999ms if the host is down. Makes it easier to send alarm if the value is higher than ......

Re: Network Infrastructure Monitoring

Posted: Thursday 19 January 2017 19:39
by dutchdevil83
Thanx for sharing this.

Going to use this for my systemcontrol page!

Re: Network Infrastructure Monitoring

Posted: Thursday 19 January 2017 22:36
by franzelare
I added my versions of the script and more network monitoring in this topic:
viewtopic.php?f=23&t=15553

I'm also runing uptime counters and device on timers

Re: Network Infrastructure Monitoring

Posted: Saturday 21 January 2017 11:47
by dutchdevil83
I`m getting following error when running pingall.sh

Code: Select all

pi@raspberrypi:~/domoticz/scripts $ sh pingall.sh
: not found 3: pingall.sh:
pingall.sh: 4: pingall.sh: Syntax error: "(" unexpected
My scriptfile is looking like this:

Code: Select all

echo start >> /home/pi/domoticz/scripts/pingall.log
date >> /home/pi/domoticz/scripts/pingall.log

vars=(
"192.168.192.1 3 602 Ping Ziggo"
"192.168.192.6 3 603 Ping Camera"
)


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

Re: Network Infrastructure Monitoring

Posted: Saturday 21 January 2017 13:25
by dutchdevil83
ok found the error. Added bin/bash to script and ran it as bash script and it works now. The ping.sh has to be edited for use with domoticz. The script wasn`t working for me. This one worked for me:

Code: Select all

#!/bin/bash
host=$1
count=$2
idx=$3
name=$4
domoticz=127.0.0.1
port=8080

value=`ping -c $count $host | awk -F '/' 'END {print $5}'`

#output if you run it manually
printf "$4 ping = $ping ms"

curl -s -i -H "Accept: application/json" "http://$domoticz:$port/json.htm?type=command&param=udevice&idx=$idx&svalue=$value"

Re: Network Infrastructure Monitoring

Posted: Sunday 22 January 2017 21:57
by felix63
MarceldeJongNL wrote:I was looking to manage my home network and to be notified for any outages. I have been looking at tools like OpenNMS, Cacti etc but I found them all to be quite complex for my needs.
Let me know what you think and if you have any suggestions!
Great.. spend an evening but now its up an running. Thanks!

Re: Network Infrastructure Monitoring

Posted: Wednesday 08 February 2017 14:50
by rickwilleme
Hmm.. Definitely worth adding to Domoticz. Thanks for the inspiration!