HowTo: monitor Synology NAS

Others (MiLight, Hue, Toon etc...)

Moderator: leecollings

Post Reply
rvmourik
Posts: 17
Joined: Tuesday 07 January 2014 22:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

HowTo: monitor Synology NAS

Post by rvmourik »

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 10:34, edited 1 time in total.
rvmourik
Posts: 17
Joined: Tuesday 07 January 2014 22:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: HowTo: monitor Synology NAS

Post by rvmourik »

No one using it besides myself? :o
Yihaaa
Posts: 23
Joined: Sunday 14 July 2013 10:31
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: The Netherlands

Re: HowTo: monitor Synology NAS

Post by Yihaaa »

Well I like to have this! Very interesting, the only thing is that I am not an expert with Linux.
BigDog
Posts: 82
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.9269
Location: The Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by BigDog »

I want to use it havent got the time yet to add it to domoticz :)
1X Raspberry4B : Domoticz Version 2023.1 [Linux 5.10.63-v7l+ armv7l]
1X Conbee II : 2.25.3 - 26720700
1X RFXtrx433 USB Firmware:183
1X Mysensors Gateway 1.5 -3
6X ESP8266: Tosmota firmware
Zigbee : 6 Operators, 13 Sensors
BigDog
Posts: 82
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.9269
Location: The Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by BigDog »

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 Raspberry4B : Domoticz Version 2023.1 [Linux 5.10.63-v7l+ armv7l]
1X Conbee II : 2.25.3 - 26720700
1X RFXtrx433 USB Firmware:183
1X Mysensors Gateway 1.5 -3
6X ESP8266: Tosmota firmware
Zigbee : 6 Operators, 13 Sensors
rvmourik
Posts: 17
Joined: Tuesday 07 January 2014 22:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: HowTo: monitor Synology NAS

Post by rvmourik »

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: 194
Joined: Friday 12 July 2013 14:08
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by mbliek »

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.
BigDog
Posts: 82
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.9269
Location: The Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by BigDog »

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
look :)
look :)
snmp.jpg (101.58 KiB) Viewed 18819 times
1X Raspberry4B : Domoticz Version 2023.1 [Linux 5.10.63-v7l+ armv7l]
1X Conbee II : 2.25.3 - 26720700
1X RFXtrx433 USB Firmware:183
1X Mysensors Gateway 1.5 -3
6X ESP8266: Tosmota firmware
Zigbee : 6 Operators, 13 Sensors
User avatar
mbliek
Posts: 194
Joined: Friday 12 July 2013 14:08
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by mbliek »

You can set your own password at v2
BigDog
Posts: 82
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.9269
Location: The Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by BigDog »

Ohhhh wait "gemeenschap" is the password... I didnt know that....:|
1X Raspberry4B : Domoticz Version 2023.1 [Linux 5.10.63-v7l+ armv7l]
1X Conbee II : 2.25.3 - 26720700
1X RFXtrx433 USB Firmware:183
1X Mysensors Gateway 1.5 -3
6X ESP8266: Tosmota firmware
Zigbee : 6 Operators, 13 Sensors
User avatar
mbliek
Posts: 194
Joined: Friday 12 July 2013 14:08
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by mbliek »

A bit wrong translated.
Luuc_a
Posts: 24
Joined: Tuesday 16 July 2013 10:12
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: HowTo: monitor Synology NAS

Post by Luuc_a »

Thanks for sharing. This is realy nice and works great.
geho
Posts: 13
Joined: Thursday 08 August 2013 22:30
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: HowTo: monitor Synology NAS

Post by geho »

I used this script and it works like a charm. Would be great if we can use GB as unit.
BigDog
Posts: 82
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.9269
Location: The Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by BigDog »

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

i get this

Code: Select all

XX@XXXXXX ~/domoticz/scripts $ ./nas.sh
bash: ./nas.sh: /bin/bash^M: bad interpreter: No such file or directory
what am i doing wrong :D
1X Raspberry4B : Domoticz Version 2023.1 [Linux 5.10.63-v7l+ armv7l]
1X Conbee II : 2.25.3 - 26720700
1X RFXtrx433 USB Firmware:183
1X Mysensors Gateway 1.5 -3
6X ESP8266: Tosmota firmware
Zigbee : 6 Operators, 13 Sensors
BigDog
Posts: 82
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.9269
Location: The Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by BigDog »

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

Code: Select all

pi@XXXXXXX ~ $ 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 Raspberry4B : Domoticz Version 2023.1 [Linux 5.10.63-v7l+ armv7l]
1X Conbee II : 2.25.3 - 26720700
1X RFXtrx433 USB Firmware:183
1X Mysensors Gateway 1.5 -3
6X ESP8266: Tosmota firmware
Zigbee : 6 Operators, 13 Sensors
tkimber
Posts: 1
Joined: Monday 15 July 2013 17:09
Target OS: -
Domoticz version:
Contact:

Re: HowTo: monitor Synology NAS

Post by tkimber »

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
BigDog
Posts: 82
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.9269
Location: The Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by BigDog »

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 Raspberry4B : Domoticz Version 2023.1 [Linux 5.10.63-v7l+ armv7l]
1X Conbee II : 2.25.3 - 26720700
1X RFXtrx433 USB Firmware:183
1X Mysensors Gateway 1.5 -3
6X ESP8266: Tosmota firmware
Zigbee : 6 Operators, 13 Sensors
BigDog
Posts: 82
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.9269
Location: The Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by BigDog »

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 Raspberry4B : Domoticz Version 2023.1 [Linux 5.10.63-v7l+ armv7l]
1X Conbee II : 2.25.3 - 26720700
1X RFXtrx433 USB Firmware:183
1X Mysensors Gateway 1.5 -3
6X ESP8266: Tosmota firmware
Zigbee : 6 Operators, 13 Sensors
rvmourik
Posts: 17
Joined: Tuesday 07 January 2014 22:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: HowTo: monitor Synology NAS

Post by rvmourik »

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: 194
Joined: Friday 12 July 2013 14:08
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: HowTo: monitor Synology NAS

Post by mbliek »

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 0 guests