import time import rrdtool from getSNMP import consultaSNMP from path import * carga_CPU = 0 while 1: carga_CPU = int( consultaSNMP('SNMPcom', 'localhost', '1.3.6.1.2.1.25.3.3.1.2.196608')) valor = "N:" + str(carga_CPU) print(valor) ret = rrdtool.update(rrdpath + rrdname, valor) rrdtool.dump(rrdpath + rrdname, 'trend.xml') time.sleep(1) if ret: print(rrdtool.error()) time.sleep(300)
import time import rrdtool from getSNMP import consultaSNMP total_input_traffic = 0 total_output_traffic = 0 while 1: total_input_traffic = int(consultaSNMP('comunidadSNMP','localhost','1.3.6.1.2.1.2.2.1.10.3')) total_output_traffic = int(consultaSNMP('comunidadSNMP','localhost','1.3.6.1.2.1.2.2.1.16.3')) valor = str(rrdtool.last("netP.rrd")+300)+":" + str(total_input_traffic) + ':' + str(total_output_traffic) print valor ret = rrdtool.update('netP.rrd', valor) rrdtool.dump('netP.rrd','netP.xml') ret = rrdtool.graph("netP.png", "--start", '1479434100', "--end",str(rrdtool.last('netP.rrd')), "--vertical-label=Bytes/s", "DEF:obs=netP.rrd:inoctets:AVERAGE", "DEF:outoctets=netP.rrd:outoctets:AVERAGE", "DEF:pred=netP.rrd:inoctets:HWPREDICT", "DEF:dev=netP.rrd:inoctets:DEVPREDICT", #"RRA:DEVSEASONAL:1d:0.1:2", #"RRA:DEVPREDICT:5d:5", #"RRA:FAILURES:1d:7:9:5"" "CDEF:scaledobs=obs,8,*", "CDEF:upper=pred,dev,2,*,+", "CDEF:lower=pred,dev,2,*,-",
def realizarConsultas(comunidad, ip, puerto, numero): total_input_traffic = 0 total_output_traffic = 0 total_input_ipReceives = 0 total_input_IcmpMsgs = 0 total_output_IcmpMsgs = 0 total_input_tcpSegs = 0 total_output_tcpSegs = 0 total_input_DatgramasUdp = 0 total_output_DatgramasUdp = 0 arch1Rrd = 'octets' + str(numero) + '.rrd' arch2Rrd = 'ipInReceives' + str(numero) + '.rrd' arch3Rrd = 'icmpMsgs' + str(numero) + '.rrd' arch4Rrd = 'tcpSegs' + str(numero) + '.rrd' arch5Rrd = 'udpDatagrams' + str(numero) + '.rrd' arch1Xml = 'octets' + str(numero) + '.xml' arch2Xml = 'ipInReceives' + str(numero) + '.xml' arch3Xml = 'icmpMsgs' + str(numero) + '.xml' arch4Xml = 'tcpSegs' + str(numero) + '.xml' arch5Xml = 'udpDatagrams' + str(numero) + '.xml' while 1: # Tráfico Interfaz total_input_traffic = int( consultaSNMP(comunidad, ip, '1.3.6.1.2.1.2.2.1.10.3', puerto)) #El último dígito es la interfaz a trabajar total_output_traffic = int( consultaSNMP(comunidad, ip, '1.3.6.1.2.1.2.2.1.16.3', puerto)) #El último dígito es la interfaz a trabajar valor = "N:" + str(total_input_traffic) + ':' + str(total_output_traffic) print (valor) rrdtool.update(arch1Rrd, valor) rrdtool.dump(arch1Rrd,arch1Xml) time.sleep(1) # IP In Receives total_input_ipReceives = int( consultaSNMP(comunidad, ip, '1.3.6.1.2.1.4.3.0', puerto)) #El último dígito es la interfaz a trabajar valor = "N:" + str(total_input_ipReceives) print (valor) rrdtool.update(arch2Rrd, valor) rrdtool.dump(arch2Rrd,arch2Xml) time.sleep(1) # ICMP Mensajes entrada/salida total_input_IcmpMsgs = int( consultaSNMP(comunidad, ip, '1.3.6.1.2.1.5.1.0', puerto)) #El último dígito es la interfaz a trabajar total_output_IcmpMsgs = int( consultaSNMP(comunidad, ip, '1.3.6.1.2.1.5.14.0', puerto)) #El último dígito es la interfaz a trabajar valor = "N:" + str(total_input_IcmpMsgs) + ':' + str(total_output_IcmpMsgs) print (valor) rrdtool.update(arch3Rrd, valor) rrdtool.dump(arch3Rrd,arch3Xml) time.sleep(1) # TCP Segs entrada/salida total_input_tcpSegs = int( consultaSNMP(comunidad, ip, '1.3.6.1.2.1.6.10.0', puerto)) #El último dígito es la interfaz a trabajar total_output_tcpSegs = int( consultaSNMP(comunidad, ip, '1.3.6.1.2.1.6.11.0', puerto)) #El último dígito es la interfaz a trabajar valor = "N:" + str(total_input_tcpSegs) + ':' + str(total_output_tcpSegs) print (valor) rrdtool.update(arch4Rrd, valor) rrdtool.dump(arch4Rrd,arch4Xml) time.sleep(1) # Datagramas UDP total_input_DatgramasUdp = int( consultaSNMP(comunidad, ip, '1.3.6.1.2.1.7.1.0', puerto)) #El último dígito es la interfaz a trabajar total_output_DatgramasUdp = int( consultaSNMP(comunidad, ip, '1.3.6.1.2.1.7.4.0', puerto)) #El último dígito es la interfaz a trabajar valor = "N:" + str(total_input_DatgramasUdp) + ':' + str(total_output_DatgramasUdp) print (valor) rrdtool.update(arch5Rrd, valor) rrdtool.dump(arch5Rrd,arch5Xml) time.sleep(1) if ret: print (rrdtool.error()) time.sleep(300) #realizarConsultas('Stefan10', 'localhost', 161)
def EjecutarLb(comunidad, ip, port, name, times): agentPath = lbPath + name + "/" # 1 RAM de interfaz ramUsada = int( consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.25.2.3.1.6.1')) ramTotal = int( consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.25.2.3.1.5.1')) valor = "N:" + str(ramUsada) + ':' + str(ramTotal) rrdtool.update(str(agentPath + name) + 'RAM.rrd', valor) # 1 Grafica RAM de interfaz finalTime = int(rrdtool.last(str(agentPath + name) + "RAM.rrd")) initialTime = finalTime - 3600 ret = rrdtool.graphv( str(agentPath + name) + "RAM.png", "--start", str(initialTime), "--vertical-label=Carga RAM", "--title=USO DE RAM - LINEA DE BASE", "--color", "ARROW#009900", '--vertical-label', "Uso de RAM (%)", '--lower-limit', '0', '--upper-limit', '100', "DEF:usada=" + str(agentPath + name) + "RAM.rrd:RAMusado:AVERAGE", "DEF:total=" + str(agentPath + name) + "RAM.rrd:RAMtotal:AVERAGE", "CDEF:porciento=usada,100,*,total,/", "VDEF:cargaSTDEV=usada,STDEV", "GPRINT:cargaSTDEV:%6.2lf %SSTDEV", "AREA:porciento#00FF00:RAM Storage", 'VDEF:ultimo=porciento,LAST', "VDEF:RAMlast=porciento,LAST", "VDEF:RAMmin=porciento,MINIMUM", "VDEF:RAMavg=porciento,AVERAGE", "VDEF:RAMmax=porciento,MAXIMUM", "VDEF:RAMmax2=porciento,STDEV", "CDEF:aux=porciento,5,+", "CDEF:aux2=porciento,2,+", "VDEF:RAMavg2=aux,AVERAGE", "VDEF:RAMavg3=aux2,AVERAGE", "HRULE:RAMavg2#BB0000:Umbral Go", "HRULE:RAMavg3#00BB00:Umbral Set", "HRULE:RAMavg#000000:Umbral Ready", "CDEF:umbral25=porciento,RAMavg2,LT,0,porciento,IF", "AREA:umbral25#FF9F00:Tráfico de carga mayor que umbral 3", #'CDEF:abc=porciento,RAMavg,100,LIMIT', "PRINT:ultimo:%12.0lf%s", "PRINT:RAMavg2:%12.0lf%s ", "COMMENT: Last Now Min Avg Max//n", "GPRINT:RAMlast:%12.0lf%s", "GPRINT:RAMmin:%10.0lf%s", "GPRINT:RAMavg:%13.0lf%s", "GPRINT:RAMmax:%13.0lf%s", ) #----------------------------------------------------------------------------------------- # 2 CPU de interfaz #if name=='linux'or name=="linuxmario": carga_CPU = int( consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.25.3.3.1.2.768')) #elif name=="examen": # carga_CPU = int(consultaSNMP(comunidad , ip , port ,'1.3.6.1.2.1.25.3.3.1.2.769')) #else: # carga_CPU = int(consultaSNMP(comunidad , ip , port ,'1.3.6.1.2.1.25.3.3.1.2.3')) #carga_CPU = int(consultaSNMP(comunidad , ip , port ,'1.3.6.1.2.1.25.3.3.1.2.196608')) valor = "N:" + str(carga_CPU) time.sleep(1) rrdtool.update(str(agentPath + name) + 'CPU.rrd', valor) tiempo_final = int(rrdtool.last(str(agentPath + name) + "CPU.rrd")) tiempo_inicial = tiempo_final - 3600 ret2 = rrdtool.graphv( str(agentPath + name) + "CPU.png", "--start", str(tiempo_inicial), "--end", str(tiempo_final + 1000), "--title", "Carga de CPU", "--vertical-label=Uso de CPU (%)", '--lower-limit', '0', '--upper-limit', '100', "DEF:carga=" + str(agentPath + name) + "CPU.rrd:CPUload:AVERAGE", # "CDEF:umbral25=carga,"+str(umbral)+",LT,0,carga,IF", "VDEF:cargaMAX=carga,MAXIMUM", "VDEF:cargaMIN=carga,MINIMUM", "VDEF:cargaSTDEV=carga,STDEV", "VDEF:cargaLAST=carga,LAST", "AREA:carga#00FF00:Carga del CPU", # "HRULE:"+str(umbral)+"#FF0000:"+str(umbral)+"%", "GPRINT:cargaMIN:%6.2lf %SMIN", "GPRINT:cargaSTDEV:%6.2lf %SSTDEV", "GPRINT:cargaLAST:%6.2lf %SLAST", # ---METODO DE MINIMOS CUADRADOS #"VDEF:m=carga,LSLSLOPE", #"VDEF:b=carga,LSLINT", #'CDEF:avg2=carga,POP,m,COUNT,*,b,+', #"LINE2:avg2#FFBB00", #'VDEF:um=m,0,LT,90,0,IF' #'VDEF:um2=um,100,LT,0,90,0,IF' "VDEF:CPUavg=carga,AVERAGE", "CDEF:aux=carga,5,+", "CDEF:aux2=carga,2,+", "VDEF:CPUavg2=aux,AVERAGE", "VDEF:CPUavg3=aux2,AVERAGE", "HRULE:CPUavg2#BB0000:Umbral Go", "HRULE:CPUavg3#00BB00:Umbral Set", "HRULE:CPUavg#000000:Umbral Ready", "CDEF:umbral25=carga,CPUavg2,LT,0,carga,IF", "AREA:umbral25#FF9F00:Tráfico de carga mayor que CPUavg2", "AREA:umbral25#FF9F00:Tráfico de carga mayor que umbral 3", # 'CDEF:abc=avg2,'+str(umbral)+','+str(umbral+ 100000000)+',LIMIT', # 'CDEF:abc2=avg2,-10,0,LIMIT', #'VDEF:primero=abc,FIRST', #'VDEF:primero2=abc2,FIRST', #"GPRINT:primero: Alcanzara el umbral "+ str(umbral)+"% @ %c :strftime", #"GPRINT:primero2: Alcanzara el umbral 0% @ %c :strftime", #"PRINT:primero: Alcanzara umbral el @ %c :strftime", "PRINT:cargaLAST:%6.2lf %S ", "PRINT:CPUavg2:%6.2lf %S ") #alcanza_umbral=ret2['print[0]'] #ultimo_valor= ret2['print[0]'] #limite= ret2['print[1]'] #print (ultimo_valor + limite) #if float(ultimo_valor)>float(limite): # sendAlertEmail("Evidencia 3 Equipo2 Grupo 4cm1 :Agente "+name+"Sobrepasó umbral CPU Go con :"+str(ultimo_valor), str(agentPath + name) +"CPU.png",str(agentPath + name) + "CPU.rrd") # peirnt ("Envie correo ") #time.sleep(3600) #----------------------------------------------------------------------------------------- # 3 HDD de interfaz # 1 RAM de interfaz #if name=="linux" or name=="linuxmario": ramUsada = int( consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.25.2.3.1.6.36')) ramTotal = int( consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.25.2.3.1.5.36')) #else : # ramUsada = int(consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.25.2.3.1.5.1')) # ramTotal = int(consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.25.2.3.1.4.1')) valor = "N:" + str(ramUsada) + ':' + str(ramTotal) rrdtool.update(str(agentPath + name) + 'HDD.rrd', valor) rrdtool.dump( str(agentPath + name) + 'HDD.rrd', str(agentPath + name) + 'HDD.xml') # 1 Grafica RAM de interfaz finalTime = int(rrdtool.last(str(agentPath + name) + "HDD.rrd")) initialTime = finalTime - 3600 ret = rrdtool.graphv( str(agentPath + name) + "HDD.png", "--start", str(initialTime), "--vertical-label=Carga HDD", "--title=USO DE HDD - LINEA DE BASE", "--color", "ARROW#009900", '--vertical-label', "Uso de RAM (%)", '--lower-limit', '0', '--upper-limit', '100', "DEF:usada=" + str(agentPath + name) + "HDD.rrd:HDDusado:AVERAGE", "DEF:total=" + str(agentPath + name) + "HDD.rrd:HDDtotal:AVERAGE", "CDEF:porciento=usada,100,*,total,/", "VDEF:cargaSTDEV=usada,STDEV", "GPRINT:cargaSTDEV:%6.2lf %SSTDEV", "AREA:porciento#00FF00:RAM Storage", 'VDEF:ultimo=porciento,LAST', #'VDEF:ultimo2=carga,LAST', "VDEF:RAMlast=porciento,LAST", "VDEF:RAMmin=porciento,MINIMUM", "VDEF:RAMavg=porciento,AVERAGE", "VDEF:RAMmax=porciento,MAXIMUM", "VDEF:RAMmax2=porciento,STDEV", "CDEF:aux=porciento,5,+", "CDEF:aux2=porciento,2,+", "VDEF:RAMavg2=aux,AVERAGE", "VDEF:RAMavg3=aux2,AVERAGE", "HRULE:RAMavg2#BB0000:Umbral Go", "HRULE:RAMavg3#00BB00:Umbral Set", "HRULE:RAMavg#000000:Umbral Ready", "CDEF:umbral25=porciento,RAMavg2,LT,0,porciento,IF", "AREA:umbral25#FF9F00:Tráfico de carga mayor que umbral 3", #'CDEF:abc=porciento,RAMavg,100,LIMIT', "PRINT:RAMlast:%12.0lf%s", "PRINT:RAMavg2:%12.0lf%s ", "COMMENT: Last Now Min Avg Max//n", "GPRINT:RAMlast:%12.0lf%s", "GPRINT:RAMmin:%10.0lf%s", "GPRINT:RAMavg:%13.0lf%s", "GPRINT:RAMmax:%13.0lf%s", )
import time import rrdtool from getSNMP import consultaSNMP total_input_traffic = 0 total_output_traffic = 0 while 1: print("IP_UpdateRRD.py_ ") total_input_traffic = int( consultaSNMP('comunidad4cm3','localhost', '1.3.6.1.2.1.2.2.1.10.3')) total_output_traffic = int( consultaSNMP('comunidad4cm3','localhost', '1.3.6.1.2.1.2.2.1.16.3')) valor = "N:" + str(total_input_traffic) + ':' + str(total_output_traffic) print (valor) rrdtool.update('traficoRED.rrd', valor) rrdtool.dump('traficoRED.rrd','traficoRED.xml') time.sleep(1) if ret: print (rrdtool.error()) time.sleep(300)
opcion = int( input("Ingrese la opcion que desae realizar para el startup-config: ")) if opcion == 1: print("\n****************************************************") print("* = Inicio = *") print("****************************************************\n") if numdisp != 0: print(" Dispositivos en monitoreo: ", numdisp) # Ahora ya sabiendo el numero de dispositivos que hay, obtendremos su informacion p = 0 for k in range(numdisp): try: name = str( consultaSNMP(listaleida[p + 2], listaleida[p], '1.3.6.1.2.1.1.1.0')) if name == 'Hardware:': name = "Windows" _OID = '1.3.6.1.2.1.2.2.1.8.3' # OID para la interfaz en el mio es el 3 else: # Cuando name == Linux _OID = '1.3.6.1.2.1.2.2.1.8.3' # En caso de Linux como es nuestra compu es wlan0, hay que buscar que numero tiene print("\n >> Agente " + str(k + 1) + " : " + name) OperStatus = consultaSNMP(listaleida[p + 2], listaleida[p], _OID) if OperStatus == '1': status = 'up' elif OperStatus == '2': status = 'down'
def EjecutarP(hilo, comunidad, ip, port, name): agentPath = lbPathmc + name + "/" fname = "netPred.rrd" consulta = int(consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.2.2.1.10.1')) valor = "N:" + str(consulta) ret = rrdtool.update(str(agentPath + name + fname), valor) rrdtool.dump(str(agentPath + name + fname), str(agentPath) + name + 'netP.xml') title = "Deteccion de comportamiento anomalo" ultimo = rrdtool.last(str(agentPath + name + fname)) inicio = ultimo - 300 ayerInicio = (inicio - 300) ayerFinal = ultimo - 300 primero = rrdtool.first(str(agentPath + name + fname)) #cambia el valor de alfa rrdtool.tune(str(agentPath + name + fname), '--alpha', '0.8') #rrdtool.tune(str(agentPath + name + fname),'--beta','0.1') #rrdtool.tune(str(agentPath + name + fname),'--gamma','0.1') ret = rrdtool.graphv( str(agentPath + name) + "prediccion.png", '--start', str(inicio), '--end', str(ultimo + 5), '--title=' + title, "--vertical-label=Bytes/s", '--slope-mode', "DEF:obs=" + str(agentPath + name + fname) + ":inoctets:AVERAGE", #"DEF:outoctets=" + str(agentPath + fname) + ":outoctets:AVERAGE", "DEF:pred=" + str(agentPath + name + fname) + ":inoctets:HWPREDICT", "DEF:dev=" + str(agentPath + name + fname) + ":inoctets:DEVPREDICT", "DEF:fail=" + str(agentPath + name + fname) + ":inoctets:FAILURES", "DEF:yvalue=" + str(agentPath + name + fname) + ":inoctets:AVERAGE:start=" + str(ayerInicio) + ":end=" + str(ayerFinal), 'SHIFT:yvalue:300', #"RRA:DEVSEASONAL:1d:0.1:2", #"RRA:DEVPREDICT:5d:5", #"RRA:FAILURES:1d:7:9:5"" "CDEF:scaledh=yvalue,8,*", "CDEF:scaledobs=obs,8,*", "CDEF:upper=pred,dev,2,*,+", "CDEF:lower=pred,dev,2,*,-", "CDEF:scaledupper=upper,8,*", "CDEF:scaledlower=lower,8,*", "CDEF:scaledpred=pred,8,*", "AREA:scaledh#C9C9C9:Yesterday", "TICK:fail#FDD017:1.0:FFallas", "LINE3:scaledobs#00FF00:In traffic", "LINE1:scaledpred#FF00FF:Prediccion\\n", #"LINE1:outoctets#0000FF:Out traffic", "LINE1:scaledupper#ff0000:Upper Bound Average bits in\\n", "LINE1:scaledlower#0000FF:Lower Bound Average bits in", "VDEF:lastfail=fail,LAST", #"VDEF:max=fail,MAXIMUM", #"VDEF:min=fail,MINIMUM", "PRINT:lastfail: %c :strftime", "PRINT:lastfail:%6.2lf %S ", 'PRINT:fail:MIN:%1.0lf', 'PRINT:fail:MAX:%1.0lf', ) #bandera=0 time_falla = ret['print[0]'] ultima_falla = ret['print[1]'] fmin = ret['print[2]'] fmax = ret['print[3]'] #f = open(str(agentPath)+"log.txt","a") #print("Fallas "+ str(ultima_falla) +"----"+ str(time_falla)) if float(ultima_falla) == 1: if hilo.ban == 0: # inicio de falla bandera de 0 a 1 hilo.inicio = str(time_falla) hilo.ban = 1 print("INICIO DE FALLA") if hilo.unaVez == 0: sendAlertEmail( "Agente : " + name + " Inicio aberración : " + str(hilo.inicio), str(agentPath) + "prediccion.png", str(agentPath + name + fname)) hilo.unaVez = 1 elif hilo.ban == 1: # aun no termina la falla y gardo el ultimo tiempo hilo.fin = str(time_falla) print("CONTINUA" + hilo.fin) elif float(ultima_falla ) == 0 and hilo.ban == 1: #termina la falla bandera de 1 a 0 hilo.ban = 0 f = open(str(lbPathmc) + "log.txt", "a") f.write(str("\tFalla " + name + "\n")) f.write("Inicio : " + str(hilo.inicio) + "\n") if hilo.fin == "": hilo.fin = str(time_falla) f.write("Fin: " + str(hilo.fin) + "\n") else: f.write("Fin: " + str(hilo.fin) + "\n") print("FIN DE FALLA" + hilo.fin) if hilo.unaVez == 1: sendAlertEmail( "Agente : " + name + " Fin aberración : " + str(hilo.fin), str(agentPath) + "prediccion.png", str(agentPath + name + fname)) hilo.unaVez = 2 hilo.fin = "" hilo.inicio = "" f.close()
def getAgentInfo(self, oid): return consultaSNMP(self.agent['comunity'], self.agent['hostname'], self.agent['port'], oid)
def getAgentInfo(ip_community): print 'getAgentInfo' status_array = [] interface_name_status = [] global agentCount r = 6 ro = 6 for computer in ip_community: status_received = ping(computer['ip']) #ip_for['ip] status_array.append(status_received) if status_received == 'Activa': print('\n * * * * * * * *\nEl status es: ' + status_received) agents = consultaSNMP(computer['community'], computer['port'], computer['ip'], '1.3.6.1.2.1.1.1.0') print agents if not agents: continue interfaces = consultaSNMP(computer['community'], computer['port'], computer['ip'], '1.3.6.1.2.1.2.1.0') print interfaces for i in range(1, int(interfaces) + 1): name_interfaces = consultaSNMP(computer['community'], computer['port'], computer['ip'], '1.3.6.1.2.1.2.2.1.2.' + str(i)) status_inter = consultaSNMP(computer['community'], computer['port'], computer['ip'], '1.3.6.1.2.1.2.2.1.8.' + str(i)) if name_interfaces[1] == '0': interface_name = name_interfaces[3:].decode('hex') Label(canvasFrame, text=interface_name, width=100, fg='black').grid(row=ro, column=3, sticky="nsew") else: Label(canvasFrame, text=name_interfaces, width=100, fg='black').grid(row=ro, column=3, sticky="nsew") if int(status_inter) == 1: Label(canvasFrame, text='Activo', width=20, fg='black').grid(row=ro, column=4, sticky="nsew") elif int(status_inter) == 2: Label(canvasFrame, text='Inactivo', width=20, fg='black').grid(row=ro, column=4, sticky="nsew") elif int(status_inter) == 3: Label(canvasFrame, text='Testing', width=20, fg='black').grid(row=ro, column=4, sticky="nsew") ro = ro + 1 agentes_nombre = Label(canvasFrame, text=agents, width=70, fg='black').grid(row=r, column=0, sticky="nsew") Label(canvasFrame, text=status_received, width=10, fg='black').grid(row=r, column=1, sticky="nsew") Label(canvasFrame, text=interfaces, width=10, fg='black').grid(row=r, column=2, sticky="nsew") Tkinter.Button(canvasFrame, text="Graficas", width=10, command=lambda name=[ computer['community'], computer['port'], computer['ip'], '1.3.6.1.2.1.2.2.1.2.' + str(i) ]: graphics(name)).grid(row=r, column=5, sticky="nsew") Tkinter.Button( canvasFrame, text="Estado", width=10, command=lambda name=computer['ip']: MostrarEstado(name)).grid( row=r, column=6, sticky="nsew") Tkinter.Button( canvasFrame, text="Eliminar", width=10, command=lambda name=computer['ip']: eliminarAgente(name)).grid( row=r, column=7, sticky="nsew") r = r + int(interfaces) else: Label(canvasFrame, text=computer['ip'], width=70, fg='red').grid(row=r, column=0, sticky="nsew") Label(canvasFrame, text=status_received, width=10, fg='red').grid(row=r, column=1, sticky="nsew") Label(canvasFrame, text='Informacion no disponible', width=50, fg='red').grid(row=ro, column=3, sticky="nsew") Tkinter.Button( canvasFrame, text="Eliminar", width=10, command=lambda name=computer['ip']: eliminarAgente(name)).grid( row=r, column=7, sticky="nsew") r = r + 1 ro = ro + 1 Label(canvasFrame, text='Numero de agentes: ' + str(agentCount), width=25, fg='black').grid(row=1, column=1, sticky="nsew") #Inicia actualizaciones de las BD de cada host encontrado y vivo inicia_capturas()
from getSNMP import consultaSNMP #from Notify import check_aberration total_input_traffic = 0 total_output_traffic = 0 rrdpath = "/home/alina/Escritorio/Trend-Non-Linear/" pngpath = "/home/alina/Escritorio/Trend-Non-Linear/" fname = "netP.rrd" pngfname = "predict.png" title = "Deteccion de comportamiento anomalo" # Generate charts for last 24 hours endDate = rrdtool.last(fname) #ultimo valor del XML begDate = endDate - 86000 while 1: total_input_traffic = int( consultaSNMP('public', '10.100.71.100', '1.3.6.1.2.1.2.2.1.21.1')) #total_output_traffic = int(consultaSNMP('public','localhost','1.3.6.1.2.1.2.2.1.16.1')) valor = str(rrdtool.last(fname) + 100) + ":" + str( total_input_traffic) #+ ':' + str(total_output_traffic) print valor #ret = rrdtool.update(fname, valor) rrdtool.dump(fname, 'netP.xml') time.sleep(1) #print check_aberration(rrdpath,fname) if ret: print rrdtool.error() time.sleep(300)
import time import rrdtool from getSNMP import consultaSNMP total_input_traffic = 0 total_output_traffic = 0 while 1: total_input_traffic = int( consultaSNMP('SNMPcom', 'localhost', '1.3.6.1.2.1.2.2.1.10.3')) total_output_traffic = int( consultaSNMP('SNMPcom', 'localhost', '1.3.6.1.2.1.2.2.1.16.3')) valor = "N:" + str(total_input_traffic) + ':' + str(total_output_traffic) print(valor) rrdtool.update('traficoRED.rrd', valor) rrdtool.dump('traficoRED.rrd', 'traficoRED.xml') time.sleep(1) if ret: print(rrdtool.error()) time.sleep(300)
import time import rrdtool from getSNMP import consultaSNMP total_input_traffic = 0 total_output_traffic = 0 while 1: total_input_traffic = int( consultaSNMP('grupo4cm1', '10.100.71.200', '1.3.6.1.2.1.2.2.1.10.1')) valor = "N:" + str(total_input_traffic) + ':' + str(total_output_traffic) print(valor) rrdtool.update('traficoRED.rrd', valor) rrdtool.dump('traficoRED.rrd', 'traficoRED.xml') time.sleep(1) if ret: print(rrdtool.error()) time.sleep(300)
import time import rrdtool from getSNMP import consultaSNMP total_input_traffic = 0 total_output_traffic = 0 while 1: total_input_traffic = int( consultaSNMP('comunidadSNMP', '192.168.1.69', '1.3.6.1.2.1.2.2.1.10.3')) total_output_traffic = int( consultaSNMP('comunidadSNMP', '192.168.1.69', '1.3.6.1.2.1.2.2.1.16.3')) valor = "N:" + str(total_input_traffic) + ':' + str(total_output_traffic) print valor rrdtool.update('net3.rrd', valor) rrdtool.dump('net3.rrd', 'net3.xml') time.sleep(1) if ret: print rrdtool.error() time.sleep(300)
rendimiento.setResponseDNS(dnsServer("10.100.77.61",53,"examen.tanibabys.xyz",20)) rendimiento.setStatusDNS("Ready") #--------FTP rendimiento.setStatusFTP("Ready") aux2=ftp_client("localhost", "usuario1", "usuario1") aux2=aux2.split("||") rendimiento.setTimeResponseFTP(aux2[0]) rendimiento.setResponseFTP(aux2[1]) #------- HTTP banda = consultaSNMP(com, ip ,int(pto) ,'1.3.6.1.2.1.2.2.1.5.1') rendimiento.setResponseHTTP(check_webserver("10.100.73.153", 80, "/index.html")) rendimiento.setBytesReceiveHTTP(aux[1]) rendimiento.setSpeedDownload(banda) rendimiento.setStatusHTTP("Ready") rendimiento.setPathImageRAM("rrd/RAM.png") rendimiento.setPathImageHDD("rrd/HDD.png") rendimiento.setPathImageCPU("rrd/CPU.png") createPdf(rendimiento)
def EjecutarLb(monitor, comunidad, ip, port, name, times): agentPath = lbPath + name + "/" # 1 RAM de interfaz availableRam = int( consultaSNMP(comunidad, ip, port, '1.3.6.1.4.1.2021.4.6.0')) value = "N:" + str(availableRam) rrdtool.update(str(agentPath + name) + 'RAM.rrd', value) # 1 Grafica RAM de interfaz finalTime = int(rrdtool.last(str(agentPath + name) + "RAM.rrd")) initialTime = finalTime - 1800 ret = rrdtool.graphv( str(agentPath + name) + "RAM.png", "--start", str(initialTime), "--vertical-label=Carga RAM", "--title=USO DE RAM - LINEA DE BASE", "--color", "ARROW#009900", '--vertical-label', "Uso de RAM (%)", '--lower-limit', '0', '--upper-limit', '800000000', "DEF:carga=" + str(agentPath + name) + "RAM.rrd:RAMload:AVERAGE", # ---LINEA DE BASE "HRULE:" + str(monitor.ramRsg[0]) + "#000000:Umbral 1", "HRULE:" + str(monitor.ramRsg[1]) + "#00BB00:Umbral 2", "HRULE:" + str(monitor.ramRsg[2]) + "#BB0000:Umbral 3", # ---GRAFICAR AREA RAM "AREA:carga#00FF00:RAM Storage", # ---ENTRADA DE RAM "VDEF:RAMlast=carga,LAST", "VDEF:RAMmin=carga,MINIMUM", "VDEF:RAMavg=carga,AVERAGE", "VDEF:RAMmax=carga,MAXIMUM", "COMMENT: Last Now Min Avg Max//n", "GPRINT:RAMlast:%12.0lf%s", "GPRINT:RAMmin:%10.0lf%s", "GPRINT:RAMavg:%13.0lf%s", "GPRINT:RAMmax:%13.0lf%s") #print("Ram: " + str(availableRam)) if availableRam <= monitor.ramRsg[2]: if not monitor.ramOverflow: monitor.ramOverflow = True #print("Umbral 3 superado") sendAlertEmail( 'Umbral de RAM superado: ' + name + ' ' + str(availableRam) + '/' + str(monitor.ramRsg[2]), str(agentPath + name) + 'RAM.png', str(agentPath + name) + 'RAM.rrd') else: if monitor.ramOverflow: monitor.ramOverflow = False #----------------------------------------------------------------------------------------- # 2 CPU de interfaz cores = walkSNMP(comunidad, ip, port, '1.3.6.1.2.1.25.3.3.1.2') for coreOid, coreLoad in cores: coreId = coreOid[(coreOid.rfind('.') + 1):] coreLoad = int(coreLoad) value = "N:" + str(coreLoad) rrdtool.update(str(agentPath + name + coreId) + 'CPU.rrd', value) # 2 Grafica CPU por nucleo de interfaz finalTime = int( rrdtool.last(str(agentPath + name + coreId) + "CPU.rrd")) initialTime = finalTime - 1800 ret = rrdtool.graphv( str(agentPath + name + coreId) + "CPU.png", "--start", str(initialTime), "--vertical-label=Carga CPU", "--title=USO DE CPU - LINEA DE BASE", "--color", "ARROW#009900", '--vertical-label', "Uso de CPU (%)", '--lower-limit', '0', '--upper-limit', '100', "DEF:carga=" + str(agentPath + name + coreId) + "CPU.rrd:CPUload:AVERAGE", # ---LINEA DE BASE "HRULE:" + str(monitor.cpuRsg[0]) + "#000000:Umbral 1", "HRULE:" + str(monitor.cpuRsg[1]) + "#00BB00:Umbral 2", "HRULE:" + str(monitor.cpuRsg[2]) + "#BB0000:Umbral 3", # ---GRAFICAR AREA CPU "AREA:carga#00FF00:CPU load", # ---ENTRADA DE CPU "VDEF:CPUlast=carga,LAST", "VDEF:CPUmin=carga,MINIMUM", "VDEF:CPUavg=carga,AVERAGE", "VDEF:CPUmax=carga,MAXIMUM", "COMMENT: Last Now Min Avg Max//n", "GPRINT:CPUlast:%12.0lf%s", "GPRINT:CPUmin:%10.0lf%s", "GPRINT:CPUavg:%13.0lf%s", "GPRINT:CPUmax:%13.0lf%s") #print("CoreLoad " + coreId + ": " + str(coreLoad)) if coreLoad >= monitor.cpuRsg[2]: if not coreId in monitor.cpuOverflow: monitor.cpuOverflow.append(coreId) #print("Umbral 3 superado") sendAlertEmail( 'Umbral de CPU (' + coreId + ') superado: ' + name + ' ' + str(coreLoad) + '/' + str(monitor.cpuRsg[2]), str(agentPath + name + coreId) + 'CPU.png', str(agentPath + name + coreId) + 'CPU.rrd') else: if coreId in monitor.cpuOverflow: monitor.cpuOverflow.remove(coreId) #----------------------------------------------------------------------------------------- # 3 HDD de interfaz hddLoad = int(consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.25.2.3.1.6.1')) value = "N:" + str(hddLoad) rrdtool.update(str(agentPath + name) + 'HDD.rrd', value) # 3 Grafica HDD de interfaz finalTime = int(rrdtool.last(str(agentPath + name) + "HDD.rrd")) initialTime = finalTime - 1800 ret = rrdtool.graphv( str(agentPath + name) + "HDD.png", "--start", str(initialTime), "--vertical-label=Carga HDD", "--title=USO DE HDD - LINEA DE BASE", "--color", "ARROW#009900", '--vertical-label', "Uso de HDD (%)", '--lower-limit', '0', '--upper-limit', '10000000', "DEF:carga=" + str(agentPath + name) + "HDD.rrd:HDDload:AVERAGE", # ---LINEA DE BASE "HRULE:" + str(monitor.hddRsg[0]) + "#000000:Umbral 1", "HRULE:" + str(monitor.hddRsg[1]) + "#00BB00:Umbral 2", "HRULE:" + str(monitor.hddRsg[2]) + "#BB0000:Umbral 3", # ---GRAFICAR AREA HDD "AREA:carga#00FF00:HDD load", # ---ENTRADA DE HDD "VDEF:HDDlast=carga,LAST", "VDEF:HDDmin=carga,MINIMUM", "VDEF:HDDavg=carga,AVERAGE", "VDEF:HDDmax=carga,MAXIMUM", "COMMENT: Last Now Min Avg Max//n", "GPRINT:HDDlast:%12.0lf%s", "GPRINT:HDDmin:%10.0lf%s", "GPRINT:HDDavg:%13.0lf%s", "GPRINT:HDDmax:%13.0lf%s") #print("HDD: " + str(hddLoad)) if hddLoad >= monitor.hddRsg[2]: if not monitor.hddOverflow: monitor.hddOverflow = True #print("Umbral 3 superado") sendAlertEmail( 'Umbral de HDD superado: ' + name + ' ' + str(hddLoad) + '/' + str(monitor.hddRsg[2]), str(agentPath + name) + 'HDD.png', str(agentPath + name) + 'HDD.rrd') else: if monitor.hddOverflow: monitor.hddOverflow = False
def llenaBaseRRD(nombre, direccionIP, comunidad): comunidad = comunidad.strip( ) #Se quitan los caracteres de op. de linea como \n \t \r de la cadena dirSinPuntos = direccionIP.replace(".", "_") directorio = os.getcwd() + "/" + dirSinPuntos i = 0 while (1): i = i + 1 total_input_trafficICMP = int( consultaSNMP(comunidad, direccionIP, INPUT_ICMP)) #Paquetes ICMP de entrada total_output_trafficICMP = int( #y de salida consultaSNMP(comunidad, direccionIP, OUTPUT_ICMP)) total_input_trafficUDP = int( consultaSNMP( comunidad, direccionIP, '1.3.6.1.2.1.7.1.0')) #Paquetes UDP de entrada y salida total_output_trafficUDP = int( consultaSNMP(comunidad, direccionIP, '1.3.6.1.2.1.7.4.0')) total_input_trafficTCP = int( consultaSNMP( comunidad, direccionIP, '1.3.6.1.2.1.6.10.0')) #Paquetes TCP de entrada y salida total_output_trafficTCP = int( consultaSNMP(comunidad, direccionIP, '1.3.6.1.2.1.6.11.0')) total_input_trafficPING = int( consultaSNMP( comunidad, direccionIP, '1.3.6.1.2.1.5.9.0')) #Ecos ICMP (PINGs) de entrada y salida total_output_trafficPING = int( consultaSNMP(comunidad, direccionIP, '1.3.6.1.2.1.5.22.0')) total_output_trafficTCP_Cons = int( consultaSNMP(comunidad, direccionIP, '1.3.6.1.2.1.6.9.0')) #Conexiones TCP establecidas valor = "N:" + str(total_input_trafficICMP) + ':' + str(total_output_trafficICMP) + ':' \ + str(total_input_trafficUDP) + ':' + str(total_output_trafficUDP) + ':' \ + str(total_input_trafficTCP) + ':' + str(total_output_trafficTCP) + ':' \ + str(total_input_trafficPING) + ':' + str(total_output_trafficPING) + ':' + str(total_output_trafficTCP_Cons) ret = rrdtool.update( directorio + "/agente.rrd", valor) #Se actualiza la BD en los valores adquiridos via SNMP rrdtool.dump( directorio + "/agente.rrd", directorio + "/agente.xml") #Se pondran los datos de la BD en tales archivos time.sleep(2) # Llenado de la base de recursos if os.path.exists(directorio + "/recursos.rrd"): # Tiene la base de recursos # Se obtienen los identificadores que estan en el archivo de procesadores proc_arch = open(directorio + "/procesadores.txt", "r") identificadores = proc_arch.readlines() # Se agrega la informacion del agente referente a recursos adicionInfoProcesadoresAgente(directorio, identificadores, comunidad, direccionIP) # Llenado de la base de storages if os.path.exists(directorio + "/memoria.rrd"): # Tiene la base de recursos # Se obtienen los identificadores que estan en el archivo de procesadores proc_arch = open(directorio + "/storages.txt", "r") lineas = proc_arch.readlines() #print "Lineas leidas: "+str(lineas) arregloDeIndices = [] for ln in lineas: arregloDeIndices.append(ln.split("<<-->>")[0]) # Se agrega la informacion del agente referente a recursos adicionInfoStorageAgente(directorio, arregloDeIndices, comunidad, direccionIP) if ret: print rrdtool.error() time.sleep(300)
import time import rrdtool from getSNMP import consultaSNMP total_input_traffic = 0 total_output_traffic = 0 while 1: total_input_traffic = int( consultaSNMP('ComunidadASR','localhost', '1.3.6.1.2.1.2.2.1.10.2')) total_output_traffic = int( consultaSNMP('ComunidadASR','localhost', '1.3.6.1.2.1.2.2.1.16.2')) valor = "N:" + str(total_input_traffic) + ':' + str(total_output_traffic) print(valor) rrdtool.update('trafico1.rrd', valor) rrdtool.dump('trafico1.rrd','trafico1.xml') time.sleep(1) if ret: print(rrdtool.error()) time.sleep(300)
init_time = rrdtool.last(BASE_RRD) #para ventana: --start init_time_100 tiempo_actual = int(time.time()) #sin ventana --start tiempo_actual timeOfLastSentMail = int(time.time() - (60 * VENTANA_CORREO)) #MUST BE this value for my condicional OID = '1.3.6.1.2.1.2.2.1.10.2' COMUNIDAD = 'variation/virtualtable' HOST = '10.100.71.200' falla_actual = 0 falla_anterior = 0 bandera_falla_iniciada = 0 # 3.6.1.2.1.2.2.1.10.10 while 1: total_input_traffic = int(consultaSNMP(COMUNIDAD, HOST, OID)) valor = "N:" + str(total_input_traffic) print valor ret = rrdtool.update(BASE_RRD, valor) rrdtool.dump(BASE_RRD, 'netP.xml') ret = rrdtool.graph( NOMBRE_PNG, "--start", str(tiempo_actual), "--end", str(rrdtool.last( BASE_RRD)), #"--end", str(rrdtool.last('netPred.rrd') + 300), "--vertical-label=Bytes/s", "--width=1000",
import time import rrdtool from getSNMP import consultaSNMP #from Notify import check_aberration total_input_traffic = 0 total_output_traffic = 0 rrdpath="/home/alina/Documentos/Redes3/Parcial2/Trend-Non-Linear(actualizado)/Trend-Non-Linear/" pngpath="/home/alina/Documentos/Redes3/Parcial2/Trend-Non-Linear(actualizado)/Trend-Non-Linear/" fname="/RRD/netP.rrd" pngfname="predict.png" title="Deteccion de comportamiento anomalo" # Generate charts for last 24 hours endDate = rrdtool.last(fname) #ultimo valor del XML begDate = endDate - 86000 while 1: total_input_traffic = int(consultaSNMP('ComunidadASR','localhost','1.3.6.1.2.1.2.2.1.10.1')) total_output_traffic = int(consultaSNMP('ComunidadASR','localhost','1.3.6.1.2.1.2.2.1.16.1')) valor = str(rrdtool.last(fname)+100)+":" + str(total_input_traffic) + ':' + str(total_output_traffic) print valor #ret = rrdtool.update(fname, valor) rrdtool.dump(fname,'Prueba.xml') time.sleep(1) #print check_aberration(rrdpath,fname) if ret: print rrdtool.error() time.sleep(300)
def getOS(agente): return consultaSNMP(agente.getComunity(), agente.getHost(), oidsarr['os'], agente.getPort())
def actualizarRRD (archivo, comunidad, host, oid): total_input_traffic = int(consultaSNMP(comunidad,host,oid)) valor = "N:" + str(total_input_traffic) print (valor) rrdtool.update("rrd/"+archivo+".rrd", valor) rrdtool.dump("rrd/"+archivo+".rrd","xml/"+archivo+".xml")
def getInterfacesNumber(agente): return consultaSNMP(agente.getComunity(), agente.getHost(), oidsarr['interfacesNumber'], agente.getPort())
def Ejecutar(comunidad, ip, port, name, times): #1 Trafico de interfaz total_input_traffic = int( consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.2.2.1.10.1')) total_output_traffic = int( consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.2.2.1.16.1')) valor = "N:" + str(total_input_traffic) + ':' + str(total_output_traffic) rrdtool.update(str(name) + 'Trafico.rrd', valor) #rrdtool.dump( name + 'Trafico.rrd' , name + 'Trafico.xml' ) #1 Grafica Trafico de interfaz ret = rrdtool.graph( str(name) + "GraficoTrafico.png", "--start", str(times), # "--end","N", "--vertical-label=Bytes/s", "DEF:inoctets=" + str(name) + "Trafico.rrd:InTraffic:AVERAGE", "DEF:outoctets=" + str(name) + "Trafico.rrd:OutTraffic:AVERAGE", "AREA:inoctets#00FF00:In traffic", "LINE1:outoctets#0000FF:Out traffic\r") #2 Estadisticas IP total_input_ipv4 = int( consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.4.3.0')) total_output_ipv4 = int( consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.4.10.0')) valor = "N:" + str(total_input_ipv4) + ':' + str(total_output_ipv4) rrdtool.update(str(name) + 'Estadisticaip.rrd', valor) #rrdtool.dump( name + 'Estadisticaip.rrd' , name + 'Estadisticaip.xml' ) #2 Grafica Estadisticas IP ret = rrdtool.graph( str(name) + "GraficoEstadisticaip.png", "--start", str(times), # "--end","N", "--vertical-label=Bytes/s", "DEF:inoctets=" + str(name) + "Estadisticaip.rrd:InEstadisticaIP:AVERAGE", "DEF:outoctets=" + str(name) + "Estadisticaip.rrd:OutEstadisticaIP:AVERAGE", "AREA:inoctets#00FF00:In Estadistica IP", "LINE1:outoctets#0000FF:Out Estadistica IP\r") #3 Estadisticas ICMP total_input_icmp = int( consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.5.1.0')) total_output_icmp = int( consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.5.14.0')) valor = "N:" + str(total_input_icmp) + ':' + str(total_output_icmp) rrdtool.update(str(name) + 'Estadisticaicmp.rrd', valor) #rrdtool.dump( name + 'Estadisticaicmp.rrd' , name + 'Estadisticaicmp.xml' ) #3 Grafica Estadisticas ICMP ret = rrdtool.graph( str(name) + "GraficoEstadisticaicmp.png", "--start", str(times), # "--end","N", "--vertical-label=Bytes/s", "DEF:inoctets=" + str(name) + "Estadisticaicmp.rrd:InEstadisticaICMP:AVERAGE", "DEF:outoctets=" + str(name) + "Estadisticaicmp.rrd:OutEstadisticaICMP:AVERAGE", "AREA:inoctets#00FF00:In Estadistica ICMP", "LINE1:outoctets#0000FF:Out Estadistica ICMP\r") #4 Estadisticas SNMP total_input_snmp = int( consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.5.1.0')) total_output_snmp = int( consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.5.14.0')) valor = "N:" + str(total_input_snmp) + ':' + str(total_output_snmp) rrdtool.update(str(name) + 'Estadisticasnmp.rrd', valor) #rrdtool.dump( name + 'Estadisticasnmp.rrd' , name + 'Estadisticasnmp.xml' ) #4 Grafica Estadisticas SNMP ret = rrdtool.graph( str(name) + "GraficoEstadisticasnmp.png", "--start", str(times), # "--end","N", "--vertical-label=Bytes/s", "DEF:inoctets=" + str(name) + "Estadisticasnmp.rrd:InEstadisticaSNMP:AVERAGE", "DEF:outoctets=" + str(name) + "Estadisticasnmp.rrd:OutEstadisticaSNMP:AVERAGE", "AREA:inoctets#00FF00:In Estadistica SNMP", "LINE1:outoctets#0000FF:Out Estadistica SNMP\r") #5 Estadisticas TCP total_input_tpc = int( consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.6.10.0')) total_output_tpc = int( consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.6.11.0')) valor = "N:" + str(total_input_tpc) + ':' + str(total_output_tpc) rrdtool.update(str(name) + 'Estadisticastpc.rrd', valor) #rrdtool.dump( name + 'Estadisticastpc.rrd' , name + 'Estadisticastpc.xml' ) #5 Grafica Estadisticas TCP ret = rrdtool.graph( str(name) + "GraficoEstadisticatcp.png", "--start", str(times), # "--end","N", "--vertical-label=Bytes/s", "DEF:inoctets=" + str(name) + "Estadisticastpc.rrd:InEstadisticaTCP:AVERAGE", "DEF:outoctets=" + str(name) + "Estadisticastpc.rrd:OutEstadisticaTCP:AVERAGE", "AREA:inoctets#00FF00:In Estadistica TCP", "LINE1:outoctets#0000FF:Out Estadistica TCP\r") time.sleep(10)
import time import rrdtool from getSNMP import consultaSNMP ifInNUcastPkts = 0 while 1: ifInNUcastPkts = int( consultaSNMP('variation/virtualtable', '10.100.71.230', '1.3.6.1.2.1.2.2.1.12.1')) valor = "N:" + str(ifInNUcastPkts) print(valor) rrdtool.update('examen.rrd', valor) rrdtool.dump('examen.rrd', 'examen.xml') time.sleep(1) if ret: print(rrdtool.error()) time.sleep(300)
import time import rrdtool from getSNMP import consultaSNMP total_input_traffic = 0 total_output_traffic = 0 while 1: total_input_traffic = int( consultaSNMP('ComunidadASR', 'localhost', '1.3.6.1.2.1.25.3.3.1.2.196608')) #Procesador valor = "N:" + str(total_input_traffic) print valor rrdtool.update('netPr.rrd', valor) rrdtool.dump('netPr.rrd', 'netPr.xml') time.sleep(1) if ret: print rrdtool.error() time.sleep(300)
def predicInOctets(): print("Inicia prediccion no lineal...") rrdtool.dump(f, 'predHistoric.xml') #sys.exit(0) while 1: endDate = rrdtool.last(f) #ultimo valor del XML begDate = endDate - 50000 InicioAyer = begDate - 86400 FinAyer = endDate - 86400 total_input_traffic = int( consultaSNMP('gr_4cm3', 'localhost', '1.3.6.1.2.1.2.2.1.10.1')) total_output_traffic = int( consultaSNMP('gr_4cm3', 'localhost', '1.3.6.1.2.1.2.2.1.16.1')) info = rrdtool.info(f) # RETURNS A DICTIONARY #print(info) #print("info['last_update']", info['last_update']) <--- LAST UPDATE VALUE #valor = str(info['last_update'] + 1) + ":" + str(total_input_traffic) + ":" + str(total_output_traffic) """ CAMBIAR EL VALOR DE 180 PARA UN DESPLAZAMIENTO MAS RÁPIDO DE LA GRAFICA O QUITAR EL VALOR PARA QUE VAYA CONFORME AL STEP """ valor = str(rrdtool.last(f) + 180) + ":" + str( total_input_traffic) + ":" + str(total_output_traffic) #valor = "N" + ":" + str(total_input_traffic) + ":" + str(total_output_traffic) print("In Traffic:", valor, " bytes/s") ret = rrdtool.update(f, valor) #rrdtool.dump(f,'RRD/predHistoric.xml') time.sleep(0.5) print(check_aberration(rrdpath, rrdname)) # Changes alpha/beta/gamma value, useful under specific situations. verify functionallity #rrdtool.tune(f, '--alpha', '0.1') ret = rrdtool.graph( png, '--start', str(begDate), '--end', str(endDate), '--title=' + title, "--vertical-label=Bytes/s", '--slope-mode', "DEF:obs=" + f + ":inoctets:AVERAGE", "DEF:obsAyer=" + f + ":inoctets:AVERAGE:start=" + str(InicioAyer) + ":end=" + str(FinAyer), "DEF:pred=" + f + ":inoctets:HWPREDICT", "DEF:dev=" + f + ":inoctets:DEVPREDICT", "DEF:fail=" + f + ":inoctets:FAILURES", "SHIFT:obsAyer:86400", #"RRA:DEVSEASONAL:1d:0.1:2", #"RRA:DEVPREDICT:5d:5", #"RRA:FAILURES:1d:7:9:5"" "CDEF:scaledobs=obs,8,*", "CDEF:scaledobsAyer=obsAyer,8,*", "CDEF:upper=pred,dev,2,*,+", "CDEF:lower=pred,dev,2,*,-", "CDEF:scaledupper=upper,8,*", "CDEF:scaledlower=lower,8,*", "CDEF:scaledpred=pred,8,*", "VDEF:FALLA1=fail,FIRST", "VDEF:FALLA2=fail,LAST", "TICK:fail#FDD017:1.0: Fallas", "AREA:scaledobsAyer#9C9C9C:Ayer", "LINE3:scaledobs#00FF00:In traffic", "LINE1:scaledpred#FF00FF:Prediccion", #"LINE1:outoctets#0000FF:Out traffic", "LINE1:scaledupper#ff0000:Upper Bound Average bits in", "LINE1:scaledlower#0000FF:Lower Bound Average bits in")