[pysnmp-users] Multiple OID request - need help
Brought to you by:
elie
|
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 |