Page 1 of 3

HowTo: monitor QNAP NAS

Posted: Wednesday 08 January 2014 22:19
by mbliek
Anyone interested in monitoring HD temp and Free HD space for QNAP systems?

If so, I would write a how to.

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

Re: HowTo: monitor QNAP NAS

Posted: Wednesday 08 January 2014 23:37
by camillo777
Yes!! I did a couple of simple sh scripts for generic Linux I can publish as well

Re: HowTo: monitor QNAP NAS

Posted: Thursday 09 January 2014 10:57
by andriej
Both of you, publish them. :-)

Re: HowTo: monitor QNAP NAS

Posted: Thursday 09 January 2014 15:15
by camillo777
Some scripts to monitor the Domoticz process:

#!/bin/sh
# Get Domoticz Process CPU
ps -C domoticz -o %cpu | tail -n +2

#!/bin/sh
# Get Domoticz Process Memory
ps -C domoticz -o %mem | tail -n +2

#!/bin/sh
# Get Domoticz Folder Size
du -shb /home/pi/camillo/domoticz-code | awk -F " " {'print $1'}

HowTo: monitor QNAP NAS

Posted: Thursday 09 January 2014 16:42
by mbliek
Now in the WIKI: http://www.domoticz.com/wiki/NAS_Monitoring

The script is changed, use the one on the WIKI page.

Here is my HowTo

First enable SNMP on your QNAP NAS:

http://docs.qnap.com/nas/en/index.html? ... ttings.htm

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:
snmpget -v 2c -c PASSWORD -O qv NASIPADDRESS 1.3.6.1.4.1.24681.1.2.11.1.3.1

You should get something like this:
"37 C/98 F"


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="00.00.00.00"			# NAS IP Address
PASSWORD="password"			# SNMP Password
DOMO_IP="00.00.00.00"		# Domoticz IP Address
DOMO_PORT="0000"			# Domoticz Port

# 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=184&switchcmd=On"

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

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

		# Remaining HD size
		size=`snmpget -v 2c -c $PASSWORD -O qv $NASIP 1.3.6.1.4.1.24681.1.2.17.1.5.1 | cut -c 2-7`
			# Send data
			curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=183&nvalue=0&svalue=$size"

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

2.052
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.

Re: HowTo: monitor QNAP NAS

Posted: Saturday 11 January 2014 23:47
by Jastrzi
mbliek thank you for this HOWTO, it's briliant! :)

As I have some issues with temp. of all my HDDs I start reporting Sys temp.
I've replaced one of yours command with following one:
snmpget -v 2c -c password -O qv NASIP 1.3.6.1.4.1.24681.1.2.6.0

This returns the Sys temperature.
Just FYI if somebody will looking for it.

Re: HowTo: monitor QNAP NAS

Posted: Sunday 12 January 2014 9:42
by mbliek
I couldn't get my system temp. Will test it when I got home.

Re: HowTo: monitor QNAP NAS

Posted: Sunday 12 January 2014 16:57
by mbliek
Thanks for that Jastrzi. Got my system temp now as well.
Will update my howto later

Re: HowTo: monitor QNAP NAS

Posted: Saturday 08 February 2014 11:16
by gdekeijzer
Great stuff. One question, what is the 'Switch' used for?

Re: HowTo: monitor QNAP NAS

Posted: Saturday 08 February 2014 12:28
by Jastrzi
Switch is showing you wheter Qnap is on or off

Re: HowTo: monitor QNAP NAS

Posted: Monday 10 February 2014 18:05
by gdekeijzer
Oh, just status :)

Switching off / on your NAS would be not the best thing using a switch :)

Re: HowTo: monitor QNAP NAS

Posted: Wednesday 12 February 2014 22:21
by mbliek
I added CPU temp and made a WIKI page for this.

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

Re: HowTo: monitor QNAP NAS

Posted: Tuesday 06 May 2014 22:15
by kimhav
Great stuff! But, is there a limit to how many drives one could monitor with this script or with Domoticz; asking since you've only included 2 drives where I would need to monitor 4 drives?

Re: HowTo: monitor QNAP NAS

Posted: Tuesday 06 May 2014 22:37
by mbliek
There is no limit. My NAS has only 2 drives, that's why this script includes 2 drives.

Re: HowTo: monitor QNAP NAS

Posted: Tuesday 06 May 2014 23:34
by kimhav
Ok, Just copied and updated the script to monitor 4 drives. Only thing that I'm not getting to work is the NAS Free HD parameter; it comes out empty in the Device. But, assume that's due to device error as the input data isn't what is expected (temperatur);

Code: Select all

<html><head><title>Bad Request</title></head><body><h1>400 Bad Request</h1></body></html>

Re: HowTo: monitor QNAP NAS

Posted: Monday 12 May 2014 19:12
by brijoco
Hi,

I was having the same problem so I put a few echo's in the script and got ...

>>> HD free: > 1.41 T <
HTTP/1.0 400 Bad Request
Content-Length: 89
Content-Type: text/html

<html><head><title>Bad Request</title></head><body><h1>400 Bad Request</h1></body></html>pi@PI-DOMO ~/domoticz/scripts $ ./brinas.sh

When I changed the 'cut -c 2-7' to 'cut -c 2-5' I got ...

>>> HD free: > 1.41 <
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"
}

So, I am using the change in the cut as a work around until I can find what is the max content length and how it relates to the length of the string passed.

Any suggestions or pointers gratefully received.

Regards,

Re: HowTo: monitor QNAP NAS

Posted: Thursday 22 May 2014 17:51
by kimhav
Using "cut -c 2-5" did not do the trick on my side; still error and no update.

Re: HowTo: monitor QNAP NAS

Posted: Thursday 29 May 2014 19:27
by BobdeBouwer
Thanx for starting this, it is great for learning and reading!
I downloaded the MIB file from my QNAP TS219P admin pages, used the snmpB browser and "walked" some tree's.
That information will be nice to combine with Domoticz via the scripts and the WIKI HowTo.
I did not find a query for the system Fan speed, perhaps later.

My 2 cents:
First of all, the HDD queries makes the disk spin-up, so if you query them every 5 minutes they will never spin-down.

Secondly, some more variables to use.

Code: Select all

$COMM is community string
$IP is QNAP NAS IP-address
#system CPU usage
snmpget -v 2c -c $COMM -O qv $IP 1.3.6.1.4.1.24681.1.2.1.0

#system total memory
snmpget -v 2c -c $COMM -O qv $IP 1.3.6.1.4.1.24681.1.2.2.0

#system free memory
snmpget -v 2c -c $COMM -O qv $IP 1.3.6.1.4.1.24681.1.2.3.0

#Uptime of network portion of system
snmpget -v 2c -c $COMM -O qv $IP 1.3.6.1.4.1.24681.1.2.4.0

#System uptime - fraction longer
snmpget -v 2c -c $COMM -O qv $IP 1.3.6.1.2.1.25.1.1.0

#System temp
snmpget -v 2c -c $COMM -O qv $IP 1.3.6.1.4.1.24681.1.2.6.0


Re: HowTo: monitor QNAP NAS

Posted: Thursday 17 July 2014 16:10
by martjah
Hello,

In the past the QNAP script made my domoticz crash a few times a week. I've added an extra check in my version, it checks if only numbers are returned, if not, then it does not update Domoticz with the new value. I did not make it for the free space check because i'm not using that part. Here is an example:

Code: Select all

       # Temperature CPU
          CPUtemp=`snmpget -v 2c -c $PASSWORD -O qv $NASIP 1.3.6.1.4.1.24681.1.2.6.0 | cut -c 2-3`
				if [[ $CPUtemp == ?(-)+([0-9.]) ]]; then
                     # Send data
                             curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$CPU_TEMP_IDX&nvalue=0&svalue=$CPUtemp"
			   else
									  echo "Oeps, er komen niet alleen cijfers terug!"
		    fi


Re: HowTo: monitor QNAP NAS

Posted: Sunday 21 September 2014 16:54
by BobdeBouwer
Hi All,
I was having some discussions with my QNAP NAS 219P as to why it would not spin down. A lot of reading can be done on this topic and long story short is that I decided to disable the cloud service and edit my CRONTAB (and reload it) with my maintanance window set to 21:00, most chances are that one ore more PC's are performing a back-up or are using shares anyway. To keep track on the spin up / down count I made a little script of bits and pieces that I would like to share here.

It uses a virtual device QNAP and a virtual counter on that virtual device. Via CURL and JSON I plan to update that counter once a day.
That way I can look at the spin up/ down count in Domoticz and keep track on irregularities when the disks fail to spin down.
The script is placed on one of the shares, pick your own spot.
Make it executable, plan it in Crontab (do try to get the maintanance together) and do not forget to reload CRON.
#reload crontab
crontab /etc/config/crontab
#restart cron
/etc/init.d/crond.sh restart

This is the script that runs on the QNAP:

Code: Select all

#!/bin/sh
#Mind you this works with Domoticz and QNAP QTS 4.1.0 - Use at your own risk -
#In Domoticz - Define a virtual device then add a counter - make it visable and then adjust to counter type
#Search the Idx value in the devices list and set the number for IDN in this script

#Does require disk to spin bescause it is a script on disk - schedule in CRONTAB during maintanance window of create TMPFS
#edit the crontab file on the QNAP with your favorite editor /etc/config/crontab to your needs
#Make sure the script is exacutable
#To make it last - be sure to restart CRON /etc/init.d/crond.sh restart

# Declare Variables
DomoticzIP="192.168.X.ZZZ"   # IP of Domoticz instance
Port="8080"                  # Port number of Domoticz listner
IDN="ZZ"                     # Device number of virtual switch in Domoticz
Disk="1"                     # Choose a disk from your QNAP NAS to query with get_hd_smartinfo

#Proceed only if Domoticz is around in network
if ping -c 1 $DomoticzIP &> /dev/null
 then
   echo "host found @" $DomoticzIP
   regel=`/sbin/get_hd_smartinfo -d $Disk | /bin/grep Start_Stop_Count`
#  echo $regel                 # uncomment to see what you found

#  print third string as this holds the count we look for
   ststop=` echo $regel | awk '{  print $3  }' `
   echo "Start Stop Count of disk no." $Disk "=" $ststop   # see what you found

   # Post it to Domoticz
   curl -s -i -H "Accept: application/json" "http://$DomoticzIP:$Port/json.htm?type=command&param=udevice&idx=$IDN&svalue=$ststop"


 else
   echo "no host found @" $DomoticzIP
fi

#nice exit no matter what
exit 0

As an example My Crontab line to run it at 21:00 hrs :

Code: Select all

# m h dom m dow cmd
00 21 * * * /share/<<sharename-you-picked>>/PostSpinUp.sh > /dev/null 2>&1
Hope this works for you.