def getHostOsDetailsFromRegistry(self): ' -> HostDo' hostDo = HostDo() hostOsName = queryRegistry(self.shell, HostDiscovererByShell.KEY_NAME_WIN_VERSION, 'ProductName') currentVersion = queryRegistry( self.shell, HostDiscovererByShell.KEY_NAME_WIN_VERSION, 'CurrentVersion') buildNumber = queryRegistry(self.shell, HostDiscovererByShell.KEY_NAME_WIN_VERSION, 'CurrentBuildNumber') servicePack = queryRegistry(self.shell, HostDiscovererByShell.KEY_NAME_WIN_VERSION, 'CSDVersion') if hostOsName: (vendor, name, install_type) = separateCaption(hostOsName) hostDo.hostOsName = name hostDo.installType = install_type hostDo.vendor = vendor if currentVersion and buildNumber: hostDo.ntVersion = '%s.%s' % (currentVersion, buildNumber) hostDo.buildNumber = buildNumber hostDo.servicePack = __parseServicePack(servicePack) return hostDo
def getHostOsDetailsFromCmd(self): hostDo = HostDo() hostOsName = None ntVersion = None strWindowsVersion = self.langBund.getString( 'windows_ver_str_version') + ' ' ver = self.shell.execCmd( 'ver', useCache=1) #@@CMD_PERMISION ntcmd protocol execution if ver: m = re.match("(.*)\s+\[.*\s+(.*)\]", ver) if m: ntVersion = m.group(2) hostOsName = m.group(1).strip() else: startIndex = ver.find(strWindowsVersion) if (startIndex > 0): hostOsName = ver[:startIndex] ntVersion = ver[startIndex:] else: hostOsName = ver ntVersion = self.__standardizeVersion(ntVersion) hostDo.hostOsName = hostOsName hostDo.ntVersion = ntVersion return hostDo
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
def getOperatingSystemInfo(self): '''@types: -> HostDo @raise Exception: if wmi query failed''' hostDo = HostDo() queryBuilder = self._wmiProvider.getBuilder('Win32_OperatingSystem') queryBuilder.addWmiObjectProperties('Caption', 'otherTypeDescription', 'Version', 'BuildNumber', 'csdversion', 'lastBootUpTime', 'registeredUser', 'totalVisibleMemorySize', 'organization') osDataList = self._wmiProvider.getAgent().getWmiData(queryBuilder) for osData in osDataList: if osData.Caption: otherTypeDescription = osData.otherTypeDescription if not otherTypeDescription: otherTypeDescription = None (vendor, name, installType) = separateCaption( self.__normalizeWindowsOSAndType(osData.Caption), self.__normalizeWindowsOSAndType(otherTypeDescription)) hostDo.hostOsName = name hostDo.installType = installType hostDo.vendor = vendor hostDo.registeredOwner = osData.registeredUser hostDo.physicalMemory = osData.totalVisibleMemorySize hostDo.organization = osData.organization else: logger.warn( "Caption field is empty. Host OS name, installation type and vendor will not be parsed out." ) if osData.Version: hostDo.ntVersion = self.__normalizeWindowsOSAndType( osData.Version) else: logger.warn('Version field is empty. Skipping.') if osData.csdversion: hostDo.servicePack = __parseServicePack( self.__normalizeWindowsOSAndType(osData.csdversion)) else: logger.warn('Service pack field is empty. Skipping.') if osData.BuildNumber: hostDo.buildNumber = osData.BuildNumber else: logger.warn('Build number filed is empty. Skipping') try: hostDo.lastBootDate = modeling.getDateFromUtcString( osData.lastBootUpTime) except: logger.warn("Failed to parse last boot date from value '%s'" % osData.lastBootUpTime) return hostDo
def getHostOsDetailsFromProdspecFile(self): #@raise Exception: hostDo = HostDo() resultBuffer = self.shell.safecat('%systemroot%\system32\prodspec.ini') if resultBuffer: matcher = re.search('\n\s*Product=(.+?)\n', resultBuffer) if matcher: prodspec = matcher.group(1).strip() (vendor, name, install_type) = separateCaption(prodspec) hostDo.installType = install_type or prodspec hostDo.hostOsName = name hostDo.vendor = vendor else: #raise Exception ? logger.warn('Failed to discover OS install type.') return hostDo
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
def __init__(self, shell, langBund=None, Framework=None, hostDo=None): self.shell = shell self.langBund = langBund self.framework = Framework self.hostDo = hostDo or HostDo()
def discover(self): hostDo = HostDo() try: hostDo = self.getOperatingSystemInfo() except Exception, ex: logger.warn('Failed getting OS details. %s' % ex.message)