Page 2 of 3

Re: HowTo: monitor QNAP NAS

Posted: Thursday 09 October 2014 19:53
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

Re: HowTo: monitor QNAP NAS

Posted: Monday 21 March 2016 15:16
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.

Re: HowTo: monitor QNAP NAS

Posted: Saturday 19 November 2016 21:28
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

Re: HowTo: monitor QNAP NAS

Posted: Sunday 20 November 2016 23:54
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.

Re: HowTo: monitor QNAP NAS

Posted: Monday 21 November 2016 0:29
by Zoekm
OK, thanks for your time, I will try and let you know if it works out.

Re: HowTo: monitor QNAP NAS

Posted: Tuesday 22 November 2016 0:12
by Zoekm
stlaha2007, thanks for your tip! It works now! Can you show us the enhancements you made, besides adding the 2 extra drives?

Re: RE: Re: HowTo: monitor QNAP NAS

Posted: Tuesday 22 November 2016 7:12
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 :-)

Re: HowTo: monitor QNAP NAS

Posted: Thursday 12 January 2017 1:03
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 ???

Re: RE: Re: HowTo: monitor QNAP NAS

Posted: Thursday 12 January 2017 7:23
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.

Re: HowTo: monitor QNAP NAS

Posted: Thursday 12 January 2017 21:04
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.

Re: HowTo: monitor QNAP NAS

Posted: Friday 13 January 2017 1:35
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 !

Re: HowTo: monitor QNAP NAS

Posted: Friday 13 January 2017 7:28
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.

Re: HowTo: monitor QNAP NAS

Posted: Friday 13 January 2017 9:27
by guantolento
What kind of custom sensor you choose for example ???

Inviato dal mio GT-I9301I utilizzando Tapatalk

Re: HowTo: monitor QNAP NAS

Posted: Friday 13 January 2017 11:27
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.

Re: HowTo: monitor QNAP NAS

Posted: Sunday 15 January 2017 15:39
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.

Re: RE: Re: HowTo: monitor QNAP NAS

Posted: Sunday 15 January 2017 17:43
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.

Re: HowTo: monitor QNAP NAS

Posted: Tuesday 17 January 2017 18:10
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

Re: HowTo: monitor QNAP NAS

Posted: Wednesday 18 January 2017 18:54
by guantolento
now i take another 2 value. ram free and hdd free.

Re: HowTo: monitor QNAP NAS

Posted: Wednesday 18 October 2017 14:27
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"

Re: HowTo: monitor QNAP NAS

Posted: Friday 29 June 2018 8:30
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$