예제 #1
0
 def getSystemInfo(self):
     ''' Get general system info (manufacturer, name, model and domain)
     If host is not in domain, WORKGROUP name will be returned instead of
     domain.
     @note: Host name can be shorter than original due to AD restrictions,
     only 15 symbols. Recommended to use discoverHostInfo method
     @types: -> HostDo
     @raise Exception: WMI query failed
     '''
     queryBuilder = self._wmiProvider.getBuilder('Win32_ComputerSystem')
     queryBuilder.addWmiObjectProperties('Manufacturer', 'Name', 'Model',
                                         'Domain', 'NumberOfProcessors')
     items = self._wmiProvider.getAgent().getWmiData(queryBuilder)
     if not items:
         raise Exception("WMI query failed. No data returned")
     host = HostDo()
     system = items[0]
     # make sure that host name will be in lower case to prevent
     # from false history changes
     host.hostName = system.Name.lower()
     host.hostManufacturer = system.Manufacturer
     host.hostModel = system.Model
     if system.Domain:
         host.osDomain = system.Domain
     if system.NumberOfProcessors:
         try:
             cpuNumber = int(system.NumberOfProcessors.strip())
             host.winProcessorsNumber = cpuNumber
         except:
             logger.warn('Number of processors value is not an integer'
                         ' type: %s' % system.NumberOfProcessors)
     return host
예제 #2
0
 def getSystemInfo(self):
     ''' Get general system info (manufacturer, name, model and domain)
     If host is not in domain, WORKGROUP name will be returned instead of
     domain.
     @note: Host name can be shorter than original due to AD restrictions,
     only 15 symbols. Recommended to use discoverHostInfo method
     @types: -> HostDo
     @raise Exception: WMI query failed
     '''
     queryBuilder = self._wmiProvider.getBuilder('Win32_ComputerSystem')
     queryBuilder.addWmiObjectProperties('Manufacturer', 'Name', 'Model',
                                         'Domain', 'NumberOfProcessors')
     items = self._wmiProvider.getAgent().getWmiData(queryBuilder)
     if not items:
         raise Exception("WMI query failed. No data returned")
     host = HostDo()
     system = items[0]
     # make sure that host name will be in lower case to prevent
     # from false history changes
     host.hostName = system.Name.lower()
     host.hostManufacturer = system.Manufacturer
     host.hostModel = system.Model
     if system.Domain:
         host.osDomain = system.Domain
     if system.NumberOfProcessors:
         try:
             cpuNumber = int(system.NumberOfProcessors.strip())
             host.winProcessorsNumber = cpuNumber
         except:
             logger.warn('Number of processors value is not an integer'
                         ' type: %s' % system.NumberOfProcessors)
     return host
예제 #3
0
    def getModelAndBiosUuid(self):
        '''@types: -> HostDo
        @raise Exception: WMI query failed
        '''
        convertToMicrosoftStandart = GeneralSettingsConfigFile.getInstance().getPropertyStringValue('setBiosUuidToMicrosoftStandart', 'false')

        hostDo = HostDo()
        queryBuilder = self._wmiProvider.getBuilder('win32_ComputerSystemProduct')
        queryBuilder.addWmiObjectProperties('uuid', 'name')
        computerProductList = self._wmiProvider.getAgent().getWmiData(queryBuilder)
        for computerProduct in computerProductList:
            if computerProduct.uuid:
                if (re.match(r"(0{8}-0{4}-0{4}-0{4}-0{12})", computerProduct.uuid) or
                     re.match(r"([fF]{8}-[fF]{4}-[fF]{4}-[fF]{4}-[fF]{12})", computerProduct.uuid)):
                    logger.debug('Invalid UUID was received. Skipping.')
                    continue
                if convertToMicrosoftStandart.lower() == 'false':
                    #returned 00010203-0405-0607-0809-0a0b0c0d0e0f
                    #should be 03020100-0504-0706-0809-0a0b0c0d0e0f
                    byteStyle = re.match(r"(\w{2})(\w{2})(\w{2})(\w{2})\-(\w{2})(\w{2})-(\w{2})(\w{2})(.*)", computerProduct.uuid)
                    if byteStyle:
                        group1 = byteStyle.group(4) + byteStyle.group(3) + byteStyle.group(2) + byteStyle.group(1)
                        group2 = byteStyle.group(6) + byteStyle.group(5)
                        group3 = byteStyle.group(8) + byteStyle.group(7)
                        uuidFormated = group1 + '-' + group2 + '-' + group3 + byteStyle.group(9)
                        hostDo.biosUUID = uuidFormated
                    else:
                        logger.warn('UUID is not in proper format.')
                else:
                    hostDo.biosUUID = computerProduct.uuid
                    logger.warn('BIOS UUID is reported according to Microsoft definitions since parameter setBiosUuidToMicrosoftStandart is set to True.')

            hostDo.hostModel = computerProduct.name

        return hostDo
예제 #4
0
    def getModelAndBiosUuid(self):
        '''@types: -> HostDo
        @raise Exception: WMI query failed
        '''
        convertToMicrosoftStandart = GeneralSettingsConfigFile.getInstance(
        ).getPropertyStringValue('setBiosUuidToMicrosoftStandart', 'false')

        hostDo = HostDo()
        queryBuilder = self._wmiProvider.getBuilder(
            'win32_ComputerSystemProduct')
        queryBuilder.addWmiObjectProperties('uuid', 'name')
        computerProductList = self._wmiProvider.getAgent().getWmiData(
            queryBuilder)
        for computerProduct in computerProductList:
            if computerProduct.uuid:
                if (re.match(r"(0{8}-0{4}-0{4}-0{4}-0{12})",
                             computerProduct.uuid) or re.match(
                                 r"([fF]{8}-[fF]{4}-[fF]{4}-[fF]{4}-[fF]{12})",
                                 computerProduct.uuid)):
                    logger.debug('Invalid UUID was received. Skipping.')
                    continue
                if convertToMicrosoftStandart.lower() == 'false':
                    #returned 00010203-0405-0607-0809-0a0b0c0d0e0f
                    #should be 03020100-0504-0706-0809-0a0b0c0d0e0f
                    byteStyle = re.match(
                        r"(\w{2})(\w{2})(\w{2})(\w{2})\-(\w{2})(\w{2})-(\w{2})(\w{2})(.*)",
                        computerProduct.uuid)
                    if byteStyle:
                        group1 = byteStyle.group(4) + byteStyle.group(
                            3) + byteStyle.group(2) + byteStyle.group(1)
                        group2 = byteStyle.group(6) + byteStyle.group(5)
                        group3 = byteStyle.group(8) + byteStyle.group(7)
                        uuidFormated = group1 + '-' + group2 + '-' + group3 + byteStyle.group(
                            9)
                        hostDo.biosUUID = uuidFormated
                    else:
                        logger.warn('UUID is not in proper format.')
                else:
                    hostDo.biosUUID = computerProduct.uuid
                    logger.warn(
                        'BIOS UUID is reported according to Microsoft definitions since parameter setBiosUuidToMicrosoftStandart is set to True.'
                    )

            hostDo.hostModel = computerProduct.name

        return hostDo