2016-09-05 7 views
1

수 있도록 전환 .1.3.6.1.2.1.2.2.1.7.369098771 내가 1시스코는</p> <p>snmpset -v (c) -On -r 5 -t 2 -c 사설 IP 주소를 pysnmp하려면이 줄을 변환하려고 포트 pysnmp

내가 일하는 도보 기능을 가지고 SNMP 내 지식은 매우 어려운이 pysnmp.entity의 코드

의 한 부분이다

pysnmp의 문서를 이해 할 수 있지만 수정하려고 .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

감사합니다! 그 일! –