HowTo: monitor Synology NAS

Compatibility (hardware, devices and OS)
Post Reply
rvmourik
Posts: 54
Joined: Tuesday 07 January 2014 23:39
Target OS: Raspberry Pi
Domoticz version:
Contact:

HowTo: monitor Synology NAS

Post by rvmourik » Sunday 12 January 2014 15:05

Now in the WIKI: http://www.domoticz.com/wiki/NAS_Monitoring

In addition to the post of mbliek about setting up monitoring for a QNAP NAS, here is the how to for a Synology NAS.

I have used most of the info from his topic (http://www.domoticz.com/forum/viewtopic.php?f=17&t=1337), so the credits are for him :-)

Below you'll find the how-to:

First enable SNMP on your Synology NAS:

You can find the option in the Configuration Screen, it's a sub-option in "Network Services".

You can use V1/V2
And set a password (Community)

Then install SNMP on your RaspberryPi

sudo apt-get install snmpd
sudo apt-get install snmp

Reboot Pi

Check if SNMP is up and running:

Code: Select all

snmpget -c PASSWORD -v2c -O qv NASIPADDRESS .1.3.6.1.4.1.6574.1.2.0
The result will be an Integer giving you the temperature in Degrees Celcius, in my case it was:

"40"

Every device (I.E. Qnap or Synology has it own implementation layer regarding commands for SNMP, you can use the documentation together with the command line tool snmpwalk to get more information on which codes to use to get a specific output for temperature of used disk space. Below you'll find an example using snmpwalk to get more information:

Code: Select all

snmpwalk -c PASSWORD -v2c -O qv NASIPADDRESS .1.3.6.1.4.1.6574.1.2

Ouput will be someting like:

iso.3.6.1.4.1.6574.1.2.0 = INTEGER: 40

as you can see, you need to use the additional ".0" at the end to get the temperature of your Synology NAS.
Make 3 new virtual Temperature Sensors (NAS HD1, NAS HD2 and NAS Free HD)
And 1 new virtual Switch (NAS)

nas.sh (in domoticz/scripts/)

Code: Select all

#!/bin/bash

# Settings

NASIP="0.0.0.0"         # NAS IP Address
PASSWORD="password"         # SNMP Password
DOMO_IP="0.0.0.0"      # Domoticz IP Address
DOMO_PORT="0000"         # Domoticz Port

NAS_IDX="16"               # NAS Switch IDX
NAS_HD1_TEMP_IDX="14"        # NAS HD1 Temp IDX
NAS_HD2_TEMP_IDX="13"        # NAS HD2 Temp IDX
NAS_HD_SPACE_IDX="15"        # NAS HD1 Temp IDX

# Check if NAS in online 

PINGTIME=`ping -c 1 -q $NASIP | awk -F"/" '{print $5}' | xargs`

echo $PINGTIME
if expr "$PINGTIME" '>' 0
then
       echo "NAS ON"
       # Send data
        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$NAS_IDX&switchcmd=On"

        # Temperature HD1
        HDtemp1=`snmpget -v 2c -c $PASSWORD -O qv $NASIP 1.3.6.1.4.1.6574.2.1.1.6.0`
        # Send data
        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$NAS_HD1_TEMP_IDX&nvalue=0&svalue=$HDtemp1"

        # Temperature HD2
        HDtemp2=`snmpget -v 2c -c $PASSWORD -O qv $NASIP 1.3.6.1.4.1.6574.2.1.1.6.1`
        # Send data
        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$NAS_HD2_TEMP_IDX&nvalue=0&svalue=$HDtemp2"

        # Free space volume
        HDUnit=`snmpget -v 2c -c $PASSWORD -O qv $NASIP 1.3.6.1.2.1.25.2.3.1.4.36`
        HDTotal=`snmpget -v 2c -c $PASSWORD -O qv $NASIP 1.3.6.1.2.1.25.2.3.1.5.36`
        HDUsed=`snmpget -v 2c -c $PASSWORD -O qv $NASIP 1.3.6.1.2.1.25.2.3.1.6.36`
        HDFree=$((($HDTotal - $HDUsed) * $HDUnit / 1024 / 1024 / 1024))

        # Send data
        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$NAS_HD_SPACE_IDX&nvalue=0&svalue=$HDFree"

else
       echo "NAS OFF"
       # Send data
          curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$NAS_IDX&switchcmd=Off"

fi

Change the idx to your own idx

Make this script executable:
sudo chmod +x nas.sh

Try the script out:
./nas.sh

You should get something like:

Code: Select all

0.809
1
NAS ON
HTTP/1.0 200 OK
Content-Length: 51
Content-Type: text/html;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache

{
   "status" : "OK",
   "title" : "SwitchLight"
}
HTTP/1.0 200 OK
Content-Length: 53
Content-Type: text/html;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache

{
   "status" : "OK",
   "title" : "Update Device"
}
HTTP/1.0 200 OK
Content-Length: 53
Content-Type: text/html;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache

{
   "status" : "OK",
   "title" : "Update Device"
}
HTTP/1.0 200 OK
Content-Length: 53
Content-Type: text/html;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache

{
   "status" : "OK",
   "title" : "Update Device"
}

Make a new crontab job:
crontab -e
*/5 * * * * /home/pi/domoticz/scripts/nas.sh (= every 5 minutes)

Forgot to say
I did made a room called NAS and put all my virtual sensors and switch there.

Thats it, any question? Just ask.

As mbliek mentioned in his topic:
Forgot to say
I did made a room called NAS and put all my virtual sensors and switch there.
This is it for now, if you have any questions let me know. And again the credits go out to the original poster mbliek with his topic:

http://www.domoticz.com/forum/viewtopic.php?f=17&t=1337

07-02-14 change Changed a hardcoded number into a variable, thanks to BigDog for noticing
Last edited by rvmourik on Friday 07 February 2014 11:34, edited 1 time in total.

rvmourik
Posts: 54
Joined: Tuesday 07 January 2014 23:39
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: HowTo: monitor Synology NAS

Post by rvmourik » Wednesday 29 January 2014 17:44

No one using it besides myself? :o

Yihaaa
Posts: 67
Joined: Sunday 14 July 2013 10:31
Target OS: Raspberry Pi
Domoticz version: beta
Location: The Netherlands

Re: HowTo: monitor Synology NAS

Post by Yihaaa » Wednesday 29 January 2014 19:36

Well I like to have this! Very interesting, the only thing is that I am not an expert with Linux.

User avatar
BigDog
Posts: 288
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi
Domoticz version: V2.3530
Location: The Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by BigDog » Wednesday 29 January 2014 20:48

I want to use it havent got the time yet to add it to domoticz :)
1x Raspberry With Domoticz V2.3530 [Linux version 4.1.6+]
PiRack With
-1X PiFace Digital(headache device)
-1X RaZberry - OpenZWave USB
1X RFXtrx433 USB Firmware: 183
5X Arduno: mysensors V1.5(Testing)
6x ESP8266: easy firmware(Testing)
1X Synology Nas

User avatar
BigDog
Posts: 288
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi
Domoticz version: V2.3530
Location: The Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by BigDog » Thursday 30 January 2014 13:40

the nas server SNMP requested a username and a password
in the script it only shows a password
where do i put the username?
or isn't that necessary?
1x Raspberry With Domoticz V2.3530 [Linux version 4.1.6+]
PiRack With
-1X PiFace Digital(headache device)
-1X RaZberry - OpenZWave USB
1X RFXtrx433 USB Firmware: 183
5X Arduno: mysensors V1.5(Testing)
6x ESP8266: easy firmware(Testing)
1X Synology Nas

rvmourik
Posts: 54
Joined: Tuesday 07 January 2014 23:39
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: HowTo: monitor Synology NAS

Post by rvmourik » Thursday 30 January 2014 17:40

BigDog wrote:the nas server SNMP requested a username and a password
in the script it only shows a password
where do i put the username?
or isn't that necessary?
From the top of my head: you're trying to use the newest version of SNMP with Synology. When you're using V2 it only uses a password. I'm not exactly sure how to implement the newer version.

User avatar
mbliek
Posts: 809
Joined: Friday 12 July 2013 14:08
Target OS: Raspberry Pi
Domoticz version: beta
Location: the Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by mbliek » Thursday 30 January 2014 17:48

Thats true, you are using V3 then.

This line should be edited then:

snmpget -v 2c -c $PASSWORD -O qv $NASIP 1.3.6.1.4.1.6574.2.1.1.6.0

Don't know how, you should use google for this.
Or change to V2 and you don't need a username.

User avatar
BigDog
Posts: 288
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi
Domoticz version: V2.3530
Location: The Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by BigDog » Thursday 30 January 2014 21:27

i have dubbelchecked it if i acticate SNMP and put a V on V2 i cant enter password only "gemeenschap" (dutch version) and below my information contact person and stuff i dont know if i dont set a pass ... is that a security isue? or if someone sees the snmp of the nas they only can see the temp and free storage nothing else?
Attachments
snmp.jpg
look :)
snmp.jpg (101.58 KiB) Viewed 9399 times
1x Raspberry With Domoticz V2.3530 [Linux version 4.1.6+]
PiRack With
-1X PiFace Digital(headache device)
-1X RaZberry - OpenZWave USB
1X RFXtrx433 USB Firmware: 183
5X Arduno: mysensors V1.5(Testing)
6x ESP8266: easy firmware(Testing)
1X Synology Nas

User avatar
mbliek
Posts: 809
Joined: Friday 12 July 2013 14:08
Target OS: Raspberry Pi
Domoticz version: beta
Location: the Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by mbliek » Thursday 30 January 2014 22:25

You can set your own password at v2

User avatar
BigDog
Posts: 288
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi
Domoticz version: V2.3530
Location: The Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by BigDog » Thursday 30 January 2014 23:09

Ohhhh wait "gemeenschap" is the password... I didnt know that....:|
1x Raspberry With Domoticz V2.3530 [Linux version 4.1.6+]
PiRack With
-1X PiFace Digital(headache device)
-1X RaZberry - OpenZWave USB
1X RFXtrx433 USB Firmware: 183
5X Arduno: mysensors V1.5(Testing)
6x ESP8266: easy firmware(Testing)
1X Synology Nas

User avatar
mbliek
Posts: 809
Joined: Friday 12 July 2013 14:08
Target OS: Raspberry Pi
Domoticz version: beta
Location: the Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by mbliek » Thursday 30 January 2014 23:15

A bit wrong translated.

Luuc_a
Posts: 65
Joined: Tuesday 16 July 2013 10:12
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: HowTo: monitor Synology NAS

Post by Luuc_a » Friday 31 January 2014 11:50

Thanks for sharing. This is realy nice and works great.

geho
Posts: 40
Joined: Thursday 08 August 2013 22:30
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: HowTo: monitor Synology NAS

Post by geho » Friday 31 January 2014 18:39

I used this script and it works like a charm. Would be great if we can use GB as unit.

User avatar
BigDog
Posts: 288
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi
Domoticz version: V2.3530
Location: The Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by BigDog » Thursday 06 February 2014 10:40

strange my raspberry cant start the script nas.sh :S

i get this

Code: Select all

[email protected] ~/domoticz/scripts $ ./nas.sh
bash: ./nas.sh: /bin/bash^M: bad interpreter: No such file or directory
what am i doing wrong :D
1x Raspberry With Domoticz V2.3530 [Linux version 4.1.6+]
PiRack With
-1X PiFace Digital(headache device)
-1X RaZberry - OpenZWave USB
1X RFXtrx433 USB Firmware: 183
5X Arduno: mysensors V1.5(Testing)
6x ESP8266: easy firmware(Testing)
1X Synology Nas

User avatar
BigDog
Posts: 288
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi
Domoticz version: V2.3530
Location: The Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by BigDog » Thursday 06 February 2014 11:11

have stromble to another strange thing when i run the script with sudo it works but then i get this :S

Code: Select all

[email protected] ~ $ sudo bash domoticz/scripts/nas.sh
domoticz/scripts/nas.sh: line 2: $'\r': command not found
domoticz/scripts/nas.sh: line 4: $'\r': command not found
domoticz/scripts/nas.sh: line 9: $'\r': command not found
domoticz/scripts/nas.sh: line 14: $'\r': command not found
domoticz/scripts/nas.sh: line 16: $'\r': command not found
domoticz/scripts/nas.sh: line 18: $'\r': command not found
0.731
domoticz/scripts/nas.sh: line 52: syntax error: unexpected end of file

and the nas a virtual switch ? when i make one in domoticz you can only add it as a temp a counter and stuff but
1x Raspberry With Domoticz V2.3530 [Linux version 4.1.6+]
PiRack With
-1X PiFace Digital(headache device)
-1X RaZberry - OpenZWave USB
1X RFXtrx433 USB Firmware: 183
5X Arduno: mysensors V1.5(Testing)
6x ESP8266: easy firmware(Testing)
1X Synology Nas

tkimber
Posts: 3
Joined: Monday 15 July 2013 17:09
Target OS: -
Domoticz version:
Contact:

Re: HowTo: monitor Synology NAS

Post by tkimber » Thursday 06 February 2014 13:58

Your nas.sh script is in DOS format instead of unix format. You need to convert the \r\n characters to \n characters. This can be done with the 'tr' command, e.g.

tr -d '\015' <DOS-file >UNIX-file

More details at StackOverflow: http://stackoverflow.com/questions/2613 ... ash-script

User avatar
BigDog
Posts: 288
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi
Domoticz version: V2.3530
Location: The Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by BigDog » Thursday 06 February 2014 20:42

Thanks it works :D :D :D

i had only a question about the free space volume i see only the free space of HD1 like 398 degrades i dont see de HD2 and not the total/used/units and stuff
cant it be made that you see all the info and in MB or GB?
1x Raspberry With Domoticz V2.3530 [Linux version 4.1.6+]
PiRack With
-1X PiFace Digital(headache device)
-1X RaZberry - OpenZWave USB
1X RFXtrx433 USB Firmware: 183
5X Arduno: mysensors V1.5(Testing)
6x ESP8266: easy firmware(Testing)
1X Synology Nas

User avatar
BigDog
Posts: 288
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi
Domoticz version: V2.3530
Location: The Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by BigDog » Friday 07 February 2014 8:26

hi there i found a Bug in the script

else
echo "NAS OFF"
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=184&switchcmd=Off"

fi
the highlighted part must be $NAS_IDX :)

i saw it when the button dasn't go off :)

glad that i can help 8-)
1x Raspberry With Domoticz V2.3530 [Linux version 4.1.6+]
PiRack With
-1X PiFace Digital(headache device)
-1X RaZberry - OpenZWave USB
1X RFXtrx433 USB Firmware: 183
5X Arduno: mysensors V1.5(Testing)
6x ESP8266: easy firmware(Testing)
1X Synology Nas

rvmourik
Posts: 54
Joined: Tuesday 07 January 2014 23:39
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: HowTo: monitor Synology NAS

Post by rvmourik » Friday 07 February 2014 11:37

BigDog wrote:hi there i found a Bug in the script

else
echo "NAS OFF"
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=184&switchcmd=Off"

fi
the highlighted part must be $NAS_IDX :)

i saw it when the button dasn't go off :)

glad that i can help 8-)
thanks, i've changed the start topic.

User avatar
mbliek
Posts: 809
Joined: Friday 12 July 2013 14:08
Target OS: Raspberry Pi
Domoticz version: beta
Location: the Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by mbliek » Wednesday 12 February 2014 23:19

I made a Wiki page for the NAS monitoring.
I added the link in the first post.

http://www.domoticz.com/wiki/NAS_Monitoring

I edited your script a bit @rvmourik

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests