Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asking for help, what's the right way to query multiple remote host without the trouble I meet #315

Open
Storm-Born opened this issue Sep 29, 2019 · 3 comments

Comments

@Storm-Born
Copy link

  1. so, there are 10 hosts with the same authentication configuration. In a loop I query each of them with the async api and responses seem to be ok.
  2. what's werid me is that when I give a wrong authPass to a host in the loop, it also respond the value instead of telling me wrong pdu digest.
  3. if there is only one host, I give a wrong authPass to query something, it will respond the wrong pdu digest as I wish.
    4.I have tryed the multiple snmp engine demo,but it's not ok.
  4. so what's the right way to use the api for concurrent query multiple hosts.
@etingof
Copy link
Owner

etingof commented Sep 29, 2019

This is weird. Can you share the code snippet that exhibits this behavior?

Generally, this example might do the job upon some adjustment.

@Storm-Born
Copy link
Author

`def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
if errorIndication:
print(errorIndication)
return
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
return
else:
for varBind in varBinds:
print('%s %s %s'%( cbCtx['host'], cbCtx['pwd'], ' = '.join([x.prettyPrint() for x in varBind])))

snmpEngine = SnmpEngine()

hosts = ['node-a','node-b','node-c','node-d']

for host in hosts:
auth_pass = 'root@123'
# if host == 'node-d':
# auth_pass = 'root@125'
# print(auth_pass)
getCmd(snmpEngine,
UsmUserData('root', auth_pass ,'root@123', authProtocol=usmHMACSHAAuthProtocol, privProtocol=usmAesCfb128Protocol),
UdpTransportTarget((host, 161)),
ContextData(),
ObjectType(ObjectIdentity('1.3.6.1.2.1.1.3.0')),
cbFun=cbFun,
cbCtx={'host':host,'pwd':auth_pass})

snmpEngine.transportDispatcher.runDispatcher()`

=================================================================
running result:
node-a root@123 SNMPv2-MIB::sysUpTime.0 = 485832
node-b root@123 SNMPv2-MIB::sysUpTime.0 = 460159
node-c root@123 SNMPv2-MIB::sysUpTime.0 = 445637
node-d root@123 SNMPv2-MIB::sysUpTime.0 = 415837

when modify the auth_pass of node-d, I can also get the sysUptime
node-b root@123 SNMPv2-MIB::sysUpTime.0 = 475118
node-a root@123 SNMPv2-MIB::sysUpTime.0 = 500792
node-d root@125 SNMPv2-MIB::sysUpTime.0 = 430795
node-c root@123 SNMPv2-MIB::sysUpTime.0 = 460599

then I remove other items in hosts,only node-d left.as:
hosts = ['node-d']
the runing result is:

root@125
Wrong SNMP PDU digest

===================================================================
another test code list below, also respond a targetValue when give a wrong auth_pass to node-d.
I use the getCmd method instead of nextCmd method given in the online example.

def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
if errorIndication:
print(errorIndication)
return
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
return
else:
for varBind in varBinds:
print('%s %s %s'%( cbCtx[0], cbCtx[1], ' = '.join([x.prettyPrint() for x in varBind])))

targets = (

# 3-nd target (SNMPv3 over IPv4/UDP)
(UsmUserData('root', 'root@123'  ,'root@123', authProtocol=usmHMACSHAAuthProtocol, privProtocol=usmAesCfb128Protocol),
 UdpTransportTarget(('node-a', 161)),
 (ObjectType(ObjectIdentity('1.3.6.1.2.1.1.3.0')),)),

 (UsmUserData('root', 'root@124'  ,'root@123', authProtocol=usmHMACSHAAuthProtocol, privProtocol=usmAesCfb128Protocol),
 UdpTransportTarget(('node-b', 161)),
 (ObjectType(ObjectIdentity('1.3.6.1.2.1.1.3.0')),)),

 (UsmUserData('root', 'root@123'  ,'root@123', authProtocol=usmHMACSHAAuthProtocol, privProtocol=usmAesCfb128Protocol),
 UdpTransportTarget(('node-c', 161)),
 (ObjectType(ObjectIdentity('1.3.6.1.2.1.1.3.0')),)),

 (UsmUserData('root', 'root@123'  ,'root@123', authProtocol=usmHMACSHAAuthProtocol, privProtocol=usmAesCfb128Protocol),
 UdpTransportTarget(('node-d', 161)),
 (ObjectType(ObjectIdentity('1.3.6.1.2.1.1.3.0')),)),

)

snmpEngine = SnmpEngine()

Submit initial GETNEXT requests and wait for responses

for authData, transportTarget, varBinds in targets:
getCmd(snmpEngine, authData, transportTarget, ContextData(),
*varBinds, **dict(cbFun=cbFun, cbCtx=(authData, transportTarget)))

snmpEngine.transportDispatcher.runDispatcher()

===================RESULT==========================================
UsmUserData(userName='root', authKey=, privKey=, authProtocol=(1, 3, 6, 1, 6, 3, 10, 1, 1, 3), privProtocol=(1, 3, 6, 1, 6, 3, 10, 1, 2, 4), securityEngineId='', securityName='root', authKeyType=0, privKeyType=0) UdpTransportTarget(('172.16.227.11', 161), timeout=1, retries=5, tagList='') SNMPv2-MIB::sysUpTime.0 = 546353
UsmUserData(userName='root', authKey=, privKey=, authProtocol=(1, 3, 6, 1, 6, 3, 10, 1, 1, 3), privProtocol=(1, 3, 6, 1, 6, 3, 10, 1, 2, 4), securityEngineId='', securityName='root', authKeyType=0, privKeyType=0) UdpTransportTarget(('172.16.227.12', 161), timeout=1, retries=5, tagList='') SNMPv2-MIB::sysUpTime.0 = 520680
UsmUserData(userName='root', authKey=, privKey=, authProtocol=(1, 3, 6, 1, 6, 3, 10, 1, 1, 3), privProtocol=(1, 3, 6, 1, 6, 3, 10, 1, 2, 4), securityEngineId='', securityName='root', authKeyType=0, privKeyType=0) UdpTransportTarget(('172.16.227.14', 161), timeout=1, retries=5, tagList='') SNMPv2-MIB::sysUpTime.0 = 476357
UsmUserData(userName='root', authKey=, privKey=, authProtocol=(1, 3, 6, 1, 6, 3, 10, 1, 1, 3), privProtocol=(1, 3, 6, 1, 6, 3, 10, 1, 2, 4), securityEngineId='', securityName='root', authKeyType=0, privKeyType=0) UdpTransportTarget(('172.16.227.13', 161), timeout=1, retries=5, tagList='') SNMPv2-MIB::sysUpTime.0 = 506161

@Storm-Born
Copy link
Author

Can You help me for this problem, or what's the correct way to reach the thing that I want to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants