pysnmp-users Mailing List for SNMP library for Python (Page 40)
Brought to you by:
elie
You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
(2) |
Sep
(3) |
Oct
(2) |
Nov
(4) |
Dec
(4) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
|
Feb
(3) |
Mar
(16) |
Apr
(3) |
May
(6) |
Jun
|
Jul
(7) |
Aug
(12) |
Sep
(4) |
Oct
(2) |
Nov
(11) |
Dec
(6) |
2004 |
Jan
(1) |
Feb
(41) |
Mar
(4) |
Apr
(1) |
May
(6) |
Jun
|
Jul
(8) |
Aug
(5) |
Sep
(8) |
Oct
(10) |
Nov
(3) |
Dec
(1) |
2005 |
Jan
|
Feb
(4) |
Mar
(8) |
Apr
(4) |
May
(10) |
Jun
(5) |
Jul
(10) |
Aug
(6) |
Sep
(6) |
Oct
(39) |
Nov
(20) |
Dec
(21) |
2006 |
Jan
(14) |
Feb
(6) |
Mar
(15) |
Apr
|
May
(5) |
Jun
(16) |
Jul
(16) |
Aug
(18) |
Sep
(35) |
Oct
(12) |
Nov
(3) |
Dec
(3) |
2007 |
Jan
(12) |
Feb
(19) |
Mar
(27) |
Apr
(14) |
May
(32) |
Jun
|
Jul
(35) |
Aug
(11) |
Sep
(11) |
Oct
(6) |
Nov
(13) |
Dec
(4) |
2008 |
Jan
(7) |
Feb
(4) |
Mar
(2) |
Apr
(3) |
May
(3) |
Jun
(5) |
Jul
(5) |
Aug
(1) |
Sep
(2) |
Oct
(3) |
Nov
(19) |
Dec
(7) |
2009 |
Jan
(2) |
Feb
(2) |
Mar
(12) |
Apr
(16) |
May
(16) |
Jun
(23) |
Jul
(7) |
Aug
(2) |
Sep
(17) |
Oct
(20) |
Nov
(20) |
Dec
(5) |
2010 |
Jan
(11) |
Feb
(17) |
Mar
(20) |
Apr
(7) |
May
(6) |
Jun
(14) |
Jul
(5) |
Aug
(10) |
Sep
(23) |
Oct
(16) |
Nov
(32) |
Dec
(21) |
2011 |
Jan
(6) |
Feb
(11) |
Mar
(3) |
Apr
(1) |
May
(4) |
Jun
(1) |
Jul
(4) |
Aug
(8) |
Sep
(20) |
Oct
(9) |
Nov
(29) |
Dec
(25) |
2012 |
Jan
(2) |
Feb
(5) |
Mar
(2) |
Apr
(22) |
May
(21) |
Jun
(7) |
Jul
(6) |
Aug
(2) |
Sep
(12) |
Oct
(20) |
Nov
(17) |
Dec
(17) |
2013 |
Jan
(4) |
Feb
(4) |
Mar
(8) |
Apr
(8) |
May
(10) |
Jun
(2) |
Jul
(23) |
Aug
(12) |
Sep
(14) |
Oct
(12) |
Nov
(4) |
Dec
(18) |
2014 |
Jan
(2) |
Feb
(7) |
Mar
(3) |
Apr
(8) |
May
(7) |
Jun
(1) |
Jul
(5) |
Aug
(2) |
Sep
(8) |
Oct
|
Nov
(2) |
Dec
(1) |
2015 |
Jan
(3) |
Feb
(15) |
Mar
(14) |
Apr
(4) |
May
(6) |
Jun
(3) |
Jul
(1) |
Aug
(6) |
Sep
(5) |
Oct
(21) |
Nov
(43) |
Dec
(10) |
2016 |
Jan
|
Feb
(2) |
Mar
(6) |
Apr
(4) |
May
(6) |
Jun
(2) |
Jul
(6) |
Aug
(5) |
Sep
(4) |
Oct
|
Nov
(3) |
Dec
(11) |
2017 |
Jan
(1) |
Feb
(8) |
Mar
|
Apr
(7) |
May
|
Jun
|
Jul
(5) |
Aug
|
Sep
(9) |
Oct
(8) |
Nov
|
Dec
|
2018 |
Jan
|
Feb
|
Mar
(2) |
Apr
(2) |
May
(1) |
Jun
(2) |
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
From: Roland K. <kne...@gm...> - 2008-11-06 15:43:05
|
Hi, I am new to Python and pysnmp and i am trying to send some SNMP-Get requests to a system. I'm using the 2.0.9 Release of PYSNMP and windows pc. I modified the snmpget.py example to fit my requirements (I deleted all the commandline stuff and set the port, oid stuff). That looks like that: import sys # Import PySNMP modules from pysnmp import asn1, v1, v2c from pysnmp import role # Initialize defaults port = 161 retries = 5 timeout = 1 version = 'v2c' host = 'printsrv86' oid='1.3.6.1.2.1.1.1' community_string = 'public' # Create SNMP manager object client = role.manager((host,port)) # Pass it a few options client.timeout = timeout client.retries = retries # Create a SNMP request&response objects from protocol version # specific module. try: req = eval('v2c').GETREQUEST() rsp = eval('v2c').GETRESPONSE() except (NameError, AttributeError): print 'Unsupported SNMP protocol version: %s\n%s' % (version, usage) sys.exit(-1) # Encode OIDs, encode SNMP request message and try to send # it to SNMP agent and receive a response (answer, src) = client.send_and_receive( \ req.encode(community=community_string, \ encoded_oids=map(asn1.OBJECTID().encode, oid[0:]))) # Decode SNMP response rsp.decode(answer) # Make sure response matches request (request IDs, communities, etc) if req != rsp: raise 'Unmatched response: %s vs %s' % (str(req), str(rsp)) # Decode BER encoded Object IDs. oids = map(lambda x: x[0], map(asn1.OBJECTID().decode, \ rsp['encoded_oids'])) # Decode BER encoded values associated with Object IDs. vals = map(lambda x: x[0](), map(asn1.decode, rsp['encoded_vals'])) # Check for remote SNMP agent failure if rsp['error_status']: raise 'SNMP error #' + str(rsp['error_status']) + ' for OID #' \ + str(rsp['error_index']) # Print out results for (oid, val) in map(None, oids, vals): print oid + ' ---> ' + str(val) But when i run the script to send a snmp get request i get this: Traceback (most recent call last): File "C:\Python26\SkriptS\Collect.py", line 49, in <module> encoded_oids=map(asn1.OBJECTID().encode, oid[0:]))) File "C:\Python26\lib\pysnmp\asn1.py", line 272, in encode result = self._encode() File "C:\Python26\lib\pysnmp\asn1.py", line 440, in _encode raise BadArgument('Short Object ID: ' + str(oid)) BadArgument: Short Object ID: [1L] The set oid is: '1.3.6.1.2.1.1.1' I think that the script is somehow deleting a part of the given oid while converting it in the asn1.py one line 567. I hope sombody can help me. |
From: Eric B. <br...@br...> - 2008-11-05 18:40:30
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body bgcolor="#ffffff" text="#000000"> In order to get around some performance problems I recently rewrote some code to use an asynchronous trap mechanism rather than the synchronous version of the calls I'd been using. Now my trap recipient is getting two traps each time I try to send one. I don't know if I'm calling the dispatcher when I shouldn't be or what...<br> <br> I'll strip down the code here as much as I can without getting rid of anything important.<br> <br> <blockquote> <pre># Some globals so I don't have to create them over and over destinations = ( ("10.255.20.30", standardtrapport ), ( "10.255.20.60", standardtrapport ) ) transports = [ ntforg.UdpTransportTarget((host, port)) for host, port in destinations ] def sendTrap(trapOID, blah, blah, blah, some varbinds ): global OIDs, transports, timer, notifier, community # OIDs is a dict of OIDs, unimportant # transports is the above tuple of two trap destinations # timer is the last time.time() that I ran the dispatcher # notifier is a global instance of ntforg.NotificationOriginator() # community is duh try: varbinds = (blah, blah, blah, nothing important to the issue) # here I want to queue one trap for each destination for transport in transports: log( 3, 'sending to %s' % transport ) notifier.asyncSendNotification( community, transport, 'trap', (trapOID), varbinds) except: # Deleted exception handling as unimportant, # I log the traceback, then move on pass # This is my question, I queue up traps for 10 seconds, then # run the dispatcher. Is that correct? if time.time() - timer > 10: notifier.snmpEngine.transportDispatcher.runDispatcher() timer = time.time() </pre> </blockquote> The code actually runs great, except for the duplicate traps. If I only have one transport in the transports tuple, then the single transport gets one trap, if there are two transports, they each get two traps.<br> <br> Any advice is greatly appreciated.<br> <br> <br> </body> </html> |
From: Filippo G. <fgi...@gm...> - 2008-10-30 14:19:24
|
On Thu, Oct 30, 2008 at 03:16:30PM +0100, Filippo Giunchedi wrote: > I'm sending out notifications using NotificationOriginator which includes > sysUpTime from __SNMPv2-MIB but without a smiRead() (obviously) but using > sysuptime.syntax, thus the reported value is time(). > Or at least that is my new best guess :) > > Is this a known issue and/or how to fix it? I came up with the attached patch, which while not clean as I'd like to, gets the job done. filippo -- Filippo Giunchedi - http://esaurito.net PGP key: 0x6B79D401 random quote follows: The only way to get rid of a temptation is to yield to it. -- Oscar Wilde |
From: Filippo G. <fgi...@gm...> - 2008-10-30 14:16:46
|
On Mon, Oct 27, 2008 at 11:35:09AM +0100, Filippo Giunchedi wrote: > class SysUpTime(TimeTicks): > def smiRead(self, name, value, idx): > return self.clone(int(time()-self._value)*100) > > in fact self._value is never setted if I'm not mistaken thus the reported uptime > is the current unix epoch. > Is this a known bug (self._value is used elsewhere as well) or I'm missing > something? After reading a bit through the code it seems another "bug" though. I'm sending out notifications using NotificationOriginator which includes sysUpTime from __SNMPv2-MIB but without a smiRead() (obviously) but using sysuptime.syntax, thus the reported value is time(). Or at least that is my new best guess :) Is this a known issue and/or how to fix it? thanks in advance, filippo -- Filippo Giunchedi - http://esaurito.net PGP key: 0x6B79D401 random quote follows: Everyone is entitled to his own opinion, but not his own facts. -- Daniel Patrick Moynihan |
From: Filippo G. <fgi...@gm...> - 2008-10-27 12:20:48
|
Hi, first things first: thanks for pysnmp! I'm trying pysnmp 4.1.10a and while sending out notification it seems that sysuptime is setted incorrectly: 2008-10-27 11:29:11 localhost [UDP: [127.0.0.1]:47232]: DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (1225103351) 141 days, 19:03:53.51 while I have just launched the example ntforg. Digging the code it seems the problem is at pysnmp/v4/smi/mibs/instances/__SNMPv2-MIB.py in class SysUpTime(TimeTicks): def smiRead(self, name, value, idx): return self.clone(int(time()-self._value)*100) in fact self._value is never setted if I'm not mistaken thus the reported uptime is the current unix epoch. Is this a known bug (self._value is used elsewhere as well) or I'm missing something? thanks in advance, filippo -- Filippo Giunchedi - http://esaurito.net PGP key: 0x6B79D401 random quote follows: It's not that I'm afraid to die, I just don't want to be there when it happens. -- Woody Allen |
From: Ilya E. <il...@gl...> - 2008-09-26 16:21:11
|
Per, Could I see the type and value of "val" variable in your example? I do not have your MIB-FILE, so I can't replay your issue. Although, the following code works for me (I'm using pysnmp-4.1.10a which has some IpAddress-related fixes): >>> from pysnmp.entity.rfc3413.oneliner import cmdgen >>> from pysnmp.proto import rfc1902 >>> >>> cmdGen = cmdgen.CommandGenerator() >>> cmdGen.setCmd( ... cmdgen.CommunityData('guest', 'guest', 0), ... cmdgen.UdpTransportTarget(('localhost', 161)), ... ((1,3,6,1,2,1,1,5,0), rfc1902.IpAddress( '10.10.10.10' ))) ('requestTimedOut', 0, 0, ()) BTW, this "oneliner" API allows for passing all your mib, var, suf, value parameters right to setCmd() method, so I'm not sure if you need to do explicit MIB lookup and value type coercing. thanks, ilya > Most likely a silly newbie question, but I am having problems doing a set > on an IpAddress variable. The code in question is lifted from the set > example and works for simple integer values: > > def set( mib, var, suf, value ): > oid, suffix = cmdgen.mibvar.mibNameToOid( > cmdGen.mibViewController, > (( mib, var), suf) > ) > val = cmdgen.mibvar.cloneFromMibValue( > cmdGen.mibViewController, > mib, var, value > ) > > errorIndication, errorStatus, errorIndex, \ > varBinds = cmdGen.setCmd( > cmdgen.CommunityData('guest', 'guest', 0), > cmdgen.UdpTransportTarget(( agent, 161 )), > (oid + suffix, val) > ) > > ... error handling deleted ... > > The result I get when I call set( 'MIB-FILE', 'addr', 1, '10.10.10.10' ) > is: > > File "/home/pknudsgaard/pysnmp/pysnmp/entity/rfc3413/oneliner/cmdgen.py", > line 310, in setCmd > authData, transportTarget, varBinds, (__cbFun, appReturn) > File "/home/pknudsgaard/pysnmp/pysnmp/entity/rfc3413/oneliner/cmdgen.py", > line 238, in asyncSetCmd > self.snmpEngine, addrName, __varBinds, cbFun, cbCtx > File "/home/pknudsgaard/pysnmp/pysnmp/entity/rfc3413/cmdgen.py", line 291, > in sendReq > reqPDU = rfc2576.v2ToV1(reqPDU) > File "/home/pknudsgaard/pysnmp/pysnmp/proto/proxy/rfc2576.py", line 280, > in v2ToV1 > v1.apiPDU.setVarBinds(v1Pdu, v1VarBinds) > File "/home/pknudsgaard/pysnmp/pysnmp/proto/api/v1.py", line 98, in > setVarBinds > varBindList.getComponentByPosition(idx), varBind > File "/home/pknudsgaard/pysnmp/pysnmp/proto/api/v1.py", line 32, in > setOIDVal > > varBind.setComponentByPosition(1).getComponentByPosition(1).setComponentByType(val.getTagSet(), > val, 1) > File "/var/lib/python-support/python2.5/pyasn1/v1/type/univ.py", line 523, > in setComponentByType > idx = self._componentType.getPositionByType(tagSet) > File "/var/lib/python-support/python2.5/pyasn1/v1/type/namedtype.py", line > 61, in getPositionByType > raise error.PyAsn1Error('Type %s not found' % tagSet) > pyasn1.error.PyAsn1Error: Type TagSet() not found > > It works fine if I do set( 'MIB-FILE', 'int', 1, 10 ). I have tried > replacing '10.10.10.10' with IpAddress( '10.10.10.10' ) but it results in > the same error. |
From: Per K. <pkn...@gm...> - 2008-09-24 22:38:29
|
Hi, Most likely a silly newbie question, but I am having problems doing a set on an IpAddress variable. The code in question is lifted from the set example and works for simple integer values: def set( mib, var, suf, value ): oid, suffix = cmdgen.mibvar.mibNameToOid( cmdGen.mibViewController, (( mib, var), suf) ) val = cmdgen.mibvar.cloneFromMibValue( cmdGen.mibViewController, mib, var, value ) errorIndication, errorStatus, errorIndex, \ varBinds = cmdGen.setCmd( cmdgen.CommunityData('guest', 'guest', 0), cmdgen.UdpTransportTarget(( agent, 161 )), (oid + suffix, val) ) ... error handling deleted ... The result I get when I call set( 'MIB-FILE', 'addr', 1, '10.10.10.10' ) is: File "/home/pknudsgaard/pysnmp/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 310, in setCmd authData, transportTarget, varBinds, (__cbFun, appReturn) File "/home/pknudsgaard/pysnmp/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 238, in asyncSetCmd self.snmpEngine, addrName, __varBinds, cbFun, cbCtx File "/home/pknudsgaard/pysnmp/pysnmp/entity/rfc3413/cmdgen.py", line 291, in sendReq reqPDU = rfc2576.v2ToV1(reqPDU) File "/home/pknudsgaard/pysnmp/pysnmp/proto/proxy/rfc2576.py", line 280, in v2ToV1 v1.apiPDU.setVarBinds(v1Pdu, v1VarBinds) File "/home/pknudsgaard/pysnmp/pysnmp/proto/api/v1.py", line 98, in setVarBinds varBindList.getComponentByPosition(idx), varBind File "/home/pknudsgaard/pysnmp/pysnmp/proto/api/v1.py", line 32, in setOIDVal varBind.setComponentByPosition(1).getComponentByPosition(1).setComponentByType(val.getTagSet(), val, 1) File "/var/lib/python-support/python2.5/pyasn1/v1/type/univ.py", line 523, in setComponentByType idx = self._componentType.getPositionByType(tagSet) File "/var/lib/python-support/python2.5/pyasn1/v1/type/namedtype.py", line 61, in getPositionByType raise error.PyAsn1Error('Type %s not found' % tagSet) pyasn1.error.PyAsn1Error: Type TagSet() not found It works fine if I do set( 'MIB-FILE', 'int', 1, 10 ). I have tried replacing '10.10.10.10' with IpAddress( '10.10.10.10' ) but it results in the same error. It is most likely something trivial, but I would appreciate if someone could point it out to me. Thanks, -- Per. |
From: Ilya E. <il...@gl...> - 2008-08-17 06:35:12
|
Stock pysnmp currently does not work with py2exe due to its dynamic access to some python modules and PATH mangling. There were patches that work these problems around, though I'm still thinking over a straight solution.. What is wrong with your code. Please, clarify. -ilya On Tue, 15 Jul 2008, Mr.V. RAJKUMAR(TM) wrote: > > Good Morning to All, > > > > > > Can sombody please help me on *py2exe for pysnmp.* > > > > I will be thankful, if you help me with sample source code. > > > > My Source Code is: > > or download the attachment: > > import pysnmp.v4.entity.rfc3413.oneliner.cmdgen as cmdgen > class SNMP_WALKER(): > def __init__ ( self ,RcedIP ,RcedCommunityString ): > > self.IPAddress=RcedIP > self.SNMP_OK_FLAG=0 > self.Host_Switch_Flag=0 > self.OperatingSystem="" > self.HostName="" > self.MACAddress="" > self.Manufacturer="" > self.CommunityString="" > self.Switch="" > self.Port="" > self.Softwares_Installed={} > self.Softwares_Installed["Software_Name"]=[] > self.Softwares_Installed["Installed_On"]=[] > self.Process_Running={} > self.Process_Running["Process_Name"]=[] > self.Process_Running["Process_Path"]=[] > self.Parse_Comm_String(RcedCommunityString) > def Hexify( self,octets ): > try: > return " ".join( [ '%x'%(ord(c)) for c in octets ] ) > except: > return None > def NormaliseMAC(self,str1): > try: > str1=str1.strip() > str1=str1.upper() > NewMacs=str1.split(" ") > NewMac1="" > for i in range(0,len(NewMacs)): > if(len(NewMacs[i])==1): > K="0"+NewMacs[i] > else: > K=NewMacs[i] > NewMac1+=K > if(i!=len(NewMacs)-1): > NewMac1+="-" > return NewMac1 > except: > return None > def DateFormat_From_Hex_List(self,NewStr2_List): > try: > Year=int(NewStr2_List[0]+NewStr2_List[1],16) > Month=int(NewStr2_List[2],16) > Date=int(NewStr2_List[3],16) > Hour=int(NewStr2_List[4],16) > Minute=int(NewStr2_List[5],16) > Second=int(NewStr2_List[6],16) > #print > str(Year)+"-"+str(Month)+"-"+str(Date)+","+str(Hour)+":"+str(Minute)+":"+str(Second) > > RetStr=str(Year)+"-"+str(Month)+"-"+str(Date)+","+str(Hour)+":"+str(Minute)+":"+str(Second) > return RetStr > except: > return "" > def Check_Object(self,String): > try: > if(String=="311"): > self.Host_Switch_Flag=1 > elif(String=="9"): > self.Host_Switch_Flag=2 > elif(String=="1916"): > self.Host_Switch_Flag=3 > elif(String=="2636"): > self.Host_Switch_Flag=4 > else: > self.Host_Switch_Flag=0 > except: > print "EXCEPTION: Occured in Check Object Method" > > > def Parse_Comm_String(self,Combined_Comm_String): > temp_string_1=Combined_Comm_String > temp_string_list_1=temp_string_1.split("||") > self.Parsed_Comm_String=[] > > for temp_string_2 in temp_string_list_1: > print "COMM:",temp_string_2 > temp_string_3=temp_string_2.strip() > self.Parsed_Comm_String.append(temp_string_3) > errorIndication, errorStatus, errorIndex, varBinds = > cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', > temp_string_3, 0),cmdgen.UdpTransportTarget((self.IPAddress, > 161)),(1,3,6,1,2,1,1,2) ) > if(errorIndication==None): > self.CommunityString=temp_string_3 > self.SNMP_OK_FLAG=1 > varBindTableRow=varBinds[0] > NewStr=str(varBindTableRow[0][1][6]) > self.Check_Object(NewStr) > break > if(self.SNMP_OK_FLAG==1): > self.Get_Operating_System() > if(self.Host_Switch_Flag==1): > self.Get_MACAddress() > if(self.MACAddress!=""): > self.Get_Manufacturer() > self.Get_Service_List() > self.Get_Software_List() > if(self.Host_Switch_Flag==2): > self.Get_MACAddress() > if(self.MACAddress!=""): > self.Get_Manufacturer() > self.Get_Switches_Port() > self.Get_Service_List() > if(self.Parsed_Comm_String[0]==""): > print "SNMPWALK::"+self.IPAddress+"> Invalid Community String." > > def Get_Operating_System(self): > print "OS and HOSTNAME" > errorIndication, errorStatus, errorIndex, varBinds = > cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', > self.CommunityString, 0),cmdgen.UdpTransportTarget((self.IPAddress, > 161)),(1,3,6,1,2,1,1) ) > if(errorIndication==None): > for varBindTableRow in varBinds:#varBindTable: > NewStr=str(varBindTableRow[0][0]) > ## NewStr1=str(varBindTableRow[0][1]) > ## print NewStr,NewStr1 > if(NewStr=="(1, 3, 6, 1, 2, 1, 1, 1, 0)"): > OS_Str=str(varBindTableRow[0][1]) > OS_Strss=OS_Str.split("\n") > try: > > OS_Strs=OS_Strss[0].split("Software:") > self.OperatingSystem=OS_Strs[1].strip() > except: > self.OperatingSystem=OS_Strss[0].strip() > #print > "OS:",OS_Strs[1].strip()#str(varBindTableRow[0][1]) > elif(NewStr=="(1, 3, 6, 1, 2, 1, 1, 5, 0)"): > Host_Str=str(varBindTableRow[0][1]) > Host_Strs=Host_Str.strip() > self.HostName=Host_Strs > #print "HOSTNAME:",Host_Str > > pass > ## def Get_Host_Name(self): > ## pass > def Get_MACAddress(self): > errorIndication, errorStatus, errorIndex, varBinds = > cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', > self.CommunityString, 0),cmdgen.UdpTransportTarget((self.IPAddress, > 161)),(1,3,6,1,2,1,2,2,1,6) ) > if(errorIndication==None): > for varBindTableRow in varBinds:#varBindTable: > #print varBindTableRow[0] > NewStr=str(varBindTableRow[0][1]) > NewStr1=self.Hexify(NewStr) > if(NewStr1!=None): > MACStr=self.NormaliseMAC(NewStr1) > if(MACStr!=""): > self.MACAddress=MACStr > break > > def Get_Manufacturer(self): > import MySQLdb > ManValue="" > Manfacturerval="" > Manuf=self.MACAddress > for i in range(0,len(Manuf)-9): > ManValue+=Manuf[i] > try: > conn = MySQLdb.connect (host = "localhost",user = "root", passwd > = "demo",db = "lms_cat_desk") > cursor = conn.cursor () > except OperationalError: > wx.MessageBox("\"MySQLdb\" DataBase Not Found.\n Or MySQL not > Installed.","Info",0) > return > try: > SQL_CMD1="SELECT manfacturer FROM lanmapper_mac_info WHERE > mackey='"+ManValue+"'" > cursor.execute(SQL_CMD1) > except: > print "SNMPWALK::Executing Query to Read Manufacturer Values > Failed" > return > try: > while(1): > row1=cursor.fetchone() > if row1 == None: > break > Manfacturerval=row1[0] > except: > print "SNMPWALK::MAnufacturer Value Not Found in the Table" > return > try: > cursor.close () > conn.commit () > conn.close () > except: > print "SNMPWALK::Closing SQL Cursor Failed" > self.Manufacturer=Manfacturerval > ## pass > ## def Get_CommunityString(self): > ## pass > def Get_Software_List(self): > errorIndication, errorStatus, errorIndex, varBinds = > cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', > self.CommunityString, 0),cmdgen.UdpTransportTarget((self.IPAddress, > 161)),(1,3,6,1,2,1,25,6,3,1,2) ) > if(errorIndication==None): > for varBindTableRow in varBinds:#varBindTable: > #print varBindTableRow[0] > NewStr=str(varBindTableRow[0][1]) > > self.Softwares_Installed["Software_Name"].append(str(NewStr)) > > errorIndication, errorStatus, errorIndex, varBinds = > cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', > self.CommunityString, 0),cmdgen.UdpTransportTarget((self.IPAddress, > 161)),(1,3,6,1,2,1,25,6,3,1,5) ) > if(errorIndication==None): > for varBindTableRow in varBinds:#varBindTable: > #print varBindTableRow[0] > NewStr=str(varBindTableRow[0]) > NewStr1=varBindTableRow[0][1] > NewStr2=self.Hexify(NewStr1) > if(NewStr2!=None): > NewStr2_List=NewStr2.split() > #print "Date:",DateFormat_From_Hex_List(NewStr2_List) > DateStr=self.DateFormat_From_Hex_List(NewStr2_List) > self.Softwares_Installed["Installed_On"].append(DateStr) > else: > self.Softwares_Installed["Installed_On"].append("") > > def Get_Service_List(self): > errorIndication, errorStatus, errorIndex, varBinds = > cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', > self.CommunityString, 0),cmdgen.UdpTransportTarget((self.IPAddress, > 161)),(1,3,6,1,2,1,25,4,2,1,2) ) > if(errorIndication==None): > for varBindTableRow in varBinds:#varBindTable: > #print varBindTableRow[0] > NewStr=str(varBindTableRow[0][1]) > self.Process_Running["Process_Name"].append(str(NewStr)) > #print NewStr > errorIndication, errorStatus, errorIndex, varBinds = > cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', > self.CommunityString, 0),cmdgen.UdpTransportTarget((self.IPAddress, > 161)),(1,3,6,1,2,1,25,4,2,1,4) ) > if(errorIndication==None): > for varBindTableRow in varBinds:#varBindTable: > #print varBindTableRow[0] > NewStr=str(varBindTableRow[0][1]) > self.Process_Running["Process_Path"].append(str(NewStr)) > > def Get_Switches_MAC_Address(self): > pass > def Get_Switches_Port(self): > errorIndication, errorStatus, errorIndex, varBinds = > cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', > self.CommunityString, 0),cmdgen.UdpTransportTarget((self.IPAddress, > 161)),(1,3,6,1,2,1,17,4,3,1,2) ) > if(errorIndication==None): > for varBindTableRow in varBinds:#varBindTable: > NewStr1=str(varBindTableRow[0][0]) > if(NewStr1=="(1, 3, 6, 1, 2, 1, 17, 4, 3, 1, 2, 0, 7, 235, > 119, 87, 128)"): > NewStr2=str(varBindTableRow[0][1]) > self.Port=NewStr2 > > pass > def SNMPWALK_RETURNS(self): > pass > def __del__ ( self ): > try: > del self.IPAddress > del self.OperatingSystem > del self.HostName > del self.MACAddress > del self.Manufacturer > del self.CommunityString > del self.Switch > del self.Port > del self.Softwares_Installed > del self.Process_Running > except: > pass > SnmpObj=SNMP_WALKER("192.168.10.100","public1||public1") > print "IP:",SnmpObj.IPAddress > print "SNMP_OK:",SnmpObj.SNMP_OK_FLAG > print "HOST/SWITCH",SnmpObj.Host_Switch_Flag > print "OS:",SnmpObj.OperatingSystem > print "HOST:",SnmpObj.HostName > print "MAC:",SnmpObj.MACAddress > print "MANUNFACT:",SnmpObj.Manufacturer > print "COMMSTRING:",SnmpObj.CommunityString > print "SWITCH:",SnmpObj.Switch > print "PORT:",SnmpObj.Port > print "SOFTS::::",SnmpObj.Softwares_Installed > print "PROCESS::",SnmpObj.Process_Running > print len(SnmpObj.Softwares_Installed["Software_Name"]) > print len(SnmpObj.Softwares_Installed["Installed_On"]) > print len(SnmpObj.Process_Running["Process_Name"]) > print len(SnmpObj.Process_Running["Process_Path"]) > > > > > > > Thank You. > > Raj. > > > > . > > > |
From: Mr.V. R. <raj...@gm...> - 2008-07-15 04:41:36
|
import pysnmp.v4.entity.rfc3413.oneliner.cmdgen as cmdgen class SNMP_WALKER(): def __init__ ( self ,RcedIP ,RcedCommunityString ): self.IPAddress=RcedIP self.SNMP_OK_FLAG=0 self.Host_Switch_Flag=0 self.OperatingSystem="" self.HostName="" self.MACAddress="" self.Manufacturer="" self.CommunityString="" self.Switch="" self.Port="" self.Softwares_Installed={} self.Softwares_Installed["Software_Name"]=[] self.Softwares_Installed["Installed_On"]=[] self.Process_Running={} self.Process_Running["Process_Name"]=[] self.Process_Running["Process_Path"]=[] self.Parse_Comm_String(RcedCommunityString) def Hexify( self,octets ): try: return " ".join( [ '%x'%(ord(c)) for c in octets ] ) except: return None def NormaliseMAC(self,str1): try: str1=str1.strip() str1=str1.upper() NewMacs=str1.split(" ") NewMac1="" for i in range(0,len(NewMacs)): if(len(NewMacs[i])==1): K="0"+NewMacs[i] else: K=NewMacs[i] NewMac1+=K if(i!=len(NewMacs)-1): NewMac1+="-" return NewMac1 except: return None def DateFormat_From_Hex_List(self,NewStr2_List): try: Year=int(NewStr2_List[0]+NewStr2_List[1],16) Month=int(NewStr2_List[2],16) Date=int(NewStr2_List[3],16) Hour=int(NewStr2_List[4],16) Minute=int(NewStr2_List[5],16) Second=int(NewStr2_List[6],16) #print str(Year)+"-"+str(Month)+"-"+str(Date)+","+str(Hour)+":"+str(Minute)+":"+str(Second) RetStr=str(Year)+"-"+str(Month)+"-"+str(Date)+","+str(Hour)+":"+str(Minute)+":"+str(Second) return RetStr except: return "" def Check_Object(self,String): try: if(String=="311"): self.Host_Switch_Flag=1 elif(String=="9"): self.Host_Switch_Flag=2 elif(String=="1916"): self.Host_Switch_Flag=3 elif(String=="2636"): self.Host_Switch_Flag=4 else: self.Host_Switch_Flag=0 except: print "EXCEPTION: Occured in Check Object Method" def Parse_Comm_String(self,Combined_Comm_String): temp_string_1=Combined_Comm_String temp_string_list_1=temp_string_1.split("||") self.Parsed_Comm_String=[] for temp_string_2 in temp_string_list_1: print "COMM:",temp_string_2 temp_string_3=temp_string_2.strip() self.Parsed_Comm_String.append(temp_string_3) errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', temp_string_3, 0),cmdgen.UdpTransportTarget((self.IPAddress, 161)),(1,3,6,1,2,1,1,2) ) if(errorIndication==None): self.CommunityString=temp_string_3 self.SNMP_OK_FLAG=1 varBindTableRow=varBinds[0] NewStr=str(varBindTableRow[0][1][6]) self.Check_Object(NewStr) break if(self.SNMP_OK_FLAG==1): self.Get_Operating_System() if(self.Host_Switch_Flag==1): self.Get_MACAddress() if(self.MACAddress!=""): self.Get_Manufacturer() self.Get_Service_List() self.Get_Software_List() if(self.Host_Switch_Flag==2): self.Get_MACAddress() if(self.MACAddress!=""): self.Get_Manufacturer() self.Get_Switches_Port() self.Get_Service_List() if(self.Parsed_Comm_String[0]==""): print "SNMPWALK::"+self.IPAddress+"> Invalid Community String." def Get_Operating_System(self): print "OS and HOSTNAME" errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', self.CommunityString, 0),cmdgen.UdpTransportTarget((self.IPAddress, 161)),(1,3,6,1,2,1,1) ) if(errorIndication==None): for varBindTableRow in varBinds:#varBindTable: NewStr=str(varBindTableRow[0][0]) ## NewStr1=str(varBindTableRow[0][1]) ## print NewStr,NewStr1 if(NewStr=="(1, 3, 6, 1, 2, 1, 1, 1, 0)"): OS_Str=str(varBindTableRow[0][1]) OS_Strss=OS_Str.split("\n") try: OS_Strs=OS_Strss[0].split("Software:") self.OperatingSystem=OS_Strs[1].strip() except: self.OperatingSystem=OS_Strss[0].strip() #print "OS:",OS_Strs[1].strip()#str(varBindTableRow[0][1]) elif(NewStr=="(1, 3, 6, 1, 2, 1, 1, 5, 0)"): Host_Str=str(varBindTableRow[0][1]) Host_Strs=Host_Str.strip() self.HostName=Host_Strs #print "HOSTNAME:",Host_Str pass ## def Get_Host_Name(self): ## pass def Get_MACAddress(self): errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', self.CommunityString, 0),cmdgen.UdpTransportTarget((self.IPAddress, 161)),(1,3,6,1,2,1,2,2,1,6) ) if(errorIndication==None): for varBindTableRow in varBinds:#varBindTable: #print varBindTableRow[0] NewStr=str(varBindTableRow[0][1]) NewStr1=self.Hexify(NewStr) if(NewStr1!=None): MACStr=self.NormaliseMAC(NewStr1) if(MACStr!=""): self.MACAddress=MACStr break def Get_Manufacturer(self): import MySQLdb ManValue="" Manfacturerval="" Manuf=self.MACAddress for i in range(0,len(Manuf)-9): ManValue+=Manuf[i] try: conn = MySQLdb.connect (host = "localhost",user = "root", passwd = "demo",db = "lms_cat_desk") cursor = conn.cursor () except OperationalError: wx.MessageBox("\"MySQLdb\" DataBase Not Found.\n Or MySQL not Installed.","Info",0) return try: SQL_CMD1="SELECT manfacturer FROM lanmapper_mac_info WHERE mackey='"+ManValue+"'" cursor.execute(SQL_CMD1) except: print "SNMPWALK::Executing Query to Read Manufacturer Values Failed" return try: while(1): row1=cursor.fetchone() if row1 == None: break Manfacturerval=row1[0] except: print "SNMPWALK::MAnufacturer Value Not Found in the Table" return try: cursor.close () conn.commit () conn.close () except: print "SNMPWALK::Closing SQL Cursor Failed" self.Manufacturer=Manfacturerval ## pass ## def Get_CommunityString(self): ## pass def Get_Software_List(self): errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', self.CommunityString, 0),cmdgen.UdpTransportTarget((self.IPAddress, 161)),(1,3,6,1,2,1,25,6,3,1,2) ) if(errorIndication==None): for varBindTableRow in varBinds:#varBindTable: #print varBindTableRow[0] NewStr=str(varBindTableRow[0][1]) self.Softwares_Installed["Software_Name"].append(str(NewStr)) errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', self.CommunityString, 0),cmdgen.UdpTransportTarget((self.IPAddress, 161)),(1,3,6,1,2,1,25,6,3,1,5) ) if(errorIndication==None): for varBindTableRow in varBinds:#varBindTable: #print varBindTableRow[0] NewStr=str(varBindTableRow[0]) NewStr1=varBindTableRow[0][1] NewStr2=self.Hexify(NewStr1) if(NewStr2!=None): NewStr2_List=NewStr2.split() #print "Date:",DateFormat_From_Hex_List(NewStr2_List) DateStr=self.DateFormat_From_Hex_List(NewStr2_List) self.Softwares_Installed["Installed_On"].append(DateStr) else: self.Softwares_Installed["Installed_On"].append("") def Get_Service_List(self): errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', self.CommunityString, 0),cmdgen.UdpTransportTarget((self.IPAddress, 161)),(1,3,6,1,2,1,25,4,2,1,2) ) if(errorIndication==None): for varBindTableRow in varBinds:#varBindTable: #print varBindTableRow[0] NewStr=str(varBindTableRow[0][1]) self.Process_Running["Process_Name"].append(str(NewStr)) #print NewStr errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', self.CommunityString, 0),cmdgen.UdpTransportTarget((self.IPAddress, 161)),(1,3,6,1,2,1,25,4,2,1,4) ) if(errorIndication==None): for varBindTableRow in varBinds:#varBindTable: #print varBindTableRow[0] NewStr=str(varBindTableRow[0][1]) self.Process_Running["Process_Path"].append(str(NewStr)) def Get_Switches_MAC_Address(self): pass def Get_Switches_Port(self): errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', self.CommunityString, 0),cmdgen.UdpTransportTarget((self.IPAddress, 161)),(1,3,6,1,2,1,17,4,3,1,2) ) if(errorIndication==None): for varBindTableRow in varBinds:#varBindTable: NewStr1=str(varBindTableRow[0][0]) if(NewStr1=="(1, 3, 6, 1, 2, 1, 17, 4, 3, 1, 2, 0, 7, 235, 119, 87, 128)"): NewStr2=str(varBindTableRow[0][1]) self.Port=NewStr2 pass def SNMPWALK_RETURNS(self): pass def __del__ ( self ): try: del self.IPAddress del self.OperatingSystem del self.HostName del self.MACAddress del self.Manufacturer del self.CommunityString del self.Switch del self.Port del self.Softwares_Installed del self.Process_Running except: pass SnmpObj=SNMP_WALKER("192.168.10.100","public1||public1") print "IP:",SnmpObj.IPAddress print "SNMP_OK:",SnmpObj.SNMP_OK_FLAG print "HOST/SWITCH",SnmpObj.Host_Switch_Flag print "OS:",SnmpObj.OperatingSystem print "HOST:",SnmpObj.HostName print "MAC:",SnmpObj.MACAddress print "MANUNFACT:",SnmpObj.Manufacturer print "COMMSTRING:",SnmpObj.CommunityString print "SWITCH:",SnmpObj.Switch print "PORT:",SnmpObj.Port print "SOFTS::::",SnmpObj.Softwares_Installed print "PROCESS::",SnmpObj.Process_Running print len(SnmpObj.Softwares_Installed["Software_Name"]) print len(SnmpObj.Softwares_Installed["Installed_On"]) print len(SnmpObj.Process_Running["Process_Name"]) print len(SnmpObj.Process_Running["Process_Path"]) |
From: Mr.V. R. <raj...@gm...> - 2008-07-15 04:37:50
|
Good Morning to All, Can sombody please help me on *py2exe for pysnmp.* I will be thankful, if you help me with sample source code. Thank You. Raj. On Sat, Jul 12, 2008 at 12:21 AM, Ilya Etingof <il...@gl...> wrote: > > A non-empty "errorIndication" means request failure, in your case - > requestTimeout, what leads to empty result. > > SNMP protocol supports 32-bit width integers so 2^32 values will pass > through. > > >From your description it looks like your SNMP Agent is sometimes slow > responding to your requests. You may want to try increasing timeout value > in your SNMP Manager script: > > UdpTransportTarget( > transportAddr, > timeout, > retries > ) > > -ilya > > [ skipped ] > > > The code to get a value is: > > -------- > > newmibs=tuple(newmibs) > > errorIndication, errorStatus, errorIndex, varBinds = > > > apply(cmdgen.CommandGenerator().getCmd,(cmdgen.CommunityData('my-agent',PASSWD,0),cmdgen.UdpTransportTarget((IP, > PORT))) + newmibs) > > print varBinds > > print errorIndication,errorStatus,errorIndex > > -------- > > > > If it's working I get: > > -------- > > [(ObjectName('1.3.6.1.2.1.2.2.1.4.1'), Integer32('1500'))] > > None 0 0 > > -------- > > > > If it's not working: > > -------- > > () > > requestTimedOut 0 0 > > -------- > > ------------------------------------------------------------------------- > Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! > Studies have shown that voting for your favorite open source project, > along with a healthy diet, reduces your potential for chronic lameness > and boredom. Vote Now at http://www.sourceforge.net/community/cca08 > _______________________________________________ > pysnmp-users mailing list > pys...@li... > https://lists.sourceforge.net/lists/listinfo/pysnmp-users > -- S.V.RAJKUMAR, XOU Solutions India Private Limited No. 37, PM Towers, Greams Road, Thousand Lights, Chennai - 6 . Mobile No : +91 - 9940632275. |
From: Ilya E. <il...@gl...> - 2008-07-11 19:26:25
|
Try setting the 'BROADCAST' flag to the socket your are sending SNMP out: >>> import socket >>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) >>> s.sendto('a', ('111.112.214.255', 1611)) Traceback (most recent call last): File "<stdin>", line 1, in ? socket.error: (13, 'Permission denied') >>> if hasattr(socket,'SO_BROADCAST'): ... s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) >>> s.sendto('a', ('111.112.214.255', 1611)) 1 >>> The socket object is available as a 'socket' attribute of role.manager class instance. -ilya [ skipped ] > Traceback (most recent call last): > File "./snmp.py", line 8, in <module> > [...] > File "/var/lib/python-support/python2.5/pysnmp/v2/role.py", line 92, in open > raise NetworkError('connect() error: %s: %s' % (self.agent, why)) > pysnmp.role.NetworkError: connect() error: ('192.168.1.255', 161): > (13, 'Permission denied') > > I don't know what does it mean, since we are running the script as > root. Could it be a configuration in a router? |
From: Ilya E. <il...@gl...> - 2008-07-11 18:52:59
|
A non-empty "errorIndication" means request failure, in your case - requestTimeout, what leads to empty result. SNMP protocol supports 32-bit width integers so 2^32 values will pass through. >From your description it looks like your SNMP Agent is sometimes slow responding to your requests. You may want to try increasing timeout value in your SNMP Manager script: UdpTransportTarget( transportAddr, timeout, retries ) -ilya [ skipped ] > The code to get a value is: > -------- > newmibs=tuple(newmibs) > errorIndication, errorStatus, errorIndex, varBinds = > apply(cmdgen.CommandGenerator().getCmd,(cmdgen.CommunityData('my-agent',PASSWD,0),cmdgen.UdpTransportTarget((IP, PORT))) + newmibs) > print varBinds > print errorIndication,errorStatus,errorIndex > -------- > > If it's working I get: > -------- > [(ObjectName('1.3.6.1.2.1.2.2.1.4.1'), Integer32('1500'))] > None 0 0 > -------- > > If it's not working: > -------- > () > requestTimedOut 0 0 > -------- |
From: Carles P. i E. <ca...@pi...> - 2008-07-08 12:28:10
|
Hello, We are using pysnmp for more than one year and works really good, thanks for the nice piece of software. Now we have a problem trying to get a value. I can get some of the values like: [(ObjectName('1.3.6.1.2.1.2.2.1.4.1'), Integer32('1500'))] But some other value returns an empty value: () When should return: snmpwalk -v2c -c PASSWD 10.1.1.111 1.3.6.1.2.1.2.2.1.10.1 IF-MIB::ifInOctets.1 = Counter32: 3089151836 Is it a 32 bits value not supported? The correct value in this case is >2^31 and < 2^32 but I have tested another machine with a value <2^31 and it's not working either. We are using a Debian stable with: python-pysnmp-common 4.1.6a-1 python-pysnmp4 4.1.6a-1 python-pysnmp4-mibs 0.0.4a-1 The code to get a value is: -------- newmibs=tuple(newmibs) errorIndication, errorStatus, errorIndex, varBinds = apply(cmdgen.CommandGenerator().getCmd,(cmdgen.CommunityData('my-agent',PASSWD,0),cmdgen.UdpTransportTarget((IP, PORT))) + newmibs) print varBinds print errorIndication,errorStatus,errorIndex -------- If it's working I get: -------- [(ObjectName('1.3.6.1.2.1.2.2.1.4.1'), Integer32('1500'))] None 0 0 -------- If it's not working: -------- () requestTimedOut 0 0 -------- But using snmpwalk I can get both values. Thank you very much! -- Carles Pina i Estany GPG id: 0x8CBDAE64 http://pinux.info Manresa - Barcelona |
From: Ilya E. <il...@gl...> - 2008-06-24 06:39:55
|
The bullet-proof way would be to unicast SNMP messages to every IP in your local network. Otherwise: > Is there a way to send broadcast SNMP packets with PySNMP? If so, how > can I do it? To my impression, the SNMPv3 architecture is not really suitable for broadcast mode because of its built-in request-response logic, not mentioning the crypto part of the system. Although, if you would use a lower-level SNMPv1/v2c, broadacasting looks much more promising. You would use basic Manager code (examples/v1arch/manager/getgen.py) with a modified response handler to let it deal with possible multiple responses to a single request. It may be sufficient to just comment out the transportDispatcher.jobFinished(1) line for that. Let's see if it helps when you send a request to a IP network broadcast address? -ilya |
From: Eric B. <br...@br...> - 2008-06-23 20:54:41
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> Adam Victor Nazareth Brandizzi wrote: <blockquote cite="mid:9f0...@ma..." type="cite"> <pre wrap="">On Mon, Jun 23, 2008 at 4:32 PM, Ilya Etingof <a class="moz-txt-link-rfc2396E" href="mailto:il...@gl..."><il...@gl...></a> wrote: </pre> <blockquote type="cite"> <pre wrap="">I've not heard of a possibility of SNMP broadcasting. If you do, please, let me see how it's to be done. </pre> </blockquote> <pre wrap=""><!----> Well, it seems plausible, since SNMP runs over UDP, but I'm just a newbie about SNMP and my opinions probably aren't acceptable :) </pre> </blockquote> <br> Simply send the packet as you normally would, but send it to the broadcast address of your network.<br> <br> <br> <blockquote cite="mid:9f0...@ma..." type="cite"> <pre wrap=""></pre> <blockquote type="cite"> <pre wrap="">Otherwise, what's your goal in the first place? </pre> </blockquote> <pre wrap=""><!----> I'm trying to find printers in a network. Since <a class="moz-txt-link-freetext" href="http://www.kdedevelopers.org/node/2138">http://www.kdedevelopers.org/node/2138</a> says CUPS uses a broadcast SNMP packet to find printes, I'd like to try it too. </pre> <blockquote type="cite"> <pre wrap="">-ilya </pre> <blockquote type="cite"> <pre wrap="">Is there a way to send broadcast SNMP packets with PySNMP? If so, how can I do it? </pre> </blockquote> </blockquote> <pre wrap=""><!----> </pre> </blockquote> <br> </body> </html> |
From: Adam V. N. B. <bra...@gm...> - 2008-06-23 20:00:53
|
On Mon, Jun 23, 2008 at 4:32 PM, Ilya Etingof <il...@gl...> wrote: > I've not heard of a possibility of SNMP broadcasting. If you do, please, > let me see how it's to be done. Well, it seems plausible, since SNMP runs over UDP, but I'm just a newbie about SNMP and my opinions probably aren't acceptable :) > Otherwise, what's your goal in the first place? I'm trying to find printers in a network. Since http://www.kdedevelopers.org/node/2138 says CUPS uses a broadcast SNMP packet to find printes, I'd like to try it too. > -ilya > >> Is there a way to send broadcast SNMP packets with PySNMP? If so, how >> can I do it? > -- Adam Victor Nazareth Brandizzi http://brandizzi.googlepages.com/ |
From: Ilya E. <il...@gl...> - 2008-06-23 19:32:35
|
I've not heard of a possibility of SNMP broadcasting. If you do, please, let me see how it's to be done. Otherwise, what's your goal in the first place? -ilya > Is there a way to send broadcast SNMP packets with PySNMP? If so, how > can I do it? |
From: Adam V. N. B. <bra...@gm...> - 2008-06-23 19:18:18
|
Hi! Is there a way to send broadcast SNMP packets with PySNMP? If so, how can I do it? Thanks! -- Adam Victor Nazareth Brandizzi http://brandizzi.googlepages.com/ |
From: Ivan B. <ibr...@gm...> - 2008-05-21 14:07:13
|
first thing thanks for writing such useful module. I haw few questions I am using pysnmp to query devices for some GET wales and also for some WALK's, and it is doing fine but since I plan in near future to query cca 3000 devices I am looking at asynchronous mode. Currently I am using synchronous queries in pool of worker thread's, it is working fine. But as I seen from documentation and other examples asynchronous model would be better for souch task. Now some questions. 1. I tried examples from mailing list for WALK and it works but then I can't use GET example , do I need to to haw 2 *cbFun functions for this? 2. Actually I don't need full SNMP WALK only number values in that tree is there faster way then snmpwalk and then count values? 3. If I have for instance 3000 gets to do in *asynchronous can they make network congestion if they go altogether, and can I set some limit there? Thanks Ivan |
From: Ilya E. <il...@gl...> - 2008-05-11 20:59:11
|
... You need to convert your string OID representation (such as '.1.2.3.5.6') into either of: 1. tuple of integer sub-OIDs: >>> import string >>> oid = '.1.2.3.5.6' >>> tuple(map(string.atoi, string.split(oid, '.')[1:])) (1, 2, 3, 5, 6) or 2. ObjectIdentifier class instance: >>> from pyasn1.type import univ >>> univ.ObjectIdentifier(oid) ObjectIdentifier('1.2.3.5.6') >>> The #2 option looks more elegant. -ilya > Of course it wans't as simple as i you like it to be. I just can't > manage to change the OID, for example when i do this: > > ... > errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd( > > cmdgen.CommunityData('my-agent', 'public', 0), > > cmdgen.UdpTransportTarget((host, 161)), #<-- this works perfectly, each host is checked > > (pyoid) # <-- this doesn't work > > ) > ... > > I receive a type error => TypeError: can only concatenate tuple (not > "str") to tuple. I tried transforming pyoid in a tuple then > concatenating it but it doesn't change anything. How can i solve this? I > guess it should be easy to solve but don't know how. |
From: Aidan H. <pu...@ho...> - 2008-05-08 10:16:09
|
Hello. I'm working on a project that envolves requesting different OID values from different hosts. (The OID and Host are stored in a DB as strings). This app has a simple purpose, it connects to a db containing a list of host associated with their OIDs. It then TRIES TO retreive each OID value for each host and insert the value in the DB. Here is the catch, i can't put the new OID value from the database in the SNMP request. Here is the code import MySQLdb from pysnmp.entity.rfc3413.oneliner import cmdgen # db connection and use connection= MySQLdb.connect(bla bla bla) cursor= connection.cursor() # on recupere chaque OID pour chaque host cursor.execute("SELECT r.table_name, ro.host, ro.oid FROM reference r, reference_oid ro WHERE ro.host=r.host LIMIT 10") result= cursor.fetchall() for host_oid in result: table= host_oid[0] host= host_oid[1] # looks like '192.168.1.1' oid= host_oid[2] # looks like '.1.2.3.5.6' pyoid= oid.replace('.', '', 1) pyoid= pyoid.replace('.', ',') #What I would like to solve is here: #change the host dynamically #change the OID dynamically errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd( cmdgen.CommunityData('my-agent', 'public', 0), cmdgen.UdpTransportTarget(('localhost', 161)), (1,3,6,1,2,1,1,1,0) ) #suppose no errors print varBinds #just print them for now but will get the value and INSERT it in the database cursor.close() connection.commit() connection.close() Of course it wans't as simple as i you like it to be. I just can't manage to change the OID, for example when i do this: ... errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd( cmdgen.CommunityData('my-agent', 'public', 0), cmdgen.UdpTransportTarget((host, 161)), #<-- this works perfectly, each host is checked (pyoid) # <-- this doesn't work ) ... I receive a type error => TypeError: can only concatenate tuple (not "str") to tuple. I tried transforming pyoid in a tuple then concatenating it but it doesn't change anything. How can i solve this? I guess it should be easy to solve but don't know how. Thanks in advance to everyone! _________________________________________________________________ Discover the new Windows Vista http://search.msn.com/results.aspx?q=windows+vista&mkt=en-US&form=QBRE |
From: Ilya E. <il...@gl...> - 2008-04-27 21:54:15
|
Similar solution, though a bit more MT-safer, is now in CVS. Please, take a look and let me know if it does not work as expected. thanks, ilya > Eventually, I did use something similar to a class static counter (I think > my version is more a module static counter :-) ). > I am just worried that it might not be the best way to do it. > > In the cmdgen module, I added this global function: > > def gen_handle_number(list1=[0]): > list1[0] += 1 > return int(list1[0]) > > Then I updated all the sendReq definitions of the subclasses > (GetCommandGenerator, SetCommandGenerator, NextCommandGenerator ...) to use > the gen_handle_number function to generate a "unique" handle number (unique > for this session). [ ... ] |
From: Ilya E. <il...@gl...> - 2008-04-25 10:35:53
|
> And I don't want to use a global counter that all instances of the command > generators read. Could you please explain, what would be wrong with using class-static counter there? Sorry for delaying for so long. -ilya |
From: Ashirvaad R. <ax...@gm...> - 2008-04-15 12:30:19
|
Hello I am new to python and SNMP. I am experiencing a little difficulty with pysnmp, and trawling through the documentation, source code, and mailing lists has not been able to help me. I hope someone can point me in the right direction with the information below: I am trying to use pysnmp to asynchronously poll a number of devices. It seemed easiest to do this using pysnmp.entity.rfc3413.oneliner: handle = cmdgen.AsynCommandGenerator().asyncGetCmd( authData, transportTarget, varNames, (handle_asyn_snmp_response, (self, context_id))) authData, transportTarget, varNames are correctly initialised before the call to asyncGetCmd(). handle_asyn_snmp_response is the name of the callback function. as the context data, i'm passing a reference to the calling object, and a custom specified id (a string which is used to identify the request sender). after the call to asyncGetCmd(), I store some data in a dictionary, using "handle" as the key, based on the assumption that every request/response is generated with a unique handle number. That is not exactly how it turns out. I send an SNMP NEXT request to each device: handle = cmdgen.AsynCommandGenerator().asyncNextCmd( authData, transportTarget, varNames, (handle_asyn_snmp_response, (self, context_id))) When a response is received (if it is not timed out and no error has occurred), I then send the same device an SNMP GET request, using an almost identical call: handle = cmdgen.AsynCommandGenerator().asyncGetCmd( authData, transportTarget, varNames, (handle_asyn_snmp_response, (self, context_id))) The problem is that this method always returns a handle ID of 1. Looking at the source has revealed that a new instance of the command generator is created for each call, and this is why the handle number is never incremented. One obvious way I managed to solve this problem was to extend the cmdgen.AsynCommandGenerator class and change things a little in there, that is by creating and reusing a single command generator object. That worked for the case where I send out only SNMP NEXT or only SNMP GET requests. But I am, within the same session, sending out both GET and NEXT requests, and the handles generated are not unique. Looking at the class hierarchy, I see that GetCommandGenerator, SetCommandGenerator, NextCommandGenerator, and BulkCommandGenerator all inherit from CommandGeneratorBase. This means I have no way of getting them to obtain handles from a shared source. Any suggestions? I don't want to have to hack this whole project by rewriting most of Ilya's code. And I don't want to use a global counter that all instances of the command generators read. And the oneliner module so closely almost does exactly what I need it to do! Is there something I can do to take advantage of its elegance, eloquence, and simplicity? Thanks for your time and patience! Ashir -- all is chaos. seek harmony, not control. axdk |
From: Ilya E. <il...@gl...> - 2008-03-30 09:01:04
|
Try the following methods: <mibobj>.getSyntax().getTagSet() >>> from pysnmp.smi import builder >>> mibNode, = mibBuilder.importSymbols('SNMP-FRAMEWORK-MIB', 'snmpEngineID') >>> mibNode MibScalar((1, 3, 6, 1, 6, 3, 10, 2, 1, 1), "─O") >>> mibNode.getSyntax() SnmpEngineID("'\\x80\\x00O\\xb8\\x05\\x7f\\x00\\x00\\x01\\x0f\\x1c'") >>> mibNode.getSyntax().getTagSet() TagSet(Tag(tagClass=0, tagFormat=0, tagId=4)) >>> -ilya > I'd like to access the range constraints of MIB leafs. They are > contained in the generated MIBs with that code: > Integer32().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, 199)) > > but I don't know how I could read them from a mibNode that I get from > mibBuilder.importSymbols(). Isn't there anything like getMaxAccess(), > but for the range? > > Robert |