def getInstancePaths(localClient, isWindows, possibleInstallLocations): try: instancePaths = [] ## Prepopulate possible install locations with some common directories if len(possibleInstallLocations) < 1: if isWindows == 'true': possibleInstallLocations.append('%HOMEDRIVE%\ibm') possibleInstallLocations.append('%SYSTEMDRIVE%\ibm') possibleInstallLocations.append('%PROGRAMFILES%\ibm') possibleInstallLocations.append('%PROGRAMFILES(x86)%\ibm') possibleInstallLocations.append('%HOMEDRIVE%\db2') possibleInstallLocations.append('%SYSTEMDRIVE%\db2') possibleInstallLocations.append('%PROGRAMFILES%\db2') possibleInstallLocations.append('%PROGRAMFILES(x86)%\db2') possibleInstallLocations.append('%DB2_HOME%') possibleInstallLocations.append('%DB2HOME%') else: possibleInstallLocations.append('/u01') possibleInstallLocations.append('/u02') possibleInstallLocations.append('/opt') possibleInstallLocations.append('/usr/opt') possibleInstallLocations.append('/usr/local') possibleInstallLocations.append('$DB2_HOME') possibleInstallLocations.append('$DB2HOME') for location in possibleInstallLocations: logger.debug('location to search is: ', location) # added for debugging - Daniel La ## Search for DB2 command processor executable db2cmdLocations = [] ## DB2 command processor executable has a different name on Windows if isWindows == 'true': db2cmdLocations = dbconnect_utils.findFile(localClient, 'db2cmd.exe', location, isWindows) else: db2cmdLocations = dbconnect_utils.findFile(localClient, 'db2', location, isWindows) ## If an executable was found, check if it is indeed a DB2 ## instance and extract the install path if db2cmdLocations and len(db2cmdLocations) > 0: logger.debug('location is ', db2cmdLocations) # added for debugging - Daniel La for db2cmdLocation in db2cmdLocations: if not dbconnect_utils.isValidString(db2cmdLocation): dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':getInstancePaths] (1) DB2 command processor executable found in an invalid location <%s>! Skipping...' % location) continue if db2cmdLocation.lower().find('sqllib') > 0: logger.debug('we are here') #instancePath = db2cmdLocation[:db2cmdLocation.lower().find('sqllib')-1] # Instance path is upto the "sqllib" string minus trailing slash instancePath = '' if isWindows == 'true': instancePath = db2cmdLocation[:db2cmdLocation.rfind('\\')] else: instancePath = db2cmdLocation[:db2cmdLocation.rfind('/')] if dbconnect_utils.isValidString(instancePath) and instancePath not in instancePaths: # instanceName = '' # if isWindows == 'true': # instanceName = instancePath[instancePath.rfind('\\'):] # else: # instanceName = instancePath[instancePath.rfind('/'):] # if dbconnect_utils.isValidString(instanceName) and not instanceName.strip().lower() == 'ibm': ## dbDict[instanceName] = ['db2', dbconnect_utils.UNKNOWN, instancePath, dbconnect_utils.UNKNOWN, localClient.getIpAddress()] # dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':getInstancePaths] (1) Found DB2 command processor for instance <%s> at <%s>. Appending <%s> to install locations' % (instanceName, location, instancePath)) # else: # dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':getInstancePaths] (1) Found DB2 command processor at <%s> with an invalid instance name! Skipping...' % location) # continue instancePaths.append(instancePath) else: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':getInstancePaths] (1) Found DB2 command processor at <%s> already in install locations' % location) continue else: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':getInstancePaths] (1) DB2 command processor executable found in <%s> does not contain "sqllib" in its path. This is most likely not valid for DB2...skipping!' % location) continue else: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':getInstancePaths] (1) No DB2 command processor found in <%s>' % location) continue # ## Search for db2set executable # db2setLocations = dbconnect_utils.findFile(localClient, 'db2set', location, isWindows) # ## If an executable was found, check if it is indeed a DB2 # ## instance and extract the install path # if db2setLocations and len(db2setLocations) > 1: # for db2setLocation in db2setLocations: # if not dbconnect_utils.isValidString(db2setLocation): # dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':getInstancePaths] (2) db2set executable found in an invalid location...skipping!' % location) # continue # if db2setLocation.lower().find('sqllib') > 0: # instancePath = db2setLocation[:db2setLocation.lower().find('sqllib')] # if dbconnect_utils.isValidString(instancePath) and instancePath not in instancePaths: # instanceName = '' # if isWindows == 'true': # instanceName = instancePath[instancePath.rfind('\\'):] # else: # instanceName = instancePath[instancePath.rfind('/'):] # if dbconnect_utils.isValidString(instanceName): ## dbDict[instanceName] = ['db2', dbconnect_utils.UNKNOWN, instancePath, dbconnect_utils.UNKNOWN, localClient.getIpAddress()] # dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':getInstancePaths] (1) Found DB2 command processor for instance <%s> at <%s>. Appending <%s> to install locations' % (instanceName, location, instancePath)) # else: # dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':getInstancePaths] (1) Found DB2 command processor at <%s> with an invalid instance name...skipping!' % location) # continue # instancePaths.append(instancePath) # else: # dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':getInstancePaths] (2) Found db2set at <%s> already in install locations' % location) # else: # dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':getInstancePaths] (2) db2set executable found in <%s> does not contain "sqllib" in its path. This is most likely not valid for DB2...skipping!' % location) # continue # else: # dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':getInstancePaths] (2) No db2set executable found in <%s>' % location) # continue return instancePaths except: excInfo = logger.prepareJythonStackTrace('') dbconnect_utils.debugPrint('[' + SCRIPT_NAME + ':getInstancePaths] Exception: <%s>' % excInfo) pass
def findTnsnamesOra(localClient, p2pDict, dbDict, isWindows, installLocs): try: ## Locals searchLocations = [] # Try locations in the database dictionary if len(dbDict) > 0: logger.debug('dbDict locations') for sid in dbDict.keys(): if (dbDict[sid])[dbconnect_utils.PATH_INDEX] != dbconnect_utils.UNKNOWN: path = (dbDict[sid])[dbconnect_utils.PATH_INDEX].lower() if path in searchLocations: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] [1] <%s> already in search locations' % path) continue elif path.find('\\') > 0 or path.find('/') >= 0: dbconnect_utils.debugPrint(2, '[' + SCRIPT_NAME + ':findTnsnamesOra] [1] Adding <%s> to search locations' % path) searchLocations.append(path) else: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] [1] <%s> is not a valid path' % path) continue # Try locations in the p2p dictionary if len(p2pDict) > 0: logger.debug('p2pDict locations') for pid in p2pDict.keys(): processName = (p2pDict[pid])[dbconnect_utils.PROCESSNAME_INDEX].lower() path = (p2pDict[pid])[dbconnect_utils.PATH_INDEX].lower() if re.search('tns', processName) or re.search('dbconsole', processName) or re.search('jobscheduler', processName) or re.search('oradb', processName) or re.search('oracle', processName) or re.search('ora_', processName): ## Remove /bin/tnslsnr from TNS process path if re.search('/bin/tnslsnr', path): path = path[:path.find('/bin/tnslsnr')] if path in searchLocations: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] [2] <%s> already in search locations' % path) continue elif path.find('\\') > 0 or path.find('/') >= 0: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] [2] Adding <%s> to search locations' % path) searchLocations.append(path) else: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] [2] <%s> is not a valid path' % path) continue # If we have no search locations so far, try some known/standard ones if 1: #len(searchLocations) < 1: if isWindows == 'true': logger.debug('additional locations') searchLocations.append('%HOMEDRIVE%\oracle') searchLocations.append('%SYSTEMDRIVE%\oracle') searchLocations.append('%PROGRAMFILES%\oracle') searchLocations.append('%PROGRAMFILES(x86)%\oracle') searchLocations.append('%ORA_HOME%') searchLocations.append('%ORACLE_HOME%') #searchLocations.append('%ORACLE_HOME%\\network\\admin') else: searchLocations.append('/u01') searchLocations.append('/u02') searchLocations.append('/opt') searchLocations.append('/usr/local') searchLocations.append('$ORACLE_HOME') #searchLocations.append('$ORACLE_HOME/network/admin') searchLocations.append('$ORA_HOME') searchLocations.append('$ORACLE_BASE') # Add oracle paths found from other sources if installLocs and len(installLocs) > 0: logger.debug('other locations') for installLoc in installLocs: if installLoc and len(installLoc) > 0: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] [3] Adding <%s> to search locations' % installLoc) searchLocations.append(installLoc) logger.debug('list of locations...') for location in searchLocations: logger.debug('*** location: ', location) # Search filesystem and parse tnsnames.ora entries for location in searchLocations: tnsnamesLocations = dbconnect_utils.findFile(localClient, 'tnsnames.ora', location, isWindows) if tnsnamesLocations == None: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] No tnsnames.ora found in <%s>' % location) continue for tnsnamesLocation in tnsnamesLocations: # We don't want the sample TNSNAMES.ORA which is # installed by default if re.search('sample', tnsnamesLocation.lower()): dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] Skipping sample tnsnames.ora in <%s>' % tnsnamesLocation) continue tnsnamesContent = dbconnect_utils.getFileContent(localClient, tnsnamesLocation, isWindows) dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':findTnsnamesOra] Got content of <%s>: <%s>' % (tnsnamesLocation, tnsnamesContent)) if tnsnamesContent != None or tnsnamesContent != '' or len(tnsnamesContent) <1: tnsEntries = dbutils.parseTNSNames(tnsnamesContent, '') for tnsEntry in tnsEntries: sidFound = tnsEntry[3].strip().lower() ## Truncate domain name if this is fully qualified SID if sidFound.find('.') > 0: shortSID = sidFound[:sidFound.find('.')] dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':findTnsnamesOra] Stripping domain from SID <%s> to <%s>' % (sidFound, shortSID)) sidFound = shortSID tnslsnrPort = tnsEntry[2].strip().lower() ipAddress = dbconnect_utils.fixIP(tnsEntry[5].strip().lower(), localClient.getIpAddress()) if ipAddress == dbconnect_utils.UNKNOWN: dbconnect_utils.debugPrint('[' + SCRIPT_NAME + ':findTnsnamesOra] Skipping instance <%s> listening at port <%s> because it\'s IP address is not valid' % (sidFound, tnslsnrPort)) continue if sidFound in dbDict.keys(): installPath = (dbDict[sidFound])[dbconnect_utils.PATH_INDEX] version = (dbDict[sidFound])[dbconnect_utils.VERSION_INDEX] statusFlag = (dbDict[sidFound])[dbconnect_utils.STATUS_INDEX] # If port and IP are already populated, don't overwrite them # because this information from active processes (above) is # guaranteed to be correct and tnsnames.ora may not be up-to-date ## Vinay 01/04/2010 - Commenting out conditional update below ## because the port and IP for an Oracle instance is not on the Oracle ## process but on the TNS listener process which may be listening for ## multiple instances on different ports. This makes associating an ## Oracle instance to its corresponding port impossible. ## So any ports found in TNSnames.ora will be used to overwrite ## previously found ports # if (dbDict[sidFound])[dbconnect_utils.PORT_INDEX] != dbconnect_utils.UNKNOWN: # tnslsnrPort = (dbDict[sidFound])[dbconnect_utils.PORT_INDEX] # if (dbDict[sidFound])[dbconnect_utils.IP_INDEX] != dbconnect_utils.UNKNOWN: # ipAddress = (dbDict[sidFound])[dbconnect_utils.IP_INDEX] dbDict[sidFound] = ['oracle', tnslsnrPort, ipAddress, installPath, version, statusFlag] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] Found known Oracle instance <%s> listening at port <%s> on <%s>' % (sidFound, tnslsnrPort, ipAddress)) # Don't want to add non running databases - Daniel La # else: # dbDict[sidFound] = ['oracle', tnslsnrPort, ipAddress, dbconnect_utils.UNKNOWN, dbconnect_utils.UNKNOWN, dbconnect_utils.UNKNOWN] # dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] Added Oracle instance <%s> listening at port <%s> on <%s>' % (sidFound, tnslsnrPort, ipAddress)) else: logger.debug('[' + SCRIPT_NAME + ':findTnsnamesOra] Invalid TNSNAMES.ORA at <%s>: <%s>' % (tnsnamesLocation, tnsnamesContent)) except: excInfo = logger.prepareJythonStackTrace('') dbconnect_utils.debugPrint('[' + SCRIPT_NAME + ':findTnsnamesOra] Exception: <%s>' % excInfo) pass
def findTnsnamesOra(localClient, p2pDict, dbDict, isWindows, installLocs): try: ## Locals searchLocations = [] # Try locations in the database dictionary if len(dbDict) > 0: for sid in dbDict.keys(): if (dbDict[sid])[dbconnect_utils.PATH_INDEX] != dbconnect_utils.UNKNOWN: path = (dbDict[sid])[dbconnect_utils.PATH_INDEX].lower() if path in searchLocations: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] [1] <%s> already in search locations' % path) continue elif path.find('\\') > 0 or path.find('/') >= 0: dbconnect_utils.debugPrint(2, '[' + SCRIPT_NAME + ':findTnsnamesOra] [1] Adding <%s> to search locations' % path) searchLocations.append(path) else: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] [1] <%s> is not a valid path' % path) continue # Try locations in the p2p dictionary if len(p2pDict) > 0: for pid in p2pDict.keys(): processName = (p2pDict[pid])[dbconnect_utils.PROCESSNAME_INDEX].lower() path = (p2pDict[pid])[dbconnect_utils.PATH_INDEX].lower() if re.search('tns', processName) or re.search('dbconsole', processName) or re.search('jobscheduler', processName) or re.search('oradb', processName) or re.search('oracle', processName) or re.search('ora_', processName): ## Remove /bin/tnslsnr from TNS process path if re.search('/bin/tnslsnr', path): path = path[:path.find('/bin/tnslsnr')] if path in searchLocations: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] [2] <%s> already in search locations' % path) continue elif path.find('\\') > 0 or path.find('/') >= 0: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] [2] Adding <%s> to search locations' % path) searchLocations.append(path) else: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] [2] <%s> is not a valid path' % path) continue # If we have no search locations so far, try some known/standard ones if 1: #len(searchLocations) < 1: if isWindows == 'true': searchLocations.append('%HOMEDRIVE%\oracle') searchLocations.append('%SYSTEMDRIVE%\oracle') searchLocations.append('%PROGRAMFILES%\oracle') searchLocations.append('%PROGRAMFILES(x86)%\oracle') searchLocations.append('%ORA_HOME%') searchLocations.append('%ORACLE_HOME%') #searchLocations.append('%ORACLE_HOME%\\network\\admin') else: searchLocations.append('/u01') searchLocations.append('/u02') searchLocations.append('/opt') searchLocations.append('/usr/local') searchLocations.append('$ORACLE_HOME') #searchLocations.append('$ORACLE_HOME/network/admin') searchLocations.append('$ORA_HOME') searchLocations.append('$ORACLE_BASE') # Add oracle paths found from other sources if installLocs and len(installLocs) > 0: for installLoc in installLocs: if installLoc and len(installLoc) > 0: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] [3] Adding <%s> to search locations' % installLoc) searchLocations.append(installLoc) # Search filesystem and parse tnsnames.ora entries for location in searchLocations: tnsnamesLocations = dbconnect_utils.findFile(localClient, 'tnsnames.ora', location, isWindows) if tnsnamesLocations == None: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] No tnsnames.ora found in <%s>' % location) continue for tnsnamesLocation in tnsnamesLocations: # We don't want the sample TNSNAMES.ORA which is # installed by default if re.search('sample', tnsnamesLocation.lower()): dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] Skipping sample tnsnames.ora in <%s>' % tnsnamesLocation) continue tnsnamesContent = dbconnect_utils.getFileContent(localClient, tnsnamesLocation, isWindows) dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':findTnsnamesOra] Got content of <%s>: <%s>' % (tnsnamesLocation, tnsnamesContent)) if tnsnamesContent != None or tnsnamesContent != '' or len(tnsnamesContent) <1: tnsEntries = dbutils.parseTNSNames(tnsnamesContent, '') for tnsEntry in tnsEntries: sidFound = tnsEntry[3].strip().lower() ## Truncate domain name if this is fully qualified SID if sidFound.find('.') > 0: shortSID = sidFound[:sidFound.find('.')] dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':findTnsnamesOra] Stripping domain from SID <%s> to <%s>' % (sidFound, shortSID)) sidFound = shortSID tnslsnrPort = tnsEntry[2].strip().lower() ipAddress = dbconnect_utils.fixIP(tnsEntry[5].strip().lower(), localClient.getIpAddress()) if ipAddress == dbconnect_utils.UNKNOWN: dbconnect_utils.debugPrint('[' + SCRIPT_NAME + ':findTnsnamesOra] Skipping instance <%s> listening at port <%s> because it\'s IP address is not valid' % (sidFound, tnslsnrPort)) continue if sidFound in dbDict.keys(): installPath = (dbDict[sidFound])[dbconnect_utils.PATH_INDEX] version = (dbDict[sidFound])[dbconnect_utils.VERSION_INDEX] statusFlag = (dbDict[sidFound])[dbconnect_utils.STATUS_INDEX] # If port and IP are already populated, don't overwrite them # because this information from active processes (above) is # guaranteed to be correct and tnsnames.ora may not be up-to-date ## Vinay 01/04/2010 - Commenting out conditional update below ## because the port and IP for an Oracle instance is not on the Oracle ## process but on the TNS listener process which may be listening for ## multiple instances on different ports. This makes associating an ## Oracle instance to its corresponding port impossible. ## So any ports found in TNSnames.ora will be used to overwrite ## previously found ports # if (dbDict[sidFound])[dbconnect_utils.PORT_INDEX] != dbconnect_utils.UNKNOWN: # tnslsnrPort = (dbDict[sidFound])[dbconnect_utils.PORT_INDEX] # if (dbDict[sidFound])[dbconnect_utils.IP_INDEX] != dbconnect_utils.UNKNOWN: # ipAddress = (dbDict[sidFound])[dbconnect_utils.IP_INDEX] dbDict[sidFound] = ['oracle', tnslsnrPort, ipAddress, installPath, version, statusFlag] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] Found known Oracle instance <%s> listening at port <%s> on <%s>' % (sidFound, tnslsnrPort, ipAddress)) else: dbDict[sidFound] = ['oracle', tnslsnrPort, ipAddress, dbconnect_utils.UNKNOWN, dbconnect_utils.UNKNOWN, dbconnect_utils.UNKNOWN] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':findTnsnamesOra] Added Oracle instance <%s> listening at port <%s> on <%s>' % (sidFound, tnslsnrPort, ipAddress)) else: logger.debug('[' + SCRIPT_NAME + ':findTnsnamesOra] Invalid TNSNAMES.ORA at <%s>: <%s>' % (tnsnamesLocation, tnsnamesContent)) except: excInfo = logger.prepareJythonStackTrace('') dbconnect_utils.debugPrint('[' + SCRIPT_NAME + ':findTnsnamesOra] Exception: <%s>' % excInfo) pass
def parseEtcFiles(localClient, p2pDict, dbDict, isWindows): try: pathsFound = [] ## Windows doesn't have /etc/oratab or /etc/oraInst.loc if isWindows == 'true': return else: ## Process oratab if found oratabLocation = dbconnect_utils.findFile(localClient, 'oratab', '/etc/', isWindows) if oratabLocation == None: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiles] oratab not found in /etc/') else: oratabContent = dbconnect_utils.getFileContent(localClient, oratabLocation[0], isWindows) if oratabContent: oratabLines = dbconnect_utils.splitCommandOutput(oratabContent) if oratabLines and len(oratabLines) > 0: for oratabLine in oratabLines: ## Ignore comment line or lines with nothing if len(oratabLine.strip()) < 1 or oratabLine.strip()[0] == '#': continue dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [1] Processing oratab line <%s>' % oratabLine) oratabLineSplit = oratabLine.strip().split(':') ## Ignore lines if the format is not sid:path:startup if len(oratabLineSplit) < 3: dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [1] Ignoring oratab line <%s>' % oratabLine) continue ## We should have an instance and its path sidFound = oratabLineSplit[0].strip().lower() pathFound = oratabLineSplit[1].strip().lower() ipAddress = localClient.getIpAddress() ## If the SID is "*", ignore it and use the path if sidFound == "*": dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [1] Ignoring oracle SID <%s>' % sidFound) if pathFound not in pathsFound: dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [1] Adding path <%s> to return array' % pathFound) pathsFound.append(pathFound) else: dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [1] Found known path <%s>' % pathFound) continue ## If this SID already exists in the dbDict, overwrite the install path ## associated with it. If not, add and entry and path if sidFound in dbDict.keys(): (dbDict[sidFound])[dbconnect_utils.PATH_INDEX] = pathFound dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiiles] [1] Found known Oracle instance <%s> with path <%s> on <%s>' % (sidFound, pathFound, ipAddress)) else: dbDict[sidFound] = ['oracle', dbconnect_utils.UNKNOWN, ipAddress, pathFound, dbconnect_utils.UNKNOWN, dbconnect_utils.UNKNOWN] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiles] [1] Added Oracle instance <%s> with path <%s> on <%s>' % (sidFound, pathFound, ipAddress)) else: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiles] [1] Invalid entries /etc/oratab: <%s>!' % oratabContent) else: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiles] [1] Empty or invalid /etc/oratab!') ## Process oraInst.loc if found oraInstLocation = dbconnect_utils.findFile(localClient, 'oraInst.loc', '/etc/', isWindows) if oraInstLocation == None: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiles] oraInst.loc not found in /etc/') else: oraInstContent = dbconnect_utils.getFileContent(localClient, oraInstLocation[0], isWindows) if oraInstContent: oraInstLines = dbconnect_utils.splitCommandOutput(oraInstContent) if oraInstLines and len(oraInstLines) > 0: for oraInstLine in oraInstLines: ## Ignore comment line or lines with nothing if len(oraInstLine.strip()) < 1 or oraInstLine.strip()[0] == '#': continue dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [2] Processing oraInst line <%s>' % oraInstLine) oraInstLineSplit = oraInstLine.strip().split('=') ## Ignore lines if the format is not inventory_loc=<path> if len(oraInstLineSplit) < 2 or oraInstLineSplit[0].strip() != 'inventory_loc': dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [2] Ignoring oraInst line <%s>' % oraInstLine) continue ## We should have an install path pathFound = oraInstLineSplit[1].strip().lower() dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiles] [2] Found oracle installation path <%s>' % pathFound) if pathFound not in pathsFound: dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [2] Adding path <%s> to return array' % pathFound) pathsFound.append(pathFound) else: dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [2] Found known path <%s>' % pathFound) else: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiles] [2] Invalid entries /etc/oraInst.loc: <%s>' % oraInstContent) else: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiles] [2] Empty or invalid /etc/oraInst.loc!') return pathsFound except: excInfo = logger.prepareJythonStackTrace('') dbconnect_utils.debugPrint('[' + SCRIPT_NAME + ':parseEtcFiles] Exception: <%s>' % excInfo) pass
def parseEtcFiles(localClient, p2pDict, dbDict, isWindows): try: pathsFound = [] ## Windows doesn't have /etc/oratab or /etc/oraInst.loc if isWindows == 'true': return else: ## Process oratab if found oratabLocation = dbconnect_utils.findFile(localClient, 'oratab', '/etc/', isWindows) if oratabLocation == None: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiles] oratab not found in /etc/') else: oratabContent = dbconnect_utils.getFileContent(localClient, oratabLocation[0], isWindows) if oratabContent: oratabLines = dbconnect_utils.splitCommandOutput(oratabContent) if oratabLines and len(oratabLines) > 0: for oratabLine in oratabLines: ## Ignore comment line or lines with nothing if len(oratabLine.strip()) < 1 or oratabLine.strip()[0] == '#': continue if oratabLine.strip().lower().endswith(":n"): #we do not want to process potentially non running instances continue dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [1] Processing oratab line <%s>' % oratabLine) oratabLineSplit = oratabLine.strip().split(':') ## Ignore lines if the format is not sid:path:startup if len(oratabLineSplit) < 3: dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [1] Ignoring oratab line <%s>' % oratabLine) continue ## We should have an instance and its path sidFound = oratabLineSplit[0].strip().lower() pathFound = oratabLineSplit[1].strip().lower() ipAddress = localClient.getIpAddress() ## If the SID is "*", ignore it and use the path if sidFound == "*": dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [1] Ignoring oracle SID <%s>' % sidFound) if pathFound not in pathsFound: dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [1] Adding path <%s> to return array' % pathFound) pathsFound.append(pathFound) else: dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [1] Found known path <%s>' % pathFound) continue ## If this SID already exists in the dbDict, overwrite the install path ## associated with it. If not, add and entry and path if sidFound in dbDict.keys(): (dbDict[sidFound])[dbconnect_utils.PATH_INDEX] = pathFound dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiiles] [1] Found known Oracle instance <%s> with path <%s> on <%s>' % (sidFound, pathFound, ipAddress)) else: dbDict[sidFound] = ['oracle', dbconnect_utils.UNKNOWN, ipAddress, pathFound, dbconnect_utils.UNKNOWN, dbconnect_utils.UNKNOWN] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiles] [1] Added Oracle instance <%s> with path <%s> on <%s>' % (sidFound, pathFound, ipAddress)) else: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiles] [1] Invalid entries /etc/oratab: <%s>!' % oratabContent) else: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiles] [1] Empty or invalid /etc/oratab!') ## Process oraInst.loc if found oraInstLocation = dbconnect_utils.findFile(localClient, 'oraInst.loc', '/etc/', isWindows) if oraInstLocation == None: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiles] oraInst.loc not found in /etc/') else: oraInstContent = dbconnect_utils.getFileContent(localClient, oraInstLocation[0], isWindows) if oraInstContent: oraInstLines = dbconnect_utils.splitCommandOutput(oraInstContent) if oraInstLines and len(oraInstLines) > 0: for oraInstLine in oraInstLines: ## Ignore comment line or lines with nothing if len(oraInstLine.strip()) < 1 or oraInstLine.strip()[0] == '#': continue dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [2] Processing oraInst line <%s>' % oraInstLine) oraInstLineSplit = oraInstLine.strip().split('=') ## Ignore lines if the format is not inventory_loc=<path> if len(oraInstLineSplit) < 2 or oraInstLineSplit[0].strip() != 'inventory_loc': dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [2] Ignoring oraInst line <%s>' % oraInstLine) continue ## We should have an install path pathFound = oraInstLineSplit[1].strip().lower() dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiles] [2] Found oracle installation path <%s>' % pathFound) if pathFound not in pathsFound: dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [2] Adding path <%s> to return array' % pathFound) pathsFound.append(pathFound) else: dbconnect_utils.debugPrint(4, '[' + SCRIPT_NAME + ':parseEtcFiles] [2] Found known path <%s>' % pathFound) else: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiles] [2] Invalid entries /etc/oraInst.loc: <%s>' % oraInstContent) else: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':parseEtcFiles] [2] Empty or invalid /etc/oraInst.loc!') return pathsFound except: excInfo = logger.prepareJythonStackTrace('') dbconnect_utils.debugPrint('[' + SCRIPT_NAME + ':parseEtcFiles] Exception: <%s>' % excInfo) pass