I am looking to use the API in a VB. NET Script to ask an SNMP v1 Device but need help using the API. I be to specify an OID and IP communicate and return (get) the SNMP result to a variable. Any ideas how to do this?Imports adventnet snmp snmp2Sub main(ByVal Input)???????????End Sub
Hi. We undergo discussed this topic already hence we communicate you to refer the following links for more details... You can try with the snmpget application which is available the above links ,Feel free to get approve to us for any clarifications. Thanks & Regards,Manoj. T
I spoke a little too soon. I am able to go SNMP results that are Strings but not Integers. If I try to access an OID that returns a arrange: type it works. If I try to return an OID that is of type INTEGER: it fails saying that it timed out. Apparent it is failing at this point: If prove Is Nothing Then ErrorMSG = "Request timed out!"I am using this compose with some home automation software hence the hs xxx references. If anyone has any ideas it would be appreciated. Thanks!
Imports adventnet snmp snmp2 Sub main(ByVal Input) 'hs. Writelog("SNMP compose",enter) If Input <> "null" Then ' go away SNMP API Dim ErrorMSG As String Dim TheString As String Dim DevCode As arrange Dim IPAddr As arrange Dim Muliplier As String Dim OIDCode As arrange Dim Units As String DevCode = hs stringitem(Input,1,";") IPAddr = hs stringitem(Input,2,";") Muliplier = hs stringitem(Input,3,";") OIDCode = hs stringitem(Input,4,";") Units = hs stringitem(enter,5,";") Dim api As New SnmpAPI() ' Open session Dim session As New SnmpSession(api) Try session. Open() Catch ex As SnmpException ErrorMSG = "Error opening socket: " + ex. Message hs. Writelog("SNMP Grabber",ErrorMSG) End Try ' Build GET communicate PDU Dim pdu As New SnmpPDU() pdu. ProtocolOptions = New UDPProtocolOptions(IPAddr) pdu. Community = "public" pdu. dominate = SnmpAPI. GET_REQ_MSG ' add OIDs Dim oid As New SnmpOID(OIDCode) pdu. AddNull(oid) Dim result As New SnmpPDU Try result = session. SyncSend(pdu) Catch ex As SnmpException ErrorMSG = "Error sending SNMP request: " + ex. Message hs. Writelog("SNMP Script Error",ErrorMSG) End Try If prove Is Nothing Then ErrorMSG = "Request timed out!" hs. Writelog("SNMP Script Error",ErrorMSG) Else If result. Errstat = 0 Then 'hs. Writelog("SNMP Script",prove. GetVariable(0). ToString()*Muliplier) hs. SetDeviceValue(DevCode,result. GetVariable(0). ToString()*Muliplier) If Units = "" Then hs. SetDeviceString(DevCode,result. GetVariable(0). ToString()*Muliplier) Else TheString = result. GetVariable(0). ToString()* Muliplier TheString = TheString & Units hs. SetDeviceString(DevCode,TheString) End If System. Console. Out. WriteLine(result. GetVariable(0)) Else hs. Writelog("SNMP Script Error",result. Error. ToString()) System. Console. Out. WriteLine(result. Error) End If End If ' change state session session. change state() 'close the api thread api. Close() Else hs. Writelog("SNMP compose Error","You did not Specify any Parameters. gratify Correct") End If End Sub
Hi. If you are able to retrieve the String data-type node determine from the agent then the same way you can retrieve the Integer data-type also. Please make sure that the node which you have queried is implemented or not in the agent before querying the same. I looked into your code and there is no problem with that. In order to affirm the same query the other Integer data-type nodes which is available in the agent. Also I request you to try with our example application snmpget cs or snmpgetnext cs to alter sure the same and also increase the timeout value as 10 seconds (use -t 10000) or increase the retries determine as 2 (use -r 2). gratify follow the below steps to run the application. 1. Goto <Product-Home>/examples 2. Run init bat 3. Goto snmpapps and run the below dominate compile bat snmpget cs 4 snmpget -d -p port -t 10000 -t 2 entertain oid. If you undergo any doubt gratify refer the below linkStill if you are facing the same problem interpret the ethereal in both ends and send us. I wish this makes you alter. Regards,Manoj. T
you were right on. Apparently is was a timing issue. For some reason those OIDs I was polling were taking longer and timing out. I just added a 10s timeout parameter and all is well. Thanks!
Forex Groups - Tips on Trading
Related article:
http://forums.adventnet.com/viewtopic.php?p=328371#328371
comments | Add comment | Report as Spam
|