def registryLookup(procToPortDict, dbInstanceDict, localClient, wmiRegistryClient): try: # Store all found listening Port activeListenerPorts = [] for pid in procToPortDict.keys(): activeListenerPorts.append( (procToPortDict[pid])[dbconnect_utils.PORT_INDEX]) ## Locals logger.debug('Initial dbInstanceDict %s' % dbInstanceDict) instanceNameList = [] installNameTointernalInstanceName = {} # If SQL Server is present on this box, get instance names installedInstancesKeypath = 'SOFTWARE\\Microsoft\\Microsoft SQL Server' installedInstances = dbconnect_utils.getRegValues( localClient, wmiRegistryClient, installedInstancesKeypath, 'InstalledInstances') if installedInstances == None or str( installedInstances) == '[[], []]' or str( installedInstances) == '{}': if dbInstanceDict != None and len(dbInstanceDict) > 0: instancesString = '' for dbName in dbInstanceDict.keys(): instancesString = instancesString + dbName.upper() + '\n' installedInstances = {} installedInstances.update( {installedInstancesKeypath: instancesString[:-1]}) # chop last \n else: dbconnect_utils.debugPrint( 2, '[' + SCRIPT_NAME + ':registryLookup] SQL Server not installed on this box') return None logger.debug("Discovered installed instances %s" % installedInstances) if installedInstances: ## We have SQL Server dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] SQL Server present on this box <%s>' % installedInstances) installedInstanceNames = installedInstances[ installedInstancesKeypath] if installedInstanceNames.find( '\n') > 0 or installedInstanceNames.find(' _ ') > 0: ## Multiple SQL Server instances installedIstanceNameList = re.split(' _ |\n', installedInstanceNames) else: installedIstanceNameList = [installedInstanceNames] logger.debug('Installed instance name list %s' % installedIstanceNameList) for installedInstanceName in installedIstanceNameList: instanceNameList.append(installedInstanceName.strip()) dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Found SQL Server instance <%s>' % installedInstanceName.strip()) internalInstanceNameKeyPath = 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL' internalInstanceNameDict = dbconnect_utils.getRegValues( localClient, wmiRegistryClient, internalInstanceNameKeyPath, installedInstanceName) internalInstanceName = internalInstanceNameDict[ internalInstanceNameKeyPath] if internalInstanceName: dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Found registry name <%s> for internal SQL instance name <%s>' % (internalInstanceName, installedInstanceName)) installNameTointernalInstanceName[ installedInstanceName.strip( )] = internalInstanceName.strip() else: installNameTointernalInstanceName[ installedInstanceName.strip( )] = installedInstanceName.strip() logger.debug("installNameTointernalInstanceName %s" % installNameTointernalInstanceName) logger.debug("instanceNameList %s " % instanceNameList) # If we're here, one or more SQL Server instances are present # Look for additional SQL Server information sqlServerDetailKeypaths = [ 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\MSSQLServer\\SuperSocketNetLib\\Tcp', 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\Setup', 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\MSSQLServer\\CurrentVersion', 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\Cluster', 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\Cluster' ] sqlServerDetailFilters = [ 'TcpPort', 'SQLPath', 'CurrentVersion', 'ClusterIpAddr', 'ClusterName' ] for instanceName in instanceNameList: sqlServerDetailValues = [] for sqlServerDetailIndex in range(len(sqlServerDetailKeypaths)): sqlServerDetailKeypath = '' ## Replace instance names in registry key path as appropriate if instanceName == 'MSSQLSERVER': if sqlServerDetailKeypaths[sqlServerDetailIndex].find( 'luster') > 0: sqlServerDetailKeypath = string.replace( sqlServerDetailKeypaths[sqlServerDetailIndex], 'iNsTaNcEnAmE', installNameTointernalInstanceName.get( instanceName)) else: sqlServerDetailKeypath = string.replace( sqlServerDetailKeypaths[sqlServerDetailIndex], 'Microsoft SQL Server\\iNsTaNcEnAmE', 'MSSQLServer') else: if sqlServerDetailKeypaths[sqlServerDetailIndex].find( 'luster') > 0: sqlServerDetailKeypath = string.replace( sqlServerDetailKeypaths[sqlServerDetailIndex], 'iNsTaNcEnAmE', installNameTointernalInstanceName.get( instanceName)) else: sqlServerDetailKeypath = string.replace( sqlServerDetailKeypaths[sqlServerDetailIndex], 'iNsTaNcEnAmE', instanceName) regValues = dbconnect_utils.getRegValues( localClient, wmiRegistryClient, sqlServerDetailKeypath, sqlServerDetailFilters[sqlServerDetailIndex]) if regValues == None or str(regValues) == '[[], []]' or str( regValues) == '{}': dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Got nothing for key <%s> with filter <%s>' % (sqlServerDetailKeypath, sqlServerDetailFilters[sqlServerDetailIndex])) sqlServerDetailValues.insert(sqlServerDetailIndex, None) else: sqlServerDetailValues.insert( sqlServerDetailIndex, regValues[sqlServerDetailKeypath]) dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Got value <%s> for key <%s> with filter <%s>' % (sqlServerDetailValues[sqlServerDetailIndex], sqlServerDetailKeypath, sqlServerDetailFilters[sqlServerDetailIndex])) logger.debug("instanceNameList %s " % instanceNameList) ## We should have all details for this instance now - add it to DB dictionary listenerPort = sqlServerDetailValues[0] dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Got port <%s> for instance <%s>' % (listenerPort, instanceName)) installPath = sqlServerDetailValues[1] dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Got path <%s> for instance <%s>' % (installPath, instanceName)) version = sqlServerDetailValues[2] dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Got version <%s> for instance <%s>' % (version, instanceName)) ipAddress = dbconnect_utils.fixIP(sqlServerDetailValues[3], localClient.getIpAddress()) dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Got IP <%s> for instance <%s>' % (ipAddress, instanceName)) clusterName = sqlServerDetailValues[4] dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Got Cluster Name <%s> for instance <%s>' % (clusterName, instanceName)) if clusterName: clusterIp = netutils.getHostAddress(clusterName) if clusterIp and netutils.isValidIp(clusterIp): ipAddress = clusterIp ## If the instance is already in the DB dict, don't overwrite all values if instanceName == 'MSSQLSERVER': dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Got unnamed SQL Server instance') instanceName = dbconnect_utils.getServerName(localClient) else: instanceName = dbconnect_utils.getServerName( localClient) + '\\' + instanceName.lower() installPath = installPath.lower() if instanceName in dbInstanceDict.keys(): statusFlag = ( dbInstanceDict[instanceName])[dbconnect_utils.STATUS_INDEX] # If port is already populated, don't overwrite it because # port number information from active processes (above) is # guaranteed to be correct and the registry may not be up-to-date if (dbInstanceDict[instanceName] )[dbconnect_utils.PORT_INDEX] != dbconnect_utils.UNKNOWN: if listenerPort not in activeListenerPorts: listenerPort = (dbInstanceDict[instanceName] )[dbconnect_utils.PORT_INDEX] dbInstanceDict[instanceName] = [ 'MicrosoftSQLServer', listenerPort, ipAddress, installPath, version, statusFlag ] dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Found known SQL Server <%s> instance <%s> listening at port <%s> on <%s> and installed in <%s>' % (version, instanceName, listenerPort, ipAddress, installPath)) else: dbInstanceDict[instanceName] = [ 'MicrosoftSQLServer', listenerPort, ipAddress, installPath, version, dbconnect_utils.UNKNOWN ] dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Added SQL Server <%s> instance <%s> listening at port <%s> on <%s> and installed in <%s>' % (version, instanceName, listenerPort, ipAddress, installPath)) logger.debug("instanceNameList %s " % instanceNameList) logger.debug("dbInstanceDict %s" % dbInstanceDict) ## Replace dictionary entry of serverName\sqlInstanceName with clusterName\sqlInstanceName if clusterName and instanceName in dbInstanceDict.keys(): if instanceName.find('\\') > 0: newInstanceName = clusterName + '\\' + instanceName[ instanceName.find('\\') + 1:] else: newInstanceName = clusterName dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Replacing SQL Server instance <%s> with <%s> because it is part of a cluster' % (instanceName, newInstanceName)) dbInstanceDict[newInstanceName] = dbInstanceDict[instanceName] del dbInstanceDict[instanceName] logger.debug("dbInstanceDict %s" % dbInstanceDict) #print dbInstanceDict logger.debug("instanceNameList %s " % instanceNameList) except: excInfo = logger.prepareJythonStackTrace('') dbconnect_utils.debugPrint('[' + SCRIPT_NAME + ':registryLookup] Exception: <%s>' % excInfo) pass
def registryLookup(procToPortDict, dbInstanceDict, localClient, wmiRegistryClient): try: # Store all found listening Port activeListenerPorts = [] for pid in procToPortDict.keys(): activeListenerPorts.append((procToPortDict[pid])[dbconnect_utils.PORT_INDEX]) ## Locals logger.debug('Initial dbInstanceDict %s' % dbInstanceDict) instanceNameList = [] installNameTointernalInstanceName = {} # If SQL Server is present on this box, get instance names installedInstancesKeypath = 'SOFTWARE\\Microsoft\\Microsoft SQL Server' installedInstances = dbconnect_utils.getRegValues(localClient, wmiRegistryClient, installedInstancesKeypath, 'InstalledInstances') if installedInstances == None or str(installedInstances) == '[[], []]' or str(installedInstances) == '{}': if dbInstanceDict != None and len(dbInstanceDict) > 0: instancesString = '' for dbName in dbInstanceDict.keys(): instancesString = instancesString + dbName.upper() + '\n' installedInstances = {} installedInstances.update({installedInstancesKeypath:instancesString[:-1]}) # chop last \n else: dbconnect_utils.debugPrint(2, '[' + SCRIPT_NAME + ':registryLookup] SQL Server not installed on this box') return None logger.debug("Discovered installed instances %s" % installedInstances) if installedInstances: ## We have SQL Server dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] SQL Server present on this box <%s>' % installedInstances) installedInstanceNames = installedInstances[installedInstancesKeypath] if installedInstanceNames.find('\n') > 0 or installedInstanceNames.find(' _ ') > 0: ## Multiple SQL Server instances installedIstanceNameList = re.split(' _ |\n', installedInstanceNames) else: installedIstanceNameList = [installedInstanceNames] logger.debug('Installed instance name list %s' % installedIstanceNameList) for installedInstanceName in installedIstanceNameList: instanceNameList.append(installedInstanceName.strip()) dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Found SQL Server instance <%s>' % installedInstanceName.strip()) internalInstanceNameKeyPath = 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL' internalInstanceNameDict = dbconnect_utils.getRegValues(localClient, wmiRegistryClient, internalInstanceNameKeyPath, installedInstanceName) internalInstanceName = internalInstanceNameDict[internalInstanceNameKeyPath] if internalInstanceName: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Found registry name <%s> for internal SQL instance name <%s>' % (internalInstanceName, installedInstanceName)) installNameTointernalInstanceName[installedInstanceName.strip()] = internalInstanceName.strip() else: installNameTointernalInstanceName[installedInstanceName.strip()] = installedInstanceName.strip() logger.debug("installNameTointernalInstanceName %s" % installNameTointernalInstanceName) logger.debug("instanceNameList %s " % instanceNameList) # If we're here, one or more SQL Server instances are present # Look for additional SQL Server information sqlServerDetailKeypaths = ['SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\MSSQLServer\\SuperSocketNetLib\\Tcp', 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\Setup', 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\MSSQLServer\\CurrentVersion', 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\Cluster', 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\Cluster'] sqlServerDetailFilters = ['TcpPort', 'SQLPath', 'CurrentVersion', 'ClusterIpAddr', 'ClusterName'] for instanceName in instanceNameList: sqlServerDetailValues = [] for sqlServerDetailIndex in range(len(sqlServerDetailKeypaths)): sqlServerDetailKeypath = '' ## Replace instance names in registry key path as appropriate if instanceName == 'MSSQLSERVER': if sqlServerDetailKeypaths[sqlServerDetailIndex].find('luster') > 0: sqlServerDetailKeypath = string.replace(sqlServerDetailKeypaths[sqlServerDetailIndex], 'iNsTaNcEnAmE', installNameTointernalInstanceName.get(instanceName)) else: sqlServerDetailKeypath = string.replace(sqlServerDetailKeypaths[sqlServerDetailIndex], 'Microsoft SQL Server\\iNsTaNcEnAmE', 'MSSQLServer') else: if sqlServerDetailKeypaths[sqlServerDetailIndex].find('luster') > 0: sqlServerDetailKeypath = string.replace(sqlServerDetailKeypaths[sqlServerDetailIndex], 'iNsTaNcEnAmE', installNameTointernalInstanceName.get(instanceName)) else: sqlServerDetailKeypath = string.replace(sqlServerDetailKeypaths[sqlServerDetailIndex], 'iNsTaNcEnAmE', instanceName) regValues = dbconnect_utils.getRegValues(localClient, wmiRegistryClient, sqlServerDetailKeypath, sqlServerDetailFilters[sqlServerDetailIndex]) if regValues == None or str(regValues) == '[[], []]' or str(regValues) == '{}': dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Got nothing for key <%s> with filter <%s>' % (sqlServerDetailKeypath, sqlServerDetailFilters[sqlServerDetailIndex])) sqlServerDetailValues.insert(sqlServerDetailIndex, None) else: sqlServerDetailValues.insert(sqlServerDetailIndex, regValues[sqlServerDetailKeypath]) dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Got value <%s> for key <%s> with filter <%s>' % (sqlServerDetailValues[sqlServerDetailIndex], sqlServerDetailKeypath, sqlServerDetailFilters[sqlServerDetailIndex])) logger.debug("instanceNameList %s " % instanceNameList) ## We should have all details for this instance now - add it to DB dictionary listenerPort = sqlServerDetailValues[0] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Got port <%s> for instance <%s>' % (listenerPort, instanceName)) installPath = sqlServerDetailValues[1] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Got path <%s> for instance <%s>' % (installPath, instanceName)) version = sqlServerDetailValues[2] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Got version <%s> for instance <%s>' % (version, instanceName)) ipAddress = dbconnect_utils.fixIP(sqlServerDetailValues[3], localClient.getIpAddress()) dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Got IP <%s> for instance <%s>' % (ipAddress, instanceName)) clusterName = sqlServerDetailValues[4] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Got Cluster Name <%s> for instance <%s>' % (clusterName, instanceName)) if clusterName: clusterIp = netutils.getHostAddress(clusterName) if clusterIp and netutils.isValidIp(clusterIp): ipAddress = clusterIp ## If the instance is already in the DB dict, don't overwrite all values if instanceName == 'MSSQLSERVER': dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Got unnamed SQL Server instance') instanceName = dbconnect_utils.getServerName(localClient) else: instanceName = dbconnect_utils.getServerName(localClient) + '\\' + instanceName.lower() installPath = installPath.lower() if instanceName in dbInstanceDict.keys(): statusFlag = (dbInstanceDict[instanceName])[dbconnect_utils.STATUS_INDEX] # If port is already populated, don't overwrite it because # port number information from active processes (above) is # guaranteed to be correct and the registry may not be up-to-date if (dbInstanceDict[instanceName])[dbconnect_utils.PORT_INDEX] != dbconnect_utils.UNKNOWN: if listenerPort not in activeListenerPorts: listenerPort = (dbInstanceDict[instanceName])[dbconnect_utils.PORT_INDEX] dbInstanceDict[instanceName] = ['MicrosoftSQLServer', listenerPort, ipAddress, installPath, version, statusFlag] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Found known SQL Server <%s> instance <%s> listening at port <%s> on <%s> and installed in <%s>' % (version, instanceName, listenerPort, ipAddress, installPath)) else: dbInstanceDict[instanceName] = ['MicrosoftSQLServer', listenerPort, ipAddress, installPath, version, dbconnect_utils.UNKNOWN] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Added SQL Server <%s> instance <%s> listening at port <%s> on <%s> and installed in <%s>' % (version, instanceName, listenerPort, ipAddress, installPath)) logger.debug("instanceNameList %s " % instanceNameList) logger.debug("dbInstanceDict %s" % dbInstanceDict) ## Replace dictionary entry of serverName\sqlInstanceName with clusterName\sqlInstanceName if clusterName and instanceName in dbInstanceDict.keys(): if instanceName.find('\\') > 0 : newInstanceName = clusterName + '\\' + instanceName[instanceName.find('\\')+1:] else: newInstanceName = clusterName dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Replacing SQL Server instance <%s> with <%s> because it is part of a cluster' % (instanceName, newInstanceName)) dbInstanceDict[newInstanceName] = dbInstanceDict[instanceName] del dbInstanceDict[instanceName] logger.debug("dbInstanceDict %s" % dbInstanceDict) #print dbInstanceDict logger.debug("instanceNameList %s " % instanceNameList) except: excInfo = logger.prepareJythonStackTrace('') dbconnect_utils.debugPrint('[' + SCRIPT_NAME + ':registryLookup] Exception: <%s>' % excInfo) pass
def getProcListByWMI(localClient, wmiRegistryClient): try: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':getProcListByWMI]') procToPortDict = {} HOST_IP = localClient.getIpAddress() ## Not using WMI HR scripts since they are not split into a main discovery and ## utils script. Using them will result in those discoveries being executed for ## this destination and host resource data will be added to the CMDB ## Get a list of processes try: resultSet = localClient.executeQuery('SELECT name, processid, executablepath, commandline FROM Win32_Process') while resultSet.next(): ## Name processName = resultSet.getString(1).strip() if processName == None or processName == '' or len(processName) <1: ## We don't care about nameless processes continue pid = resultSet.getString(2).strip() ## PID processPath = resultSet.getString(3).strip() ## Path processPath = string.replace(processPath, '"', '') processCmdline = resultSet.getString(4).strip() ## Command line processCmdline = string.replace(processCmdline, '"', '') ## Add this to the dictionary dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':getProcListByWMI] Got PROCESS <%s:%s> with path <%s> and command line <%s>' % (pid, processName, processPath, processCmdline)) ## {PID:[processName, listeningPort, ipAddress, path, version, status, processCommandline]} # procToPortDict[pid] = [processName, dbconnect_utils.UNKNOWN, HOST_IP, processPath, dbconnect_utils.UNKNOWN, 'Running', processCmdline] if dbconnect_utils.populateProcToPortDict(procToPortDict, pid, processName, dbconnect_utils.UNKNOWN, dbconnect_utils.UNKNOWN, processPath, dbconnect_utils.UNKNOWN, 'Running', processCmdline) == 0: logger.debug('[' + SCRIPT_NAME + ':getProcToPortDictOnWindows] Unable to add PROCESS <%s:%s> (%s) with path <%s> and command line <%s> to the procToPort dictionary' % (pid, processName, 'Running', processPath, processCmdline)) except: excInfo = logger.prepareJythonStackTrace('') logger.debug('[' + SCRIPT_NAME + ':getProcListByWMI] Unable to get a list of proceses: <%s>' % excInfo) pass ## Get a list of services try: resultSet = localClient.executeQuery('SELECT displayname, processid, pathname, started FROM Win32_Service') fakePid = 0 while resultSet.next(): ## Name serviceName = resultSet.getString(1).strip() if serviceName == None or serviceName == '' or len(serviceName) <1: ## We don't care about nameless services continue pid = resultSet.getString(2).strip() ## PID if pid == '0': pid = 'SERVICE ' + str(fakePid) fakePid = fakePid + 1 dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':getProcListByWMI] Using fake PID <%s> for service <%s>' % (pid, serviceName)) servicePath = resultSet.getString(3).strip() ## Path servicePath = string.replace(servicePath, '"', '') serviceStatus = resultSet.getString(4).strip() ## Status if serviceStatus.lower() == 'true': serviceStatus = 'Running' else: serviceStatus = 'Not Running' serviceCmdline = servicePath ## Add this to the dictionary dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':getProcListByWMI] Got SERVICE <%s:%s> (%s) with path <%s> and command line <%s>' % (pid, serviceName, serviceStatus, servicePath, serviceCmdline)) ## {PID:[serviceName, listeningPort, ipAddress, path, version, status, processCommandline]} # procToPortDict[pid] = [serviceName, dbconnect_utils.UNKNOWN, HOST_IP, servicePath, dbconnect_utils.UNKNOWN, serviceStatus, serviceCmdline] if dbconnect_utils.populateProcToPortDict(procToPortDict, pid, serviceName, dbconnect_utils.UNKNOWN, HOST_IP, servicePath, dbconnect_utils.UNKNOWN, serviceStatus, serviceCmdline) == 0: logger.debug('[' + SCRIPT_NAME + ':getProcListByWMI] Unable to add SERVICE <%s:%s> (%s) with path <%s> and command line <%s> to the procToPort dictionary' % (pid, serviceName, serviceStatus, servicePath, serviceCmdline)) except: excInfo = logger.prepareJythonStackTrace('') logger.debug('[' + SCRIPT_NAME + ':getProcListByWMI] Unable to get a list of services: <%s>' % excInfo) pass ## Get a list of installed software try: fakePid = 0 regKeypath = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall' swNames = dbconnect_utils.getRegValues(localClient, wmiRegistryClient, regKeypath, 'DisplayName') swPaths = dbconnect_utils.getRegValues(localClient, wmiRegistryClient, regKeypath, 'UninstallString') swVersions = dbconnect_utils.getRegValues(localClient, wmiRegistryClient, regKeypath, 'DisplayVersion') for swName in swNames.keys(): swName = swNames.get(swName) swPath = swPaths.get(swName) swVersion = swVersions.get(swName) pid = 'SOFTWARE ' + str(fakePid) fakePid = fakePid + 1 ## Add this to the dictionary dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':getProcListByWMI] Got SOFTWARE <%s:%s> with path <%s> and version <%s>' % (pid, swName, swPath, swVersion)) ## {PID:[serviceName, listeningPort, ipAddress, path, version, status, processCommandline]} if dbconnect_utils.populateProcToPortDict(procToPortDict, pid, swName, dbconnect_utils.UNKNOWN, HOST_IP, swPath, swVersion, dbconnect_utils.UNKNOWN, dbconnect_utils.UNKNOWN) == 0: logger.debug('[' + SCRIPT_NAME + ':getProcListByWMI] Unable to add SOFTWARE <%s:%s> with path <%s> and version <%s>' % (pid, swName, swPath, swVersion)) except: excInfo = logger.prepareJythonStackTrace('') logger.debug('[' + SCRIPT_NAME + ':getProcListByWMI] Unable to get a list of software: <%s>' % excInfo) pass ## Should have proc to port map if len(procToPortDict) > 0: dbconnect_utils.debugPrint(2, '[' + SCRIPT_NAME + ':getProcListByWMI] Returning process to port dictionary with <%s> items' % len(procToPortDict)) return procToPortDict else: dbconnect_utils.debugPrint(2, '[' + SCRIPT_NAME + ':getProcListByWMI] Returning EMPTY process to port dictionary') return None except: excInfo = logger.prepareJythonStackTrace('') dbconnect_utils.debugPrint('[' + SCRIPT_NAME + ':getProcListByWMI] Exception: <%s>' % excInfo) pass