2016-09-05 30 views
1

試圖此行轉換爲pysnmpCisco交換機啓用端口pysnmp

snmpset -v 2C -On -r -t 5 2 -C私有IP地址.1.3.6.1.2.1.2.2.1.7.369098771我1

我試圖採取步行的工作功能和修改,但我與SNMP知識使得它很難理解pysnmp DOC

這僅僅是一個代碼

從pysnmp.entity的一部分.rfc3413.oneliner import cmdgen

 device_target = (self.ip, self.port) 
     res = None 
     # Create a PYSNMP cmdgen object 
     cmd_gen = cmdgen.CommandGenerator() 
     (error_detected, error_status, error_index, snmp_data) = cmd_gen.setCmd(
      cmdgen.CommunityData(community_string), 
      cmdgen.UdpTransportTarget(device_target), '.1.3.6.1.2.1.2.2.1.7.369098771', 1 
      lookupNames=True, lookupValues=True) 

我知道我失去了一些東西,任何一個可以幫助請

回答

0

我會強烈建議您pysnmp升級到最新發布的版本,並使用「hlapi」界面。

from pysnmp.hlapi import * 

device_target = (self.ip, self.port) 
community_string = 'private' 

cmd_gen = setCmd(SnmpEngine(), 
       CommunityData(community_string), 
       UdpTransportTarget(device_target, timeout=2.0, retries=5), 
       ContextData(), 
       ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.7.369098771'), Integer32(1)), 
       lookupMib=False 
) 

res = None # True denotes a failure 

errorIndication, errorStatus, errorIndex, varBinds = next(cmd_gen) 

if errorIndication: 
    res = errorIndication 
elif errorStatus: 
    res = '%s at %s' % (errorStatus.prettyPrint(), 
         errorIndex and varBinds[int(errorIndex) - 1][0] or '?') 

if res: 
    print('SNMP failed: %s' % res) 

參考文獻:here

+0

感謝!它的工作! –

相關問題