def parseNetworkingInformation(self, buffer): """ This function performs parsing of the 'lshmc -n' command output @param buffer: string buffer of the command output @return: host and ip information @rtype: instance of HostDo object """ host = ibm_hmc_lib.Host() if buffer: propertiesDict = self.buildPropertiesDict(buffer) host.hostname = propertiesDict.get('hostname') host.domainName = propertiesDict.get('domain') for (key, value) in propertiesDict.items(): if key.startswith('ipv4addr_eth'): if value and netutils.isValidIp(value) and not netutils.isLocalIp(value): ip = ibm_hmc_lib.Ip(value, propertiesDict.get(key.replace('addr', 'netmask'))) host.ipList.append(ip) if not host.ipList: #another version of HMC outputs, for the minor HMC version change ipStr = propertiesDict.get('ipaddr') netMaskStr = propertiesDict.get('networkmask') if ipStr and netMaskStr: ipList = ipStr.split(',') netMaskList = netMaskStr.split(',') for i in range(len(ipList)): ipAddr = ipList[i].strip() netMask = netMaskList[i].strip() if ipAddr and netutils.isValidIp(ipAddr) and not netutils.isLocalIp(ipAddr): ip = ibm_hmc_lib.Ip(ipAddr, netMask) host.ipList.append(ip) if not host.ipList: raise ValueError("Failed parsing HMC host IP addresses from %s " % buffer) return host
def _resolve(hostname): '@types: str -> str?' if netutils.isValidIp(hostname): return hostname ip = netutils.getHostAddress(hostname) if ip and not netutils.isLocalIp(ip): return ip
def fixLocalIp(self, ip): ''' @deprecated: not used, doesn't work with ipv6 ''' if netutils.isLocalIp(ip) or (not re.match('\d+\.\d+\.\d+\.\d+', ip)): ip = self.client.getIpAddress() return ip
def getUrl(WSDLUrl, containerOSH): res = ObjectStateHolderVector() urlIP = None try: url = URL(WSDLUrl) hostName = url.getHost() urlIP = netutils.getHostAddress(hostName, None) if (not netutils.isValidIp(urlIP)) or netutils.isLocalIp(urlIP): urlIP = None except: urlIP = None urlOSH = modeling.createUrlOsh(containerOSH, WSDLUrl, 'wsdl') urlIpOSH = None if urlIP != None: try: urlIpOSH = modeling.createIpOSH(urlIP) except: urlIpOSH = None res.add(urlOSH) if urlIpOSH: res.add(urlIpOSH) urlToIpOSH = modeling.createLinkOSH('depend', urlOSH, urlIpOSH) res.add(urlToIpOSH) return res
def __init__(self, props, nlbClusterOsh, hostOSH, framework): if not nlbClusterOsh: raise Exception( 'NLB cluster discovery misconfigured; NLB node have to be linked to existing cluster' ) self.nlbClusterOsh = nlbClusterOsh self.hostOSH = hostOSH self.priority = props['HostPriority'] self.modeOnStart = props['ClusterModeOnStart'] if props['DedicatedIPAddresses/']: self.ip = props['DedicatedIPAddresses/'].split('/')[0] netMask = props['DedicatedIPAddresses/'].split('/')[1] else: self.ip = props['DedicatedIPAddress'] netMask = props['DedicatedNetworkMask'] self.dedicatedIpOSH = None #check the IP #very unreal situation but we have to handle it if not netutils.isValidIp(self.ip) or netutils.isLocalIp(self.ip): msg = 'Dedicated IP of cluster node is local or invalid: ' + str( self.ip) logger.warn(msg) framework.reportWarning( 'Dedicated IP of cluster node is local or invalid') else: self.dedicatedIpOSH = modeling.createIpOSH(self.ip, netMask)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() urlString = Framework.getParameter(PARAM_URL) reportPoweredOffVms = 0 reportPoweredOffVmsValue = Framework.getParameter(PARAM_REPORT_POWERED_OFF_VMS) if reportPoweredOffVmsValue and reportPoweredOffVmsValue.lower() =='true': reportPoweredOffVms = 1 ipAddress = None try: urlObject = URL(urlString) hostname = urlObject.getHost() if not hostname: logger.debug("Hostname is not defined in URL '%s'" % urlString) raise MalformedURLException() ipAddress = vcloud_discover.getIpFromUrlObject(urlObject) if not ipAddress or not netutils.isValidIp(ipAddress) or netutils.isLocalIp(ipAddress): msg = "Failed to resolve the IP address of server from specified URL" errormessages.resolveAndReport(msg, vcloud_discover.VcloudProtocol.DISPLAY, Framework) return OSHVResult except MalformedURLException: msg = "Specified URL '%s' is malformed" % urlString errormessages.resolveAndReport(msg, vcloud_discover.VcloudProtocol.DISPLAY, Framework) except: msg = logger.prepareJythonStackTrace("") errormessages.resolveAndReport(msg, vcloud_discover.VcloudProtocol.DISPLAY, Framework) else: #configure how connections should be discovered/established connectionDiscoverer = vcloud_discover.ConnectionDiscoverer(Framework) urlGenerator = vcloud_discover.ConstantUrlGenerator(urlString) connectionDiscoverer.setUrlGenerator(urlGenerator) connectionDiscoverer.addIp(ipAddress) #configure how established/failed connection should be used connectionHandler = vcloud_discover.BaseDiscoveryConnectionHandler(Framework) topologyDiscoverer = vcloud_discover.createVcloudDiscoverer(Framework) topologyReporter = vcloud_report.createVcloudReporter(Framework, None, reportPoweredOffVms) connectionHandler.setDiscoverer(topologyDiscoverer) connectionHandler.setReporter(topologyReporter) connectionDiscoverer.setConnectionHandler(connectionHandler) connectionDiscoverer.initConnectionConfigurations() connectionDiscoverer.discover(firstSuccessful=0) if not connectionHandler.connected: for errorMsg in connectionHandler.connectionErrors: Framework.reportError(errorMsg) for warningMsg in connectionHandler.connectionWarnings: Framework.reportWarning(warningMsg) return OSHVResult
def getVirtualMachinesByEsx(client, esxInstance): ''' CimClient -> list(VmComputerSystem) ''' vmInstances = cim_discover.getAssociatorsWithTypeEnforcement( client, esxInstance.getObjectPath(), "VMWARE_HostedDependency", "VMWARE_VMComputerSystem") vmList = [] for vmInstance in vmInstances: vm = VmComputerSystem() vm.setObjectPath(vmInstance.getObjectPath()) vm.name = cim_discover.cleanString( _getCimInstanceProperty(vmInstance, "Name")) elementName = _getCimInstanceProperty(vmInstance, "ElementName") elementName = cim_discover.cleanString(elementName) # html unescape : & -> & elementName = cim_discover.htmlUnescape(elementName) # url unescape: %25 -> % # vmware escapes 3 characters, both slashes and % elementName = urllib.unquote(elementName) vm.elementName = elementName description = _getCimInstanceProperty(vmInstance, "Description") description = cim_discover.cleanString(description) vm.description = cim_discover.htmlUnescape(description) identifyingDescriptions = _getCimInstanceProperty( vmInstance, 'IdentifyingDescriptions') identifyingDescriptions = map(cim_discover.cleanString, identifyingDescriptions) otherIdentifyingInfo = _getCimInstanceProperty(vmInstance, 'OtherIdentifyingInfo') otherIdentifyingInfo = map(cim_discover.cleanString, otherIdentifyingInfo) customProperties = _dictionaryFromCrossCollections( identifyingDescriptions, otherIdentifyingInfo) vm.biosUuid = customProperties.get("BIOS UUID") vm.hostName = customProperties.get("Hostname") primaryIpAddress = customProperties.get("Primary IP Address") if netutils.isValidIp( primaryIpAddress) and not netutils.isLocalIp(primaryIpAddress): vm.primaryIpAddress = primaryIpAddress operationalStatusArray = _getCimInstanceProperty( vmInstance, 'OperationalStatus') if operationalStatusArray is not None: for statusValue in operationalStatusArray: if statusValue is not None: statusValueInt = cim_discover.getIntFromCimInt(statusValue) vm.operationalStatus.add(statusValueInt) vmList.append(vm) return vmList
def _parceLsofOutput(self, output): results = [] if output: matcher = re.compile('TCP\s+([\d\.]+)\:(\d+)\s+\(LISTEN') for block in re.split('\n', output): match = matcher.search(block) if match and netutils.isValidIp(match.group(1)) and not netutils.isLocalIp(match.group(1)): results.append(netutils.createTcpEndpoint(match.group(1), match.group(2))) return results
def parseNetworkingInformation(self, output): host = ibm_hmc_lib.Host() if output: potential_ips = re.findall('e[nt]+\s+([\da-fA-F:]+)\s+([\da-fA-F:]+)', output) for (ipAddr, mask) in potential_ips: if ipAddr and netutils.isValidIp(ipAddr) and not netutils.isLocalIp(ipAddr): ip = ibm_hmc_lib.Ip(ipAddr, mask) host.ipList.append(ip) return host
def createURLOSHV(urlString, framework = None): OSHVResult = ObjectStateHolderVector() #urlOSH2 = modeling.createOshByCmdbIdString('uri_endpoint', urlId) logger.debug("Starting URL discovery on '%s'" % urlString) #urlString = urlString[1:len(urlString)-1] if not urlString: return OSHVResult try: urlString = str(urlString).replace("\\", "//") urlObject = URL(urlString) hostname = urlObject.getHost() if not hostname: raise MalformedURLException("Hostname is not defined in URL '%s'" % urlString) urlObjectResolver = URLObjectResolver(urlObject) protocol = urlObjectResolver.getProtocolFromUrlObject() if not protocol: raise Exception("Failed to resolve the http/https protocol from specified URL") port = urlObjectResolver.getPortFromUrlObject() if not port: raise Exception("Failed to resolve the port number from specified URL") # get topology # create business element CI and attach the url as configuration document CI to it ips = urlObjectResolver.getIpFromUrlObject() for ipAddress in ips: logger.debug('%s: Reporting ip address: %s' % (urlString, ipAddress)) if not ipAddress or not netutils.isValidIp(ipAddress) or netutils.isLocalIp(ipAddress): raise Exception("Failed to resolve the IP address of server from specified URL") hostOSH, ipOSH, OSHVResult2 = createIPEndpointOSHV(framework, ipAddress, port, protocol, hostname) OSHVResult.addAll(OSHVResult2) # create UriEndpoint and relations between business element and UriEndpoint urlOSH = modeling.createUrlOsh(hostOSH, urlString, None) #urlOSH.setCmdbObjectId(urlOSH2.getCmdbObjectId()) OSHVResult.add(urlOSH) OSHVResult.add(modeling.createLinkOSH('dependency', urlOSH, ipOSH)) #create Web Server except: logger.warnException("Error creating URL OSH for %s" % urlString) return OSHVResult
def parseNslookupOutput(nslookupOutput, hostname): if re.search(r"Non-existent host", nslookupOutput): return None pattern = "Name:[^\n]+\s*\nAddress:\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})" matcher = re.search(pattern, nslookupOutput, re.I) if matcher: resolvedIp = matcher.group(1) if resolvedIp is not None: resolvedIp = resolvedIp.strip() if netutils.isValidIp(resolvedIp) and not netutils.isLocalIp(resolvedIp): return resolvedIp
def _resolveHostNameWithCaching(self, hostName): # TODO: use external resolver ip = None if self.__resolveCache.has_key(hostName): ip = self.__resolveCache.get(hostName) else: ip = netutils.getHostAddress(hostName) self.__resolveCache[hostName] = ip if ip and netutils.isValidIp(ip) and not netutils.isLocalIp(ip): return ip
def parseNetworkingInformation(self, output): host = ibm_hmc_lib.Host() if output: potential_ips = re.findall( 'e[nt]+\s+([\da-fA-F:]+)\s+([\da-fA-F:]+)', output) for (ipAddr, mask) in potential_ips: if ipAddr and netutils.isValidIp( ipAddr) and not netutils.isLocalIp(ipAddr): ip = ibm_hmc_lib.Ip(ipAddr, mask) host.ipList.append(ip) return host
def parseNetworkingInformation(self, buffer): """ This function performs parsing of the 'lshmc -n' command output @param buffer: string buffer of the command output @return: host and ip information @rtype: instance of HostDo object """ host = ibm_hmc_lib.Host() if buffer: propertiesDict = self.buildPropertiesDict(buffer) host.hostname = propertiesDict.get('hostname') host.domainName = propertiesDict.get('domain') for (key, value) in propertiesDict.items(): if key.startswith('ipv4addr_eth'): if value and netutils.isValidIp( value) and not netutils.isLocalIp(value): ip = ibm_hmc_lib.Ip( value, propertiesDict.get(key.replace('addr', 'netmask'))) host.ipList.append(ip) if not host.ipList: #another version of HMC outputs, for the minor HMC version change ipStr = propertiesDict.get('ipaddr') netMaskStr = propertiesDict.get('networkmask') if ipStr and netMaskStr: ipList = ipStr.split(',') netMaskList = netMaskStr.split(',') for i in range(len(ipList)): ipAddr = ipList[i].strip() netMask = netMaskList[i].strip() if ipAddr and netutils.isValidIp( ipAddr) and not netutils.isLocalIp(ipAddr): ip = ibm_hmc_lib.Ip(ipAddr, netMask) host.ipList.append(ip) if not host.ipList: raise ValueError( "Failed parsing HMC host IP addresses from %s " % buffer) return host
def _parceLsofOutput(self, output): results = [] if output: matcher = re.compile('TCP\s+([\d\.]+)\:(\d+)\s+\(LISTEN') for block in re.split('\n', output): match = matcher.search(block) if match and netutils.isValidIp( match.group(1)) and not netutils.isLocalIp( match.group(1)): results.append( netutils.createTcpEndpoint(match.group(1), match.group(2))) return results
def discoverIpAddressFromLogFile(self, filePath): ''' Discovers assigned ip and subnets from log file @param filePath: string - path to log file @returns: list of strings - list of ips ''' result = [] ipStrList = self._getEntriesFromLogFile(filePath, 'Adding IP', 'Adding\s+IP\s+address\s([\d\.]+)') if ipStrList: for ipStr in ipStrList: if ipStr and netutils.isValidIp(ipStr) and not netutils.isLocalIp(ipStr): dnsName = netutils.resolveFQDN(self._shell, ipStr) result.append(Ip(ipStr, dnsName)) return result
def getVirtualMachinesByEsx(client, esxInstance): ''' CimClient -> list(VmComputerSystem) ''' vmInstances = cim_discover.getAssociatorsWithTypeEnforcement(client, esxInstance.getObjectPath(), "VMWARE_HostedDependency", "VMWARE_VMComputerSystem") vmList = [] for vmInstance in vmInstances: vm = VmComputerSystem() vm.setObjectPath(vmInstance.getObjectPath()) vm.name = cim_discover.cleanString(_getCimInstanceProperty(vmInstance, "Name")) elementName = _getCimInstanceProperty(vmInstance, "ElementName") elementName = cim_discover.cleanString(elementName) # html unescape : & -> & elementName = cim_discover.htmlUnescape(elementName) # url unescape: %25 -> % # vmware escapes 3 characters, both slashes and % elementName = urllib.unquote(elementName) vm.elementName = elementName description = _getCimInstanceProperty(vmInstance, "Description") description = cim_discover.cleanString(description) vm.description = cim_discover.htmlUnescape(description) identifyingDescriptions = _getCimInstanceProperty(vmInstance, 'IdentifyingDescriptions') identifyingDescriptions = map(cim_discover.cleanString, identifyingDescriptions) otherIdentifyingInfo = _getCimInstanceProperty(vmInstance, 'OtherIdentifyingInfo') otherIdentifyingInfo = map(cim_discover.cleanString, otherIdentifyingInfo) customProperties = _dictionaryFromCrossCollections(identifyingDescriptions, otherIdentifyingInfo) vm.biosUuid = customProperties.get("BIOS UUID") vm.hostName = customProperties.get("Hostname") primaryIpAddress = customProperties.get("Primary IP Address") if netutils.isValidIp(primaryIpAddress) and not netutils.isLocalIp(primaryIpAddress): vm.primaryIpAddress = primaryIpAddress operationalStatusArray = _getCimInstanceProperty(vmInstance, 'OperationalStatus') if operationalStatusArray is not None: for statusValue in operationalStatusArray: if statusValue is not None: statusValueInt = cim_discover.getIntFromCimInt(statusValue) vm.operationalStatus.add(statusValueInt) vmList.append(vm) return vmList
def getIpFromUrlString(urlString): try: urlObject = URL(urlString) hostname = urlObject.getHost() if not hostname: logger.debug("Hostname is not defined in URL '%s'" % urlString) raise MalformedURLException() ipAddress = getIpFromUrlObject(urlObject) if not ipAddress or not netutils.isValidIp(ipAddress) or netutils.isLocalIp(ipAddress): raise ValueError("Failed determining the IP address of server") return ipAddress except: logger.warnException("Invalid URL")
def _parsePFilesOutput(self, output): results = [] if output: matcher = re.compile('localaddr/port\s+=\s+([\w\.]+)\s*/\s*(\d+).*listening') for block in re.split('S_ISSOCK', output): match = matcher.search(block) ip = None if match: if not netutils.isValidIp(match.group(1)): ip = netutils.resolveIP(self._shell, match.group(1)) else: ip = match.group(1) if not netutils.isLocalIp(ip): results.append(netutils.createTcpEndpoint(ip, match.group(2))) return results
def __init__(self, props, config, hostOSH, framework, connectedIp): self.nlbClusterOSH = None self.hostOSH = hostOSH self.props = props self.config = config self.ip = props['ClusterIPAddress'] if connectedIp == self.ip: raise ConnectedToClusterIpException() netMask = props['ClusterNetworkMask'] #check the IP; if cluster IP is invalid no cluster will be reported if not netutils.isValidIp(self.ip) or netutils.isLocalIp(self.ip): msg = 'Cluster IP is local or invalid: %s' % str(self.ip) raise InvalidIpException(self.ip) self.clusterIpOSH = modeling.createIpOSH(self.ip, netMask)
def discoverIpAddressFromLogFile(self, filePath): ''' Discovers assigned ip and subnets from log file @param filePath: string - path to log file @returns: list of strings - list of ips ''' result = [] ipStrList = self._getEntriesFromLogFile( filePath, 'Adding IP', 'Adding\s+IP\s+address\s([\d\.]+)') if ipStrList: for ipStr in ipStrList: if ipStr and netutils.isValidIp( ipStr) and not netutils.isLocalIp(ipStr): dnsName = netutils.resolveFQDN(self._shell, ipStr) result.append(Ip(ipStr, dnsName)) return result
def reportDatabaseServerFromAddress(self, dbServer): r""" Reports database server (running application) and related topology where container is built from server address as incomplete host by IP address @types: db.DatabaseServer -> ObjectStateHolderVector @raise ValueError: Address for the specified server is not valid or is local @raise ValueError: Server to report is not specified """ if not dbServer: raise ValueError("Server to report is not specified") address = dbServer.address if not (address and netutils.isValidIp(address) and not netutils.isLocalIp(address)): msg = "Address for the specified server is not valid or is local" raise ValueError(msg) hostOsh = modeling.createHostOSH(dbServer.address) return self.reportServerAndDatabases(dbServer, hostOsh)
def _parsePFilesOutput(self, output): results = [] if output: matcher = re.compile( 'localaddr/port\s+=\s+([\w\.]+)\s*/\s*(\d+).*listening') for block in re.split('S_ISSOCK', output): match = matcher.search(block) ip = None if match: if not netutils.isValidIp(match.group(1)): ip = netutils.resolveIP(self._shell, match.group(1)) else: ip = match.group(1) if not netutils.isLocalIp(ip): results.append( netutils.createTcpEndpoint(ip, match.group(2))) return results
def resolveIpsByHostname(self, hostname): ''' Process cases with loopback address (local IP) - when hostname is 'localhost' destination Ip address will be returned - resolved local IP address will be replaced by destination IP @types: str -> list[str] @raise ResolveException: Failed to resolve IP ''' if hostname == 'localhost': return [self.__destinationIpAddress] ips = self.__dnsResolver.resolveIpsByHostname(hostname) isNotLocalIp = lambda ip: not netutils.isLocalIp(ip) nonLocalIps = filter(isNotLocalIp, ips) if len(nonLocalIps) < len(ips): # seems like we have local IPs nonLocalIps.append(self.__destinationIpAddress) ips = nonLocalIps return ips
def parseNetworkingInformation(self, buffer): """ This function performs parsing of the 'lshmc -n' command output for HMC 3.7 version @param buffer: string buffer of the command output @return: host and ip information @rtype: instance of HostDo object """ host = ibm_hmc_lib.Host() if buffer: propertiesDict = self.buildPropertiesDict(buffer, '\n', ':') host.hostname = propertiesDict.get('Host Name') host.domainName = propertiesDict.get('Domain Name') for (key, value) in propertiesDict.items(): if re.match('TCP/IP Interface \d+ Address', key): if value and netutils.isValidIp(value) and not netutils.isLocalIp(value): ip = ibm_hmc_lib.Ip(value, propertiesDict.get(key.replace('Address', 'Network Mask'))) host.ipList.append(ip) return host
def _findHostKeyAndIps(self): if self.networkConnectionSection is not None: macs = [] connections = self.networkConnectionSection.getNetworkConnection() for connection in connections: isConnected = connection.isIsConnected() if isConnected: rawMac = connection.getMACAddress() if netutils.isValidMac(rawMac): mac = netutils.parseMac(rawMac) macs.append(mac) ip = connection.getIpAddress() if ip is not None and netutils.isValidIp(ip) and not netutils.isLocalIp(ip): self._ips.append(ip) self._validMacs = macs macs.sort() if macs: self._hostKey = macs[0]
def _findHostKeyAndIps(self): if self.networkConnectionSection is not None: macs = [] connections = self.networkConnectionSection.getNetworkConnection() for connection in connections: isConnected = connection.isIsConnected() if isConnected: rawMac = connection.getMACAddress() if netutils.isValidMac(rawMac): mac = netutils.parseMac(rawMac) macs.append(mac) ip = connection.getIpAddress() if ip is not None and netutils.isValidIp( ip) and not netutils.isLocalIp(ip): self._ips.append(ip) self._validMacs = macs macs.sort() if macs: self._hostKey = macs[0]
def __init__(self, props, nlbClusterOsh, hostOSH, framework): if not nlbClusterOsh: raise Exception('NLB cluster discovery misconfigured; NLB node have to be linked to existing cluster') self.nlbClusterOsh = nlbClusterOsh self.hostOSH = hostOSH self.priority = props['HostPriority'] self.modeOnStart = props['ClusterModeOnStart'] if props['DedicatedIPAddresses/']: self.ip = props['DedicatedIPAddresses/'].split('/')[0] netMask = props['DedicatedIPAddresses/'].split('/')[1] else: self.ip = props['DedicatedIPAddress'] netMask = props['DedicatedNetworkMask'] self.dedicatedIpOSH = None #check the IP #very unreal situation but we have to handle it if not netutils.isValidIp(self.ip) or netutils.isLocalIp(self.ip): msg = 'Dedicated IP of cluster node is local or invalid: ' + str(self.ip) logger.warn(msg) framework.reportWarning('Dedicated IP of cluster node is local or invalid') else: self.dedicatedIpOSH = modeling.createIpOSH(self.ip, netMask)
def parseNetworkingInformation(self, buffer): """ This function performs parsing of the 'lshmc -n' command output for HMC 3.7 version @param buffer: string buffer of the command output @return: host and ip information @rtype: instance of HostDo object """ host = ibm_hmc_lib.Host() if buffer: propertiesDict = self.buildPropertiesDict(buffer, '\n', ':') host.hostname = propertiesDict.get('Host Name') host.domainName = propertiesDict.get('Domain Name') for (key, value) in propertiesDict.items(): if re.match('TCP/IP Interface \d+ Address', key): if value and netutils.isValidIp( value) and not netutils.isLocalIp(value): ip = ibm_hmc_lib.Ip( value, propertiesDict.get( key.replace('Address', 'Network Mask'))) host.ipList.append(ip) return host
def parseNetworking(self, output): """ This function performs parsing of the 'lsnetcfg -n' command output @param output: string buffer of the command output @return: host and ip information @rtype: instance of HostDo object """ hostDo = ibm_fsm.Host() m = re.search('hostname:\s+([\w\-\.]+)', output) hostDo.hostname = m and m.group(1) m = re.search('domain:\s+([\w\-\.]+)', output) hostDo.domain_name = m and m.group(1) m = re.search('gateway:\s+([\w\-\.]+)', output) hostDo.gateway = m and m.group(1) m = re.search('nameserver:\s+"*([\w\-\.]+)"*', output) hostDo.dns_servers = m and m.group(1).split(',') m = re.search('ipaddr:\s+"*([\d\-\.\,]+)"*', output) ips = m and m.group(1).split(',') m = re.search('networkmask:\s+"*([\d\-\.\,]+)"*', output) masks = m and m.group(1).split(',') for i in xrange(len(ips)): if ips[i] and netutils.isValidIp(ips[i]) and not netutils.isLocalIp(ips[i]): ip = ibm_fsm.Ip(ips[i], masks[i]) hostDo.ipList.append(ip) if not ips: logger.warn('Failed to get IP of the FSM') hostDo.networking = self.parseInterfaces(output) return hostDo
def parseNetworking(self, output): """ This function performs parsing of the 'lsnetcfg -n' command output @param output: string buffer of the command output @return: host and ip information @rtype: instance of HostDo object """ hostDo = ibm_fsm.Host() m = re.search('hostname:\s+([\w\-\.]+)', output) hostDo.hostname = m and m.group(1) m = re.search('domain:\s+([\w\-\.]+)', output) hostDo.domain_name = m and m.group(1) m = re.search('gateway:\s+([\w\-\.]+)', output) hostDo.gateway = m and m.group(1) m = re.search('nameserver:\s+"*([\w\-\.]+)"*', output) hostDo.dns_servers = m and m.group(1).split(',') m = re.search('ipaddr:\s+"*([\d\-\.\,]+)"*', output) ips = m and m.group(1).split(',') m = re.search('networkmask:\s+"*([\d\-\.\,]+)"*', output) masks = m and m.group(1).split(',') for i in xrange(len(ips)): if ips[i] and netutils.isValidIp( ips[i]) and not netutils.isLocalIp(ips[i]): ip = ibm_fsm.Ip(ips[i], masks[i]) hostDo.ipList.append(ip) if not ips: logger.warn('Failed to get IP of the FSM') hostDo.networking = self.parseInterfaces(output) return hostDo
def __discoverInterfacesInfo(self): ips = {} masks = {} interfacesDict = {} interfacesList = [] # Separate out the entries from the network information class entries for entry in self.__ipInfo: interfaceDescr = entry.interfaceDescr interfacesDict[interfaceDescr] = entry.interfaceName ip = entry.ip mask = entry.mask if netutils.isValidIp(ip) and not netutils.isLocalIp(ip): inIPs = ips.get(interfaceDescr, []) if not inIPs: ips[interfaceDescr] = inIPs inIPs.append(ip) inMasks = masks.get(interfaceDescr, []) if not inMasks: masks[interfaceDescr] = inMasks inMasks.append(mask) maclist = self.__getMACsData() if maclist == None: logger.warn('Invalid MAC info, skipping.') else: for interfaceDesc in maclist.keys(): mac = maclist.get(interfaceDesc) if netutils.isValidMac(mac): logger.debug("Interface: %s, MAC: %s" % (interfaceDesc, mac)) mac = netutils.parseMac(mac) interface = NetworkInterface(interfaceDesc, mac, ips.get(interfaceDesc), masks.get(interfaceDesc), -1, 0) interface.name = interfacesDict.get(interfaceDescr) or None; interfacesList.append(interface) return interfacesList
def hostnamelookup(shell, namesToResolve, Framework): filename = '/etc/hosts' cmdResult = None nodeDictionary = {} try: #rawCmdResult = simulatecmd('c:/etchosts.txt') rawCmdResult = shell.safecat(filename) cmdResult = rawCmdResult.strip() except: msg = "Failed reading /etc/host file." errobj = errorobject.createError(errorcodes.COMMAND_OUTPUT_VERIFICATION_FAILED, None, msg) logger.reportWarningObject(errobj) logger.debug(msg) return nodeDictionary keywords = ['Permission\s*Denied', 'Cannot Open'] for keyword in keywords: if re.search(keyword,cmdResult,re.I): msg = "Permission failure." errobj = errorobject.createError(errorcodes.PERMISSION_DENIED, None, msg) logger.reportErrorObject(errobj) logger.debug(msg) return nodeDictionary if (re.search('\r\n', cmdResult)): cmdResult = cmdResult.split('\r\n') elif (re.search('\n', cmdResult)): cmdResult = cmdResult.split('\n') ## Only parse the node names at first, for resolution before ## trying to map the actual interface content for line in cmdResult: try: line = line.strip() ## Parse out headers and blank lines if not line or re.match('#', line): continue Address = None ## Remove trailing comments if (re.search('#', line)): tmp = line.split('#', 1) line = tmp[0] tmp = line.split() # IP Address will be the first entry # Names will follow corresponding to the IP. # We will validate the IP then search for the name to match # If we find it then we will add it into our node dictionary # Alphanumeric representation of the host: # hostname, FQDN, alias.... # Most objects will only have two names # The order (of FQDN, short name, aliases) is not #necessarily standard across platforms/versions if len(tmp) > 1: Address = tmp[0] tmp = tmp[1:] if not Address or not netutils.isValidIp(Address) or netutils.isLocalIp(Address): continue for entry in tmp: if entry in namesToResolve: logger.debug ('Name to resolve ',entry,' Address = ', Address) if nodeDictionary.has_key(entry): logger.debug(concatenate(' From /etc/host output: Node ', entry, ' already has an address; ignoring ' , Address)) else: nodeDictionary[entry] = Address logger.debug(concatenate(' From /etc/host output: Adding ', entry, ' to the list with address: ', Address)) except: msg = "Failed to parse etc/host file." errobj = errorobject.createError(errorcodes.COMMAND_OUTPUT_VERIFICATION_FAILED, None, msg) logger.reportWarningObject(errobj) logger.debug(msg) return nodeDictionary
def hostnamelookup(shell, namesToResolve, Framework): filename = '/etc/hosts' cmdResult = None nodeDictionary = {} try: #rawCmdResult = simulatecmd('c:/etchosts.txt') rawCmdResult = shell.safecat(filename) cmdResult = rawCmdResult.strip() except: msg = "Failed reading /etc/host file." errobj = errorobject.createError( errorcodes.COMMAND_OUTPUT_VERIFICATION_FAILED, None, msg) logger.reportWarningObject(errobj) logger.debug(msg) return nodeDictionary keywords = ['Permission\s*Denied', 'Cannot Open'] for keyword in keywords: if re.search(keyword, cmdResult, re.I): msg = "Permission failure." errobj = errorobject.createError(errorcodes.PERMISSION_DENIED, None, msg) logger.reportErrorObject(errobj) logger.debug(msg) return nodeDictionary if (re.search('\r\n', cmdResult)): cmdResult = cmdResult.split('\r\n') elif (re.search('\n', cmdResult)): cmdResult = cmdResult.split('\n') ## Only parse the node names at first, for resolution before ## trying to map the actual interface content for line in cmdResult: try: line = line.strip() ## Parse out headers and blank lines if not line or re.match('#', line): continue Address = None ## Remove trailing comments if (re.search('#', line)): tmp = line.split('#', 1) line = tmp[0] tmp = line.split() # IP Address will be the first entry # Names will follow corresponding to the IP. # We will validate the IP then search for the name to match # If we find it then we will add it into our node dictionary # Alphanumeric representation of the host: # hostname, FQDN, alias.... # Most objects will only have two names # The order (of FQDN, short name, aliases) is not #necessarily standard across platforms/versions if len(tmp) > 1: Address = tmp[0] tmp = tmp[1:] if not Address or not netutils.isValidIp( Address) or netutils.isLocalIp(Address): continue for entry in tmp: if entry in namesToResolve: logger.debug('Name to resolve ', entry, ' Address = ', Address) if nodeDictionary.has_key(entry): logger.debug( concatenate(' From /etc/host output: Node ', entry, ' already has an address; ignoring ', Address)) else: nodeDictionary[entry] = Address logger.debug( concatenate(' From /etc/host output: Adding ', entry, ' to the list with address: ', Address)) except: msg = "Failed to parse etc/host file." errobj = errorobject.createError( errorcodes.COMMAND_OUTPUT_VERIFICATION_FAILED, None, msg) logger.reportWarningObject(errobj) logger.debug(msg) return nodeDictionary
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() DISCOVERED_IP = Framework.getDestinationAttribute('ip_address') DISCOVERED_IP_ID = Framework.getDestinationAttribute('ip_id') # ip = modeling.createOshByCmdbIdString('ip_address', DISCOVERED_IP_ID) ucmdbVersion = modeling.CmdbClassModel().version() if ucmdbVersion >= 9: ipClass = 'ip_address' else: ipClass = 'ip' protocols = Framework.getAvailableProtocols( DISCOVERED_IP, ClientsConsts.SNMP_PROTOCOL_NAME) if protocols.__len__() == 0: errStr = 'No credentials defined for the triggered ip' logger.debug(errStr) Framework.reportWarning(errStr) else: for protocol in protocols: sysplexNameList = None lparIpList = None snmpOSH = modeling.createSnmpOSH(DISCOVERED_IP, None) client = None try: client = Framework.createClient(protocol) logger.debug('got snmp agent for: ', DISCOVERED_IP) isMultiOid = client.supportMultiOid() sysplexNameList = client.executeQuery( '1.3.6.1.4.1.2.6.19.2.2.2.41,1.3.6.1.4.1.2.6.19.2.2.2.41,string,1.3.6.1.4.1.2.6.19.2.2.2.40,string' ) #@@CMD_PERMISION snmp protocol execution sysplexNameList = sysplexNameList.asTable() lparIpList = client.executeQuery( '1.3.6.1.2.1.4.20.1.1,1.3.6.1.2.1.4.20.1.2,string' ) #@@CMD_PERMISION snmp protocol execution lparIpList = lparIpList.asTable() mainframeMacList = client.executeQuery( '1.3.6.1.2.1.2.2.1.6,1.3.6.1.2.1.2.2.1.7,hexa' ) #@@CMD_PERMISION snmp protocol execution mainframeMacList = mainframeMacList.asTable() snmpOSH.setAttribute('application_port', client.getPort()) snmpOSH.setAttribute('application_timeout', client.getTimeout()) snmpOSH.setAttribute('snmp_port', client.getPort()) snmpOSH.setAttribute('credentials_id', client.getCredentialId()) snmpOSH.setAttribute('snmp_retry', client.getRetries()) snmpOSH.setAttribute('snmp_timeout', client.getTimeout()) if isMultiOid == 1: snmpOSH.setBoolAttribute('snmp_supportmultioid', 1) else: snmpOSH.setBoolAttribute('snmp_supportmultioid', 0) except: logger.debugException('Unexpected SNMP_AGENT Exception:') continue if client != None: client.close() mainframeKey = getMainframeKey(mainframeMacList) if mainframeKey: mainframeOSH = modeling.createCompleteHostOSH( 'mainframe', mainframeKey, machineName=mainframeKey) modeling.setHostOsFamily(mainframeOSH, 'mainframe') OSHVResult.add(mainframeOSH) for currSysplex in sysplexNameList: if logger.isDebugEnabled(): logger.debug('SYSPLEX : ', currSysplex[1]) logger.debug('LPAR : ', currSysplex[2]) logger.debug('MainframeKEY : ', mainframeKey) lparKey = mainframeKey + ':' + currSysplex[2] lparOSH = modeling.createCompleteHostOSH( 'lpar', lparKey, machineName=currSysplex[2]) OSHVResult.add(lparOSH) snmpOSH.setContainer(lparOSH) OSHVResult.add(snmpOSH) # Create contained link between discovered IP and lpar OSHVResult.add( modeling.createLinkOSH( 'contained', lparOSH, modeling.createOshByCmdbIdString( ipClass, DISCOVERED_IP_ID))) # Create member link between lpar and Mainframe OSHVResult.add( modeling.createLinkOSH('member', mainframeOSH, lparOSH)) # Create sysplex sysplexOSH = ObjectStateHolder('sysplex') sysplexOSH.setAttribute('data_name', currSysplex[1]) OSHVResult.add(sysplexOSH) # Create member link between lpar and sysplex OSHVResult.add( modeling.createLinkOSH('member', sysplexOSH, lparOSH)) # Create member link between mainframe and sysplex OSHVResult.add( modeling.createLinkOSH('member', mainframeOSH, sysplexOSH)) # connect all ips to lpar for currLparIp in lparIpList: if netutils.isLocalIp(currLparIp[1]): continue currIpOSH = modeling.createIpOSH(currLparIp[1]) OSHVResult.add(currIpOSH) OSHVResult.add( modeling.createLinkOSH('contained', lparOSH, currIpOSH)) break else: logger.debug("Failed to get Mainframe key.") else: errormessages.resolveAndReport( "Could not perform snmp connection to %s" % DISCOVERED_IP, ClientsConsts.SNMP_PROTOCOL_NAME, Framework) return OSHVResult
def createURLOSHV(urlString, framework=None): OSHVResult = ObjectStateHolderVector() #urlOSH2 = modeling.createOshByCmdbIdString('uri_endpoint', urlId) logger.debug("Starting URL discovery on '%s'" % urlString) #urlString = urlString[1:len(urlString)-1] if not urlString: return OSHVResult try: urlString = str(urlString).replace("\\", "//") urlObject = URL(urlString) hostname = urlObject.getHost() if not hostname: raise MalformedURLException("Hostname is not defined in URL '%s'" % urlString) urlObjectResolver = URLObjectResolver(urlObject) protocol = urlObjectResolver.getProtocolFromUrlObject() if not protocol: raise Exception( "Failed to resolve the http/https protocol from specified URL") port = urlObjectResolver.getPortFromUrlObject() if not port: raise Exception( "Failed to resolve the port number from specified URL") # get topology # create business element CI and attach the url as configuration document CI to it ips = urlObjectResolver.getIpFromUrlObject() for ipAddress in ips: logger.debug('%s: Reporting ip address: %s' % (urlString, ipAddress)) if not ipAddress or not netutils.isValidIp( ipAddress) or netutils.isLocalIp(ipAddress): raise Exception( "Failed to resolve the IP address of server from specified URL" ) hostOSH, ipOSH, OSHVResult2 = createIPEndpointOSHV( framework, ipAddress, port, protocol, hostname) OSHVResult.addAll(OSHVResult2) # create UriEndpoint and relations between business element and UriEndpoint urlOSH = modeling.createUrlOsh(hostOSH, urlString, None) #urlOSH.setCmdbObjectId(urlOSH2.getCmdbObjectId()) OSHVResult.add(urlOSH) OSHVResult.add(modeling.createLinkOSH('dependency', urlOSH, ipOSH)) #create Web Server except: logger.warnException("Error creating URL OSH for %s" % urlString) return OSHVResult
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ms_domain_name = Framework.getDestinationAttribute('ms_domain_name') if not ms_domain_name: ms_domain_name = 'NULL' try: netUtil = MsNetworkUtil() hostsOutput = netUtil.doNetServerEnum('NULL', SV_TYPE_SERVER, ms_domain_name) if hostsOutput != None: discoverUnknownIPs = 1 try: strDiscoverUnknownIPs = Framework.getParameter( 'discoverUnknownIPs') discoverUnknownIPs = Boolean.parseBoolean( strDiscoverUnknownIPs) except: pass oshMsDomain = ObjectStateHolder('msdomain') oshMsDomain.setStringAttribute('data_name', ms_domain_name) alreadyDiscoveredIps = HashMap() for hostInfo in hostsOutput: hostType = Long(hostInfo[1]).longValue() hostName = (str(hostInfo[0])).lower() try: ip = InetAddress.getByName(hostInfo[0]).getHostAddress() if netutils.isLocalIp(ip): continue cachedHostName = alreadyDiscoveredIps.get(ip) if cachedHostName != None: logger.debug( 'IP ', ip, ' already reported for host ' + cachedHostName, ' current host ', hostName, ' - skipping') continue else: logger.debug('Discovered IP ' + ip + ' for host ' + hostName) alreadyDiscoveredIps.put(ip, hostName) ipDomain = DomainScopeManager.getDomainByIp(ip) if not discoverUnknownIPs and ipDomain == 'unknown': logger.debug( 'ip: ' + ip + ' is out of probe range and will be excluded') continue if SV_TYPE_CLUSTER_NT & hostType: logger.debug( 'Not reporting the entry %s because it is a Cluster' % hostName) continue hostOsType = 'nt' if SV_TYPE_SERVER_UNIX & hostType: hostOsType = 'unix' oshHost = modeling.createHostOSH(ip, hostOsType) oshHost.setStringAttribute("host_hostname", hostName) OSHVResult.add(oshHost) link = modeling.createLinkOSH('member', oshMsDomain, oshHost) OSHVResult.add(link) ipOSH = modeling.createIpOSH(ip) OSHVResult.add(ipOSH) contained = modeling.createLinkOSH('contained', oshHost, ipOSH) OSHVResult.add(contained) except: errorMsg = str(sys.exc_info()[1]).strip() logger.warn('Failed to resolve host ', hostInfo[0], ' : ', errorMsg) else: message = 'Failed to discover hosts on MS Domain' logger.warn(message) logger.reportWarning(message) except: errorMsg = str(sys.exc_info()[1]).strip() logger.errorException('Failed to discovery MS Domains') errorMessage = errormessages.makeErrorMessage( "msdomain", errorMsg, errormessages.ERROR_FAILED_DISCOVERING_MSDOMAIN_HOSTS) errobj = errorobject.createError( errorcodes.FAILED_DISCOVERIING_MSDOMAIN_HOST, ["msdomain", errorMsg], errorMessage) logger.reportErrorObject(errobj) return OSHVResult
def __init__(self, dnsResolver, destinationIpAddress): r'@types: netutils.BaseDnsResolver, str' assert (dnsResolver and destinationIpAddress and not netutils.isLocalIp(destinationIpAddress)) self.__dnsResolver = dnsResolver self.__destinationIpAddress = destinationIpAddress
def doQueryMainframeTCP(client, OSHVResult, Framework): ip_address = client.getIpAddress() hostOSH = modeling.createHostOSH(client.getIpAddress()) modeling.setHostOsFamily(hostOSH, 'mainframe') ################ Query and data ################################ resultSetList = client.executeQuery( '1.3.6.1.4.1.2.6.19.2.2.7.1.1.37,1.3.6.1.4.1.2.6.19.2.2.7.1.1.38,string' ) #@@CMD_PERMISION snmp protocol execution resultSetList = resultSetList.asTable() tcpUtil = tcpdbutils.TcpDbUtils(Framework) regExp = '(\d+\.\d+\.\d+\.\d+)\.(\d+)\.(\d+\.\d+\.\d+\.\d+)\.(\d+)' for resultSet in resultSetList: try: currRowData = string.strip(resultSet[0]) processName = string.strip(resultSet[1]) processOSH = modeling.createProcessOSH(processName, hostOSH) OSHVResult.add(processOSH) resArray = re.search(regExp, currRowData) if resArray: ip1 = resArray.group(1) port1 = resArray.group(2) ip2 = resArray.group(3) port2 = resArray.group(4) processName = resultSet[1] # Create # Discard invalid lines (No port#) if port1 == '0': continue # Loop back and listen if netutils.isLocalIp(ip1): prot = 6 #tcp protocol tcpUtil.addPortToProcess(ip_address, int(port1), -1, 1, prot) continue tcpUtil.addTcpConnection(ip1, int(port1), ip2, int(port2)) tcpUtil.addTcpConnection(ip2, int(port2), ip1, int(port1)) # print '--------------------------------' # print 'ip1 :' , ip1 # print 'port1 :' , port1 # print 'ip2 :' , ip2 # print 'port2 :' , port2 # print 'processName :' , processName # print '--------------------------------' except: logger.warnException('Failed ip: %s' % (ip_address)) try: tcpUtil.flushPortToProcesses() except: pass try: tcpUtil.flushTcpConnection() except: pass tcpUtil.close() logger.debug('Finished to process results')
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() urlString = Framework.getParameter(PARAM_URL) reportPoweredOffVms = 0 reportPoweredOffVmsValue = Framework.getParameter( PARAM_REPORT_POWERED_OFF_VMS) if reportPoweredOffVmsValue and reportPoweredOffVmsValue.lower() == 'true': reportPoweredOffVms = 1 ipAddress = None try: urlObject = URL(urlString) hostname = urlObject.getHost() if not hostname: logger.debug("Hostname is not defined in URL '%s'" % urlString) raise MalformedURLException() ipAddress = vcloud_discover.getIpFromUrlObject(urlObject) if not ipAddress or not netutils.isValidIp( ipAddress) or netutils.isLocalIp(ipAddress): msg = "Failed to resolve the IP address of server from specified URL" errormessages.resolveAndReport( msg, vcloud_discover.VcloudProtocol.DISPLAY, Framework) return OSHVResult except MalformedURLException: msg = "Specified URL '%s' is malformed" % urlString errormessages.resolveAndReport(msg, vcloud_discover.VcloudProtocol.DISPLAY, Framework) except: msg = logger.prepareJythonStackTrace("") errormessages.resolveAndReport(msg, vcloud_discover.VcloudProtocol.DISPLAY, Framework) else: #configure how connections should be discovered/established connectionDiscoverer = vcloud_discover.ConnectionDiscoverer(Framework) urlGenerator = vcloud_discover.ConstantUrlGenerator(urlString) connectionDiscoverer.setUrlGenerator(urlGenerator) connectionDiscoverer.addIp(ipAddress) #configure how established/failed connection should be used connectionHandler = vcloud_discover.BaseDiscoveryConnectionHandler( Framework) topologyDiscoverer = vcloud_discover.createVcloudDiscoverer(Framework) topologyReporter = vcloud_report.createVcloudReporter( Framework, None, reportPoweredOffVms) connectionHandler.setDiscoverer(topologyDiscoverer) connectionHandler.setReporter(topologyReporter) connectionDiscoverer.setConnectionHandler(connectionHandler) connectionDiscoverer.initConnectionConfigurations() connectionDiscoverer.discover(firstSuccessful=0) if not connectionHandler.connected: for errorMsg in connectionHandler.connectionErrors: Framework.reportError(errorMsg) for warningMsg in connectionHandler.connectionWarnings: Framework.reportWarning(warningMsg) return OSHVResult
def doUddiExplore(uddiAgent, registryOSH, OSHVResult): table = uddiAgent.doTableCommand("") Empty = '' rows = table.getRowCount() logger.debug('XXXXXXXXXXXXXXX There are Business entity:', rows) for row in range(rows): properties = table.getCell(row, 0) #businessEntity entityName = properties.getProperty(UDDIUtil.BUSINESS_ENTITY_NAME, Empty) entityDescription = properties.getProperty( UDDIUtil.BUSINESS_ENTITY_DESC, Empty) bsOSH = ObjectStateHolder('organization') bsOSH.setAttribute('name', entityName) bsOSH.setAttribute('description', entityDescription) bsOSH.setAttribute('organization_type', 'department') logger.debug('XXXXXXXXXXXXXXX add Business entity:', entityName) contacts = properties.get(UDDIUtil.BUSINESS_ENTITY_CONTACTS) contactinfo = [] if contacts != None: itc = contacts.iterator() while itc.hasNext(): contact = itc.next() contactName = contact.getProperty(UDDIUtil.CONTACT_NAME, Empty) contactPhon = contact.getProperty(UDDIUtil.CONTACT_PHONE, Empty) contactEmail = contact.getProperty(UDDIUtil.CONTACT_EMAIL, Empty) contactUse = contact.getProperty(UDDIUtil.CONTACT_USE_TYPE, Empty) contactinfo.append("[") contactinfo.append(contactName) contactinfo.append(" Phone:") contactinfo.append(contactPhon) contactinfo.append(" Email:") contactinfo.append(contactEmail) contactinfo.append(" Use type:") contactinfo.append(contactUse) contactinfo.append("] ") contactInfoData = ''.join(contactinfo) bsOSH.setAttribute('contact_info', contactInfoData) OSHVResult.add(bsOSH) link2Reg = modeling.createLinkOSH('containment', registryOSH, bsOSH) OSHVResult.add(link2Reg) services = properties.get(UDDIUtil.BUSINESS_ENTITY_SERVICES) if services != None: logger.debug('XXXXXXXXXXXXXXX services:', services.size()) its = services.iterator() while its.hasNext(): service = its.next() name = service.getProperty(UDDIUtil.NAME, Empty) description = service.getProperty(UDDIUtil.DESCRIPTION, Empty) key = service.getProperty(UDDIUtil.KEY, Empty) wsdlUrl = service.getProperty(UDDIUtil.WSDL_URL, Empty) url = service.getProperty(UDDIUtil.URL, Empty) namespace = service.getProperty(UDDIUtil.TARGET_NAME_SPACE, Empty) if not wsdlUrl and url: wsdlUrl = url urlIP = None try: url = URL(wsdlUrl) except: logger.warn("Incorrect URL \"%s\" found. Skipped." % wsdlUrl) continue try: hostName = url.getHost() urlIP = netutils.getHostAddress(hostName, None) if (not netutils.isValidIp(urlIP) ) or netutils.isLocalIp(urlIP): urlIP = None except: urlIP = None urlOSH = modeling.createUrlOsh(registryOSH, wsdlUrl, 'wsdl') urlIpOSH = None if urlIP != None: try: urlIpOSH = modeling.createIpOSH(urlIP) except: urlIpOSH = None OSHVResult.add(urlOSH) if urlIpOSH: OSHVResult.add(urlIpOSH) urlToIpOSH = modeling.createLinkOSH( 'dependency', urlOSH, urlIpOSH) OSHVResult.add(urlToIpOSH) wsOSH = ObjectStateHolder('webservice') wsOSH.setAttribute('name', namespace) wsOSH.setAttribute('description', description) wsOSH.setAttribute('service_name', name) wsOSH.setAttribute('wsdl_url', wsdlUrl) OSHVResult.add(wsOSH) urlToWsOSH = modeling.createLinkOSH('dependency', wsOSH, urlOSH) OSHVResult.add(urlToWsOSH) logger.debug('Service Name: ', name) logger.debug('Service Key: ', key) logger.debug('Service Description: ', description) logger.debug('WSDL url: ', wsdlUrl) logger.debug('Service url: ', url) dependOSH = modeling.createLinkOSH('dependency', wsOSH, registryOSH) link2bus = modeling.createLinkOSH('dependency', wsOSH, bsOSH) OSHVResult.add(dependOSH) OSHVResult.add(link2bus) logger.debug('add containment link to Registry ', name)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() businessElementId = Framework.getDestinationAttribute('id') urlString = Framework.getDestinationAttribute('url') jobId = Framework.getDiscoveryJobId() dnsServers = Framework.getParameter('dnsServers') or None localShell = None if dnsServers: dnsServers = [dnsServer for dnsServer in dnsServers.split(',') if dnsServer and dnsServer.strip()] or None if dnsServers: logger.debug('Using dns servers: ', dnsServers) localShell = shellutils.ShellUtils(Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME)) if not urlString: msg = "There is no specified URL in the input BusinessElement CI" errormessages.resolveAndReport(msg, jobId, Framework) return OSHVResult try: urlString = urlString[1:len(urlString)-1] if netutils.isValidIp(urlString): createHostOSHwithIP(OSHVResult, urlString) return OSHVResult urlObject = URL(urlString) hostname = urlObject.getHost() if not hostname: logger.debug("Hostname is not defined in URL '%s'" % urlString) raise MalformedURLException() urlObjectResolver = URLObjectResolver(urlObject) protocol = urlObjectResolver.getProtocolFromUrlObject() if not protocol: msg = "Failed to resolve the http/https protocol from specified URL" errormessages.resolveAndReport(msg, jobId, Framework) return OSHVResult port = urlObjectResolver.getPortFromUrlObject() if not port: msg = "Failed to resolve the port number from specified URL" errormessages.resolveAndReport(msg, jobId, Framework) return OSHVResult # get topology # create business element CI and attach the url as configuration document CI to it bizOSH = modeling.createOshByCmdbIdString('business_element', businessElementId) urlConfigOSH = modeling.createConfigurationDocumentOSH('url.txt', '', urlString, bizOSH) linkBizUrlConifg = modeling.createLinkOSH('composition', bizOSH, urlConfigOSH) OSHVResult.add(bizOSH) OSHVResult.add(urlConfigOSH) OSHVResult.add(linkBizUrlConifg) hostDNSName = None if not netutils.isValidIp(hostname): # Treat the host name as its DNS name if it is not a valid ip address hostDNSName = hostname ipAddresses = [] if dnsServers: ipAddresses = urlObjectResolver.getIpFromUrlObjectWithDnsList(dnsServers, localShell) else: ipAddresses = urlObjectResolver.getIpFromUrlObject() for ipAddress in ipAddresses: logger.debug('Reporting ip address: ', ipAddresses) if not ipAddress or not netutils.isValidIp(ipAddress) or netutils.isLocalIp(ipAddress): msg = "Failed to resolve the IP address of server from specified URL" errormessages.resolveAndReport(msg, jobId, Framework) return OSHVResult hostOSH, ipOSH = createHostOSHwithIP(OSHVResult, ipAddress) if hostDNSName: ipOSH.setAttribute('authoritative_dns_name', hostDNSName) # create UriEndpoint and relations between business element and UriEndpoint urlOSH = modeling.createServiceURLAddressOsh(hostOSH, urlString) linkBizUrl = modeling.createLinkOSH('usage', bizOSH, urlOSH) OSHVResult.add(urlOSH) OSHVResult.add(linkBizUrl) # create ipServiceEndpoint and relations between UriEndpoint and ipServiceEndpoint ipPort = modeling.createServiceAddressOsh(hostOSH, ipAddress, port, modeling.SERVICEADDRESS_TYPE_TCP) linkUrlIP = modeling.createLinkOSH('dependency', urlOSH, ipOSH) OSHVResult.add(ipPort) OSHVResult.add(linkUrlIP) except MalformedURLException: msg = "Specified URL '%s' is malformed" % urlString errormessages.resolveAndReport(msg, jobId, Framework) except: msg = logger.prepareJythonStackTrace("") errormessages.resolveAndReport(msg, jobId, Framework) return OSHVResult
def doSnmp(client, isClient, snmpOSH, ip_address, ip_domain, Framework, host_cmdbid, host_key, host_macs): '''SnmpClient, osh, str, str, Framework, str, str, list(str) -> ObjectStateHolderVector @deprecated ''' networkList = [] vector = ObjectStateHolderVector() ucmdb_version = modeling.CmdbClassModel().version() # system table snmpQuery = '1.3.6.1.2.1.1.1,1.3.6.1.2.1.1.2,string,1.3.6.1.2.1.1.2,string,1.3.6.1.2.1.1.5,string' table = client.executeQuery(snmpQuery)#@@CMD_PERMISION snmp protocol execution sysname = None oid = None description = None try: if table.next(): description = table.getString(2) oid = table.getString(3) sysname = table.getString(4) except: logger.debugException('') node_description = description or '' sysObjId = oid className, vendorName, hostOsName, hostModel, serialNumberOid, serialNumberSNMPMethod = getNodeDetails(description, oid) logger.debug("Node details:%s, %s, %s, %s, %s, %s"%(className, vendorName, hostOsName, hostModel, serialNumberOid, serialNumberSNMPMethod)) if className == 'netprinter': sysname = getNetPrinterName(client) or sysname hostVersion, hostRelease = getOsVersionAndBuild(hostOsName, description) # since sysUpTime returns a time since the snmp was re-initialized, this # time doesn't provide us correct answer, therefore this code is disabled # snmpQuery = '1.3.6.1.2.1.1.3,1.3.6.1.2.1.1.4,string' # upTime = client.executeQuery(snmpQuery) if oid != None: snmpOSH.setAttribute('snmp_oid', oid) if((sysname != None) and (sysname != '') and (sysname != 'unknown')): snmpOSH.setAttribute('snmp_sysname', sysname) if description != None: snmpOSH.setAttribute('snmp_description', description) logger.debug('ip_address: ', ip_address, ', sysname: ' , sysname, ', className: ', className, ', oid: ', oid, ', description: ', description) #dicovery arp cache available arp_available = SNMP_Networking_Utils.isArpCacheAvailable(client) snmpOSH.setBoolAttribute('arp_cache_available', arp_available) # indx, description & mac interfaceList = [] interfaceDictionary = {} ifList = SNMP_Networking_Utils.discoverInterfaceData(client, None) for nic in ifList: if nic.ifType and int(nic.ifType) == 24: continue macAddress = str(nic.ifMac).upper() if nic.ifIndex != None and nic.ifIndex != '': inrfcindex = nic.ifIndex description = _stripVirtualMiniportInfo(nic.ifDescr) if interfaceDictionary.has_key(inrfcindex): logger.debug('this mac was already reported, skip it ... : inrfcindex: ', inrfcindex, ', descrition: ', description, ', macAddress: ', macAddress) continue logger.debug('inrfcindex: ', inrfcindex, ', description: ', description, ', macAddress: ', macAddress) interfaceDictionary[inrfcindex] = macAddress networkinterface = modeling.NetworkInterface(description, macAddress, None, None, inrfcindex) networkinterface.type = nic.ifType networkinterface.adminStatus = nic.ifAdminStatus networkinterface.operStatus = nic.ifOperStatus networkinterface.speed = nic.ifSpeed networkinterface.name = nic.ifName networkinterface.alias = nic.ifAlias if not networkinterface.name: m = re.match('(lan[\d\:\.]+)', description) if m: networkinterface.name = m.group(1) networkinterface.description = None interfaceList.append(networkinterface) # create the host and all the objects if len(interfaceList) > 0: macToInterfaceListMap = {} for interface in interfaceList: macToInterfaceListMap.setdefault(interface.macAddress, []).append(interface) for ifaceList in macToInterfaceListMap.values(): if ifaceList and len(ifaceList) < 2: continue try: iface = reduce(lambda x,y: x.interfaceIndex > y.interfaceIndex and x or y, ifaceList) iface.role = 'aggregate_interface' except: logger.debugException('') hostOSH = None try: # Get the host_key - lowest mac address of the valid interface list hostOSH = modeling.createCompleteHostOSHByInterfaceList(className, interfaceList, None, None, None, host_cmdbid, host_key, host_macs, ucmdb_version) if (className in netDeviceClasses) and (sysname != None) and (sysname != '') and ((host_cmdbid in ['NA','',None]) or (host_key and (host_key.lower() == sysname.lower()))): # JEO @ Fidelity: use SNMP system name for host key of network devices unless its null hostOSH.setAttribute('host_key', sysname) except: logger.debug('Could not find a valid MAC address for key on ip : ', ip_address) if (className in netDeviceClasses) and (sysname != None) and (sysname != '') and (host_cmdbid in ['NA','',None]): logger.debug('Network device, hostkey is sysname...') hostOSH = modeling.createCompleteHostOSH(className, sysname) else: logger.debug('Creating incomplete host...') hostOSH = modeling.createHostOSH(ip_address, className) logger.debug('Created [' + className + '] strong key=[' + hostOSH.getAttributeValue('host_key') + ']') if((sysname != None) and (sysname != '') and (sysname != 'unknown')): hostOSH.setAttribute('snmp_sys_name', sysname) # set hostname to SNMP system name less domain suffix which is typical of other data sources hostname = sysname.split('.')[0].lower() hostOSH.setAttribute('name', hostname) logger.debug("hostname=" + hostname) defaultGateway = getDefaultGateway(client) modeling.setHostDefaultGateway(hostOSH, defaultGateway) modeling.setHostOsFamily(hostOSH, None, className) if sysObjId and sysObjId.startswith('.') != -1: sysObjId = "." + sysObjId modeling.setSNMPSysObjectId(hostOSH, sysObjId) if((hostOsName != None) and (hostOsName != '') and (hostOsName != 'unknown')): modeling.setHostOsName(hostOSH, hostOsName) if((vendorName != None) and (vendorName != '') and (vendorName != 'unknown')): hostOSH.setAttribute('discovered_os_vendor', vendorName) if((hostModel != None) and (hostModel != '') and (hostModel != 'unknown')): hostOSH.setAttribute('discovered_model', hostModel) if hostRelease is not None: hostOSH.setAttribute('host_osrelease', hostRelease) if hostVersion is not None: hostOSH.setAttribute('discovered_os_version', hostVersion) # since sysUpTime returns a time since the snmp was re-initialized, this # time doesn't provide us correct answer, therefore this code is disabled # if upTime: # today = Calendar.getInstance().getTime() # setLastBootDate(hostOSH, upTime, today, Framework) vector.add(modeling.finalizeHostOsh(hostOSH)) snmpOSH.setContainer(hostOSH) if className == 'mainframe': modeling.setHostOsFamily(hostOSH, 'mainframe') interfaceOshToIndex = {} roleManager = networking_win.InterfaceRoleManager() try: reportInterfaceName = Boolean.parseBoolean(Framework.getParameter('reportInterfaceName')) except: logger.warn('Failed to parse reportInterfaceName parameter falue. Not a Boolean type.') reportInterfaceName = True for nic in interfaceList: if netutils.isValidMac(nic.macAddress): nic.osh = modeling.createInterfaceOSH(nic.macAddress, hostOSH, nic.description, nic.interfaceIndex, nic.type, nic.adminStatus, nic.operStatus, nic.speed, nic.name, nic.alias, reportInterfaceName) roleManager.assignInterfaceRole(nic) interfaceOshToIndex[nic.interfaceIndex] = nic.osh vector.add(nic.osh) else: logger.debug('MAC %s is invalid (name: %s, description: %s, index: %s)' % (nic.macAddress, nic.name, nic.description, nic.interfaceIndex)) # create the ip's logger.debug("create the ip's") snmpQuery = '1.3.6.1.2.1.4.20.1.1, 1.3.6.1.2.1.4.20.1.2, string' table = client.executeQuery(snmpQuery)#@@CMD_PERMISION snmp protocol execution ips = table.asTable() snmpQuery = '1.3.6.1.2.1.4.20.1.2, 1.3.6.1.2.1.4.20.1.3, string' table = client.executeQuery(snmpQuery)#@@CMD_PERMISION snmp protocol execution ifindexes = table.asTable() snmpQuery = '1.3.6.1.2.1.4.20.1.3, 1.3.6.1.2.1.4.20.1.4, string' table = client.executeQuery(snmpQuery)#@@CMD_PERMISION snmp protocol execution ipmasks = table.asTable() try: rfcIpV6Query = '1.3.6.1.2.1.55.1.8.1.1,1.3.6.1.2.1.55.1.8.1.5, string' rfcIpV6Result = client.executeQuery(rfcIpV6Query)#@@CMD_PERMISION snmp protocol execution results = rfcIpV6Result.asTable() except: logger.warn('Failed to get or process IPv6 MIB results.') #try to collect IPv6 addresses from IPv6 address table and connect them to corresponding interface logger.debug("Begin to discovery IPv6 related info") try: ipv6Map = {} ipv6AddressTable = SNMP_Networking_Utils.discoverIPv6AddressTable(client) if ipv6AddressTable: for row in ipv6AddressTable: if row.ipv6AddrStatus != '1':# 1 means valid ip address in arp cache continue ifIndex, ipAddress = _parseIPv6FromIndex(row.ipv6AddrAddress) if ifIndex and ipAddress: try: formatedIP = getValidIP(ipAddress) if formatedIP: ipv6Map[ifIndex] = formatedIP except: pass mixedIPAddressTable = SNMP_Networking_Utils.discoverMixedIPAddressTable(client) if mixedIPAddressTable: for row in mixedIPAddressTable: if row.ipAddressStatus != '1' or row.ipAddressRowStatus != '1':# 1 means valid ip address in arp cache continue ifIndex = row.ipAddressIfIndex ipAddress = _parseMixedIPFromIndex(row.ipAddressAddr) if ifIndex and ipAddress: try: formatedIP = getValidIP(ipAddress) if formatedIP and formatedIP.version == 6: ipv6Map[ifIndex] = formatedIP except: pass if ipv6Map and interfaceOshToIndex: for ifIndex in ipv6Map.keys(): ipv6 = ipv6Map[ifIndex] logger.debug("Discovered IPv6:", ipv6) ipOSH = modeling.createIpOSH(ipv6) vector.add(ipOSH) interfaceOsh = interfaceOshToIndex.get(str(ifIndex)) if not interfaceOsh and isClient: logger.info('client ip is not associated with an interface') msg = "Can not find the related interface for client IP: %s" % ip_address logger.reportWarningObject(errormessages.resolveError(msg, 'SNMP')) continue if interfaceOsh: parent = modeling.createLinkOSH('containment', interfaceOsh, ipOSH) vector.add(parent) interfaceMacAddress = interfaceOsh.getAttributeValue('mac_address') if (isClient == TRUE): ipOSH.setAttribute('arp_mac', interfaceMacAddress) if ( ipv6 == ip_addr_util.IPAddress(ip_address)):#compare ipv6 by the formatting to avoid same IPv6 with different format snmpOSH.setAttribute('arp_mac', interfaceMacAddress) isCompleteAttribute = hostOSH.getAttribute('host_iscomplete') if isCompleteAttribute is not None and isCompleteAttribute.getBooleanValue() == 1: contained = modeling.createLinkOSH('contained', hostOSH, ipOSH) vector.add(contained) except: logger.debug(str(sys.exc_info())) index = 0 if len(ips) > 0 and len(ifindexes) > 0: for ip in ips: try: ip_addr = ip[1] #logger.debug('candidate ip_addr: ', ip_addr) ifIndex = ifindexes[index][1] mask = ipmasks[index][1] index += 1 interfaceOsh = interfaceOshToIndex.get(ifIndex) ''' this commented out block should be removed # no such thing as netmask IPs, there are broadcast IPs which have .255 in them # but we would definitely want to discover and nic which was asssigned # such an address - #if(ip_addr.find('255.') == 0 ): #exclude netmask ip #continue ''' if netutils.isValidIp(ip_addr) and (not netutils.isLocalIp(ip_addr)): ''' netutils.isLocalIp is not finding all local addresses 127.0.0.0 through 127.255.255.255 are local additional if clause can be removed when this is fixed see http://www.tcpipguide.com/free/t_IPReservedPrivateandLoopbackAddresses.htm ''' # ip is valid and not local (i.e. 0.0.0.0, 127.0.0.1) ipOSH = modeling.createIpOSH(ip_addr, mask) else: # loopbacks are standard; don't complain about them in the logs continue logger.debug('ip_addr: ', ip_addr, ', mask: ', mask) netOSH = modeling.createNetworkOSH(ip_addr, mask) strNetAddr = str(netOSH.getAttribute('network_netaddr')) strNetMask = str(netOSH.getAttribute('network_netMask')) currNet = strNetAddr + strNetMask broadcastIp = netOSH.getAttributeValue('network_broadcastaddress') if ip_address == broadcastIp: raise BroadcastIpDiscoveryException() if not interfaceOsh and isClient: logger.info('client ip is not associated with an interface') msg = "Can not find the related interface for client IP: " + ip_addr logger.reportWarningObject(errormessages.resolveError(msg, 'SNMP')) continue if interfaceOsh: parent = modeling.createLinkOSH('containment', interfaceOsh, ipOSH) vector.add(parent) interfaceMacAddress = interfaceOsh.getAttributeValue('mac_address') if (isClient == TRUE): ipOSH.setAttribute('arp_mac', interfaceMacAddress) if (ip_addr == ip_address): snmpOSH.setAttribute('arp_mac', interfaceMacAddress) member1 = modeling.createLinkOSH('member', netOSH, ipOSH) member2 = modeling.createLinkOSH('member', netOSH, hostOSH) if currNet in networkList: pass else: networkList.append(currNet) vector.add(netOSH) vector.add(member2) vector.add(ipOSH) vector.add(member1) # link IPs to host only in case host is complete # otherwise reconciliation may fail isCompleteAttribute = hostOSH.getAttribute('host_iscomplete') if isCompleteAttribute is not None and isCompleteAttribute.getBooleanValue() == 1: contained = modeling.createLinkOSH('contained', hostOSH, ipOSH) vector.add(contained) if interfaceOsh: parent = modeling.createLinkOSH('containment', interfaceOsh, ipOSH) vector.add(parent) except BroadcastIpDiscoveryException, ex: raise ex except: pass
def isLocal(self): if isinstance(self.ip, type("")) or isinstance(self.ip, type(u"")): return netutils.isLocalIp(self.ip) else: return self.ip.is_loopback or self.ip.is_unspecified
def DiscoveryMain(Framework): """ Retrieving a list of LDAP ports we strive to connect to domain controller in member role first. So we have to choose the lowest port number in the list. """ protocolName = "LDAP" OSHVResult = ObjectStateHolderVector() baseDn = Framework.getParameter('baseDN') or None if baseDn == 'NA': baseDn = None ipAddress = Framework.getDestinationAttribute('ip_address') credentialsId = Framework.getDestinationAttribute('credentials_id') applicationPort = Framework.getDestinationAttribute("application_port") serviceAddressPort = Framework.getDestinationAttribute('port') if not applicationPort or applicationPort == 'NA': applicationPort = serviceAddressPort # build environment and connect envBuilder = active_directory_utils.LdapEnvironmentBuilder(applicationPort) client = Framework.createClient(credentialsId, envBuilder.build()) discoverer = oracle_ldap_discoverer.OracleLdapDiscoverer(client, baseDn) try: probe_client = Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME) probe_shell = shellutils.ShellFactory().createShell(probe_client) resolver = netutils.FallbackResolver([netutils.JavaDnsResolver(), netutils.DnsResolverByShell(probe_shell)]) # discover servers = discoverer.discover() # report endpoint_builder = netutils.ServiceEndpointBuilder() endpoint_reporter = netutils.EndpointReporter(endpoint_builder) oracle_builder = db_builder.Oracle() reporter = db.OracleTopologyReporter(oracle_builder, endpoint_reporter) for dbServer in servers: if dbServer: try: address = dbServer.address if not ip_addr.isValidIpAddress(address): ips = resolver.resolveIpsByHostname(address) if ips and len(ips) > 0: dbServer.address = str(ip_addr.IPAddress(ips[0])) # get Host OSH if not (dbServer.address and netutils.isValidIp(address) and not netutils.isLocalIp(address)): raise ValueError("Address for the specified server is not valid or is local") hostOsh = modeling.createHostOSH(dbServer.address) # report database OSHVResult.addAll(reporter.reportServerAndDatabases(dbServer, hostOsh)) # report TNS Listener listener = db.OracleListener(dbServer.address, dbServer.getPort()) OSHVResult.addAll(reporter.reportTnsListener(listener, hostOsh)) # report Oracle Service Names if dbServer.getServiceNames(): OSHVResult.addAll(reporter.reportServiceNameTopology(dbServer.getServiceNames(), listener.getOsh(), dbServer.getOsh())) except netutils.ResolveException: logger.error("Cannot resolve " + dbServer.address + ". Skip") except oracle_ldap_discoverer.OracleContextDiscoveryException, ex: msg = str(ex) logger.debugException(msg) logger.error(msg)
def makeAppServer(client, username, enterprise, serverObj, serverDataRow, siteOSH, Framework, OSHVResult): # init return value logger.debug('server:', string.join(serverObj), ' dataRow:', serverDataRow) datalist = serverObj sblsvrName = datalist[0] logger.debug('sblsvrName:', sblsvrName) hostName = datalist[1] installDir = datalist[2] sblmgrPID = datalist[3] serverID = datalist[9] # if no PID, server is not running. send an event on it # the message of the event will be everything that follows # the PID field if string.strip(sblmgrPID) == '': logger.debug('problem server:', serverDataRow) runningServer = 0 logger.debug('app server', sblsvrName, ' is not Running') else: runningServer = 1 # called status, but actually version details status = datalist[8] logger.debug('status:', status) versionTokens = status.split() version = versionTokens[0] build = versionTokens[1] lang = versionTokens[2] # host logger.debug('building host:', hostName) try: ip = netutils.getHostAddress(hostName) logger.debug('found ip:', ip, ' for hostName:', hostName) if ip == None: return None if netutils.isLocalIp(ip): logger.debug('got loopback ip, probably error.') return None appServerHostOSH = modeling.createHostOSH(ip) except: logger.errorException('failed to convert host name:', hostName, ' to IP') return None # siebel application server appServerOSH = modeling.createApplicationOSH('siebel_app_server', sblsvrName, appServerHostOSH, 'Enterprise App', 'oracle_corp') appServerOSH.setAttribute('application_ip', ip) appServerOSH.setAttribute('application_username', username) appServerOSH.setAttribute('install_dir', installDir) appServerOSH.setAttribute('svr_id',serverID) modeling.setAppServerType(appServerOSH) #9.0 workaround versionAsDouble = logger.Version().getVersion(Framework) if versionAsDouble >= 9: appServerOSH.removeAttribute('data_name') appServerOSH.setAttribute('name', sblsvrName) modeling.setApplicationProductName(appServerOSH, 'Siebel Server') OSHVResult.add(appServerHostOSH) OSHVResult.add(appServerOSH) if runningServer: appServerOSH.setAttribute('version', version) appServerOSH.setAttribute('application_version', version) appServerOSH.setAttribute('build', build) appServerOSH.setAttribute('lang', lang) # NOTE: setting the current app server so that all info will be only # for it prompt = client.executeCmd(string.join(['set server ', sblsvrName]), 5000)#@@CMD_PERMISION siebel protocol execution logger.debug(prompt) # get component groups (and components for each group) for this server # NOTE: as far as we know there can't be components that are not under a group # if such a situation can exist we won't find such 'leaf' components # with the current code # # makeComponentGroups(client, appServerOSH, ip, OSHVResult, enterprise, siteOSH) if version[0] == '7' or version[0] == '8': # get DB (Data Source) Attributes # table[0][0][1] means: # [0] - first row (should be only one, we are inside a server context) # [0] - first column: the parsed fields (second column is original row for error purposes) # [1] - second value in the parsed fields try: svrdsconnstrTblTxt = client.executeCmd('list parameter DSConnectString for named subsystem ServerDataSrc')#@@CMD_PERMISION siebel protocol execution svrdsconnstrTbl = siebel_common.makeTable(svrdsconnstrTblTxt) svrdsconnstr = string.upper(svrdsconnstrTbl[0][0][1]) logger.debug('svrdsconnstr:', svrdsconnstr) appServerOSH.setAttribute('srv_ds_conn_str', svrdsconnstr) except: error_message = 'failed to get DSConnectString (to set attribute srv_ds_conn_str) on server' logger.debug(error_message) Framework.reportWarning(error_message) try: svrdstypeTblTxt = client.executeCmd('list parameters DSSQLStyle for named subsystem ServerDataSrc')#@@CMD_PERMISION siebel protocol execution svrdstypeTbl = siebel_common.makeTable(svrdstypeTblTxt) if svrdstypeTbl: svrdstype = svrdstypeTbl[0][0][1] else: svrdstypeTblTxt = client.executeCmd('list parameters DSDLLName for named subsystem ServerDataSrc')#@@CMD_PERMISION siebel protocol execution svrdstypeTbl = siebel_common.makeTable(svrdstypeTblTxt) svrdstype = DLL_TO_SQL_TYPE_MAP[svrdstypeTbl[0][0][1]] logger.debug('svrdstype:', svrdstype) appServerOSH.setAttribute('svr_ds_type', svrdstype) except: error_message = 'failed to get DSSQLStyle (to set attribute svr_ds_type) on server' logger.debugException(error_message) Framework.reportWarning(error_message) serverType = getSiebelServerType(client) if serverType: appServerOSH.setStringAttribute('data_description', serverType) else: logger.warn("Cannot determine the type of server '%s', no required components were found" % sblsvrName) if version[0] == '6': # in Siebel 2000 (tested with 6.3), we can't obtain some of the parameters using command line API # get missing attributes from configuration file logger.info('Datasource parameters are not supported in version ', version) logger.info('Please run SIEBEL_DIS_APP_SERVER_CONFIG pattern to get server datasource attributes') try: odbcDSNTblTxt = client.executeCmd('list param connect')#@@CMD_PERMISION siebel protocol execution odbcDSNTbl = siebel_common.makeTable(odbcDSNTblTxt) odbcDSN = odbcDSNTbl[0][0][1] logger.debug('odbcDSN:', odbcDSN) appServerOSH.setAttribute('odbc_dsn', odbcDSN) except: error_message = 'failed to get ODBC DSN (connect param (to set attribute odbc_dsn) on server' logger.debug(error_message) Framework.reportWarning(error_message) # NOTE: unsetting the current app server prompt = client.executeCmd('unset server', 3000)#@@CMD_PERMISION siebel protocol execution logger.debug(prompt) return appServerOSH
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() DISCOVERED_IP = Framework.getDestinationAttribute('ip_address') DISCOVERED_IP_ID = Framework.getDestinationAttribute('ip_id') # ip = modeling.createOshByCmdbIdString('ip_address', DISCOVERED_IP_ID) ucmdbVersion = modeling.CmdbClassModel().version() if ucmdbVersion >= 9: ipClass = 'ip_address' else: ipClass = 'ip' protocols = Framework.getAvailableProtocols(DISCOVERED_IP, ClientsConsts.SNMP_PROTOCOL_NAME) if protocols.__len__() == 0: errStr = 'No credentials defined for the triggered ip' logger.debug(errStr) Framework.reportWarning(errStr) else: for protocol in protocols: sysplexNameList = None lparIpList = None snmpOSH = modeling.createSnmpOSH(DISCOVERED_IP, None) client = None try: client = Framework.createClient(protocol) logger.debug('got snmp agent for: ', DISCOVERED_IP) isMultiOid = client.supportMultiOid() sysplexNameList = client.executeQuery( '1.3.6.1.4.1.2.6.19.2.2.2.41,1.3.6.1.4.1.2.6.19.2.2.2.41,string,1.3.6.1.4.1.2.6.19.2.2.2.40,string' )#@@CMD_PERMISION snmp protocol execution sysplexNameList = sysplexNameList.asTable() lparIpList = client.executeQuery( '1.3.6.1.2.1.4.20.1.1,1.3.6.1.2.1.4.20.1.2,string' )#@@CMD_PERMISION snmp protocol execution lparIpList = lparIpList.asTable() mainframeMacList = client.executeQuery( '1.3.6.1.2.1.2.2.1.6,1.3.6.1.2.1.2.2.1.7,hexa' )#@@CMD_PERMISION snmp protocol execution mainframeMacList = mainframeMacList.asTable() snmpOSH.setAttribute('application_port', client.getPort()) snmpOSH.setAttribute('application_timeout', client.getTimeout()) snmpOSH.setAttribute('snmp_port', client.getPort()) snmpOSH.setAttribute('credentials_id', client.getCredentialId()) snmpOSH.setAttribute('snmp_retry', client.getRetries()) snmpOSH.setAttribute('snmp_timeout', client.getTimeout()) if isMultiOid == 1: snmpOSH.setBoolAttribute('snmp_supportmultioid', 1) else: snmpOSH.setBoolAttribute('snmp_supportmultioid', 0) except: logger.debugException('Unexpected SNMP_AGENT Exception:') continue if client != None: client.close() mainframeKey = getMainframeKey(mainframeMacList) if mainframeKey: mainframeOSH = modeling.createCompleteHostOSH('mainframe', mainframeKey, machineName = mainframeKey) modeling.setHostOsFamily(mainframeOSH, 'mainframe') OSHVResult.add(mainframeOSH) for currSysplex in sysplexNameList: if logger.isDebugEnabled(): logger.debug( 'SYSPLEX : ', currSysplex[1] ) logger.debug( 'LPAR : ', currSysplex[2] ) logger.debug( 'MainframeKEY : ', mainframeKey ) lparKey = mainframeKey + ':' + currSysplex[2] lparOSH = modeling.createCompleteHostOSH('lpar', lparKey, machineName = currSysplex[2]) OSHVResult.add(lparOSH) snmpOSH.setContainer(lparOSH) OSHVResult.add(snmpOSH) # Create contained link between discovered IP and lpar OSHVResult.add(modeling.createLinkOSH('contained', lparOSH, modeling.createOshByCmdbIdString(ipClass, DISCOVERED_IP_ID))) # Create member link between lpar and Mainframe OSHVResult.add(modeling.createLinkOSH('member', mainframeOSH, lparOSH)) # Create sysplex sysplexOSH = ObjectStateHolder('sysplex') sysplexOSH.setAttribute('data_name', currSysplex[1]) OSHVResult.add(sysplexOSH) # Create member link between lpar and sysplex OSHVResult.add(modeling.createLinkOSH('member', sysplexOSH, lparOSH)) # Create member link between mainframe and sysplex OSHVResult.add(modeling.createLinkOSH('member', mainframeOSH, sysplexOSH)) # connect all ips to lpar for currLparIp in lparIpList: if netutils.isLocalIp(currLparIp[1]): continue currIpOSH = modeling.createIpOSH(currLparIp[1]) OSHVResult.add(currIpOSH) OSHVResult.add(modeling.createLinkOSH('contained', lparOSH, currIpOSH)) break else: logger.debug("Failed to get Mainframe key.") else: errormessages.resolveAndReport("Could not perform snmp connection to %s" % DISCOVERED_IP, ClientsConsts.SNMP_PROTOCOL_NAME, Framework) return OSHVResult
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() businessElementId = Framework.getDestinationAttribute('id') urlString = Framework.getDestinationAttribute('url') jobId = Framework.getDiscoveryJobId() dnsServers = Framework.getParameter('dnsServers') or None localShell = None if dnsServers: dnsServers = [ dnsServer for dnsServer in dnsServers.split(',') if dnsServer and dnsServer.strip() ] or None if dnsServers: logger.debug('Using dns servers: ', dnsServers) localShell = shellutils.ShellUtils( Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME)) if not urlString: msg = "There is no specified URL in the input BusinessElement CI" errormessages.resolveAndReport(msg, jobId, Framework) return OSHVResult try: urlString = urlString[1:len(urlString) - 1] if netutils.isValidIp(urlString): createHostOSHwithIP(OSHVResult, urlString) return OSHVResult urlObject = URL(urlString) hostname = urlObject.getHost() if not hostname: logger.debug("Hostname is not defined in URL '%s'" % urlString) raise MalformedURLException() urlObjectResolver = URLObjectResolver(urlObject) protocol = urlObjectResolver.getProtocolFromUrlObject() if not protocol: msg = "Failed to resolve the http/https protocol from specified URL" errormessages.resolveAndReport(msg, jobId, Framework) return OSHVResult port = urlObjectResolver.getPortFromUrlObject() if not port: msg = "Failed to resolve the port number from specified URL" errormessages.resolveAndReport(msg, jobId, Framework) return OSHVResult # get topology # create business element CI and attach the url as configuration document CI to it bizOSH = modeling.createOshByCmdbIdString('business_element', businessElementId) urlConfigOSH = modeling.createConfigurationDocumentOSH( 'url.txt', '', urlString, bizOSH) linkBizUrlConifg = modeling.createLinkOSH('composition', bizOSH, urlConfigOSH) OSHVResult.add(bizOSH) OSHVResult.add(urlConfigOSH) OSHVResult.add(linkBizUrlConifg) hostDNSName = None if not netutils.isValidIp(hostname): # Treat the host name as its DNS name if it is not a valid ip address hostDNSName = hostname ipAddresses = [] if dnsServers: ipAddresses = urlObjectResolver.getIpFromUrlObjectWithDnsList( dnsServers, localShell) else: ipAddresses = urlObjectResolver.getIpFromUrlObject() for ipAddress in ipAddresses: logger.debug('Reporting ip address: ', ipAddresses) if not ipAddress or not netutils.isValidIp( ipAddress) or netutils.isLocalIp(ipAddress): msg = "Failed to resolve the IP address of server from specified URL" errormessages.resolveAndReport(msg, jobId, Framework) return OSHVResult hostOSH, ipOSH = createHostOSHwithIP(OSHVResult, ipAddress) if hostDNSName: ipOSH.setAttribute('authoritative_dns_name', hostDNSName) # create UriEndpoint and relations between business element and UriEndpoint urlOSH = modeling.createServiceURLAddressOsh(hostOSH, urlString) linkBizUrl = modeling.createLinkOSH('usage', bizOSH, urlOSH) OSHVResult.add(urlOSH) OSHVResult.add(linkBizUrl) # create ipServiceEndpoint and relations between UriEndpoint and ipServiceEndpoint ipPort = modeling.createServiceAddressOsh( hostOSH, ipAddress, port, modeling.SERVICEADDRESS_TYPE_TCP) linkUrlIP = modeling.createLinkOSH('dependency', urlOSH, ipOSH) OSHVResult.add(ipPort) OSHVResult.add(linkUrlIP) except MalformedURLException: msg = "Specified URL '%s' is malformed" % urlString errormessages.resolveAndReport(msg, jobId, Framework) except: msg = logger.prepareJythonStackTrace("") errormessages.resolveAndReport(msg, jobId, Framework) return OSHVResult
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ms_domain_name = Framework.getDestinationAttribute('ms_domain_name') if not ms_domain_name: ms_domain_name = 'NULL' try: netUtil = MsNetworkUtil() hostsOutput = netUtil.doNetServerEnum('NULL',SV_TYPE_SERVER, ms_domain_name) if hostsOutput != None: discoverUnknownIPs = 1 try: strDiscoverUnknownIPs = Framework.getParameter('discoverUnknownIPs'); discoverUnknownIPs = Boolean.parseBoolean(strDiscoverUnknownIPs); except: pass oshMsDomain = ObjectStateHolder('msdomain') oshMsDomain.setStringAttribute('data_name', ms_domain_name) alreadyDiscoveredIps = HashMap() for hostInfo in hostsOutput: hostType = Long(hostInfo[1]).longValue() hostName = (str(hostInfo[0])).lower() try: ip = InetAddress.getByName(hostInfo[0]).getHostAddress() if netutils.isLocalIp(ip): continue cachedHostName = alreadyDiscoveredIps.get(ip) if cachedHostName != None: logger.debug('IP ', ip, ' already reported for host ' + cachedHostName, ' current host ', hostName, ' - skipping') continue else: logger.debug('Discovered IP ' + ip + ' for host ' + hostName) alreadyDiscoveredIps.put(ip, hostName) ipDomain = DomainScopeManager.getDomainByIp(ip) if not discoverUnknownIPs and ipDomain == 'unknown': logger.debug('ip: ' + ip + ' is out of probe range and will be excluded') continue if SV_TYPE_CLUSTER_NT & hostType: logger.debug('Not reporting the entry %s because it is a Cluster' % hostName) continue hostOsType = 'nt' if SV_TYPE_SERVER_UNIX & hostType: hostOsType = 'unix' oshHost = modeling.createHostOSH(ip, hostOsType) oshHost.setStringAttribute("host_hostname", hostName) OSHVResult.add(oshHost) link = modeling.createLinkOSH('member', oshMsDomain, oshHost) OSHVResult.add(link) ipOSH = modeling.createIpOSH(ip) OSHVResult.add(ipOSH) contained = modeling.createLinkOSH('contained', oshHost, ipOSH) OSHVResult.add(contained) except: errorMsg = str(sys.exc_info()[1]).strip() logger.warn('Failed to resolve host ', hostInfo[0], ' : ', errorMsg) else: message = 'Failed to discover hosts on MS Domain' logger.warn(message) logger.reportWarning(message) except: errorMsg = str(sys.exc_info()[1]).strip() logger.errorException('Failed to discovery MS Domains') errorMessage = errormessages.makeErrorMessage("msdomain", errorMsg, errormessages.ERROR_FAILED_DISCOVERING_MSDOMAIN_HOSTS) errobj = errorobject.createError(errorcodes.FAILED_DISCOVERIING_MSDOMAIN_HOST, ["msdomain", errorMsg], errorMessage) logger.reportErrorObject(errobj) return OSHVResult