def generarGraficas(interfaz, comunidad, host): while 1: total_input_traffic = int( parseResultAfterEquals( snmpGet(comunidad, host, OID_INPUT_TRAFFIC + str(interfaz)))) total_output_traffic = int( parseResultAfterEquals( snmpGet(comunidad, host, OID_OUTPUT_TRAFFIC + str(interfaz)))) # total_input_pkts = int(parseResultAfterEquals( # snmpGet(comunidad, host, # OID_INPUT_PKTS + str(interfaz)))) # total_output_pkts = int(parseResultAfterEquals( # snmpGet(comunidad, host, # OID_OUTPUT_PKTS + str(interfaz)))) valor = "N:" + str(total_input_traffic) + ':' + str( total_output_traffic) print valor rrdtool.update('practica1.rrd', valor) rrdtool.dump('practica1.rrd', 'practica1.xml') time.sleep(1) if ret: print rrdtool.error() time.sleep(300)
def animate(i, comunidad, ip): if (i > 0): total_input_traffic = int( consultaSNMP(comunidad, ip, '1.3.6.1.2.1.2.2.1.10.3')) total_output_traffic = int( consultaSNMP(comunidad, ip, '1.3.6.1.2.1.2.2.1.16.3')) interfaces_ethernet = int( consultaSNMP(comunidad, ip, '1.3.6.1.2.1.2.1.0')) diagramas_udp = int( consultaSNMP(comunidad, ip, '1.3.6.1.2.1.7.1.0')) mensajes_tcp = int(consultaSNMP(comunidad, ip, '1.3.6.1.2.1.6.6.0')) 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) appendFile = open('example.txt', 'a') val = str(i) + "," + str(total_output_traffic) + "," + str( total_input_traffic) + "," + str( interfaces_ethernet) + "," + str( diagramas_udp) + "," + str(mensajes_tcp) + "\n" print(val) appendFile.write(val) appendFile.close() graph_data = open('example.txt', 'r').read() lines = graph_data.split('\n') xs = [] ys = [] zs = [] ws = [] vs = [] us = [] for line in lines: if len(line) > 1: x, y, z, w, v, u = line.split(',') xs.append(x) ys.append(y) zs.append(z) ws.append(w) vs.append(v) us.append(u) ax1.clear() ax2.clear() ax3.clear() ax4.clear() ax5.clear() ax1.plot(xs[-10:], ys[-10:]) ax2.plot(xs[-10:], zs[-10:]) ax3.plot(xs[-10:], ws[-10:]) ax4.plot(xs[-10:], vs[-10:]) ax5.plot(xs[-10:], us[-10:]) ax1.set_title('Trafico entrada') ax2.set_title('Trafico salida') ax3.set_title('Interfaces ethernet') ax4.set_title('Diagramas UDP') ax5.set_title('Mensajes TCP')
def crearRRDsHw(idAgente): # rows = "800" # seasonalPeriod = "15" # rra_num = "5" # ret = rrdtool.create("RRDsAgentes/prediccion"+ idAgente +".rrd", # '--start','N','--step','1', # "DS:inoctets:GAUGE:600:U:U", # "RRA:AVERAGE:0.5:1:60", # "RRA:HWPREDICT:" + rows + ":0.9:0.0035:" + seasonalPeriod + ":3", # "RRA:SEASONAL:" + seasonalPeriod + ":0.1:2", # "RRA:DEVSEASONAL:" + seasonalPeriod + ":0.3:2", # "RRA:DEVPREDICT:" + rows + ":3", # "RRA:FAILURES:" + rows + ":3:5:3") rows = "800" seasonalPeriod = "5" rra_num = "5" ret = rrdtool.create( "RRDsAgentes/prediccion" + idAgente + ".rrd", '--start', 'N', '--step', '1', "DS:carga:GAUGE:600:U:U", "RRA:AVERAGE:0.5:1:60", "RRA:HWPREDICT:" + rows + ":0.9:0.0035:" + seasonalPeriod + ":3", "RRA:SEASONAL:" + seasonalPeriod + ":0.1:2", "RRA:DEVSEASONAL:" + seasonalPeriod + ":0.3:2", "RRA:DEVPREDICT:" + rows + ":3", "RRA:FAILURES:" + rows + ":3:5:3") rrdtool.dump('RRDsAgentes/prediccion' + idAgente + '.rrd', 'RRDsAgentes/prediccion' + idAgente + '.xml') if ret: print(rrdtool.error())
def adicionInfoStorageAgente(directorio, indices, comunidad, ipAddr): valores = "N:" # Parte de informacion de procesadores for ide in indices: ide = ide.replace('\n', '') usado = int( consultaSNMP(comunidad, ipAddr, OID_USED_STORAGE_TABLE + "." + ide)) total = int( consultaSNMP(comunidad, ipAddr, OID_TOTAL_STORAGE_TABLE + "." + ide)) if (total == 0): total = 0.001 if (usado == 0): usado = 0.001 percent = int((float(usado) / float(total)) * 100) valores += str(percent) + ":" valores = valores[:-1] rrdtool.update(directorio + '/memoria.rrd', valores) rrdtool.dump(directorio + '/memoria.rrd', directorio + '/memoria.xml')
def iniciarGrafica1(host,version,puerto,comunidad,nombreBase): ret = rrdtool.create(nombreBase+'.rrd', "--start", 'N', # N de now. "--step", '1', "DS:inoctets:COUNTER:600:U:U", # DS: "String" nombre de la variable "RRA:AVERAGE:0.5:1:600") contadorDeGraficación = 3 tiempoInicial = int(time.time()) while 1: if (contadorDeGraficación < 1): ret = rrdtool.graph(nombreBase + ".png", "--start", str(tiempoInicial), # Abrir XML y checar un valor válido y existente # "--end", "N", "--vertical-label=Octects/s", "DEF:inoctets=" + nombreBase + ".rrd:inoctets:AVERAGE", "AREA:inoctets#00FF00:IfInOctects" ) contadorDeGraficación = 3 tiempoInicial = int(time.time()) else: total_input_traffic = int(consultaSNMP(comunidad, host, puerto, version, oid))# el 3 es de grupo de interfaz y checar si funciona la inalambrica en la interfaz 3 #total_output_traffic = int(consultaSNMP(comunidad, hostname, puerto, version, oid)) valor = "N:" + str(total_input_traffic) print(valor) rrdtool.update(nombreBase + ".rrd", valor) rrdtool.dump(nombreBase + '.rrd', nombreBase + '.xml') time.sleep(1) contadorDeGraficación -= 1 return
def export_to_xml(self, xml_name="output"): """Export RRD database to XML. More documentation @ http://oss.oetiker.ch/rrdtool/doc/rrddump.en.html """ # TODO: This should probably be implemented with rrdxport rrdtool.dump(self.database, "%s.xml" % xml_name)
def actualizarBase(nombrebase, comunidad, nombrehost): OIDparaRAM = "1.3.6.1.4.1.2021.4.6.0" #Consultar carga de un procesador carga_CPU = 0 print(OIDparaRAM) while 1: carga_CPU = int( consultaSNMP( comunidad, nombrehost, #COMUNIDAD , hostname OIDparaRAM) ) #Nodo de la MIB a consultar, el ID del procesador cambiará valor = "N:" + str(carga_CPU) print(valor) baseRRD = nombrebase + ".rrd" baseXML = nombrebase + ".xml" rrdtool.update(baseRRD, valor) rrdtool.dump(baseRRD, baseXML) time.sleep(1) if ret: print(rrdtool.error()) time.sleep(300)
def updateRRD(agent, oids): while 1: x = MongoAdmin.getHost(agent) if (x == None): break value = [] row = "N:" for mib in oids: if (mib.interface): resp = snmpGet(x["community"], x["hostaddr"], (mib.oid + "." + x["if"])) else: resp = snmpGet(x["community"], x["hostaddr"], mib.oid) if (resp == "No Such Object currently exists at this OID"): resp = "0" value.append(resp) row = row + ":".join(value) #print(row) rrdtool.update("rrd/" + x["rrdName"] + ".rrd", row) rrdtool.dump("rrd/" + x["rrdName"] + ".rrd", "xml/" + x["rrdName"] + ".xml") time.sleep(1)
def actualizarRRD(host, version, comunidad, puerto): while 1: cpu = int( consultaSNMP(comunidad, host, '1.3.6.1.2.1.25.3.3.1.2.196608')) ramTotal = float( consultaSNMP(comunidad, host, '1.3.6.1.4.1.2021.4.5.0')) ramLibre = float( consultaSNMP(comunidad, host, '1.3.6.1.4.1.2021.4.11.0')) porcentaje_ram = float(((ramTotal - ramLibre) * 100) / ramTotal) """ram = int( consultaSNMP(comunidad, host, '1.3.6.1.4.1.2021.4.5.0')) porcentaje_ram = ((8-ram)*100)/ram""" """ram = int( consultaSNMP(comunidad, host, '1.3.6.1.4.21.'+puerto)) porcentaje_ram = (ram*100)/float(16)""" hdd = float(consultaSNMP(comunidad, host, '1.3.6.1.2.1.25.2.3.1.6.1')) porcentaje_hdd = hdd / (1024 * 1024) valor = "N:" + str(cpu) + ":" + str(porcentaje_ram) + ":" + str( porcentaje_hdd) # print(valor) rrdtool.update(host + ".rrd", valor) rrdtool.dump(host + ".rrd", host + ".xml") sleep(1)
def backup(self, filename): # Write all data to disk first self.write_queue.commit() log.info(_("Backing up to %s..." % filename)) # Opening a compressed tar file with will have all files added to it with tarfile.open(filename, mode="w:gz") as archive: for path, directories, files in os.walk(DATABASE_DIR): for file in files: # Skip any non-RRD files if not file.endswith(".rrd"): continue # Compose the full file path file = os.path.join(path, file) log.debug(_("Adding %s to backup...") % file) with tempfile.NamedTemporaryFile() as t: rrdtool.dump(file, t.name) # Add the file to the archive archive.add( t.name, arcname=file[len(DATABASE_DIR):], ) log.info(_("Backup finished"))
def crearRRDsMonitoreo(idAgente, DS, RRA): ret = rrdtool.create("RRDsAgentes/monitoreo" + idAgente + ".rrd", "--start", 'N', "--step", '3', DS, RRA) rrdtool.dump('RRDsAgentes/monitoreo' + idAgente + '.rrd', 'RRDsAgentes/monitoreo' + idAgente + '.xml') if ret: print(rrdtool.error())
def crearRRDsMonitoreo(DS, RRA): print("Creando rrds") ret = rrdtool.create("RRDsAgentes/monitoreo.rrd", "--start", 'N', "--step", '3', DS, RRA) rrdtool.dump('RRDsAgentes/monitoreo.rrd', 'RRDsAgentes/monitoreo.xml') if ret: print(rrdtool.error())
def actualizarDatos(): total_input_traffic = 0 total_output_traffic = 0 total_input_SegTCP = 0 total_output_SegTCP = 0 total_input_DatUDP = 0 total_output_DatUDP = 0 total_input_PaqSNMP = 0 total_output_PaqSNMP = 0 total_input_ICP = 0 total_output_ICP = 0 session = Session(hostname='localhost', community='MacCommunity', version=2) while 1: total_input_traffic = int(obtenerValor(monitoreosSNMP[0][1])) total_output_traffic = int(obtenerValor(monitoreosSNMP[0][2])) total_input_SegTCP = int(obtenerValor(monitoreosSNMP[1][1])) total_output_SegTCP = int(obtenerValor(monitoreosSNMP[1][2])) total_input_DatUDP = int(obtenerValor(monitoreosSNMP[2][1])) total_output_DatUDP = int(obtenerValor(monitoreosSNMP[2][2])) total_input_PaqSNMP = int(obtenerValor(monitoreosSNMP[3][1])) total_output_PaqSNMP = int(obtenerValor(monitoreosSNMP[3][2])) total_input_ICP = int(obtenerValor(monitoreosSNMP[4][1])) total_output_ICP = int(obtenerValor(monitoreosSNMP[4][2])) valor1 = "N:" + str(total_input_traffic) + ':' + str( total_output_traffic) valor2 = "N:" + str(total_input_SegTCP) + ':' + str( total_output_SegTCP) valor3 = "N:" + str(total_input_DatUDP) + ':' + str( total_output_DatUDP) valor4 = "N:" + str(total_input_PaqSNMP) + ':' + str( total_output_PaqSNMP) valor5 = "N:" + str(total_input_ICP) + ':' + str(total_output_ICP) rrdtool.update('g1.rrd', valor1) rrdtool.dump('g1.rrd', 'g1.xml') rrdtool.update('g2.rrd', valor2) rrdtool.dump('g2.rrd', 'g2.xml') rrdtool.update('g3.rrd', valor3) rrdtool.dump('g3.rrd', 'g3.xml') rrdtool.update('g4.rrd', valor4) rrdtool.dump('g4.rrd', 'g4.xml') rrdtool.update('g5.rrd', valor5) rrdtool.dump('g5.rrd', 'g5.xml') time.sleep(1) if ret: print(rrdtool.error()) time.sleep(300)
def actualizarGrafica(archivo, predecidosx, predecidosy): i = 0 for predecido in predecidosy: valor = str(predecidosx[i] + 60) + ':' + str(predecido) #print(valor) rrdtool.update(archivo, valor) i += 1 rrdtool.dump(archivo, 'trend.xml')
def usoRAM(comunidad,IP,FILErrd,FILExml): ram = int( consultaSNMP(comunidad,IP, '1.3.6.1.2.1.25.2.3.1.6.1')) valor = "N:" + str(ram) #print (valor) rrdtool.update(str(FILErrd), valor) rrdtool.dump(str(FILErrd),str(FILExml))
def usocpu(comunidad,IP,FILErrd,FILExml): carga_CPU = int( consultaSNMP(comunidad,IP, '1.3.6.1.2.1.25.3.3.1.2.196608')) valor = "N:" + str(carga_CPU) #print (valor) rrdtool.update(str(FILErrd), valor) rrdtool.dump(str(FILErrd),str(FILExml))
def actualizarNoLineal(archivo,comunidad, host): total_input_traffic = int(consultaSNMP(comunidad,host,'1.3.6.1.2.1.2.2.1.10.1')) total_output_traffic = int(consultaSNMP(comunidad,host,'1.3.6.1.2.1.2.2.1.16.1')) valor = "N:" + str(total_input_traffic) + ':' + str(total_output_traffic) print (valor) ret = rrdtool.update("rrd/"+archivo+".rrd", valor) rrdtool.dump("rrd/"+archivo+".rrd","xml/"+archivo+".xml") time.sleep(1) print (check_aberration(rrdpath,rrdname))
def getICMP(comunidad, IP, FILErrd, FILExml): total_input_traffic = int(consultaSNMP(comunidad, IP, '1.3.6.1.2.1.5.1.0')) total_output_traffic = int( consultaSNMP(comunidad, IP, '1.3.6.1.2.1.5.14.0')) valor = "N:" + str(total_input_traffic) + ':' + str(total_output_traffic) rrdtool.update(FILErrd, valor) rrdtool.dump(FILErrd, FILExml) return
def UpdateBase(self, tipo, nombre): if tipo == 0: aux = "DS:" + nombre + ":GAUGE:60:U:U" print(aux) ret = rrdtool.tune("Prac1.rrd", aux) if tipo == 1: ret = rrdtool.tune("Prac1.rrd", "DEL:" + nombre) rrdtool.dump(self.nombre + ".rrd", self.nombre + ".xml") if ret: print(rrdtool.error())
def updateRRD(archivo, comunidad, host, oid, puerto): con = 0 while con < 5: input_data_snmp = int(consultaSNMP(comunidad,puerto,host,oid)) if oid == C.RAM_OID: input_data_snmp = int(consultaSNMP(comunidad, puerto, host, C.TOTAL_RAM_OID)) - input_data_snmp valor = "N:" + str(input_data_snmp) rrdtool.update("files/"+archivo+".rrd", valor) rrdtool.dump("files/"+archivo+".rrd","files/"+archivo+".xml") con += 1 return 900
def lineaBase1(comunidad,IP,FILErrd,FILExml): total_input_traffic = 0 total_output_traffic = 0 total_input_traffic = int( consultaSNMP(comunidad,IP, '1.3.6.1.2.1.25.3.3.1.2.196608')) #Procesador valor = "N:" + str(total_input_traffic) #print(valor) rrdtool.update(str(FILErrd), valor) rrdtool.dump(str(FILErrd),str(FILExml))
def actualizarObjectsRRD(archivo, comunidad, host, oid): #oid="1.3.6.1.4.1.2021.4.6.0" total_input_traffic = int(consultaSNMP(comunidad, host, oid)) #oid="1.3.6.1.2.1.25.3.3.1.2.1026" total_output_traffic = int(consultaSNMP(comunidad, host, oid)) valor = "N:" + str(total_input_traffic) + ':' + str(total_output_traffic) #print (valor) rrdtool.update("rrd/" + archivo + ".rrd", valor) rrdtool.dump("rrd/" + archivo + ".rrd", "xml/" + archivo + ".xml")
def crearRRD(host): ret = rrdtool.create(host+".rrd", "--start", 'N', "--step", '60', "DS:CPU:GAUGE:600:U:U", "DS:RAM:GAUGE:600:U:U", "DS:HDD:GAUGE:600:U:U", "RRA:AVERAGE:0.5:1:24") rrdtool.dump(host+".rrd", host+".xml") if ret: print(rrdtool.error())
def snmpOIDS(self): total_input_traffic = 0 oid_input_traffic = '1.3.6.1.2.1.2.2.1.10.3' total_output_traffic = 0 oid_output_traffic = '1.3.6.1.2.1.2.2.1.16.3' total_ipInRequest = 0 oid_ipInRequest = '1.3.6.1.2.1.4.3.0' total_ipOutRequest = 0 oid_ipOutRequest = '1.3.6.1.2.1.4.10.0' total_snmpInPkts = 0 oid_snmpInPkts = '1.3.6.1.2.1.11.1.0' total_snmpOutPkts = 0 oid_snmpOutPkts = '1.3.6.1.2.1.11.2.0' total_snmpInGetResponse = 0 oid_snmpInGetResponse = '1.3.6.1.2.1.7.1.0' total_snmpOutGetResponse = 0 oid_snmpOutGetResponse = '1.3.6.1.2.1.7.4.0' total_udpErrors = 0 oid_udpErrors = '1.3.6.1.2.1.7.3.0' total_input_traffic = int( consultaSNMP(self.comunidad, self.ip, oid_input_traffic)) total_output_traffic = int( consultaSNMP(self.comunidad, self.ip, oid_output_traffic)) total_ipInRequest = int( consultaSNMP(self.comunidad, self.ip, oid_ipInRequest)) total_ipOutRequest = int( consultaSNMP(self.comunidad, self.ip, oid_ipOutRequest)) total_snmpInPkts = int( consultaSNMP(self.comunidad, self.ip, oid_snmpInPkts)) total_snmpOutPkts = int( consultaSNMP(self.comunidad, self.ip, oid_snmpOutPkts)) total_snmpInGetResponse = int( consultaSNMP(self.comunidad, self.ip, oid_snmpInGetResponse)) total_snmpOutGetResponse = int( consultaSNMP(self.comunidad, self.ip, oid_snmpOutGetResponse)) total_udpErrors = int( consultaSNMP(self.comunidad, self.ip, oid_udpErrors)) valor = "N:{0}:{1}:{2}:{3}:{4}:{5}:{6}:{7}:{8}".format( str(total_input_traffic), str(total_output_traffic), str(total_ipInRequest), str(total_ipOutRequest), str(total_snmpInPkts), str(total_snmpOutPkts), str(total_snmpInGetResponse), str(total_snmpOutGetResponse), str(total_udpErrors)) print(self.ip + ' ? ' + valor) rrdtool.update(self.ip + '.rrd', valor) rrdtool.dump(self.ip + '.rrd', self.ip + '.xml')
def analizarExamen(comunidad, host, oid): while 1: total_input_traffic = int(consultaSNMP(comunidad, host, oid)) valor = "N:" + str(total_input_traffic) print(valor) rrdtool.update('examen.rrd', valor) rrdtool.dump('examen.rrd', 'examen.xml') time.sleep(1) if ret: print(rrdtool.error()) time.sleep(300)
def crearRRDs(idAgente): ret = rrdtool.create( "RRDsAgentes/agente" + idAgente + ".rrd", "--start", 'N', "--step", '1', "DS:ifInUcastPkts:COUNTER:600:U:U", "DS:ipInReceives:COUNTER:600:U:U", "DS:icmpOutEchos:COUNTER:600:U:U", "DS:tcpInSegs:COUNTER:600:U:U", "DS:udpInDatagrams:COUNTER:600:U:U", "RRA:AVERAGE:0.5:1:700", "RRA:AVERAGE:0.5:1:700", "RRA:AVERAGE:0.5:1:700", "RRA:AVERAGE:0.5:1:700", "RRA:AVERAGE:0.5:1:700") rrdtool.dump('RRDsAgentes/agente' + idAgente + '.rrd', 'RRDsAgentes/agente' + idAgente + '.xml') if ret: print(rrdtool.error())
def analizarExamen(): while 1: total_input_traffic = int( consultaSNMP('comunidadEquipo4_grupo4cm1', '10.100.69.46', '1.3.6.1.2.1.2.2.1.10.3')) valor = "N:" + str(total_input_traffic) print(valor) rrdtool.update('examen.rrd', valor) rrdtool.dump('examen.rrd', 'examen.xml') time.sleep(1) if ret: print(rrdtool.error()) time.sleep(300)
def actualizarHW(cadena,comunidad,host,puerto,rrd): print 'Entro actualizarHW ',cadena,comunidad,host,puerto,rrd total_input_traffic = 0 total_output_traffic = 0 rrdpath="./RRD_HW/" pngpath="./IMG_HW/" fname=rrd+".rrd" pngfname=rrd+".png" #Verifica que exista una rrd asociada al host, en caso de no existir crea una rrd nueva archivo_rrd = Path(rrdpath+fname) if archivo_rrd.is_file() == False: crearRRD.crearHW(rrdpath+fname) print "rrd HW Creada... en",rrdpath,fname else: print "Abriendo rrd HW..." endDate = rrdtool.last(rrdpath+fname) #ultimo valor del XML begDate = endDate - 3600 #Inicia proceso de adquisicion de datos HW while 1: total_input_traffic = int(consultaSNMP('public','10.100.71.100',1024,'1.3.6.1.2.1.2.2.1.18.1')) total_output_traffic = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.2.2.1.16.3')) '''total_tcp_established = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.6.9.0')) input_tcp_segs = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.6.10.0')) output_tcp_segs = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.6.11.0')) input_icmp_msgs = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.5.1.0')) output_icmp_msgs = int( consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.5.14.0')) input_snmp_getReq = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.11.15.0')) output_snmp_getResp = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.11.28.0'))''' #valor = str(rrdtool.last(rrdpath+fname)+30) + str(total_input_traffic) + ':' + str(total_output_traffic) + ':' + str(total_tcp_established) + ':' + str(input_tcp_segs) + ':' + str(output_tcp_segs) + ':' + str(input_icmp_msgs) + ':' + str(output_icmp_msgs) + ':' + str(input_snmp_getReq) + ':' + str(output_snmp_getResp) #valor = str(rrdtool.last(rrdpath+fname)+30)+":" + str(total_input_traffic) + ':' + str(total_output_traffic) + ':' + str(total_tcp_established) + ':' + str(input_tcp_segs) + ':' + str(output_tcp_segs) + ':' + str(input_icmp_msgs) + ':' + str(output_icmp_msgs) + ':' + str(input_snmp_getReq) + ':' + str(output_snmp_getResp) valor = str(rrdtool.last(rrdpath+fname)+30)+":" + str(total_input_traffic) print 'Valor: ',valor rrdtool.update(rrdpath+fname,valor) rrdtool.dump(rrdpath+fname,rrd+'.xml') #print "actualizar: ",rrdpath,fname, rrd rrdtool.tune(rrdpath+fname,'--alpha','0.1') #time.sleep(1) if ret: print rrdtool.error() time.sleep(300)
def updateAgenteComun1(com, host): total_output_received = 0 while True: # print("IP_UpdateRRD.py_ ") #Consulta multicast total_input_deliveries = int( consultaSNMP(com, host, "1.3.6.1.2.1.2.2.1.12.5")) valor = "N:" + str(total_input_deliveries) rrdtool.update("Multicast_paquetes_1.rrd", valor) rrdtool.dump("Multicast_paquetes_1.rrd", "Multicast_paquetes_1.xml") total_output_deliveries = 0 #Consulta IP total_input_deliveries = int( consultaSNMP(com, host, "1.3.6.1.2.1.4.9.0")) total_output_received = int( consultaSNMP(com, host, "1.3.6.1.2.1.4.3.0")) valor = "N:" + str(total_input_deliveries) + ':' + str( total_output_received) rrdtool.update("IP_paquetes_1.rrd", valor) rrdtool.dump("IP_paquetes_1.rrd", "IP_update_1.xml") total_output_deliveries = 0 #Consultas ICMP total_input_deliveries = int( consultaSNMP(com, host, "1.3.6.1.2.1.5.14.0")) valor = "N:" + str(total_input_deliveries) rrdtool.update("ICMP_mensajes_1.rrd", valor) rrdtool.dump("ICMP_mensajes_1.rrd", "ICMP_update_1.xml") total_output_deliveries = 0 #Consulta TCP total_input_deliveries = int( consultaSNMP(com, host, "1.3.6.1.2.1.6.11.0")) valor = "N:" + str(total_input_deliveries) rrdtool.update("TCP_segmentos_1.rrd", valor) rrdtool.dump("TCP_segmentos_1.rrd", "TCP_segmentos_1.xml") total_output_deliveries = 0 #Consulta UDP total_input_deliveries = int( consultaSNMP(com, host, "1.3.6.1.2.1.7.3.0")) valor = "N:" + str(total_input_deliveries) rrdtool.update("UDP_datagram_1.rrd", valor) rrdtool.dump("UDP_datagram_1.rrd", "UDP_datagramas_1.xml") time.sleep(1)
def actualizarHW(): a = NotifyHW() 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')) #total_input_traffic = int(obtenerValor('1.3.6.1.2.1.2.2.1.10.1')) #total_output_traffic = int(obtenerValor('1.3.6.1.2.1.2.2.1.16.1')) valor = "N:" + str(total_input_traffic) + ':' + str( total_output_traffic) ret = rrdtool.update("bdrrdtool/netPred.rrd", valor) rrdtool.dump("bdrrdtool/netPred.rrd", 'bdrrdtool/netPred.xml') # check_aberration('bdrrdtool/', 'netPred.rrd') # List of new aberrations begin_ab = [] # List of gone aberrations end_ab = [] # List files and generate charts for a.fname1 in os.listdir(a.rrdpath): a.gen_image(a.rrdpath, a.pngpath, a.fname1, a.width, a.height, a.begdate, a.enddate) # Now check files for beiaberrations for fname in os.listdir(a.rrdpath): ab_status = a.check_aberration(a.rrdpath, a.fname1) if ab_status == 1: begin_ab.append(a.fname1) if ab_status == 2: end_ab.append(a.fname1) if len(begin_ab) > 0: a.send_alert_attached('New aberrations detected', begin_ab) if len(end_ab) > 0: a.send_alert_attached('Abberations gone', end_ab) time.sleep(1) if ret: print(rrdtool.error()) time.sleep(300)