Example #1
0
def GetInformationDeviceSon(list_information_with_father):

    for element in list_information_with_father:
        list_element = element.split(';')
        if len(list_element) == 5:
            if list_element[2] != '-':

                query = "select * from dispositivo where serial = '%s'" % list_element[
                    2]

                if Query.ExistElementInDB(query) == 1:

                    query = "insert into dispositivo values ('%s', %d, '%s', '%s', '%s', %d, %d)" % (
                        list_element[2], 0, list_element[3], '',
                        list_element[1], 0, 0)
                    Query.InsertDBWithOutMessage(query)
                    UpdateModelDevice(list_element[4], list_element[2])
                else:
                    #update atributes...
                    UpdateIPDevice(list_element[2], list_element[1])
                    UpdateNameDevice(list_element[3], list_element[2])
                    UpdateModelDevice(list_element[4], list_element[2])

                try:
                    #get serial version of device by IP
                    serial = GetSerialDevice(list_element[0])
                    query = "Insert into conecta values('%s', '%s', %d)" % (
                        serial, list_element[2], 0)
                    Query.InsertDBWithOutMessage(query)
                except:
                    pass
Example #2
0
def UpdateDeviceInDataBase():

	file_read = open("information_actual_and_SNMP.csv", 'r')#open output file RecopilaInformatioSNMP.py

	#read file...
	line = file_read.readline()
	while line:

		line = line.strip('\n')
		line_information = line.split(';')
		
		#ask if device response to SNMP...
		if line_information[3] == "si":
		
			#ask if serial exists in data base...
			query = "select * from dispositivo where serial = '%s'" % line_information[0]

			if Query.ExistElementInDB(query) == 0:
				
				#update atributes...
				UpdateIPDevice(line_information[4], line_information[0])
				UpdateNameDevice(line_information[1], line_information[0])
				UpdateModelDevice(line_information[2], line_information[0])
				print line_information
			else:
				#the device not exists in data base... is necesary change element...
				print line_information[0]
				query = "insert into dispositivo values ('%s', %d, '%s', '%s', '%s', %d, %d)" % (line_information[0], 0, line_information[1], '', line_information[4], 0, 0)
				Query.InsertDBWithOutMessage(query)
				UpdateModelDevice(line_information[2], line_information[0])	

		line = file_read.readline()
	
	file_read.close()
Example #3
0
def InsertDevices(list_element):

    first_element = list_element[0]
    cont = 0
    for element in list_element:
        if element == first_element:
            cont += 1
        if cont > 1:
            break
        #make split to element
        information_element = element.split(";")
        query = "select * from dispositivo where serial = '%s'" % information_element[
            1]
        print information_element
        if Query.ExistElementInDB(query) == 1:

            query = "insert into dispositivo values ('%s', %d, '%s', '%s', '%s', %d, %d)" % (
                information_element[1], 0, information_element[2], '',
                information_element[0], 0, 0)
            Query.InsertDBWithOutMessage(query)
            UpdateModelDevice(information_element[3], information_element[1])
        else:
            #update atributes...
            UpdateIPDevice(information_element[1], information_element[0])
            UpdateNameDevice(information_element[2], information_element[1])
            UpdateModelDevice(information_element[3], information_element[1])
Example #4
0
def UpdateModelDevice(
        model_device,
        serial):  #Falta el id de la marca y del tipo de dispositivo!!!

    #evaluate if exists the model in data base...
    query = "select * from modelo where nom_modelo = '%s'" % model_device
    if Query.ExistElementInDB(query) == 0:  #exists in db...

        #get the id of model
        query = "select id_modelo from modelo where nom_modelo = '%s'" % model_device
        database_elements = Comunication.BeginComunication()  #init connection
        response = Comunication.MakeQueryDB(
            query, database_elements[1])  #manage query

        #update the id of model device...
        query = "update dispositivo set id_modelo = %d where serial = '%s'" % (
            int(response[0][0]), serial)
        Query.UpdateDBWithOutMessage(query)
    else:  #the model device not exist in data base...

        #insert model in data base...
        id_model = Query.GetMaxIDinTable(
            'modelo',
            'id_modelo')  #falta agregar el tipo de dispositivo y la marca...
        if id_model == None:
            id_model = 0
            query = "insert into modelo values (%d, %d, %d, '%s')" % (
                id_model, 0, 0, model_device)
            Query.InsertDBWithOutMessage(query)

            query = "update dispositivo set id_modelo = %d where serial = '%s'" % (
                id_model, serial)
            Query.UpdateDBWithOutMessage(query)
        else:
            id_model += 1
            query = "insert into modelo values (%d, %d, %d, '%s')" % (
                id_model, 0, 0, model_device)
            Query.InsertDBWithOutMessage(query)

            query = "update dispositivo set id_modelo = %d where serial = '%s'" % (
                id_model, serial)
            Query.UpdateDBWithOutMessage(query)
Example #5
0
def InsertModelDevice(
        model_device):  #Falta el id de la marca y del tipo de dispositivo!!!

    #evaluate if exists the model in data base...
    query = "select * from modelo where nom_modelo = '%s'" % model_device
    if Query.ExistElementInDB(query) != 0:  #exists in db...
        id_model = 0
        #insert model in data base...
        id_model = Query.GetMaxIDinTable(
            'modelo',
            'id_modelo')  #falta agregar el tipo de dispositivo y la marca...
        if id_model == None:
            id_model = 1

        else:
            id_model += 1
        query = "insert into modelo values (%d, %d, %d, '%s')" % (
            id_model, 0, 0, model_device)
        Query.InsertDBWithOutMessage(query)