def resolveNamesToIPs(self, hostNode, parsedData): if parsedData: for internalName in parsedData.keys(): nodeData = parsedData[internalName] values = nodeData.get(hostNode) if values: listenedIPs = {} for ipaddr in values: stripedIpAddr = ipaddr.strip() if netutils.isValidIp(stripedIpAddr): listenedIPs[stripedIpAddr] = '' else: resolver = DNSResolver(self.shell, stripedIpAddr) resolvedIp = resolver.getIPAddress() if resolvedIp: listenedIPs[resolvedIp.strip()] = '' else: aliasBasedIps = resolver.resolveNSLookupAliasBased( ) if aliasBasedIps: for ip in aliasBasedIps: listenedIPs[ip.strip()] = '' nodeData[hostNode] = listenedIPs.keys() parsedData[internalName] = nodeData return parsedData
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() shell = None defOraHomes = Framework.getParameter('OracleHomes') hostPrimaryIP = Framework.getDestinationAttribute('ip_address') protocol = Framework.getDestinationAttribute('Protocol') listenerNames = Framework.getTriggerCIDataAsList('listener_names') listenerPaths = Framework.getTriggerCIDataAsList('listener_process_path') errorMessage = None try: client = Framework.createClient() try: shell = shellutils.ShellUtils(client) hostOSH = modeling.createHostOSH(hostPrimaryIP) OSHVResult.add(hostOSH) if len(listenerPaths) < len(listenerNames): path = listenerPaths[0] for i in range(len(listenerNames) - len(listenerPaths)): listenerPaths.append(path) for i in range(len(listenerPaths)): try: listenerPath = listenerPaths[i] listenerName = listenerNames[i] listenerConf = ListenerConfiguration(shell, listenerName, listenerPath, defOraHomes) listenerConf.discover() listenedIPs = listenerConf.getListenedIPsAsString() resolver = DNSResolver(shell, None, hostPrimaryIP) ipPrim = resolver.resolveIpByHostname() if ipPrim and ipPrim != hostPrimaryIP: hostPrimaryIP = ipPrim resolver = DNSResolver(shell, None, hostPrimaryIP) #for UCMDB 9.x due to new reconsiliation FQDN is not vital hostDnsName = resolver.getDnsName() or ' ' if hostDnsName and listenedIPs: listenedFull = hostDnsName + ':' + hostPrimaryIP + '@' + listenedIPs listenerName = listenerConf.getListenerName() listenerVersion = listenerConf.getVersion() listenerOSH = createListenerOSH(hostOSH, listenedFull, listenerName, listenerVersion) if listenerOSH: OSHVResult.add(listenerOSH) else: Framework.reportWarning('Failed to create listener OSH. Either host name or listened ips are not defined.') except: logger.debugException('') Framework.reportWarning('Failed to discover one or more listeners parameters.') finally: try: shell and shell.closeClient() except: logger.debugException('') logger.error('Unable to close shell') except JException, ex: errorMessage = ex.getMessage()
def __parseConfig(self, listenerConfigFile): listenedIPs = {} if listenerConfigFile: hostNode = 'HOST' filter = {hostNode : 'HOST\s*=\s*([\w\-\.]+)[\s\)]*'} parser = OraConfigParser(listenerConfigFile, filter) parsedData = parser.getResultsDict() if parsedData: for listenerName in parsedData.keys(): nodeData = parsedData[listenerName] values = nodeData.get(hostNode) if values: for ipaddr in values: logger.debug('Working with possible ip: ' + ipaddr) if netutils.isValidIp(ipaddr): listenedIPs[ipaddr.strip()] = '' else: resolver = DNSResolver(self.shell, ipaddr) resolvedIP = resolver.getIPAddress() if resolvedIP: listenedIPs[resolvedIP.strip()] = '' if not self.listenerName: self.listenerName = listenerName return listenedIPs
def resolveNamesToIPs(self, hostNode, parsedData): if parsedData: for internalName in parsedData.keys(): nodeData = parsedData[internalName] values = nodeData.get(hostNode) if values: listenedIPs = {} for ipaddr in values: stripedIpAddr = ipaddr.strip() if netutils.isValidIp(stripedIpAddr): listenedIPs[stripedIpAddr] = "" else: resolver = DNSResolver(self.shell, stripedIpAddr) resolvedIp = resolver.getIPAddress() if resolvedIp: listenedIPs[resolvedIp.strip()] = "" else: aliasBasedIps = resolver.resolveNSLookupAliasBased() if aliasBasedIps: for ip in aliasBasedIps: listenedIPs[ip.strip()] = "" nodeData[hostNode] = listenedIPs.keys() parsedData[internalName] = nodeData return parsedData
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() shell = None protocol = Framework.getDestinationAttribute("Protocol") listenerName = Framework.getDestinationAttribute("listenerName") listenerPath = Framework.getDestinationAttribute("listener_process_path") defOraHomes = Framework.getParameter("OracleHomes") listenerIp = Framework.getDestinationAttribute("listener_ip") listenedIPs = Framework.getTriggerCIDataAsList("listened_ips") try: try: client = Framework.createClient() shell = shellutils.ShellUtils(client) if listenerPath: envConf = UnixOracleEnvConfig(shell) if shell.isWinOs(): envConf = WindowsOracleEnvConfig(shell) envConf.setOracleHomeEnvVar(listenerPath) else: envConf = EnvConfigurator(shell, defOraHomes) if not listenedIPs: Framework.reportError("No listened_ips attribute values found.") return OSHVResult lookuper = LookupManager(listenedIPs) serviceToNodesMap = {} srvDiscoverer = SrvctlBasedDiscoverer(shell, envConf) databases = srvDiscoverer.getDatabases() for database in databases: instanceAndNodes = srvDiscoverer.getInstancesWithNodes(database) if instanceAndNodes: serviceToNodesMap[database] = instanceAndNodes for elem in instanceAndNodes: resolver = DNSResolver(shell, elem.get("Node")) ipAddr = resolver.resolveNSLookup() if not ipAddr: ipAddr = resolver.resolveNSLookupAliasBased() ipAddr = ipAddr and ipAddr[0] try: if not ipAddr: ipAddr = resolver.resolveHostsFile() except: pass elem["ip"] = ipAddr for (serviceName, params) in serviceToNodesMap.items(): try: listeners = [] oracles = [] for elem in params: ipAddr = elem.get("ip") if not ipAddr: raise ValueError("One of the Node Ip is not discovered. Can not create full topology.") hostOSH = modeling.createHostOSH(ipAddr) OSHVResult.add(hostOSH) listenerOSH = createWeakListener(hostOSH) if listenerIp == ipAddr: listenerOSH.setStringAttribute("name", listenerName) listeners.append(listenerOSH) oracleOsh = modeling.createDatabaseOSH("oracle", elem["Instance"], None, ipAddr, hostOSH) listeners.append(oracleOsh) oracles.append(oracleOsh) racName = "" nodes = [x["Node"] for x in params if x["Node"]] nodes.sort() racName = ":".join(nodes) racOsh = createRacOSH(racName, len(params), serviceName, None) OSHVResult.add(racOsh) for listener in listeners: OSHVResult.add(listener) OSHVResult.add(modeling.createLinkOSH("member", racOsh, listener)) for oracle in oracles: OSHVResult.add(oracle) OSHVResult.add(modeling.createLinkOSH("member", racOsh, oracle)) except: Framework.reportWarning( 'Failed to lookup host name of the node. Probably not all nodes were discovered by "Oracle Listener by Shell" Job. No RAC CI will be created.' ) logger.warn("Failed to lookup host name for node with ip. No RAC CI will be created.") if not serviceToNodesMap: logger.warn("Failed to get information via srvctl. Will use old approach.") else: return OSHVResult # old flow tnsConfig = {} try: tnsConfig = TNSNamesConfig(shell, envConf) except: logger.debug("Failed to get tnsnames.ora. Trying different home.") envConf = EnvConfigurator(shell, defOraHomes) oraHome = envConf.findMatchingDefaultOracleHome() envConf = UnixOracleEnvConfig(shell) envConf.setOracleHomeEnvVar(oraHome) tnsConfig = TNSNamesConfig(shell, envConf) racParams = tnsConfig.getRacParams() servChec = ServiceChecker(shell, envConf, listenerName=listenerName) for racServiceName in racParams.keys(): parametersDict = racParams[racServiceName] racNodeNameList = [] racInstCount = len(parametersDict.keys()) if ( not servChec.isServiceRunning(racServiceName.upper()) or racInstCount == 0 or racInstCount != int(servChec.getServiceInstancesNumber(racServiceName)) ): Framework.reportWarning("Oracle RAC is not running or not all Instances were detected") continue racVersion = servChec.getVersion() shortVersion = servChec.getShortVersion() listeners = [] oracles = [] for ip in parametersDict.keys(): hostName = lookuper.lookupByIp(ip) or " " hostPrimIp = lookuper.getPrimaryIp(ip) actIp = ip if not hostName: Framework.reportError( 'Failed to lookup host name of the node. Probably not all nodes were discovered by "Oracle Listener by Shell" Job. No RAC CI will be created.' ) logger.error("Failed to lookup host name for node with ip %s . No RAC CI will be created." % ip) return ObjectStateHolderVector() racNodeNameList.append(hostName) dbSid = parametersDict[actIp] if hostPrimIp: actIp = hostPrimIp hostOSH = modeling.createHostOSH(actIp) OSHVResult.add(hostOSH) listenerOSH = createWeakListener(hostOSH) listeners.append(listenerOSH) oracleOSH = modeling.createDatabaseOSH( "oracle", dbSid, None, actIp, hostOSH, None, None, None, shortVersion, racVersion, shortVersion ) instanceNumber = servChec.getDbInstanceNumber(dbSid, racServiceName) if instanceNumber: oracleOSH.setAttribute("oracle_instancenumber", instanceNumber) oracles.append(oracleOSH) racNodeNameList.sort() racName = "" for nodeName in racNodeNameList: if racName == "": racName = nodeName else: racName += ":" + nodeName racOSH = createRacOSH(racName, racInstCount, racServiceName, racVersion) OSHVResult.add(racOSH) for listener in listeners: OSHVResult.add(listener) OSHVResult.add(modeling.createLinkOSH("member", racOSH, listener)) for oracle in oracles: OSHVResult.add(oracle) OSHVResult.add(modeling.createLinkOSH("member", racOSH, oracle)) finally: try: shell and shell.closeClient() except: logger.debugException("") logger.error("Unable to close shell") except: msg = logger.prepareFullStackTrace("") errormessages.resolveAndReport(msg, protocol, Framework) return OSHVResult
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() shell = None protocol = Framework.getDestinationAttribute('Protocol') listenerName = Framework.getDestinationAttribute('listenerName') listenerPath = Framework.getDestinationAttribute('listener_process_path') defOraHomes = Framework.getParameter('OracleHomes') listenerIp = Framework.getDestinationAttribute('listener_ip') listenedIPs = Framework.getTriggerCIDataAsList('listened_ips') try: try: client = Framework.createClient() shell = shellutils.ShellUtils(client) if listenerPath: envConf = UnixOracleEnvConfig(shell) if shell.isWinOs(): envConf = WindowsOracleEnvConfig(shell) envConf.setOracleHomeEnvVar(listenerPath) else: envConf = EnvConfigurator(shell, defOraHomes) if not listenedIPs: Framework.reportError( 'No listened_ips attribute values found.') return OSHVResult lookuper = LookupManager(listenedIPs) serviceToNodesMap = {} srvDiscoverer = SrvctlBasedDiscoverer(shell, envConf) databases = srvDiscoverer.getDatabases() for database in databases: instanceAndNodes = srvDiscoverer.getInstancesWithNodes( database) if instanceAndNodes: serviceToNodesMap[database] = instanceAndNodes for elem in instanceAndNodes: resolver = DNSResolver(shell, elem.get('Node')) ipAddr = resolver.resolveNSLookup() if not ipAddr: ipAddr = resolver.resolveNSLookupAliasBased() ipAddr = ipAddr and ipAddr[0] try: if not ipAddr: ipAddr = resolver.resolveHostsFile() except: pass elem['ip'] = ipAddr for (serviceName, params) in serviceToNodesMap.items(): try: listeners = [] oracles = [] for elem in params: ipAddr = elem.get('ip') if not ipAddr: raise ValueError( 'One of the Node Ip is not discovered. Can not create full topology.' ) hostOSH = modeling.createHostOSH(ipAddr) OSHVResult.add(hostOSH) listenerOSH = createWeakListener(hostOSH) if listenerIp == ipAddr: listenerOSH.setStringAttribute( 'name', listenerName) listeners.append(listenerOSH) oracleOsh = modeling.createDatabaseOSH( 'oracle', elem['Instance'], None, ipAddr, hostOSH) listeners.append(oracleOsh) oracles.append(oracleOsh) racName = '' nodes = [x['Node'] for x in params if x['Node']] nodes.sort() racName = ':'.join(nodes) racOsh = createRacOSH(racName, len(params), serviceName, None) OSHVResult.add(racOsh) for listener in listeners: OSHVResult.add(listener) OSHVResult.add( modeling.createLinkOSH('member', racOsh, listener)) for oracle in oracles: OSHVResult.add(oracle) OSHVResult.add( modeling.createLinkOSH('member', racOsh, oracle)) except: Framework.reportWarning( 'Failed to lookup host name of the node. Probably not all nodes were discovered by \"Oracle Listener by Shell\" Job. No RAC CI will be created.' ) logger.warn( 'Failed to lookup host name for node with ip. No RAC CI will be created.' ) if not serviceToNodesMap: logger.warn( 'Failed to get information via srvctl. Will use old approach.' ) else: return OSHVResult #old flow tnsConfig = {} try: tnsConfig = TNSNamesConfig(shell, envConf) except: logger.debug( 'Failed to get tnsnames.ora. Trying different home.') envConf = EnvConfigurator(shell, defOraHomes) oraHome = envConf.findMatchingDefaultOracleHome() envConf = UnixOracleEnvConfig(shell) envConf.setOracleHomeEnvVar(oraHome) tnsConfig = TNSNamesConfig(shell, envConf) racParams = tnsConfig.getRacParams() servChec = ServiceChecker(shell, envConf, listenerName=listenerName) for racServiceName in racParams.keys(): parametersDict = racParams[racServiceName] racNodeNameList = [] racInstCount = len(parametersDict.keys()) if not servChec.isServiceRunning(racServiceName.upper( )) or racInstCount == 0 or racInstCount != int( servChec.getServiceInstancesNumber(racServiceName)): Framework.reportWarning( 'Oracle RAC is not running or not all Instances were detected' ) continue racVersion = servChec.getVersion() shortVersion = servChec.getShortVersion() listeners = [] oracles = [] for ip in parametersDict.keys(): hostName = lookuper.lookupByIp(ip) or ' ' hostPrimIp = lookuper.getPrimaryIp(ip) actIp = ip if not hostName: Framework.reportError( 'Failed to lookup host name of the node. Probably not all nodes were discovered by \"Oracle Listener by Shell\" Job. No RAC CI will be created.' ) logger.error( 'Failed to lookup host name for node with ip %s . No RAC CI will be created.' % ip) return ObjectStateHolderVector() racNodeNameList.append(hostName) dbSid = parametersDict[actIp] if hostPrimIp: actIp = hostPrimIp hostOSH = modeling.createHostOSH(actIp) OSHVResult.add(hostOSH) listenerOSH = createWeakListener(hostOSH) listeners.append(listenerOSH) oracleOSH = modeling.createDatabaseOSH( 'oracle', dbSid, None, actIp, hostOSH, None, None, None, shortVersion, racVersion, shortVersion) instanceNumber = servChec.getDbInstanceNumber( dbSid, racServiceName) if instanceNumber: oracleOSH.setAttribute('oracle_instancenumber', instanceNumber) oracles.append(oracleOSH) racNodeNameList.sort() racName = '' for nodeName in racNodeNameList: if racName == '': racName = nodeName else: racName += ':' + nodeName racOSH = createRacOSH(racName, racInstCount, racServiceName, racVersion) OSHVResult.add(racOSH) for listener in listeners: OSHVResult.add(listener) OSHVResult.add( modeling.createLinkOSH('member', racOSH, listener)) for oracle in oracles: OSHVResult.add(oracle) OSHVResult.add( modeling.createLinkOSH('member', racOSH, oracle)) finally: try: shell and shell.closeClient() except: logger.debugException('') logger.error('Unable to close shell') except: msg = logger.prepareFullStackTrace('') errormessages.resolveAndReport(msg, protocol, Framework) return OSHVResult