(QNAP NAS) SNMP monitoring script for download

Forum over Homeseer scripts (DUTCH forum)

Moderators: TANE, Ruud

Post Reply
DJF3
Advanced Member
Advanced Member
Posts: 895
Joined: Thu Jul 12, 2007 9:28 am
Contact:

(QNAP NAS) SNMP monitoring script for download

Post by DJF3 »

'My' SNMP script is now available for download on my website
http://www.domoticaworld.com (click SNMP under 'scripts')

It's a script based on Droezel's post domoticaforum.eu/viewtopic.php?f=47&amp ... amp;t=4138.

The current version is created to pull information from QNAP NAS's (Tane?)

With some customizing you can also use it for any other SNMP device

You also have the ability to import existing MIB files to get more detailed information from SNMP capable devices.

Cheers!
DJ
jeroenkl
Starting Member
Starting Member
Posts: 47
Joined: Tue Dec 08, 2009 6:41 pm
Location: Netherlands

Re: (QNAP NAS) SNMP monitoring script for download

Post by jeroenkl »

Hi DJ,

Without importing MIB files to the SNMP dir, is it still possible to have it working?
I'm using a Synology NAS and have the SNMP oid id's available, see attachment.

Without an additional MIB I got the error message:

Code: Select all

Scripting runtime error: System.Reflection.TargetInvocationException: Het doel van een aanroep heeft een uitzondering veroorzaakt. ---> System.NullReferenceException: De objectverwijzing is niet op een exemplaar van een object ingesteld. bij SNMPDll.SNMPAgent.getValue(SNMPObject mySNMPObject) bij SNMPDll.SNMPObject.getSimpleValue(SNMPAgent myAgent) bij scriptcode9.scriptcode9.Main(Object parm) --- Einde van intern uitzonderingsstackpad --- bij System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) bij System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) bij System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) bij System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) bij System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) bij Scheduler.VsaScriptHost.Invoke(String ModuleName, String MethodName, Object[] Arguments)
Next to this I have my Homeseer XP server enabled fo SNMP, how can I get the MIB file for this to be added to the script? (SNMP dir)

many thanks for your help! (again;) )

jeroenkl
Attachments
SNMP_OID_SYNOLOGY[1].rar
(25.57 KiB) Downloaded 461 times
User avatar
RdP
Advanced Member
Advanced Member
Posts: 989
Joined: Thu May 04, 2006 10:14 am
Location: Netherlands

Re: (QNAP NAS) SNMP monitoring script for download

Post by RdP »

Can you tell what kind of information can be retrieved from the QNAP NAS. What information would be useful to see?

Thanks,
Rien
Rien
DJF3
Advanced Member
Advanced Member
Posts: 895
Joined: Thu Jul 12, 2007 9:28 am
Contact:

Re: (QNAP NAS) SNMP monitoring script for download

Post by DJF3 »

You can retrieve things like disk state (smart), free space, raid status, volume status, drive temperatures, etc.
One way to look at the data available: load the MIB in a MIB browser as shown on my website. You van also open the MIB file in a text editor.
DJF3
Advanced Member
Advanced Member
Posts: 895
Joined: Thu Jul 12, 2007 9:28 am
Contact:

Re: (QNAP NAS) SNMP monitoring script for download

Post by DJF3 »

jeroenkl wrote:Hi DJ,

Without importing MIB files to the SNMP dir, is it still possible to have it working?
I'm using a Synology NAS and have the SNMP oid id's available, see attachment.

Next to this I have my Homeseer XP server enabled fo SNMP, how can I get the MIB file for this to be added to the script? (SNMP dir)

jeroenkl
- to use non standard snmp objects ( which you want) you have to load the MIBs. Without these you can only see some standard parameters.
- If you get this error message the object number is not recognized.
- test this by using a standard snmp object number ( get number from MIB browser)
timdotcom
Starting Member
Starting Member
Posts: 32
Joined: Sun Jun 21, 2009 10:24 am
Location: Netherlands

Re: (QNAP NAS) SNMP monitoring script for download

Post by timdotcom »

Heren,

Ik heb onderstaande code van DJ`s site gedownload en aangepast naar mijn eigen smaak.
(Ik wil deze gebruiken om de temperatuur van mijn Netgear NAS uit te lezen)

Code: Select all

Imports SNMPDll

Sub Main(parm as object)
    Dim strDevice As String = "192.168.2.1"
	Dim strPublic As String = "public"
	Dim strPrivate As String = "public"
	Dim myMib As Mib = new Mib()
	Dim a As SNMPAgent = New SNMPAgent(strDevice, strPublic, strPrivate)
    myMib.loadDirectoryMib("C:\Program Files\HomeSeer HSPRO\SNMP\")

	
	'GetSNMP(<type>,<snmp-address>,<device>,<debug>,a) (do NOT change the 'a')
	'DJ:  debug  0=write   1=write+log   2=log
    GetSNMP("NAS_temperatuur", ".1.3.6.1.4.1.4526.18.5.1.2.", "V1", 1, a)
    'GetSNMP("HD_temp2",".1.3.6.1.4.1.24681.1.2.11.1.3.2","",0,a)
    'GetSNMP("HD_status1",".1.3.6.1.4.1.24681.1.2.11.1.4.1","",2,a)
    'GetSNMP("HD_status2",".1.3.6.1.4.1.24681.1.2.11.1.4.2","",0,a)
    'GetSNMP("HD_smartInfo1",".1.3.6.1.4.1.24681.1.2.11.1.7.1","",2,a)
    'GetSNMP("HD_smartInfo2",".1.3.6.1.4.1.24681.1.2.11.1.7.2","",0,a)
    'GetSNMP("HD_volumeFreeSize1",".1.3.6.1.4.1.24681.1.2.17.1.5.1","T9",1,a)
	'GetSNMP("HD_volumeFreeSize2",".1.3.6.1.4.1.24681.1.2.17.1.5.2","",2,a)
	
'
End Sub


Function GetSNMP(SNMPname,SNMPstring,device,debug,b)
	Dim strSNMPvalue as String

	GetSNMP = new SNMPObject(SNMPstring)
	strSNMPvalue = Cstr(GetSNMP.getSimpleValue(b))
	Select Case Left(SNMPname,Len(SNMPname)-1)
        Case "NAS_temperatuur"
            strSNMPvalue = Left(strSNMPvalue, 2)
            If debug < 2 And device <> "" Then hs.setdevicevalue(device, CInt(strSNMPvalue))
            strSNMPvalue = strSNMPvalue + " " + Chr(176)
		End Select

	If debug > 0 then hs.WriteLog("SNMP_02", "<i>" & SNMPname & "</i>: " & strSNMPvalue)
	If debug < 2 and device <> "" then hs.setdevicestring(device,strSNMPvalue,TRUE)
End Function
Ik krijg onderstaande foutmelding in mijn Log:

Code: Select all

15-2-2013 19:26:50  - Error - Scripting runtime error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.   at Microsoft.VisualBasic.CompilerServices.Symbols.Container.InvokeMethod(Method TargetProcedure, Object[] Arguments, Boolean[] CopyBack, BindingFlags Flags)   at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)   at scriptcode6.scriptcode6.GetSNMP(Object SNMPname, Object SNMPstring, Object device, Object debug, Object b)   at scriptcode6.scriptcode6.Main(Object parm)   --- End of inner exception stack trace ---   at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)   at Scheduler.VsaScriptHost.Invoke(String ModuleName, String MethodName, Object[] Arguments)
Ik heb de netgear MIB file (READYNAS-MIB.mib) in de aangegeven directory gezet.
De SNMP functie in mijn NAS aangezet met het IP adres van mijn homeseer server.

Maar toch gaat het nog niet goed.
Heeft iemand enig idee waar ik de mist in ga?
timdotcom
Starting Member
Starting Member
Posts: 32
Joined: Sun Jun 21, 2009 10:24 am
Location: Netherlands

Re: (QNAP NAS) SNMP monitoring script for download

Post by timdotcom »

Ben eruit.
Verkeerde SNMP string. :oops:
Herbus
Member
Member
Posts: 363
Joined: Mon Mar 27, 2006 12:28 pm
Location: Netherlands

Re: (QNAP NAS) SNMP monitoring script for download

Post by Herbus »

Is het een idee om jouw werkende script hier te delen? Hebben anderen met zo'n NAS er ook iets aan. :wink:
Herbus (Jos)
DJF3
Advanced Member
Advanced Member
Posts: 895
Joined: Thu Jul 12, 2007 9:28 am
Contact:

Re: (QNAP NAS) SNMP monitoring script for download

Post by DJF3 »

Ben ook nieuwsgierig.. Heb in de afgelopen weken helaas geen tijd gehad om e.e.a. te testen / supporten..

Groeten
DJ
timdotcom
Starting Member
Starting Member
Posts: 32
Joined: Sun Jun 21, 2009 10:24 am
Location: Netherlands

Re: (QNAP NAS) SNMP monitoring script for download

Post by timdotcom »

Hierbij het script wat nu draait voor mijn Netgear ready NAS

Code: Select all

Imports SNMPDll

Sub Main(ByVal parm As Object)
    Dim strDevice As String = "192.168.2.1"
    Dim strPublic As String = "public"
    Dim strPrivate As String = "public"
    Dim myMib As Mib = New Mib()
    Dim a As SNMPAgent = New SNMPAgent(strDevice, strPublic, strPrivate)
    myMib.loadDirectoryMib("C:\Program Files\HomeSeer HSPRO\SNMP\")


    'GetSNMP(<type>,<snmp-address>,<device>,<debug>,a) (do NOT change the 'a')
    'DJ:  debug  0=write   1=write+log   2=log
    GetSNMP("temperatureEntry 2", ".1.3.6.1.4.1.4526.18.5.1.2.1", "V1", 0, a)
    GetSNMP("NAS_freespace", ".1.3.6.1.4.1.4526.18.7.1.6.1", "V2", 0, a)
    'GetSNMP("HD_status1",".1.3.6.1.4.1.24681.1.2.11.1.4.1","",2,a)
    'GetSNMP("HD_status2",".1.3.6.1.4.1.24681.1.2.11.1.4.2","",0,a)
    'GetSNMP("HD_smartInfo1",".1.3.6.1.4.1.24681.1.2.11.1.7.1","",2,a)
    'GetSNMP("HD_smartInfo2",".1.3.6.1.4.1.24681.1.2.11.1.7.2","",0,a)
    'GetSNMP("HD_volumeFreeSize1",".1.3.6.1.4.1.24681.1.2.17.1.5.1","T9",1,a)
    'GetSNMP("HD_volumeFreeSize2",".1.3.6.1.4.1.24681.1.2.17.1.5.2","",2,a)

    '
End Sub


Function GetSNMP(ByVal SNMPname, ByVal SNMPstring, ByVal device, ByVal debug, ByVal b)
    Dim strSNMPvalue As String

    GetSNMP = New SNMPObject(SNMPstring)
    strSNMPvalue = CStr(GetSNMP.getSimpleValue(b))
    'strSNMPvalue = GetSNMP.getSimpleValue(b)
    Select Case Left(SNMPname, Len(SNMPname))
        Case "temperatureEntry 2"
            strSNMPvalue = (strSNMPvalue - 32) * (5 / 9) 'Conversie van farenheit naar graden C
            If debug < 2 And device <> "" Then hs.setdevicevalue(device, CInt(strSNMPvalue))
            strSNMPvalue = CInt(strSNMPvalue)
            strSNMPvalue = strSNMPvalue + " " + Chr(176) + "C"
        Case "NAS_freespace"
            strSNMPvalue = (strSNMPvalue / 1000)
            If debug < 2 And device <> "" Then hs.setdevicevalue(device, CInt(strSNMPvalue))
            strSNMPvalue = CInt(strSNMPvalue)
            strSNMPvalue = strSNMPvalue + " GB"
            'Case "HD_status"
            '	If strSNMPvalue = "0" then strSNMPvalue = "ready"
            '	If strSNMPvalue = "-4" then strSNMPvalue = "unknown"
            '	If strSNMPvalue = "-5" then strSNMPvalue = "no Disk"
            '	If strSNMPvalue = "-6" then strSNMPvalue = "invalid"
            '	If strSNMPvalue = "-9" then strSNMPvalue = "Read/Write Error"
            '	If debug < 2 and device <> "" then hs.setdevicevalue(device,CInt(strSNMPvalue))
            '   Case "volumeEntry 6"
            '      strSNMPvalue = Mid(strSNMPvalue, 1, Instr(strSNMPvalue, ".") - 1)
            '     If debug < 2 And device <> "" Then hs.setdevicevalue(device, strSNMPvalue)
            '    strSNMPvalue = strSNMPvalue + " MB"
    End Select

    If debug > 0 Then hs.WriteLog("SNMP_02", SNMPname & "=" & strSNMPvalue)
    If debug < 2 And device <> "" Then hs.setdevicestring(device, strSNMPvalue, True)
End Function
Groeten, Tim
Post Reply

Return to “Homeseer Scripts Forum”