Beispiel #1
0
 def set_filestate(self, filename, filestate):
     session = DBSession()
     single_record = session.query(clt_filelist).filter_by(
         file_name=filename).first()
     if single_record.State == 'I':
         single_record.State = filestate
         session.commit()
     else:
         print("状态无需修改")
Beispiel #2
0
 def __unique_file(self, filename):
     session = DBSession()
     db_result = session.query(clt_filelist).filter_by(
         file_name=filename).first()
     db_result_his = session.query(clt_filelist_his).filter_by(
         file_name=filename).first()
     # 判断数据文件是否已经入库,重复不入库
     if db_result is None and db_result_his is None:
         return True
Beispiel #3
0
    def move_file(self, filename, bakpath):
        # 读取数据库中已经处理完成的记录,转移文件记录到历史表,文件转移到备份目录
        session = DBSession()
        clt_filelist_check = session.query(clt_filelist).filter(
            clt_filelist.file_name == filename).filter(
                clt_filelist.State == 'O').first()
        if clt_filelist_check is not None:
            clt_filelist_his_record = clt_filelist_his(
                file_name=clt_filelist_check.file_name,
                file_path=BACKUP,
                file_type=clt_filelist_check.file_type,
                file_time=datetime.datetime.now().strftime('%Y%m%d%H%M%S'),
                State=clt_filelist_check.State)
        else:
            print("没有找到处理完的记录")
        session.delete(clt_filelist_check)
        session.add(clt_filelist_his_record)
        session.commit()

        try:
            shutil.move(
                os.path.join(clt_filelist_check.file_path,
                             clt_filelist_check.file_name), BACKUP)
        except Exception as e:
            print("文件移动失败", e)
Beispiel #4
0
 def set_filetype(self, filename):
     #根据文件名设定文件类型
     session = DBSession()
     db_filetype = session.query(file_type).all()
     typedict = {}
     for i in db_filetype:
         typedict[i.filter] = i.file_type
     session.close()
     for key in typedict:
         if key in filename:
             self.__filetype = typedict[key]
             break
Beispiel #5
0
 def my_command(self, command, file):
     session = DBSession()
     my_python = session.query(python_script).all()
     for i in my_python:
         if i.script_name == command:
             my_python_script = i.script_context
             my_argument = i.argument
             my_scriptname = i.script_name
             break
     my_board = session.query(board_info).filter(
         board_info.Client_id == self.__my_id).first()
     session.close()
     if my_board.SerialNumber is None:
         print("我没有序列号,无法定位我的机器")
     else:
         self.__my_uniquehash = hashlib.md5(
             my_board.SerialNumber.encode('utf-8')).hexdigest()
         self.__my_python_script = my_python_script
         self.__scriptname = my_scriptname
         self.__my_argument = my_argument
         self.__file = file
         if command in ['reboot', 'shutdown']:
             self.__control()
         elif command in ['sendfile']:
             self.__send_file()
Beispiel #6
0
def edit(script_id):
    scriptform=ScriptForm()
    my_scriptid=script_id
    session=DBSession()
    script = session.query(python_script).filter_by(id=my_scriptid).first()
    if scriptform.validate_on_submit():
        script.script_name=scriptform.ScriptName.data
        script.argument=scriptform.Arg.data
        script.script_context=scriptform.Context.data
        session.commit()
        session.close()
        return render_template('editscript.html',scriptform=scriptform)
    scriptform.ScriptName.data=script.script_name
    scriptform.Arg.data=script.argument
    scriptform.Context.data=script.script_context

    session.close()
    return render_template('editscript.html',scriptform=scriptform)
def mv_load_pid():

    #打开一个数据库Session
    session = DBSession()

    try:
        mv_load_file=LoadFile(WORKPATH)

        #获取P类型记录
        PID_File_List=mv_load_file.get_filelist('P')
    except Exception as e:
        print("获取pid文件失败",e)

    #开始一个循环,录入所有的文件内容
    for single_file in PID_File_List:

        #获取文件头,客户端ID
        Client_id = single_file.file_name.split('_')[0]

        #打开文件
        with open(os.path.join(WORKPATH, single_file.file_name), 'r') as f:
            pid_info_list = yaml.load(f.read())
            for single_record in pid_info_list:

                #开始把记录载入数据库
                new_pid_record = pid_info(Client_id=Client_id,
                                          Collection_time=single_record['Collection_time'],
                                          PID=single_record['PID'],
                                          memory_percent=single_record['memory_percent'],
                                          cpu_percent=single_record['cpu_percent'],
                                          proc_name=single_record['proc_name'],
                                          proc_exe=single_record['proc_exe']
                                          )

                #开始提交记录
                try:
                    session.add(new_pid_record)
                    session.commit()
                except Exception as e:
                    print("数据载入失败",single_record['proc_name'])

        # 整个文件处理完成后,将文件状态置为 O
        mv_load_file.set_filestate(single_file.file_name, 'O')
        # 处理完成后将记录移动到历史表中
        mv_load_file.move_file(single_file.file_name, BACKUP)

    #关闭数据库链接
    session.close()
Beispiel #8
0
def new():
    scriptform=ScriptForm()
    if scriptform.validate_on_submit():
        session=DBSession()
        script_name=scriptform.ScriptName.data
        argument=scriptform.Arg.data
        script_context=scriptform.Context.data
        new_script=python_script(script_name=script_name,argument=argument,script_context=script_context)
        session.add(new_script)
        session.commit()
        session.close()
        scriptform.ScriptName.data=''
        scriptform.Arg.data=''
        scriptform.Context.data=''
        return render_template('editscript.html',scriptform=scriptform)
    return render_template('editscript.html',scriptform=scriptform)
def mv_load_net():

    # 打开一个数据库Session
    session = DBSession()

    try:
        mv_load_file = LoadFile(WORKPATH)

        # 获取N类型记录
        Net_File_List = mv_load_file.get_filelist('N')
    except Exception as e:
        print("获取net文件失败", e)

    # 开始一个循环,录入所有的文件内容
    for single_file in Net_File_List:

        # 获取文件头,客户端ID
        Client_id = single_file.file_name.split('_')[0]

        #打开文件
        with open(os.path.join(WORKPATH, single_file.file_name), 'r') as f:
            net_dic = yaml.load(f.read())
            #开始把记录载入数据库
            new_net_record = net_info(
                Client_id=Client_id,
                Collection_time=net_dic['Collection_time'],
                IP=net_dic['IP'],
                Netmask=net_dic['Netmask'],
                MAC=net_dic['MAC'],
                Gateway=net_dic['Gateway'],
                DHCP=net_dic['DHCP'],
                DNS=net_dic['DNS'])

            # 开始提交记录
            try:
                session.add(new_net_record)
                session.commit()
            except Exception as e:
                print("数据提交失败", e)

        #整个文件处理完成后,将文件状态置为 O
        mv_load_file.set_filestate(single_file.file_name, 'O')
        #处理完成后将记录移动到历史表中
        mv_load_file.move_file(single_file.file_name, BACKUP)

        # 关闭数据库链接
    session.close()
Beispiel #10
0
def mv_load_board():

    ##打开数据库session
    session = DBSession()

    try:
        mv_load_file=LoadFile(WORKPATH)

        #获取B类型记录,B代表主板
        Board_File_List=mv_load_file.get_filelist('B')
    except Exception as e:
        print("获取board文件失败",e)




###开始循环录入各个文件内容
    for single_file in Board_File_List:
        ##根据文件名头部ID获取客户端号
        Client_id=single_file.file_name.split('_')[0]
        with open (os.path.join(WORKPATH,single_file.file_name),'r') as f:
            board_info_list=yaml.load(f.read())
            for single_record in board_info_list:

                ##开始将记录映射进数据库
                new_board_record = board_info(Client_id=Client_id,Collection_time=single_record['Collection_time'],Caption=single_record['Caption'],ConfigOptions=single_record['ConfigOptions'],
                                      CreationClassName=single_record['CreationClassName'],Description=single_record['Description'],
                                      HostingBoard=single_record['HostingBoard'],Manufacturer=single_record['Manufacturer'],
                                      Name=single_record['Name'],PoweredOn=single_record['PoweredOn'],Product=single_record['Product'],
                                      Removable=single_record['Removable'],Replaceable=single_record['Replaceable'],
                                      RequiresDaughterBoard=single_record['RequiresDaughterBoard'],SerialNumber=single_record['SerialNumber'],
                                      Status=single_record['Status'],Tag=single_record['Tag'],Version=single_record['Version'])

                ###尝试提交数据
                try:
                    session.add(new_board_record)
                    session.commit()

                except Exception as e:
                    print("数据录入失败",e)

        #整个文件处理完成后,将文件状态置为 O
        mv_load_file.set_filestate(single_file.file_name, 'O')
        #处理完成后将记录移动到历史表中
        mv_load_file.move_file(single_file.file_name,BACKUP)
    ##关闭数据库链接
    session.close()
def mv_load_srv():

    #打开一个数据库Session
    session = DBSession()

    try:
        mv_load_file = LoadFile(WORKPATH)

        #获取S类型记录
        SRV_File_List = mv_load_file.get_filelist('S')
    except Exception as e:
        print("获取SRV文件失败", e)

    #开始一个循环,录入所有的文件内容
    for single_file in SRV_File_List:

        #获取文件头,客户端ID
        Client_id = single_file.file_name.split('_')[0]

        #打开文件
        with open(os.path.join(WORKPATH, single_file.file_name), 'r') as f:
            service_info_list = yaml.load(f.read())
            for single_record in service_info_list:

                #开始把记录载入数据库
                new_service_record = service_info(
                    Client_id=Client_id,
                    Collection_time=single_record['Collection_time'],
                    srv_name=single_record['srv_name'],
                    StartMode=single_record['StartMode'],
                    State=single_record['State'])

                #开始提交记录
                try:
                    session.add(new_service_record)
                    session.commit()
                except Exception as e:
                    print("数据载入失败", single_record['srv_name'])

        #整个文件处理完成后,将文件状态置为 O
        mv_load_file.set_filestate(single_file.file_name, 'O')
        #处理完成后将记录移动到历史表中
        mv_load_file.move_file(single_file.file_name, BACKUP)

    #关闭数据库链接
    session.close()
Beispiel #12
0
def mv_load_dy_mem():

    # 打开一个数据库Session
    session = DBSession()

    try:
        mv_load_file = LoadFile(WORKPATH)

        # 获取MD类型记录
        MEM_File_List = mv_load_file.get_filelist('MD')
    except Exception as e:
        print("获取Memory文件失败", e)

    # 开始一个循环,录入所有的文件内容
    for single_file in MEM_File_List:

        # 获取文件头,客户端ID
        Client_id = single_file.file_name.split('_')[0]

        #打开文件
        with open(os.path.join(WORKPATH, single_file.file_name), 'r') as f:
            memory_dynamic_dic = yaml.load(f.read())
            #开始把记录载入数据库
            new_memory_dynamic_record = memory_dynamic_info(
                Client_id=Client_id,
                Collection_time=memory_dynamic_dic['Collection_time'],
                available=memory_dynamic_dic['available'],
                percent=memory_dynamic_dic['percent'],
                used=memory_dynamic_dic['used'],
                free=memory_dynamic_dic['free'])

            # 开始提交记录
            try:
                session.add(new_memory_dynamic_record)
                session.commit()
            except Exception as e:
                print("数据提交失败")

        #整个文件处理完成后,将文件状态置为 O
        mv_load_file.set_filestate(single_file.file_name, 'O')
        #处理完成后将记录移动到历史表中
        mv_load_file.move_file(single_file.file_name, BACKUP)

    # 关闭数据库链接
    session.close()
def mv_load_installaion():

    #打开一个数据库Session
    session = DBSession()

    try:
        mv_load_file = LoadFile(WORKPATH)

        #获取I类型记录
        Installation_File_List = mv_load_file.get_filelist('I')
    except Exception as e:
        print("获取Installation文件失败", e)

    # 开始一个循环,录入所有的文件内容
    for single_file in Installation_File_List:

        #获取文件头,客户端ID
        Client_id = single_file.file_name.split('_')[0]

        # 打开文件
        with open(os.path.join(WORKPATH, single_file.file_name), 'r') as f:
            installation_info_list = yaml.load(f.read())

            for single_record_index in range(len(installation_info_list) - 1):

                #开始把记录载入数据库
                new_installation_record = installation_info(
                    Client_id=Client_id,
                    Collection_time=installation_info_list[-1],
                    software=installation_info_list[single_record_index])

                # 开始提交记录
                # try:
                session.add(new_installation_record)
                session.commit()
                # except Exception as e:
                #     print("数据提交失败")

        #整个文件处理完成后,将文件状态置为 O
        mv_load_file.set_filestate(single_file.file_name, 'O')
        #处理完成后将记录移动到历史表中
        mv_load_file.move_file(single_file.file_name, BACKUP)

    # 关闭数据库链接
    session.close()
Beispiel #14
0
    def load_file(self, filename):

        if self.__unique_file(filename):
            session = DBSession()
            clt_file_new_record = clt_filelist(
                file_name=filename,
                file_path=self.__filepath,
                file_type=self.__filetype,
                file_time=datetime.datetime.now().strftime('%Y%m%d%H%M%S'),
                State='I')
            try:
                session.add(clt_file_new_record)
                session.commit()
            except Exception as e:
                print("录入数据库失败", e)
        else:
            print("文件重复,不录入")
Beispiel #15
0
 def get_filelist(self, filetype):
     session = DBSession()
     get_filelist = session.query(clt_filelist).filter(
         clt_filelist.State == 'I').filter(
             clt_filelist.file_type == filetype)
     return get_filelist
def mv_load_cpu():

    #打开一个数据库Session
    session = DBSession()

    try:
        mv_load_file = LoadFile(WORKPATH)

        # 获取C类型记录,C代表CPU
        CPU_File_List = mv_load_file.get_filelist('C')
    except Exception as e:
        print("获取CPU文件失败", e)

    #开始一个循环,录入所有的文件内容
    for single_file in CPU_File_List:

        #获取文件头,客户端ID
        Client_id = single_file.file_name.split('_')[0]

        #打开文件
        with open(os.path.join(WORKPATH, single_file.file_name), 'r') as f:
            cpu_info_list = yaml.load(f.read())
            for single_record in cpu_info_list:

                #开始把记录载入数据库
                new_cpu_record = cpu_info(Client_id=Client_id, Collection_time=single_record['Collection_time'],AddressWidth=single_record['AddressWidth'],
                                          Architecture=single_record['Architecture'],
                                          AssetTag=single_record['AssetTag'],
                                          Availability=single_record['Availability'],
                                          Caption=single_record['Caption'],
                                          Characteristics=single_record['Characteristics'],
                                          CpuStatus=single_record['CpuStatus'],
                                          CreationClassName=single_record['CreationClassName'],
                                          CurrentClockSpeed=single_record['CurrentClockSpeed'],
                                          CurrentVoltage=single_record['CurrentVoltage'],
                                          DataWidth=single_record['DataWidth'],
                                          Description=single_record['Description'],
                                          DeviceID=single_record['DeviceID'],
                                          ExtClock=single_record['ExtClock'],
                                          Family=single_record['Family'],
                                          L2CacheSize=single_record['L2CacheSize'],
                                          L3CacheSize=single_record['L3CacheSize'],
                                          L3CacheSpeed=single_record['L3CacheSpeed'],
                                          Level=single_record['Level'],
                                          LoadPercentage=single_record['LoadPercentage'],
                                          Manufacturer=single_record['Manufacturer'],
                                          MaxClockSpeed=single_record['MaxClockSpeed'],
                                          Name=single_record['Name'],
                                          NumberOfCores=single_record['NumberOfCores'],
                                          NumberOfEnabledCore=single_record['NumberOfEnabledCore'],
                                          NumberOfLogicalProcessors=single_record['NumberOfLogicalProcessors'],
                                          PartNumber=single_record['PartNumber'],
                                          PowerManagementSupported=single_record['PowerManagementSupported'],
                                          ProcessorId=single_record['ProcessorId'],
                                          ProcessorType=single_record['ProcessorType'],
                                          Revision=single_record['Revision'],
                                          Role=single_record['Role'],
                                          SecondLevelAddressTranslationExtensions=single_record['SecondLevelAddressTranslationExtensions'],
                                          SerialNumber=single_record['SerialNumber'],
                                          SocketDesignation=single_record['SocketDesignation'],
                                          Status=single_record['Status'],
                                          StatusInfo=single_record['StatusInfo'],
                                          SystemCreationClassName=single_record['SystemCreationClassName'],
                                          SystemName=single_record['SystemName'],
                                          ThreadCount=single_record['ThreadCount'],
                                          UpgradeMethod=single_record['UpgradeMethod'],
                                          Version=single_record['Version'],
                                          VirtualizationFirmwareEnabled=single_record['VirtualizationFirmwareEnabled'],
                                          VMMonitorModeExtensions=single_record['VMMonitorModeExtensions']
                                          )

                #开始提交记录
                try:
                    session.add(new_cpu_record)
                    session.commit()
                except Exception as e:
                    print("数据载入失败",e)

        #整个文件处理完成后,将文件状态置为 O
        mv_load_file.set_filestate(single_file.file_name, 'O')
        #处理完成后将记录移动到历史表中
        mv_load_file.move_file(single_file.file_name,BACKUP)

    #关闭数据库链接
    session.close()
Beispiel #17
0
def mv_load_st_mem():

    #打开一个数据库Session
    session = DBSession()

    try:
        mv_load_file = LoadFile(WORKPATH)

        #获取MS类型记录
        MEM_File_List = mv_load_file.get_filelist('MS')
    except Exception as e:
        print("获取Memory文件失败", e)

    # 开始一个循环,录入所有的文件内容
    for single_file in MEM_File_List:

        #获取文件头,客户端ID
        Client_id = single_file.file_name.split('_')[0]

        # 判断是否是静态信息文件,如果是,则录入静态信息表
        with open(os.path.join(WORKPATH, single_file.file_name), 'r') as f:
            memory_static_info_list = yaml.load(f.read())

            for single_record in memory_static_info_list:

                #开始把记录载入数据库
                new_memory_static_record = memory_static_info(
                    Client_id=Client_id,
                    Attributes=single_record['Attributes'],
                    BankLabel=single_record['BankLabel'],
                    Capacity=single_record['Capacity'],
                    Caption=single_record['Caption'],
                    ConfiguredClockSpeed=single_record['ConfiguredClockSpeed'],
                    CreationClassName=single_record['CreationClassName'],
                    DataWidth=single_record['DataWidth'],
                    Description=single_record['Description'],
                    DeviceLocator=single_record['DeviceLocator'],
                    FormFactor=single_record['FormFactor'],
                    InterleaveDataDepth=single_record['InterleaveDataDepth'],
                    InterleavePosition=single_record['InterleavePosition'],
                    Manufacturer=single_record['Manufacturer'],
                    MemoryType=single_record['MemoryType'],
                    Name=single_record['Name'],
                    PartNumber=single_record['PartNumber'],
                    PositionInRow=single_record['PositionInRow'],
                    SerialNumber=single_record['SerialNumber'],
                    SMBIOSMemoryType=single_record['SMBIOSMemoryType'],
                    Speed=single_record['Speed'],
                    Tag=single_record['Tag'],
                    TotalWidth=single_record['TotalWidth'],
                    TypeDetail=single_record['TypeDetail'])

                # 开始提交记录
                try:
                    session.add(new_memory_static_record)
                    session.commit()
                except Exception as e:
                    print("数据提交失败")
        #整个文件处理完成后,将文件状态置为 O
        mv_load_file.set_filestate(single_file.file_name, 'O')
        #处理完成后将记录移动到历史表中
        mv_load_file.move_file(single_file.file_name, BACKUP)

    ##关闭数据库链接
    session.close()