def EjecutarMc(comunidad, ip, port, name, times, umbral):

    if name == 'linux' or name == "linuxmario":
        carga_CPU = int(
            consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.25.3.3.1.2.196608'))
    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'))
    agentPath = lbPathmc + name + "/"
    #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 + str(name)) + 'trend.rrd', valor)

    tiempo_final = int(rrdtool.last(agentPath + str(name) + "trend.rrd"))
    tiempo_inicial = tiempo_final - 3600

    ret2 = rrdtool.graphv(
        str(agentPath + name) + "deteccion.png",
        "--start",
        str(tiempo_inicial),
        "--end",
        str(tiempo_final + 15500),
        "--title",
        "Carga de CPU",
        "--vertical-label=Uso de CPU (%)",
        '--lower-limit',
        '0',
        '--upper-limit',
        '100',
        "DEF:carga=" + agentPath + name + "trend.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",
        "AREA:umbral25#FF9F00:Tráfico de carga mayor que" + str(umbral),
        "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'
        '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 ")

    alcanza_umbral = ret2['print[0]']

    ultimo_valor = ret2['print[1]']

    #print ("alcanza umbral"+ str(alcanza_umbral)+str(ultimo_valor))
    #valores= ultimo_valor.split(" ")
    #print (ultimo_valor + alcanza_umbral)
    #print("Archivo generado en " + str(agentPath + name)+"deteccion.png")

    if float(ultimo_valor) > int(umbral):
        sendAlertEmail(
            "Agente " + name + " sobrepasó umbral de minimos cuadrados" +
            str(ultimo_valor),
            str(agentPath + name) + "deteccion.png",
            str(agentPath + str(name)) + 'trend.rrd')
    elif (float(ultimo_valor) == 0):
        sendAlertEmail(
            "Agente " + name + " sobrepasó umbral 0 de minimos cuadrados" +
            str(ultimo_valor),
            str(agentPath + name) + "deteccion.png",
            str(agentPath + str(name)) + 'trend.rrd')
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 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 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",
    )

    #ultimo_valor= float(ret['print[0]'])
    #limite= float(ret['print[1]'])

    #print (ultimo_valor )

    #valores= ultimo_valor.split(" ")
    #lim=limite.split(" ")
    #print (name+"RAM--valor" +str(ultimo_valor) + "limite "+ str(limite))
    #if float(ultimo_valor)>float(limite):
    #	sendAlertEmail("Agente "+name+"Sobrepasó umbral RAM Go con :"+str(ultimo_valor), str(agentPath + name) +"RAM.png",str(agentPath + name) + "RAM.rrd")

    #-----------------------------------------------------------------------------------------
    # 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.196608'))
    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",
    )