Messing about with IT

Network monitoring using Synology NAS and

I’ve been using this script on a Synology NAS to monitor other hosts on the same network. In the event that a host stops responding to ping, a notification is sent by This allows me to use the NAS as a basic availability monitor for other devices on the network.

About is a cron job monitoring service. It listens for HTTP requests and email messages (“pings”) from your cron jobs and scheduled tasks (“checks”). When a ping doesn’t arrive on time, Healthchecks sends out alerts. You can create a free ‘Hobbyist’ account and receive alerts for up to 20 devices, then upgrade later if you need more.

Why not just send an email?

I’ve attempted to get Network monitoring using Synology NAS and a ping script to send email from a Synology NAS in the past without success so decided to use as I had already set that up for other purposes.

In addition, you get the benefit of receiving an email when your main router is not reachable (as the alert is sent from the website, rather than from a device on your own network).

Setting up

Sign up for an account, then add a new check for each network device you’d like to monitor.

You can configure each check with an expected period and grace time, for example ‘expect a ping every five minutes and allow 4 minutes grace time in case it’s late’. If the ping is not received by the check within the grace period, then send an email alert.

For example, in the image below are three checks for devices on a local network. Each check is configured to send an email on failure. Since this screenshot was taken, I’ve added an additional ‘self check’ url to monitor the running of this script from too.

Network monitoring using Synology NAS: website showing 3 checks

Once you’ve added checks for each device you want to monitor, you should test each one by visiting the given url with your web browser. You should find the status turns green in after the browser visits the url.

You can also simulate a failure to confirm that an alert email is sent. To do so, append /fail to the end of the check url, for example:{uuid}/fail

Confirm that you receive an email as per the check configuration.

Creating the script on the Synology NAS

Save the script below into a new text file and store it on a Synology NAS volume. E.g. /volume1/Documents/ScheduledTasks/

Set the permissions so that the root user has execute permission. In this screenshot, the script owner is in the administrators group:

Set permissions for the custom script

Test the script (use sudo /path/ using an ssh session. You can see the output on screen and this is also output to a log file.

Main router ( is up
Retry count (5) exceeded
Wi-Fi access point ( is down, sending notification
Network Switch ( is up

Setting up the scheduled task on the Synology NAS

On the Synology NAS, go to Control Panel > Task Scheduler, click Create, and select Scheduled Task

See the screenshots here for guidance, or check the current Synology documentation on scheduled tasks.

  1. Enter a task name and set the user as root
Scheduled Task General Settings, set the user as root

2. Set the task to run Daily starting at 00:00 and repeat at the interval you chose when creating the checks. Set the last run time to be midnight, less check the interval

Scheduled Task recurrence settings

3. Enter the path on the NAS to the script you created earlier. No need to configure email notification here.

Network monitoring using Synology NAS: Scheduled Task settings, enter the file path for the script

How to configure the script

Note that this has only been tested with DSM 6.2. In this example, the script is configured to monitor 3 hosts. You will need to prepare the following details for your own hosts and edit the script as necessary on lines 17 to 32.

IP addressDescriptionSuccess URLFailure URL router access point Switch

Script for network monitoring using Synology NAS


# Add new elements to each of the arrays below, ensuring you keep the values
# in the same position in each array. For example, looking up 3 in the first
# array will return c, iii and # from the subseqent arrays:
#  (1 2 3 4)
#  (a b c d)
#  (i ii iii iv)
#  (£ $ # %)
# Also, ensure that each array contains the same number of elements
# While loop based on an example by Sirch from here:

# add list of ips to monitor
ips=("" "" "")

# add descriptive names for each IP address
hostnames=("Main router" "Wi-Fi access point" "Network Switch")

# add 'success' urls for each ip from
upURLs=("" "" "")

# add 'failure' urls for each ip from
downURLs=("" "" "")

# add a 'self check' url to monitor this script from

# define a log file
echo "$(date)" > $logfile

# no need to change anything below this point

# check that arrays contain same number of elements

if [ $CheckIPS -ne $CheckHostnames ] || [ $CheckIPS -ne $CheckUpURLs ] || [ $CheckIPS -ne $CheckDownURLs ]
  echo ERROR: arrays contain different number of elements, exiting 2>&1 |& tee -a $logfile
  exit 1
# arrays are OK, begin checks

# send a self-check notification that this script is running
wget -T 10 -qO - $selfCheckURL > /dev/null

# ping function
PingIP () {
  local max=5 # number of ping attempts
  local delay=1 # seconds between attempts
  local count=0 # starting count
  while [ $count -lt $max ]; do
    ping -c 1 $1 > /dev/null
    if [ $? -eq 0 ]; then
      return 0
    sleep $delay # wait for $delay seconds before retrying
    let $((count+=1)) # increment count variable by one
  echo "Retry count ($count) exceeded" 2>&1 |& tee -a $logfile
  return 1

# define counter as 'n', starting at zero

# loop through each IP address
for i in "${ips[@]}"; do
  PingIP "$i"
    if [ $? -ne 0 ]; then
      echo "${hostnames[$n]} ($i) is down, sending notification" 2>&1 |& tee -a $logfile
      # request a URL to notify the current status 
      wget -T 10 -qO - ${downURLs[$n]} > /dev/null
      echo "${hostnames[$n]} ($i) is up" 2>&1 |& tee -a $logfile
      # request a URL to notify the current status
      wget -T 10 -qO - ${upURLs[$n]} > /dev/null
    let $((n+=1)) # increment n variable by one

1 Comment

  1. Ivan

    Hi. This looks great! Is there a way of monitoring as well latency within the network so if for example is below a specific threshold it alerts?

© 2024 Tech Explorer

Theme by Anders NorénUp ↑