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 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 _reportIisTopology(self, result, discoverSharePointUrls = 0, reportIntermediateWebService = 1): """ Adds IIS topology into vector. Reports: nt, iis, iisapppool, iiswebsite, ipserver, url ObjectStateHolderVector, bool->None """ ipToIis = {} for ws in self._webServices: if ipToIis.has_key(ws.ip): iisHostOsh, iisOsh, iisWebService = ipToIis[ws.ip] else: iisHostOsh = modeling.createHostOSH(ws.ip, 'nt') #review>> why to build in report iisOsh = modeling.createWebServerOSH('Microsoft-IIS', 0, None, iisHostOsh, 0) if reportIntermediateWebService: iisWebService = ObjectStateHolder('iiswebservice') modeling.setAdditionalKeyAttribute(iisWebService, 'data_name', 'IIsWebService') iisWebService.setContainer(iisOsh) result.add(iisWebService) else: iisWebService = iisOsh result.add(iisHostOsh) result.add(iisOsh) link = modeling.createLinkOSH('member', self._farm.osh, iisOsh) result.add(link) ipToIis[ws.ip] = (iisHostOsh, iisOsh, iisWebService) appPoolOshList = [] for appPool in ws.applicationPoolNames: iisapppoolOsh = ObjectStateHolder('iisapppool') iisapppoolOsh.setAttribute('data_name', appPool) iisapppoolOsh.setContainer(iisOsh) result.add(iisapppoolOsh) appPoolOshList.append(iisapppoolOsh) for webApp in ws.webApplications: iiswebsiteOSH = ObjectStateHolder('iiswebsite') iiswebsiteOSH.setAttribute('data_name', webApp.name) iiswebsiteOSH.setContainer(iisWebService) result.add(iiswebsiteOSH) for iisapppoolOsh in appPoolOshList: link = modeling.createLinkOSH('use', iiswebsiteOSH, iisapppoolOsh) result.add(link) if (discoverSharePointUrls): for site in webApp.siteNames: urlOsh = modeling.createUrlOsh(iisHostOsh, site) result.add(urlOsh) link = modeling.createLinkOSH('contained', iiswebsiteOSH, urlOsh) result.add(link)
def _reportDbToSharePointLinks(self, result, sharepointOsh): """ Generates links between sharepoint software element and databases. Reports ipserver_address, use, clientserver ObjectStateHolderVector, OSH->None """ reportedDatabaseLinks = [] for dbConnection in self._databaseConnections: if dbConnection.name in reportedDatabaseLinks: continue dbOsh = self._dbNameToDbOsh[dbConnection.name] dbUrlOsh = modeling.createUrlOsh(dbOsh, 'sql://'+dbConnection.name) result.add(dbUrlOsh) link = modeling.createLinkOSH('client_server', sharepointOsh, dbUrlOsh) link.setAttribute('clientserver_protocol', 'SQL') result.add(link) reportedDatabaseLinks.append(dbConnection.name)
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 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 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