HowTo: monitor QNAP NAS

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

Moderator: leecollings

User avatar
elyannaz
Posts: 2
Joined: Thursday 09 October 2014 19:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: FR-Annecy
Contact:

Re: HowTo: monitor QNAP NAS

Post by elyannaz »

Hi Evreybody

I have problems with my QNAP monitoring.
I follow the tuto on the wiki, line after line but the script return to me this error
1.107
1
NAS already ON
41
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>curl CPU
HTTP/1.0 401 Unauthorized
Content-Length: 91
Content-Type: text/html

<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>HTTP/1.0 401 Unauthorized
Content-Length: 91
Content-Type: text/html

<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>HTTP/1.0 401 Unauthorized
Content-Length: 91
Content-Type: text/html

<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
Any idea ???

So sorry for my "french" english
woody4165
Posts: 476
Joined: Monday 14 March 2016 13:55
Target OS: Linux
Domoticz version: beta
Location: Rome, Italy
Contact:

Re: HowTo: monitor QNAP NAS

Post by woody4165 »

Hi

just used the script for a few days and now I'm getting timeout either from script or from terminal.
Is there a way to set timeout in the snmpget command? I search but I haven't found anything.
Cubietruck - Linux cubietruck 4.13.16 (Debian GNU/Linux 8 (jessie)) + Domoticz + RFLink, Xiaomi Gateway, Owl USB, Yeelight Color and B/W, ESP8266, Broadlink RM2, Netatmo Thermostat
Zoekm
Posts: 20
Joined: Friday 18 November 2016 11:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: HowTo: monitor QNAP NAS

Post by Zoekm »

Hello,
Trying out the script from the wiki on a rpi with Domoticz for monitoring a QNAP NAS. Testing with:

Code: Select all

snmpget -v 2c -c PASSWORD -O qv NASIPADDRESS 1.3.6.1.4.1.24681.1.2.11.1.3.1
works fine, but running the script example raised errors. I did find some errors in the wiki example (too many quotes in the Settings part), but I am unable to find what causes the last remaining error.
"./nas.sh: line 85: syntax error: unexpected end of file"
As I am not familiar with the code syntax, anyone who can tell me what causes the error?

the code:

Code: Select all

 #!/bin/bash
 # Settings
 NASIP="192.168.1.35"		        # NAS IP Address
 PASSWORD="pwd"		# SNMP Password
 DOMO_IP="192.168.1.80"		# Domoticz IP Address
 DOMO_PORT="8080"			# Domoticz Port
 NAS_IDX="5"		        # Virtual switch NAS STATUS
 CPU_TEMP_IDX="21"			# Virtual temerature sensor IDX NAS CPU
 HD1_TEMP_IDX="22"			# Virtual temerature sensor IDX HD1
 HD2_TEMP_IDX="23"			# Virtual temerature sensor IDX HD2
 HD_REMAIN_IDX="24"		# Virtual temerature sensor IDX HD REMAIN
 DOMO_LOGIN="login"
 DOMO_PASS="pw"
 # Check if NAS in online 
 PINGTIME=`ping -c 1 -q $NASIP | awk -F"/" '{print $5}' | xargs`
 echo $PINGTIME
 if expr "$PINGTIME" '>' 0
 then
 		curl -s "http://$DOMO_LOGIN:$DOMO_PASS@$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$NAS_IDX" | grep "Status" | grep "On" > /dev/null
 
         if [ $? -eq 0 ] ; then
         	        # NAS already ON
        					echo "NAS already ON"
 
           	        # Temprature 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`
                        	               # Send data
                                               curl -s -i -H "Accept: application/json" "http://$DOMO_LOGIN:$DOMO_PASS@$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$CPU_TEMP_IDX&nvalue=0&svalue=$CPUtemp"
 
          	        # 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_LOGIN:$DOMO_PASS@$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HD1_TEMP_IDX&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_LOGIN:$DOMO_PASS@$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HD2_TEMP_IDX&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_LOGIN:$DOMO_PASS@$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HD_REMAIN_IDX&nvalue=0&svalue=$size"
       else
 			# NAS ON
        					echo "NAS ON"
        					# Send data
           				       curl -s -i -H "Accept: application/json" "http://$DOMO_LOGIN:$DOMO_PASS@$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$NAS_IDX&switchcmd=On"
 
           	        # Temprature 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`
                        	              # Send data
                                              curl -s -i -H "Accept: application/json" "http://$DOMO_LOGIN:$DOMO_PASS@$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$CPU_TEMP_IDX&nvalue=0&svalue=$CPUtemp"
 
          	        # 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_LOGIN:$DOMO_PASS@$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HD1_TEMP_IDX&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_LOGIN:$DOMO_PASS@$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HD2_TEMP_IDX&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_LOGIN:$DOMO_PASS@$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HD_REMAIN_IDX&nvalue=0&svalue=$size"
         fi
 
 else
        	curl -s "http://$DOMO_LOGIN:$DOMO_PASS@$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$NAS_IDX" | grep "Status" | grep "Off" > /dev/null
        		# NAS uitgeschakeld
         if [ $? -eq 0 ] ; then
         			echo "NAS already OFF"
         			exit
         else
        				echo "NAS OFF"
        				# Send data
           				curl -s -i -H "Accept: application/json" "http://$DOMO_LOGIN:$DOMO_PASS@$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$NAS_IDX&switchcmd=Off"
         fi
fi
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: HowTo: monitor QNAP NAS

Post by stlaha2007 »

I have copied your script-code from your post, however it is crippled badly.... {newlines and extra spaces}
You better start over with the original code...

A have corrected it myself {took me half a hour or so} and also enhanced it to my liking, and works perfectly for 4 drives instead of the only 2...

So better get the original script, prefer browser, then use winSCP to create the file, open the new file and paste the code in there.
Zoekm
Posts: 20
Joined: Friday 18 November 2016 11:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: HowTo: monitor QNAP NAS

Post by Zoekm »

OK, thanks for your time, I will try and let you know if it works out.
Zoekm
Posts: 20
Joined: Friday 18 November 2016 11:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: HowTo: monitor QNAP NAS

Post by Zoekm »

stlaha2007, thanks for your tip! It works now! Can you show us the enhancements you made, besides adding the 2 extra drives?
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: RE: Re: HowTo: monitor QNAP NAS

Post by stlaha2007 »

Zoekm wrote:stlaha2007, thanks for your tip! It works now! Can you show us the enhancements you made, besides adding the 2 extra drives?
The 2 extra drives IS the enhancement.

Still being busy with getting the mountpoint usage like the PI sensors.

After that, i'm gonna try to build some detections for those sensors, so it can also do the creation for not already existing sensors.
Got that inspiration from a thread of the Synology :-)
guantolento
Posts: 129
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: LastBeta
Location: Italy BG
Contact:

Re: HowTo: monitor QNAP NAS

Post by guantolento »

stlaha2007 wrote:I have copied your script-code from your post, however it is crippled badly.... {newlines and extra spaces}
You better start over with the original code...

A have corrected it myself {took me half a hour or so} and also enhanced it to my liking, and works perfectly for 4 drives instead of the only 2...

So better get the original script, prefer browser, then use winSCP to create the file, open the new file and paste the code in there.
if i take copy / paste i think the format is'n correct .... any idea to resolv the issue ???
Master (pi3) - MB sensors + Dummy + Sysfs gpio + 1 NodOn MSP-3 + 1 Aeotec DSB28 Energy Meter + 3 Danfoss RS Room + 7 Danfoss Z Thermostat + 1 Swiid Inter + 9 FGS222
Slave01 (pi2) - MB sensors + Dummy + Weather Underground + 2 FGS223 + 1 FGWPE/F
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: RE: Re: HowTo: monitor QNAP NAS

Post by stlaha2007 »

guantolento wrote:
stlaha2007 wrote:I have copied your script-code from your post, however it is crippled badly.... {newlines and extra spaces}
You better start over with the original code...

A have corrected it myself {took me half a hour or so} and also enhanced it to my liking, and works perfectly for 4 drives instead of the only 2...

So better get the original script, prefer browser, then use winSCP to create the file, open the new file and paste the code in there.
if i take copy / paste i think the format is'n correct .... any idea to resolv the issue ???
If copy/paste results in a bad form(at), use other tools. Windows and Linux use different line endings (cariage return and newline vs. newline).

Maybe use curl on commandline to get the code (the specific post) into file and use the edit function in WinSCP to jave only the script code (delete everuthing before including

Code: Select all

 and from 
till the end.

Let me know if that works. Else gonne try to post my script as a bzip or tarbal.
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: HowTo: monitor QNAP NAS

Post by stlaha2007 »

Hereby attached, my modified version....

upload to the nas or better domoticz pi.

Then unzip and edit with nano or vi to include your nas and domoticz ipaddresses and your admin/password for domoticz.
Attachments
qnap-nas-monitor.zip
(1.04 KiB) Downloaded 183 times
guantolento
Posts: 129
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: LastBeta
Location: Italy BG
Contact:

Re: HowTo: monitor QNAP NAS

Post by guantolento »

hy stlaha2007,
thanks for all, now my 2 qnap are implemented in Domoticz. i look the 2 script (the firts from the wiki and the second .zip) and i find some difference in the syntax.
just an information. i tried to change the port from 8080 to 443 and change the setting from http to https but in this mode che script don't refresh the idx in Domoticz. so i re setting in 8080 http standard and all works.
why the sensor of hdd free space is in ° and not in % ? it's possible control the CPU and RAM value in the same mode for your experience?
that's all for now and thanks again !
Master (pi3) - MB sensors + Dummy + Sysfs gpio + 1 NodOn MSP-3 + 1 Aeotec DSB28 Energy Meter + 3 Danfoss RS Room + 7 Danfoss Z Thermostat + 1 Swiid Inter + 9 FGS222
Slave01 (pi2) - MB sensors + Dummy + Weather Underground + 2 FGS223 + 1 FGWPE/F
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: HowTo: monitor QNAP NAS

Post by stlaha2007 »

had the same with https. Need to investigate, but think that has to do with selfsigned certificate.

And the degree symbol. Depends on the sensor used for Free Space. I created a Custom Sensor, because values go Up/Down, not all sensors accept that. Eg the temp-sensors can but most counters can't.
guantolento
Posts: 129
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: LastBeta
Location: Italy BG
Contact:

Re: HowTo: monitor QNAP NAS

Post by guantolento »

What kind of custom sensor you choose for example ???

Inviato dal mio GT-I9301I utilizzando Tapatalk
Master (pi3) - MB sensors + Dummy + Sysfs gpio + 1 NodOn MSP-3 + 1 Aeotec DSB28 Energy Meter + 3 Danfoss RS Room + 7 Danfoss Z Thermostat + 1 Swiid Inter + 9 FGS222
Slave01 (pi2) - MB sensors + Dummy + Weather Underground + 2 FGS223 + 1 FGWPE/F
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: HowTo: monitor QNAP NAS

Post by stlaha2007 »

Just Click create sensor at Dummy Hardware. Choose Custom Sensor. And fill in the blanks... done that a few weeks ago, and currently not near my domoticz server.
guantolento
Posts: 129
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: LastBeta
Location: Italy BG
Contact:

Re: HowTo: monitor QNAP NAS

Post by guantolento »

i think the ° sensor in not real, i try to use a % sensor. i change the idx in the script and i think work ok. this is the screenshot. the value read in smnp is already the free spase on the disk ?? or another value ???? i don't understend this.
Attachments
prova.JPG
prova.JPG (17.47 KiB) Viewed 3323 times
Master (pi3) - MB sensors + Dummy + Sysfs gpio + 1 NodOn MSP-3 + 1 Aeotec DSB28 Energy Meter + 3 Danfoss RS Room + 7 Danfoss Z Thermostat + 1 Swiid Inter + 9 FGS222
Slave01 (pi2) - MB sensors + Dummy + Weather Underground + 2 FGS223 + 1 FGWPE/F
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: RE: Re: HowTo: monitor QNAP NAS

Post by stlaha2007 »

guantolento wrote:i think the ° sensor in not real, i try to use a % sensor. i change the idx in the script and i think work ok. this is the screenshot. the value read in smnp is already the free spase on the disk ?? or another value ???? i don't understend this.
The free space which is monitored by SNMP is the real free space in MBytes. In my case 1 RAID Volume 0,92 TB.

The others are Temp (5 in my case, 1 cpu and 4 disks)

As i recall theres no calculation of the difference and percentage.

If you want other values to be monitored use a MIB-browser. Used one myself to discover the exact oid for the freespace.
For Windows there's a java-based tool mibbrowser (free) just google for it.
guantolento
Posts: 129
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: LastBeta
Location: Italy BG
Contact:

Re: HowTo: monitor QNAP NAS

Post by guantolento »

Hi i find the list of the sensor can give qnap in SMNP. for some test actually i make the CPU_USAGE sensor and it work, i have only a problem. the value read from the mib is in full farmat, so when the cpu is working for example at 4.65% in domoticz i have 4.00%. it's possible read the 2 decimal unit ??? when i finish my test i give the code used. i think is possible make a custom sensor for HD Free and RAM Free. bye bye
Attachments
prova.JPG
prova.JPG (19.24 KiB) Viewed 3299 times
Master (pi3) - MB sensors + Dummy + Sysfs gpio + 1 NodOn MSP-3 + 1 Aeotec DSB28 Energy Meter + 3 Danfoss RS Room + 7 Danfoss Z Thermostat + 1 Swiid Inter + 9 FGS222
Slave01 (pi2) - MB sensors + Dummy + Weather Underground + 2 FGS223 + 1 FGWPE/F
guantolento
Posts: 129
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: LastBeta
Location: Italy BG
Contact:

Re: HowTo: monitor QNAP NAS

Post by guantolento »

now i take another 2 value. ram free and hdd free.
Attachments
Cattura.JPG
Cattura.JPG (44.34 KiB) Viewed 3287 times
Master (pi3) - MB sensors + Dummy + Sysfs gpio + 1 NodOn MSP-3 + 1 Aeotec DSB28 Energy Meter + 3 Danfoss RS Room + 7 Danfoss Z Thermostat + 1 Swiid Inter + 9 FGS222
Slave01 (pi2) - MB sensors + Dummy + Weather Underground + 2 FGS223 + 1 FGWPE/F
Vulpecula
Posts: 3
Joined: Wednesday 18 October 2017 14:25
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.8153
Contact:

Re: HowTo: monitor QNAP NAS

Post by Vulpecula »

Can you tell me how you got the decimal part correct? My Nas has 2,6 TB free space but domoticz sees it as 3 TB

[Edit]
Found it, need to use a "Custom sensor"
Calzor Suzay
Posts: 145
Joined: Tuesday 08 July 2014 15:10
Target OS: -
Domoticz version: 4.9700
Location: UK
Contact:

Re: HowTo: monitor QNAP NAS

Post by Calzor Suzay »

What's wrong with my command?

# 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 -k -i -H "Accept: application/json" "https://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HD_REMAIN_IDX&nvalue=0&svalue=$size"

If I replace the variables and run it from the command line it's fine bit as part of the script it fails and doesn't update, I get this from the command line when running the script itself

HTTP/1.1 200 OK
Content-Length: 53
Content-Type: application/json;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache
Access-Control-Allow-Origin: *

{
"status" : "OK",
"title" : "Update Device"
}
HTTP/1.1 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>osmc@Vero4K:~/domoticz/scripts$
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest