示例#1
0
def group6(varBindTable, lmount):
    resultl = []
    ipAdEntAddr = ipAdEntifIndex = ipAdEndNetMask = ''
    for i in lmount:
        for varBindTableRow in varBindTable:
            for name, val in varBindTableRow:
                if str(name) == '1.3.6.1.2.1.4.20.1.1.{0}'.format(i):
                    ipAdEntAddr = '|'.join([ipAdEntAddr, val.prettyPrint()])
                if str(name) == '1.3.6.1.2.1.4.20.1.2.{0}'.format(i):
                    ipAdEntifIndex = '|'.join([ipAdEntifIndex, str(val)])
                if str(name) == '1.3.6.1.2.1.4.20.1.3.{0}'.format(i):
                    ipAdEndNetMask = '|'.join(
                        [ipAdEndNetMask, val.prettyPrint()])
    resultl.append(ID)
    resultl.append(HOST)
    if ipAdEntAddr != '':
        resultl.append(ipAdEntAddr)
    resultl.append(ipAdEntifIndex)
    resultl.append(ipAdEndNetMask)
    resultl.append(datetime.today().strftime('%d/%m/%Y'))
    resultl.append(datetime.today().strftime('%H:%M:%S'))
    if len(resultl) == 7:
        reg_group6_db('{0}{1}'.format(INSTALL_PATH, DB), resultl)
        logsnmpget(
            'SUCESSO: Dados do Grupo 1 do ID {0} e Host {1} coletados.'.format(
                ID, HOST))
示例#2
0
def group3id():
    lmount = []
    mem = ''
    cmdGen = cmdgen.CommandGenerator()
    errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
        cmdgen.CommunityData('public'), cmdgen.UdpTransportTarget((HOST, 161)),
        '1.3.6.1.2.1.25.2')
    if errorIndication:
        print(errorIndication)
        logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(
            ID, HOST, errorIndication))
    else:
        if errorStatus:
            print(
                '%s at %s' %
                (errorStatus.prettyPrint(),
                 errorIndex and varBindTable[-1][int(errorIndex) - 1] or '?'))
            logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(
                ID, HOST, errorStatus.prettyPrint()))
        else:
            for varBindTableRow in varBindTable:
                for name, val in varBindTableRow:
                    if str(name) == '1.3.6.1.2.1.25.2.2.0':
                        mem = str(int(val) / 1024)
                    if str(name).find('1.3.6.1.2.1.25.2.3.1.1.') >= 0:
                        lmount.append(str(name).split('.')[-1])
    return varBindTable, lmount, mem
示例#3
0
def group6id():
    lmount = []
    cmdGen = cmdgen.CommandGenerator()
    errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
        cmdgen.CommunityData('public'), cmdgen.UdpTransportTarget((HOST, 161)),
        '1.3.6.1.2.1.4.20')
    if errorIndication:
        print(errorIndication)
        logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(
            ID, HOST, errorIndication))
    else:
        if errorStatus:
            print(
                '%s at %s' %
                (errorStatus.prettyPrint(),
                 errorIndex and varBindTable[-1][int(errorIndex) - 1] or '?'))
            logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(
                ID, HOST, errorStatus.prettyPrint()))
        else:
            for varBindTableRow in varBindTable:
                for name, val in varBindTableRow:
                    if str(name).find('1.3.6.1.2.1.4.20.1.1.') >= 0:
                        lmount.append(
                            re.search(r'1\.3\.6\.1\.2\.1\.4\.20\.1\.1\.(.*)',
                                      str(name)).group(1))
    return varBindTable, lmount
示例#4
0
def group3(varBindTable, lmount, mem):
    resultl = []
    hrStorageDescr = hrStorageSize = hrStorageUsed = ''
    for i in lmount:
        for varBindTableRow in varBindTable:
            for name, val in varBindTableRow:
                if str(name) == '1.3.6.1.2.1.25.2.3.1.3.{0}'.format(i):
                    hrStorageDescr = '|'.join([hrStorageDescr, str(val)])
                if str(name) == '1.3.6.1.2.1.25.2.3.1.5.{0}'.format(i):
                    hrStorageSize = '|'.join(
                        [hrStorageSize, str(int(val) * 0.004)])
                if str(name) == '1.3.6.1.2.1.25.2.3.1.6.{0}'.format(i):
                    hrStorageUsed = '|'.join(
                        [hrStorageUsed, str(int(val) * 0.004)])
    resultl.append(ID)
    resultl.append(HOST)
    if mem != '':
        resultl.append(mem)
    resultl.append(hrStorageDescr)
    resultl.append(hrStorageSize)
    resultl.append(hrStorageUsed)
    resultl.append(datetime.today().strftime('%d/%m/%Y'))
    resultl.append(datetime.today().strftime('%H:%M:%S'))
    if len(resultl) == 8:
        reg_group3_db('{0}{1}'.format(INSTALL_PATH, DB), resultl)
        logsnmpget(
            'SUCESSO: Dados do Grupo 1 do ID {0} e Host {1} coletados.'.format(
                ID, HOST))
示例#5
0
    def GetSNMP2(ip,community):
        hosts_list2 = []
        mem = ''
        hosts_list2 = errorIndication, errorStatus, errorIndex, varBindTable = next(
            getCmd(SnmpEngine(),
                   CommunityData(community),
                   UdpTransportTarget((ip, 161)),
                   ContextData(),

                   ObjectType(ObjectIdentity('HOST-RESOURCES-MIB', 'hrSWRunPerfCPU', 0)),
                   ObjectType(ObjectIdentity('HOST-RESOURCES-MIB', 'hrSWRunPerfMem', 0)),
                   )
        )


        if errorIndication:
            print(errorIndication)
            logs.logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(logs.ID, logs.HOST, errorIndication))
        else:
            if errorStatus:
                print('%s at %s' % (
                    errorStatus.prettyPrint(),
                    errorIndex and varBindTable[-1][int(errorIndex) - 1] or '?')
                        )
                logs.logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(logs.ID, logs.HOST, errorStatus.prettyPrint()))
            else:
                for varBindTableRow in varBindTable:
                    for name, val in varBindTableRow:
                        if str(name) == 'hrSWRunPerfCPU':
                            mem = str(int(val) / 1024)
                        if str(name).find('hrSWRunPerfMem') >= 0:
                            hosts_list2.append(str(name).split('.')[-1])

        return varBindTable, hosts_list2, mem
示例#6
0
    def GetSNMP3(ip, community):
        resultado3 = []
        mem = ''
        resultado3 = errorIndication, errorStatus, errorIndex, varBindTable = next(
            getCmd(SnmpEngine(),
                   CommunityData(community),
                   UdpTransportTarget((ip, 161)),
                   ContextData(),

                   ObjectType(ObjectIdentity('SNMPv2-MIB', 'ipForwarding', 0)),
                   ObjectType(ObjectIdentity('SNMPv2-MIB', 'ipInHdrErrors', 0)),
                   )
        )


        if errorIndication:
            print(errorIndication)
            logs.logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(logs.ID, logs.HOST, errorIndication))
        else:
            if errorStatus:
                print('%s at %s' % (
                    errorStatus.prettyPrint(),
                    errorIndex and varBindTable[-1][int(errorIndex) - 1] or '?')
                        )
                logs.logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(logs.ID, logs.HOST, errorStatus.prettyPrint()))
            else:
                for varBindTableRow in varBindTable:
                    for name, val in varBindTableRow:
                        if str(name) == 'hrSWRunPerfCPU':
                            mem = str(int(val) / 1024)
                        if str(name).find('hrSWRunPerfMem') >= 0:
                            resultado3.append(str(name).split('.')[-1])
示例#7
0
def group3id():
    lmount = []
    mem = ''
    cmdGen = cmdgen.CommandGenerator()
    errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
        cmdgen.CommunityData('public'),
        cmdgen.UdpTransportTarget((HOST, 161)),
        '1.3.6.1.2.1.25.2'
    )
    if errorIndication:
        print(errorIndication)
        logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(ID, HOST, errorIndication))
    else:
        if errorStatus:
            print('%s at %s' % (
                errorStatus.prettyPrint(),
                errorIndex and varBindTable[-1][int(errorIndex) - 1] or '?')
            )
            logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(ID, HOST, errorStatus.prettyPrint()))
        else:
            for varBindTableRow in varBindTable:
                for name, val in varBindTableRow:
                    if str(name) == '1.3.6.1.2.1.25.2.2.0':
                        mem = str(int(val) / 1024)
                    if str(name).find('1.3.6.1.2.1.25.2.3.1.1.') >= 0:
                        lmount.append(str(name).split('.')[-1])
    return varBindTable, lmount, mem
示例#8
0
    def GetSNMP(self):

        resultado = errorIndication, errorStatus, errorIndex, varBinds, varBindTable = next(
            getCmd(
                SnmpEngine(),
                CommunityData(self.community),
                UdpTransportTarget((self.ip, 161)),
                ContextData(),
                ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysContact', 0)),
                ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
                ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysObjectID', 0)),
                ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)),
                ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysUpTime', 0)),
            ), )
        print(resultado)
        host = dbmanager.Host()
        if errorIndication:
            print(errorIndication)

        else:
            if errorStatus:
                print('%s at %s' %
                      (errorStatus.prettyPrint(), errorIndex
                       and varBindTable[-1][int(errorIndex) - 1] or '?'))
                logs.logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(
                    errorStatus.prettyPrint()))
            else:
                for varBindTableRow in varBindTable:
                    for name, val in varBindTableRow:
                        if str(name) == 'sysObjectID':
                            resultado.append(val)
                            host.idObject = str(val)
                        if str(name) == 'sysContact':
                            resultado.append(val)
                            host.contact = str(val)
                        if str(name) == 'sysUpTime':
                            resultado.append(val)
                            host.uptime = str(val)
                        if str(name) == 'sysDescr':
                            resultado.append(val)
                            host.desc = str(val)
                        if str(name) == 'sysLocation':
                            resultado.append(val)
                            host.location = str(val)

            if len(resultado) == 5:
                host.ip = str(val)
                host.Comunidade = str(val)
                host.data = str(datetime.today().strftime('%d/%m/%Y'))
                host.hora = str(datetime.today().strftime('%H:%M:%S'))

                dbmanager.reg_group1_db('{0}{1}'.format(dbmanager.DB))
                logs.logsnmpget(
                    'SUCESSO: Dados do GetSNMP1 do IP {0} e Comunidade {1} coletados.'
                    .format(logs.ID, logs.HOST))
        host.save()

        return str(resultado)
示例#9
0
    def GetSNMP1(self, ip, community):
        hosts_list = []
        hosts_list = errorIndication, errorStatus, errorIndex, varBindTable = next(
            getCmd(
                SnmpEngine(),
                CommunityData(community),
                UdpTransportTarget((self.ip, 161)),
                ContextData(),
                ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysContact', 0)),
                ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
                ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysObjectID', 0)),
                ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)),
                ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysUpTime', 0)),
            ), )
        if errorIndication:
            print(errorIndication)

        else:
            if errorStatus:
                print('%s at %s' %
                      (errorStatus.prettyPrint(), errorIndex
                       and varBindTable[-1][int(errorIndex) - 1] or '?'))
                logs.logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(
                    errorStatus.prettyPrint()))
            else:
                for varBindTableRow in varBindTable:
                    for name, val in varBindTableRow:
                        if str(name) == self.ip:
                            hosts_list.append(val)
                        if str(name) == self.community:
                            hosts_list.append(val)
                        if str(name) == 'sysObjectID':
                            hosts_list.append(val)
                        if str(name) == 'sysContact':
                            hosts_list.append(val)
                        if str(name) == 'sysUpTime':
                            hosts_list.append(val)
                        if str(name) == 'sysDescr':
                            hosts_list.append(val)
                        if str(name) == 'sysLocation':
                            hosts_list.append(val)

            if len(hosts_list) == 7:
                hosts_list.append(datetime.today().strftime('%d/%m/%Y'))
                hosts_list.append(datetime.today().strftime('%H:%M:%S'))
                dbmanager.reg_group1_db('{0}{1}'.format(dbmanager.DB))
                logs.logsnmpget(
                    'SUCESSO: Dados do GetSNMP1 do IP {0} e Comunidade {1} coletados.'
                    .format(logs.ID, logs.HOST))

        return hosts_list
示例#10
0
def group5id():
    cmdGen = cmdgen.CommandGenerator()
    errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
        cmdgen.CommunityData('public'), cmdgen.UdpTransportTarget((HOST, 161)),
        '1.3.6.1.2.1.25.5')
    if errorIndication:
        print(errorIndication)
        logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(
            ID, HOST, errorIndication))
    else:
        if errorStatus:
            print(
                '%s at %s' %
                (errorStatus.prettyPrint(),
                 errorIndex and varBindTable[-1][int(errorIndex) - 1] or '?'))
            logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(
                ID, HOST, errorStatus.prettyPrint()))
        else:
            pass
    return varBindTable
示例#11
0
def group5id():
    cmdGen = cmdgen.CommandGenerator()
    errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
        cmdgen.CommunityData('public'),
        cmdgen.UdpTransportTarget((HOST, 161)),
        '1.3.6.1.2.1.25.5'
    )
    if errorIndication:
        print(errorIndication)
        logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(ID, HOST, errorIndication))
    else:
        if errorStatus:
            print('%s at %s' % (
                errorStatus.prettyPrint(),
                errorIndex and varBindTable[-1][int(errorIndex) - 1] or '?')
            )
            logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(ID, HOST, errorStatus.prettyPrint()))
        else:
            pass
    return varBindTable
示例#12
0
def group2():
    resultl = []
    cmdGen = cmdgen.CommandGenerator()
    errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
        cmdgen.CommunityData('public'),
        cmdgen.UdpTransportTarget((HOST, 161)),
        '1.3.6.1.2.1.25.1.5',
        '1.3.6.1.2.1.25.1.6',
    )
    if errorIndication:
        print(errorIndication)
        logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(ID, HOST, errorIndication))
    else:
        if errorStatus:
            print('%s at %s' % (
                errorStatus.prettyPrint(),
                errorIndex and varBindTable[-1][int(errorIndex) - 1] or '?')
            )
            logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(ID, HOST, errorStatus.prettyPrint()))
        else:
            for varBindTableRow in varBindTable:
                for name, val in varBindTableRow:
                    if str(name) == '1.3.6.1.2.1.25.1.5.0':
                        resultl.append(val)
                    if str(name) == '1.3.6.1.2.1.25.1.6.0':
                        resultl.append(val)
            if len(resultl) == 2:
                resultl.insert(0, HOST)
                resultl.insert(0, ID)
                resultl.append(datetime.today().strftime('%d/%m/%Y'))
                resultl.append(datetime.today().strftime('%H:%M:%S'))
                reg_group2_db('{0}{1}'.format(INSTALL_PATH, DB), resultl)
                logsnmpget('SUCESSO: Dados do Grupo 1 do ID {0} e Host {1} coletados.'.format(ID, HOST))
示例#13
0
def group6(varBindTable, lmount):
    resultl = []
    ipAdEntAddr = ipAdEntifIndex = ipAdEndNetMask = ''
    for i in lmount:
        for varBindTableRow in varBindTable:
            for name, val in varBindTableRow:
                if str(name) == '1.3.6.1.2.1.4.20.1.1.{0}'.format(i):
                    ipAdEntAddr = '|'.join([ipAdEntAddr, val.prettyPrint()])
                if str(name) == '1.3.6.1.2.1.4.20.1.2.{0}'.format(i):
                    ipAdEntifIndex = '|'.join([ipAdEntifIndex, str(val)])
                if str(name) == '1.3.6.1.2.1.4.20.1.3.{0}'.format(i):
                    ipAdEndNetMask = '|'.join([ipAdEndNetMask, val.prettyPrint()])
    resultl.append(ID)
    resultl.append(HOST)
    if ipAdEntAddr != '':
        resultl.append(ipAdEntAddr)
    resultl.append(ipAdEntifIndex)
    resultl.append(ipAdEndNetMask)
    resultl.append(datetime.today().strftime('%d/%m/%Y'))
    resultl.append(datetime.today().strftime('%H:%M:%S'))
    if len(resultl) == 7:
        reg_group6_db('{0}{1}'.format(INSTALL_PATH, DB), resultl)
        logsnmpget('SUCESSO: Dados do Grupo 1 do ID {0} e Host {1} coletados.'.format(ID, HOST))
示例#14
0
def group6id():
    lmount = []
    cmdGen = cmdgen.CommandGenerator()
    errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
        cmdgen.CommunityData('public'),
        cmdgen.UdpTransportTarget((HOST, 161)),
        '1.3.6.1.2.1.4.20'
    )
    if errorIndication:
        print(errorIndication)
        logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(ID, HOST, errorIndication))
    else:
        if errorStatus:
            print('%s at %s' % (
                errorStatus.prettyPrint(),
                errorIndex and varBindTable[-1][int(errorIndex) - 1] or '?')
            )
            logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(ID, HOST, errorStatus.prettyPrint()))
        else:
            for varBindTableRow in varBindTable:
                for name, val in varBindTableRow:
                    if str(name).find('1.3.6.1.2.1.4.20.1.1.') >= 0:
                        lmount.append(re.search(r'1\.3\.6\.1\.2\.1\.4\.20\.1\.1\.(.*)', str(name)).group(1))
    return varBindTable, lmount
示例#15
0
def group3(varBindTable, lmount, mem):
    resultl = []
    hrStorageDescr = hrStorageSize = hrStorageUsed = ''
    for i in lmount:
        for varBindTableRow in varBindTable:
            for name, val in varBindTableRow:
                if str(name) == '1.3.6.1.2.1.25.2.3.1.3.{0}'.format(i):
                    hrStorageDescr = '|'.join([hrStorageDescr, str(val)])
                if str(name) == '1.3.6.1.2.1.25.2.3.1.5.{0}'.format(i):
                    hrStorageSize = '|'.join([hrStorageSize, str(int(val) * 0.004)])
                if str(name) == '1.3.6.1.2.1.25.2.3.1.6.{0}'.format(i):
                    hrStorageUsed = '|'.join([hrStorageUsed, str(int(val) * 0.004)])
    resultl.append(ID)
    resultl.append(HOST)
    if mem != '':
        resultl.append(mem)
    resultl.append(hrStorageDescr)
    resultl.append(hrStorageSize)
    resultl.append(hrStorageUsed)
    resultl.append(datetime.today().strftime('%d/%m/%Y'))
    resultl.append(datetime.today().strftime('%H:%M:%S'))
    if len(resultl) == 8:
        reg_group3_db('{0}{1}'.format(INSTALL_PATH, DB), resultl)
        logsnmpget('SUCESSO: Dados do Grupo 1 do ID {0} e Host {1} coletados.'.format(ID, HOST))
示例#16
0
def group1():
    resultl = []
    cmdGen = cmdgen.CommandGenerator()
    errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
        cmdgen.CommunityData('public'),
        cmdgen.UdpTransportTarget((HOST, 161)),
        '1.3.6.1.2.1.1.1',
        '1.3.6.1.2.1.1.3',
        '1.3.6.1.2.1.1.4',
        '1.3.6.1.2.1.1.6',
        '1.3.6.1.2.1.1.7',
    )
    if errorIndication:
        print(errorIndication)
        logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(
            ID, HOST, errorIndication))
    else:
        if errorStatus:
            print(
                '%s at %s' %
                (errorStatus.prettyPrint(),
                 errorIndex and varBindTable[-1][int(errorIndex) - 1] or '?'))
            logsnmpget('FAIL: ID {0} - HOST {1} - {0}'.format(
                ID, HOST, errorStatus.prettyPrint()))
        else:
            for varBindTableRow in varBindTable:
                for name, val in varBindTableRow:
                    if str(name) == '1.3.6.1.2.1.1.1.0':
                        resultl.append(val)
                    if str(name) == '1.3.6.1.2.1.1.3.0':
                        resultl.append(time_conversion(val))
                    if str(name) == '1.3.6.1.2.1.1.4.0':
                        resultl.append(val)
                    if str(name) == '1.3.6.1.2.1.1.6.0':
                        resultl.append(val)
                    if str(name) == '1.3.6.1.2.1.1.7.0':
                        resultl.append(val)
        if len(resultl) == 5:
            resultl.insert(0, HOST)
            resultl.insert(0, ID)
            resultl.append(datetime.today().strftime('%d/%m/%Y'))
            resultl.append(datetime.today().strftime('%H:%M:%S'))
            reg_group1_db('{0}{1}'.format(INSTALL_PATH, DB), resultl)
            logsnmpget(
                'SUCESSO: Dados do Grupo 1 do ID {0} e Host {1} coletados.'.
                format(ID, HOST))