Last active
August 29, 2015 14:19
-
-
Save fndiaz/15925d53b7b22029282c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pysnmp.entity.rfc3413.oneliner import cmdgen | |
cmdGen = cmdgen.CommandGenerator() | |
def gera_snmp(var): | |
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( | |
cmdgen.CommunityData('public'), | |
cmdgen.UdpTransportTarget(('localhost', 161)), | |
var | |
) | |
return varBinds | |
#Identifica qtd de ebs | |
qtd = gera_snmp('.1.3.6.1.4.1.32624.1.1.0') | |
qtd = str(qtd[0][1]) | |
#Identifica Tipo | |
final={} | |
for i in range(int(qtd)): | |
temp={} | |
vart= gera_snmp('.1.3.6.1.4.1.32624.1.2.%s.0' %(str(i+1)) ) | |
temp['tipo']=str(vart[0][1]) | |
varse= gera_snmp('.1.3.6.1.4.1.32624.1.3.1.%s.16.0' %(str(i+1)) ) | |
temp['serial']=str(varse[0][1]) | |
varsta= gera_snmp('.1.3.6.1.4.1.32624.1.4.6.%s.0' %(varse[0][1])) | |
temp['status']=str(varsta[0][1]) | |
temp_link={} | |
if str(vart[0][1]) == '18': | |
qtd_link= gera_snmp('.1.3.6.1.4.1.32624.1.3.1.%s.1.0' %(varse[0][1])) | |
qtd_link = str(qtd_link[0][1]) | |
for x in range(int(qtd_link)): | |
st_link= gera_snmp('.1.3.6.1.4.1.32624.1.4.1.%s.%s.1.0' %(varse[0][1], str(x+1))) | |
temp_link[str(x+1)]= str(st_link[0][1]) | |
temp['link']=temp_link | |
temp_sinal={} | |
temp_ope={} | |
temp_stat={} | |
if str(vart[0][1]) == '21': | |
for y in range(16): | |
sn_gsm= gera_snmp('.1.3.6.1.4.1.32624.1.4.5.%s.%s.1.0.0' %(varse[0][1], str(y+1))) | |
op_gsm= gera_snmp('.1.3.6.1.4.1.32624.1.4.5.%s.%s.4.1.0' %(varse[0][1], str(y+1))) | |
stat_gsm= gera_snmp('.1.3.6.1.4.1.32624.1.4.5.%s.%s.3.1.0' %(varse[0][1], str(y+1))) | |
temp_sinal[str(y+1)]= str(sn_gsm[0][1]) | |
temp_ope[str(y+1)]= str(op_gsm[0][1]) | |
temp_stat[str(y+1)]= str(stat_gsm[0][1]) | |
temp['sinal']=temp_sinal | |
temp['operadora']=temp_ope | |
temp['chstat']=temp_stat | |
final[str(i+1)]=temp | |
print final | |
#print varBinds[0][1] | |
#for dado in varBinds[0]: | |
# print dado | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment