Example #1
0
def get_manager(device, community):
    sd = SNMP.sessionData(device, version=1)
    sd.add_community(community, SNMP.RW)
    sess = SNMP.new_session(sd)
    dev = HPSwitchManager(sess)
    dev.add_mibs(MIBS)
    return dev
Example #2
0
    def monitoring(self, ip, mainPojo, mainDBRRD, indexInterface, indexCPU):
        snmp = SNMP()
        hostname = mainPojo.getHostname(str(ip))
        community = mainPojo.getCommunity(str(hostname))
        version_snmp = 0 if str(mainPojo.getVersionSNMP(
            str(hostname))) == "v1" else 1
        port_snmp = int(mainPojo.getPortSNMP(str(hostname)))
        telegram = Telegram("712644612:AAHauTnCsKgno4fOh3z8p9B5fJuOnGC9-tk")
        idChat = "-343597492"
        flag = True
        while True:
            try:
                if os.system("ping -c 1 " + str(ip) +
                             " >/dev/null 2>&1 < /dev/null &"
                             ) == 0 and mainPojo.getStatus(
                                 str(ip)) == "up" and len(
                                     str(mainPojo.getStatus(str(ip)))) > 0:
                    inoctets = int(
                        snmp.get(community, version_snmp, ip, port_snmp,
                                 "1.3.6.1.2.1.2.2.1.10.1")
                    )  #OID para obtener el total de inoctets
                    mainDBRRD.insert(inoctets)
                    #######Notificacion de Fallas#######
                    try:
                        fallas = mainDBRRD.check_aberration()
                        if int(fallas) == 1 and flag:
                            flag = False
                            graphHW(ip)
                            mensaje = "Falla detectada en el Host :" + str(
                                ip) + "(" + str(time.strftime("%c")) + ")"
                            telegram.sendMessage(mensaje, idChat)
                            telegram.sendImage(str(ip) + "HW.png", idChat)

                        if int(fallas) == 2 and not flag:
                            flag = True
                            graphHW(ip)
                            mensaje = "La falla en el Host :" + str(
                                ip) + " ha sido mitigada (" + str(
                                    time.strftime("%c")) + ")"
                            telegram.sendMessage(mensaje, idChat)
                            telegram.sendImage(str(ip) + "HW.png", idChat)
                    except Exception as a:
                        print(a)
                    time.sleep(60)
                else:
                    mainPojo.setStatus(str(hostname), "down")
                    print("Server is down")
                    break
            except Exception as e:
                pa = PojoAgent("localhost", "root", "", "snmp")
                result = pa.verifyHost(str(ip))
                if len(result) == 0:
                    break
                else:
                    print(e)
Example #3
0
def main(argv):
	host = argv[1]
	sd = SNMP.sessionData(host)
	if len(argv) > 2:
		sd.add_community(argv[2])
	else:
		sd.add_community("public")
	sess = SNMP.new_session(sd)
	mgr = Manager.Manager(sess)
	mgr.add_mib(mibs.SNMPv2_MIB)
	ors = mgr.getall("sysOR")
	for ore in ors:
		print ore
Example #4
0
def get_manager(sessiondata):
	sessiondata.version = 0 # APC still only SNMPv1 !
	sess = SNMP.new_session(sessiondata)
	dev = APCManager(sess)
	dev.add_mibs([mibs.SNMPv2_MIB])
	dev.add_mib(mibs.PowerNet_MIB, apc_mangler, subclassmodule=sys.modules[__name__])
	return dev
Example #5
0
#    version 2.1 of the License, or (at your option) any later version.
#
#    This library is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#    Lesser General Public License for more details.

import sys
import SNMP.SNMP as SNMP

import pdb

#sd = SNMP.sessionData("172.20.165.20") # regression
#sd = SNMP.sessionData("172.20.149.40") # dev14
#sd = SNMP.sessionData("192.168.146.97") # sum4_1
sd = SNMP.sessionData("rosita")
sd.add_community("public", SNMP.RO)
sd.add_community("private", SNMP.RW)
session = SNMP.new_session(sd)

import mibs.SNMPv2_MIB
#import mibs.UDP_MIB
#import mibs.TCP_MIB
#import mibs.BRIDGE_MIB
#import mibs.RMON_MIB
#import mibs.RMON2_MIB
#import mibs.EtherLike_MIB
#import mibs.EXTREME_BASE_MIB
#import mibs.EXTREME_VLAN_MIB
#import mibs.EXTREME_PORT_MIB
#import mibs.EXTREME_SYSTEM_MIB
Example #6
0
def get_session(sessiondata):
    sess = SNMP.new_session(sessiondata)
    dev = HPSwitchManager(sess)
    dev.add_mibs(MIBS)
    return dev
Example #7
0
 def monitoring(self, ip, mainPojo, mainDBRRD, index):
     snmp = SNMP()
     hostname = mainPojo.getHostname(str(ip))
     community = mainPojo.getCommunity(str(hostname))
     version_snmp = 0 if str(mainPojo.getVersionSNMP(
         str(hostname))) == "v1" else 1
     port_snmp = int(mainPojo.getPortSNMP(str(hostname)))
     while True:
         if os.system("ping -c 1 " + str(ip) +
                      " >/dev/null 2>&1 < /dev/null &"
                      ) == 0 and mainPojo.getStatus(
                          str(ip)) == "up" and len(
                              str(mainPojo.getStatus(str(ip)))) > 0:
             in_network_interface = snmp.get(
                 community, version_snmp, ip, port_snmp,
                 "1.3.6.1.2.1.2.2.1.10." + str(index))
             out_network_interface = snmp.get(
                 community, version_snmp, ip, port_snmp,
                 "1.3.6.1.2.1.2.2.1.16." + str(index))
             in_icmp = snmp.get(community, version_snmp, ip, port_snmp,
                                "1.3.6.1.2.1.5.1.0")
             out_icmp = snmp.get(community, version_snmp, ip, port_snmp,
                                 "1.3.6.1.2.1.5.14.0")
             in_tcp = snmp.get(community, version_snmp, ip, port_snmp,
                               "1.3.6.1.2.1.6.10.0")
             out_tcp = snmp.get(community, version_snmp, ip, port_snmp,
                                "1.3.6.1.2.1.6.11.0")
             in_udp = snmp.get(community, version_snmp, ip, port_snmp,
                               "1.3.6.1.2.1.7.1.0")
             out_udp = snmp.get(community, version_snmp, ip, port_snmp,
                                "1.3.6.1.2.1.7.4.0")
             in_ping = int(
                 snmp.get(community, version_snmp, ip, port_snmp,
                          "1.3.6.1.2.1.5.8.0")
             )  #The number of ICMP Echo (request) messages received.
             in_ping += int(
                 snmp.get(community, version_snmp, ip, port_snmp,
                          "1.3.6.1.2.1.5.9.0")
             )  #The number of ICMP Echo Reply messages received.
             out_ping = int(
                 snmp.get(community, version_snmp, ip, port_snmp,
                          "1.3.6.1.2.1.5.21.0")
             )  #The number of ICMP Echo (request) messages sent.
             out_ping += int(
                 snmp.get(community, version_snmp, ip, port_snmp,
                          "1.3.6.1.2.1.5.22.0")
             )  #The number of ICMP Echo Reply messages sent.
             mainDBRRD.insert(in_network_interface, out_network_interface,
                              in_icmp, out_icmp, in_tcp, out_tcp, in_udp,
                              out_udp, in_ping, out_ping)
             time.sleep(1)
         else:
             mainPojo.setStatus(str(hostname), "down")
             print("")
             break
Example #8
0
def get_manager(sessiondata):
	sess = SNMP.new_session(sessiondata)
	dev = LinuxManager(sess)
	dev.add_mibs([mibs.SNMPv2_MIB, mibs.HOST_RESOURCES_MIB])
	dev.add_mib(mibs.UCD_SNMP_MIB, subclassmodule=sys.modules[__name__])
	return dev
Example #9
0
def agregarAgente():
    os.system('clear')
    hostname = ""
    status = ""
    version_snmp = ""
    port_snmp = ""
    community = ""
    index = ""
    pa = PojoAgent("localhost","root","","snmp")#Conexion con la base de datos
    paux = PojoAgent("localhost","root","","snmp")#Conexion con la base de datos
    snmp = SNMP()
    agent = "y"
    while agent == "y" or agent == "Y":
        hostname = raw_input("Introduce el hostname del agente: ")
        if str(hostname) == "q" or str(hostname) == "Q":
            break
        else:
            result = pa.verifyHost(str(hostname))
            if len(result) > 0:
                print("El hostname ya se encuentra registrado.")
                hostname = raw_input("Introduce el hostname del agente: ")
            else:
                status = "up" if os.system("ping -c 1 " + str(hostname) +" >/dev/null 2>&1 < /dev/null &") == 0 else "down"
                version_snmp = raw_input("Introduce la version de snmp ('v1' o 'v2c'): ")
                if str(version_snmp) == "q" or str(version_snmp) == "Q":
                    break
                else:
                    port_snmp = raw_input("Introduce el puerto snmp: ")
                    if str(port_snmp) == "q" or str(port_snmp) == "Q":
                        break
                    else:
                        community = raw_input("Introduce la comunidad: ")
                        if str(community) == "q" or str(community) == "Q":
                            break
                        else:
                            index = raw_input("Introduce el index de la interfaz de red del agente: ")
                            if str(index) == "q" or str(index) == "Q":
                                break
                            else:
                                indexCPU = raw_input("Index del procesador del agente: ")
                                if str(indexCPU) == "q" or str(indexCPU) == "Q":
                                    break
        version_snmp = "0" if str(version_snmp) == "v1" else "1"

        ip = str(subprocess.check_output("cat /etc/hosts | grep \""+ str(hostname) +"\" | awk '{print $1}'",shell=True)).split("\n")[0]
        if len(str(ip)) == 0:
            ip = str(subprocess.check_output("dig '"+ str(hostname) +"' +short",shell=True)).split("\n")[0]
        ip = str(hostname)

        oid = "1.3.6.1.2.1.1.1.0" #Oid para obtener la version de SO
        version_so = snmp.get(str(community),int(version_snmp),str(hostname),str(port_snmp),str(oid))

        oid = "1.3.6.1.2.1.2.1.0" #Oid para obtener el numero de interfaces
        interfaces = snmp.get(str(community),int(version_snmp),str(hostname),str(port_snmp),str(oid))

        oid = "1.3.6.1.2.1.2.2.1.9.1" #Oid para obtener el ultimo reinicio
        # last_reboot = snmp.get("variation/virtualtable",1,"10.100.71.230","1024","1.3.6.1.2.1.2.2.1.9.1")
        last_reboot = snmp.get(str(community),int(version_snmp),str(hostname),str(port_snmp),str(oid))

        oid = "1.3.6.1.2.1.1.6.0" #Oid para obtener la direccion fisica
        mac = snmp.get(str(community),int(version_snmp),str(hostname),str(port_snmp),str(oid))

        oid = "1.3.6.1.2.1.1.4.0" #Oid para obtener informacion del administrador
        info_admin = snmp.get(str(community),int(version_snmp),str(hostname),str(port_snmp),str(oid))

        pa.insertAgent(str(hostname),str(version_snmp),port_snmp,str(community),str(status),str(ip),str(version_so),str(interfaces),str(last_reboot),str(mac),str(info_admin),str(index),str(indexCPU))
        if pa.ifWindows(str(hostname)):
            print("Dispositivo Windows.")
            indexRAM = raw_input("Introduce el Index de la RAM: ")
            indexHDD = raw_input("Introduce el Index del HDD: ")
            pa.updateIndex(str(hostname),str(indexRAM),str(indexHDD))
        thread = ThreadSNMP()
        thread.startMonitoring(str(hostname),paux,str(index),str(indexCPU))
        pa.closeConnection()
        raw_input("El agente "+ str(hostname) +" ha sido agregado...Presiona una tecla para regresar al menu")
        break
Example #10
0
 def monitoring(self, ip, mainPojo, mainDBRRD, indexInterface, indexCPU):
     snmp = SNMP()
     hostname = mainPojo.getHostname(str(ip))
     community = mainPojo.getCommunity(str(hostname))
     version_snmp = 0 if str(mainPojo.getVersionSNMP(
         str(hostname))) == "v1" else 1
     port_snmp = int(mainPojo.getPortSNMP(str(hostname)))
     telegram = Telegram("712644612:AAHauTnCsKgno4fOh3z8p9B5fJuOnGC9-tk")
     #telegram.sendMessage(mensaje,"-343597492")
     idChat = "-343597492"
     umbralRAM = 80
     umbralHDD = 90
     umbralCPU = 6
     while True:
         try:
             if mainPojo.ifWindows(ip):
                 if os.system("ping -c 1 " + str(ip) +
                              " >/dev/null 2>&1 < /dev/null &"
                              ) == 0 and mainPojo.getStatus(
                                  str(ip)) == "up" and len(
                                      str(mainPojo.getStatus(str(ip)))) > 0:
                     indexRAM = mainPojo.getIndexRAM(str(ip))
                     indexHDD = mainPojo.getIndexHDD(str(ip))
                     cpuload = snmp.get(
                         community, version_snmp, ip, port_snmp,
                         "1.3.6.1.2.1.25.3.3.1.2." + str(indexCPU)
                     )  #OID para calcular promedio del ultimo minuto del porcentaje que el procesador no estuvo inactivo
                     freeram = int(
                         snmp.get(community, version_snmp, ip, port_snmp,
                                  "1.3.6.1.2.1.25.2.3.1.6." + str(indexRAM))
                     )  #OID para obtener la memoria RAM disponible en kB
                     usehdd = int(
                         snmp.get(community, version_snmp, ip, port_snmp,
                                  "1.3.6.1.2.1.25.2.3.1.6." + str(indexHDD))
                     )  #OID para obtener la cantidad de Disco Duro usado.
                     totalram = int(
                         snmp.get(community, version_snmp, ip, port_snmp,
                                  "1.3.6.1.2.1.25.2.3.1.5." + str(indexRAM))
                     )  #OID para obtener el total de la RAM
                     totalhdd = int(
                         snmp.get(community, version_snmp, ip, port_snmp,
                                  "1.3.6.1.2.1.25.2.3.1.5." + str(indexHDD))
                     )  #OID para obtener el total del HDD
                     hddload = (
                         usehdd * 100
                     ) / totalhdd  #Cantidad de Disco Duro en Porcentaje
                     ramload = (
                         (totalram - freeram) *
                         100) / totalram  #Cantidad de RAM en porcentaje
                     mainDBRRD.insert(cpuload, ramload, hddload)
                     #######Establecer umbrales#######
                     if int(ramload) > umbralRAM:
                         graphRAM(ip)
                         mensaje = "Porcentaje de RAM utilizada por el Host " + str(
                             ip) + ": " + str(ramload) + " % (" + str(
                                 time.strftime("%c")) + ")"
                         telegram.sendMessage(mensaje, idChat)
                         telegram.sendImage(str(ip) + "RAM.png", idChat)
                     if int(hddload) > umbralHDD:
                         graphHDD(ip)
                         mensaje = "Porcentaje de HDD utilizado por el Host " + str(
                             ip) + ": " + str(hddload) + " % (" + str(
                                 time.strftime("%c")) + ")"
                         telegram.sendMessage(mensaje, idChat)
                         telegram.sendImage(str(ip) + "HDD.png", idChat)
                     if int(cpuload) > umbralCPU:
                         graphCPU(ip)
                         mensaje = "Porcentaje de CPU utilizado por el Hots " + str(
                             ip) + ": " + str(cpuload) + " % (" + str(
                                 time.strftime("%c")) + ")"
                         telegram.sendMessage(mensaje, idChat)
                         telegram.sendImage(str(ip) + "CPU.png", idChat)
                     time.sleep(5)
                 else:
                     mainPojo.setStatus(str(hostname), "down")
                     print("Server is down")
                     break
             else:
                 if os.system("ping -c 1 " + str(ip) +
                              " >/dev/null 2>&1 < /dev/null &"
                              ) == 0 and mainPojo.getStatus(
                                  str(ip)) == "up" and len(
                                      str(mainPojo.getStatus(str(ip)))) > 0:
                     cpuload = snmp.get(
                         community, version_snmp, ip, port_snmp,
                         "1.3.6.1.2.1.25.3.3.1.2." + str(indexCPU)
                     )  #OID para calcular promedio del ultimo minuto del porcentaje que el procesador no estuvo inactivo
                     freeram = int(
                         snmp.get(community, version_snmp, ip, port_snmp,
                                  "1.3.6.1.4.1.2021.4.6.0")
                     )  #OID para obtener la memoria RAM disponible en kB
                     usehdd = int(
                         snmp.get(community, version_snmp, ip, port_snmp,
                                  "1.3.6.1.4.1.2021.9.1.8.1")
                     )  #OID para obtener la cantidad de Disco Duro usado. En linux agregar disk / 1 en snmpd.conf
                     totalram = int(
                         snmp.get(community, version_snmp, ip, port_snmp,
                                  "1.3.6.1.2.1.25.2.2.0")
                     )  #OID para obtener el total de la RAM
                     totalhdd = int(
                         snmp.get(community, version_snmp, ip, port_snmp,
                                  "1.3.6.1.4.1.2021.9.1.11.1")
                     )  #OID para obtener el total del HDD
                     hddload = (
                         usehdd * 100
                     ) / totalhdd  #Cantidad de Disco Duro en Porcentaje
                     ramload = (
                         (totalram - freeram) *
                         100) / totalram  #Cantidad de RAM en porcentaje
                     mainDBRRD.insert(cpuload, ramload, hddload)
                     #######Establecer umbrales#######
                     if int(ramload) > umbralRAM:
                         graphRAM(ip)
                         mensaje = "Porcentaje de RAM utilizada por el Host " + str(
                             ip) + ": " + str(ramload) + " % (" + str(
                                 time.strftime("%c")) + ")"
                         telegram.sendMessage(mensaje, idChat)
                         telegram.sendImage(str(ip) + "RAM.png", idChat)
                     if int(hddload) > umbralHDD:
                         graphHDD(ip)
                         mensaje = "Porcentaje de HDD utilizado por el Host " + str(
                             ip) + ": " + str(hddload) + " % (" + str(
                                 time.strftime("%c")) + ")"
                         telegram.sendMessage(mensaje, idChat)
                         telegram.sendImage(str(ip) + "HDD.png", idChat)
                     if int(cpuload) > umbralCPU:
                         graphCPU(ip)
                         mensaje = "Porcentaje de CPU utilizado por el Hots " + str(
                             ip) + ": " + str(cpuload) + " % (" + str(
                                 time.strftime("%c")) + ")"
                         telegram.sendMessage(mensaje, idChat)
                         telegram.sendImage(str(ip) + "CPU.png", idChat)
                     time.sleep(5)
                 else:
                     mainPojo.setStatus(str(hostname), "down")
                     print("Server is down")
                     break
         except Exception as e:
             pa = PojoAgent("localhost", "root", "", "snmp")
             result = pa.verifyHost(str(ip))
             if len(result) == 0:
                 break
             else:
                 print(e)
                 print("Ocurrio un error")
Example #11
0
def get_manager(host, community):
    box = SNMP.get_session(host, community)
    device = DiscoverManager(box)
    device.add_mibs([SNMPv2_MIB, IF_MIB, IP_MIB, RFC1213_MIB])
    device.add_mibs([CDP_MIB, LLDP_MIB])
    return device
Example #12
0
def get_manager(sessiondata):
	sess = SNMP.new_session(sessiondata)
	dev = NeopathFDManager(sess)
	dev.add_mibs([mibs.SNMPv2_MIB, mibs.RFC1213_MIB])
	dev.add_mib(mibs.NeopathFD_MIB, neopath_mangler, sys.modules[__name__])
	return dev