def discoverConfigFile(siebelRootDir,appServerOSH,client,version,OSHVResult): shellUtils = ShellUtils(client) relativePaths = [''] protocolType = client.getClientType() if protocolType == ClientsConsts.NTCMD_PROTOCOL_NAME: relativePaths = ['\\bin\\ENU\\','\\bin\\'] else: relativePaths = ['/bin/enu/','/bin/ENU/','/bin/'] found = 0 for relativePath in relativePaths: path = siebelRootDir + relativePath + 'siebel.cfg' try: data = shellUtils.safecat(path) if not error(data,protocolType): found = 1 break except: pass if found==0: logger.error('Failed getting configuration file') return if version != None and version != '' and (version[0] == '6' or version.find('7.8') == 0): updateMissingAttributes(data,appServerOSH,OSHVResult) lastUpdateTime = file_ver_lib.getFileLastModificationTime(shellUtils, path) configfile = modeling.createConfigurationDocumentOSH('siebel.cfg', '', data, appServerOSH, modeling.MIME_TEXT_PLAIN, lastUpdateTime, "Configuration file of siebel application server") logger.debug('found siebel config file:') OSHVResult.add(configfile)
def discoverConfigFile(siebelRootDir, appServerOSH, client, version, OSHVResult): shellUtils = ShellUtils(client) relativePaths = [''] protocolType = client.getClientType() if protocolType == ClientsConsts.NTCMD_PROTOCOL_NAME: relativePaths = ['\\bin\\ENU\\', '\\bin\\'] else: relativePaths = ['/bin/enu/', '/bin/ENU/', '/bin/'] found = 0 for relativePath in relativePaths: path = siebelRootDir + relativePath + 'siebel.cfg' try: data = shellUtils.safecat(path) if not error(data, protocolType): found = 1 break except: pass if found == 0: logger.error('Failed getting configuration file') return if version != None and version != '' and (version[0] == '6' or version.find('7.8') == 0): updateMissingAttributes(data, appServerOSH, OSHVResult) lastUpdateTime = file_ver_lib.getFileLastModificationTime(shellUtils, path) configfile = modeling.createConfigurationDocumentOSH( 'siebel.cfg', '', data, appServerOSH, modeling.MIME_TEXT_PLAIN, lastUpdateTime, "Configuration file of siebel application server") logger.debug('found siebel config file:') OSHVResult.add(configfile)
def getBackupFiles(self, databases, dbList, hostId, oshvResult): result = HashMap() query = Util.replace(Queries.DATABASE_BACKUP_FILES, dbList) rs = self.connection.getTable(query) disks = ArrayList() while rs.next(): currentDbName = rs.getString("name") path = rs.getString("path") if path is not None: #extract the path path = Util.replaceFileSeparator(path) disk = Util.getDisk(path, hostId) disks.add(disk) fileName = Util.getFileFromPath(path) path = Util.getPath(path) configFileOsh = modeling.createConfigurationDocumentOSH( fileName, path, None, hostId) result.put(currentDbName, configFileOsh) itr = disks.iterator() while itr.hasNext(): oshvResult.add(itr.next()) rs.close() return result
def __buildGroupConfig(self, group, fileName, description): r'@types: aws_rds.Group -> ObjectStateHolder' group = MixIn(group, Serializable) return modeling.createConfigurationDocumentOSH(fileName, None, group.serialize(), contentType=modeling.MIME_TEXT_PLAIN, description=description)
def buildFirewallConfig(config, container_osh): ''' @param config: discovered firewall config @type config: instance of FirewallConfig @param container_osh: OSH allowed to be a container for configuration_document @type container_osh: OSH @return: configuretion_document OSH ''' content = '' for key in config.type_to_rules_dict.keys(): content += '%s\n' % key logger.debug('Building %s' % key) for obj in config.type_to_rules_dict.get(key): attrs = vars(obj) logger.debug(attrs) if attrs: content += '%s\n' % ('\n'.join( ['%s = %s' % (key, value) for key, value in attrs.items()])) config_osh = modeling.createConfigurationDocumentOSH( name=config.name, path=config.name, content=content, containerOSH=container_osh) return config_osh
def getComponentParams(client, name, compOSH): paramsListing = client.executeCmd('list params for component ' + name)#@@CMD_PERMISION siebel protocol execution propmptIndex = paramsListing.find('srvrmgr:') if propmptIndex > 0: paramsListing = paramsListing[0:propmptIndex] paramsListing = paramsListing.replace(siebel_common.DELIMITER,' ') configFileOsh = modeling.createConfigurationDocumentOSH('parameters.txt', '', paramsListing, compOSH, modeling.MIME_TEXT_PLAIN, None, 'This file contains all components parameters') return configFileOsh
def _reportProfile(profileInfo, systemOsh): r'@types: tuple[str, str], ObjectStateHolder -> ObjectStateHolder' pfName, content = profileInfo return modeling.createConfigurationDocumentOSH("%s.txt" % pfName, '<sap database>', content, containerOSH=systemOsh, contentType=modeling.MIME_TEXT_PLAIN, description='SAP Profile')
def buildRegistry(self, checkConnectionRegistry): r'@types: Registry -> ObjectStateHolder[configfile]' configurationContent = self._serializeComponents(checkConnectionRegistry.getComponents()) return modeling.createConfigurationDocumentOSH( 'software_components.txt', '<sap database>', configurationContent, contentType=modeling.MIME_TEXT_PLAIN, description='List of software components')
def createConfigFileOsh(self, name, content, parentOsh): ''' Creates a configuration file OSH @param name: string @param content: string @param parentOsh: root container OSH instance @returns: ConfigurationDocumentOSH ''' return modeling.createConfigurationDocumentOSH("%s.properties" % name, '', content, parentOsh)
def createQuorumConfigurationObjects(cluster, clusterOsh, resultsVector): contents = "" if cluster.quorumDevices: contents = cluster.quorumDevices contents += '\n' if cluster.quorumStatus: contents += cluster.quorumStatus configFile = modeling.createConfigurationDocumentOSH('quorumConfiguration.txt', None, contents, clusterOsh, modeling.MIME_TEXT_PLAIN, None, "Quorum configuration for cluster '%s'" % cluster.name) resultsVector.add(configFile)
def buildRegistry(self, checkConnectionRegistry): r'@types: Registry -> ObjectStateHolder[configfile]' configurationContent = self._serializeComponents( checkConnectionRegistry.getComponents()) return modeling.createConfigurationDocumentOSH( 'software_components.txt', '<sap database>', configurationContent, contentType=modeling.MIME_TEXT_PLAIN, description='List of software components')
def build(self, config): if config is None: raise ValueError("config is None") configOsh = modeling.createConfigurationDocumentOSH( DeviceConfigBuilder.CONFIG_FILE_NAME, None, config.content, contentType=DeviceConfigBuilder.MIME_TYPE, contentLastUpdate=config.lastModifiedDate) return configOsh
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ip = Framework.getDestinationAttribute('ip_address') credential_id = Framework.getDestinationAttribute('credential_id') version = Framework.getDestinationAttribute('version') cmdb_id = Framework.getDestinationAttribute('cmdb_id') protocol = ProtocolManager.getProtocolById(credential_id) host = protocol.getProtocolAttribute('host') port = protocol.getProtocolAttribute('protocol_port') protocolName = ClientsConsts.HTTP_PROTOCOL_NAME if (host and ip != host) or not port: msg = errormessages.makeErrorMessage( protocolName, 'Invalid ip address or missing port in HTTP credential', pattern=errormessages.ERROR_OPERATION_FAILED) errobj = errorobject.createError(errorcodes.OPERATION_FAILED, [protocolName], msg) logger.reportErrorObject(errobj) else: props = Properties() props.setProperty(CollectorsConstants.ATTR_CREDENTIALS_ID, credential_id) props.setProperty('autoAcceptCerts', 'true') props.setProperty('host', ip) try: httpClient = Framework.createClient(props) builder = PolicyBuilder(ip, port, version, httpClient) doc = builder.createPolicyDoc() oamServerOSH = modeling.createOshByCmdbIdString( 'running_software', cmdb_id) policyOSH = modeling.createConfigurationDocumentOSH( 'policy.xml', '', doc, oamServerOSH) linkOSH = modeling.createLinkOSH('composition', oamServerOSH, policyOSH) OSHVResult.add(oamServerOSH) OSHVResult.add(policyOSH) OSHVResult.add(linkOSH) except UnauthorizedException, e: msg = 'Failed to authenticate: ' + e.getMessage() errobj = errorobject.createError( errorcodes.INVALID_USERNAME_PASSWORD, [protocolName], msg) logger.reportErrorObject(errobj) except JException, e: msg = 'URL is not accessable: ' + e.getMessage() errobj = errorobject.createError(errorcodes.CONNECTION_FAILED, [protocolName], msg) logger.reportErrorObject(errobj)
def createHttpContextOsh(apacheOsh, webgateHttpContextOsh, uri, default_address, resultsVector): """ Create Http Context under apache for the given uri. Create httpcontext.xml configuration document for Http Context. Create c-p link from webgate Http Context to the new Http Context """ logger.debug('add oam uri to result vector: ', uri) uri_pattern = re.compile( r"^(?P<protocol>http|https)://(?P<ip>[\w\.\-]+)(:(?P<port>\d+))?(?P<root>/.*?)?$" ) match = uri_pattern.match(uri) if not match: if uri[0] != '/': uri = '/%s' % uri uri = 'http://%s%s' % (default_address, uri) logger.debug('use absolute uri: ', uri) match = uri_pattern.match(uri) if match: protocol = match.group('protocol') ip = match.group('ip') port = match.group('port') root = match.group('root') or '/' compositeKey = "_".join([root, ip, port or '']) logger.debug('compositeKey:', compositeKey) httpContextOsh = ObjectStateHolder('httpcontext') httpContextOsh.setAttribute('data_name', compositeKey) httpContextOsh.setAttribute('httpcontext_webapplicationcontext', root) if ip and netutils.isValidIp(ip): httpContextOsh.setAttribute('httpcontext_webapplicationip', ip) elif ip: httpContextOsh.setAttribute('httpcontext_webapplicationhost', ip) if protocol: httpContextOsh.setAttribute('applicationresource_type', protocol) httpContextOsh.setContainer(apacheOsh) contextConfigOsh = modeling.createConfigurationDocumentOSH( 'httpcontext.txt', '', uri, httpContextOsh) contextConfigLinkOsh = modeling.createLinkOSH('usage', httpContextOsh, contextConfigOsh) httpConfigCPLinkOsh = modeling.createLinkOSH('consumer_provider', webgateHttpContextOsh, httpContextOsh) resultsVector.add(httpContextOsh) resultsVector.add(contextConfigOsh) resultsVector.add(contextConfigLinkOsh) resultsVector.add(httpConfigCPLinkOsh) else: logger.debug('Skip invalid uri %s' % uri) return resultsVector
def getServerConfiguration(self,sqlServerid): logger.debug('going to get sqlserver configuration:', sqlServerid.toString()) stringList=[] self.getProps(stringList) self.getProtocols(stringList) self.getRegKey(stringList,Queries.PORT_LIST_CALL) self.getRegKey(stringList,Queries.TCP_FLAGS_CALL) self.getServerProperties(stringList) self.getMailConfig(stringList) data = ''.join(stringList) logger.debug('got server configuration id:', sqlServerid.toString(), " data:", data) configFileOsh = modeling.createConfigurationDocumentOSH("mssql server configuration.txt", 'virtual', data, sqlServerid, modeling.MIME_TEXT_PLAIN) return configFileOsh
def createQuorumConfigurationObjects(cluster, clusterOsh, resultsVector): contents = "" if cluster.quorumDevices: contents = cluster.quorumDevices contents += '\n' if cluster.quorumStatus: contents += cluster.quorumStatus configFile = modeling.createConfigurationDocumentOSH( 'quorumConfiguration.txt', None, contents, clusterOsh, modeling.MIME_TEXT_PLAIN, None, "Quorum configuration for cluster '%s'" % cluster.name) resultsVector.add(configFile)
def build(self, config): if config is None: raise ValueError("config is None") configOsh = modeling.createConfigurationDocumentOSH( DeviceConfigBuilder.CONFIG_FILE_NAME, None, config.content, contentType=DeviceConfigBuilder.MIME_TYPE, contentLastUpdate=config.lastModifiedDate, ) return configOsh
def buildWebApplications(client, serverID, serverOSH, clusterOSH, mapAppNameToOSH, OSHVResult): attributes = ("servlets",) query = ('*:*,j2eeType=SAP_J2EEServiceRuntimePerNode,name=servlet_jsp,' 'SAP_J2EEClusterNode=' + serverID) webService = client.getMbeansByNamePattern(query, attributes) logger.debug('parsing web applications ...') rowCount = len(webService) for row in range(rowCount): properties = webService[row] mapAppToServlets = properties.get('servlets') if not mapAppToServlets: continue mapModuleToOSH = HashMap() itApps = mapAppToServlets.keySet().iterator() while itApps.hasNext(): appName = itApps.next() appOSH = getApplication(appName, mapAppNameToOSH, serverOSH, clusterOSH, OSHVResult) mapAliasToServlets = mapAppToServlets.get(appName) itAliases = mapAliasToServlets.keySet().iterator() while itAliases.hasNext(): alias = itAliases.next() if alias.find('_xml') > 0: continue moduleOSH = getModule(alias, 'webmodule', mapModuleToOSH, appOSH, OSHVResult) # add web application deployment descriptor deploymentDescriptorXML = mapAliasToServlets.get(alias + '_xml') if deploymentDescriptorXML != None: cfOSH = modeling.createConfigurationDocumentOSH('web.xml', '', deploymentDescriptorXML, moduleOSH, modeling.MIME_TEXT_XML, None, 'Web application deployment descriptor') OSHVResult.add(moduleOSH) OSHVResult.add(cfOSH) servlets = mapAliasToServlets.get(alias) itServlets = servlets.keySet().iterator() while itServlets.hasNext(): servlet = itServlets.next() urls = servlets.get(servlet).toString() urls = urls[1:len(urls) - 1] servletOSH = ObjectStateHolder('servlet') servletOSH.setAttribute('data_name', servlet) servletOSH.setAttribute('servlet_url', urls) servletOSH.setContainer(moduleOSH) OSHVResult.add(servletOSH)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() oracleId = Framework.getDestinationAttribute('id') credentialsId = Framework.getDestinationAttribute('credentialsId') instanceName = Framework.getDestinationAttribute('sid') protocolDbSid = Framework.getProtocolProperty( credentialsId, CollectorsConstants.SQL_PROTOCOL_ATTRIBUTE_DBSID, 'NA') try: #in some cases sid does not coinside to the instance name, so real sid should be used #e.g. when sid is written down in a world unique identifiing string format <instance name>.fulldomainname oracleClient = None if protocolDbSid and protocolDbSid != 'NA' and protocolDbSid != instanceName: try: props = Properties() props.setProperty(Protocol.SQL_PROTOCOL_ATTRIBUTE_DBSID, protocolDbSid) oracleClient = Framework.createClient(props) except: logger.debug( 'Failed to connect using sid defined in creds. Will try instance name as sid.' ) oracleClient = None if not oracleClient: props = Properties() props.setProperty(Protocol.SQL_PROTOCOL_ATTRIBUTE_DBSID, instanceName) oracleClient = Framework.createClient(props) try: configFileContent = getConfigFileContent(oracleClient) finally: oracleClient.close() oracleOsh = modeling.createOshByCmdbIdString('oracle', oracleId) configFileOsh = modeling.createConfigurationDocumentOSH( 'init_parameters.ora', 'NA', configFileContent, oracleOsh, modeling.MIME_TEXT_PLAIN, None, FILE_DESCRIPTION) OSHVResult.add(configFileOsh) except Exception, ex: logger.debugException('') strException = ex.getMessage() errormessages.resolveAndReport(strException, SQL_PROTOCOL_NAME, Framework)
def _discover(self, domainDto): r'@types: DomainDto -> AdDiscoveryResult' result = AdDiscoveryResult() dtoToOshMap = result.getMap() domainDtoToOUsTreeRoot = result.getDomainDtoToOUsTreeRootMap() if not domainDto or not domainDto.id or not domainDto.id.value: domainDao = self._daoService.getDomainDao() domainDto = domainDao.createDto(domainDao.obtainSelfDomainId()) orgUnitDao = self._daoService.getOrganizationalUnitDao() root = orgUnitDao.getDomainOrgUnitTree(domainDto) if orgUnitDao.containsOrgUnit(root): configfileOSH = modeling.createConfigurationDocumentOSH( self.CONFIG_FILE_NAME, '', root.toXmlString(), self._containerOsh, MIME_TEXT_XML) dtoToOshMap[domainDto] = configfileOSH domainDtoToOUsTreeRoot[domainDto] = root return result
def buildFile(self, file_): r''' Builder uses modeling method so far, but in further versions build procedure will be rewritten to get rid of modeling @types: File -> ObjectStateHolder''' osh = modeling.createConfigurationDocumentOSH( file_.getName(), file_.path, file_.content, containerOSH=None, # can be specified in container level only contentType=None, # no corresponding attribute contentLastUpdate=file_.lastModificationTime(), description=None, # no corresponding attribute version=file_.version, charsetName=None) # no corresponding attribute if file_.owner: osh.setAttribute('document_osowner', file_.owner) if file_.permissions(): osh.setAttribute('document_permissions', file_.permissions()) return osh
def getServerStartup(self,sqlServerid): logger.debug('going to get sqlserver startup') stringList=[] self.getStartupStoredProcedures(stringList) idx=0 while idx<=10: try: self.getServerStartupParam(stringList,idx) except: idx=10 idx=idx+1 data = ''.join(stringList) logger.debug('got sqlserver startup: ', data) configFileOsh = None if data: configFileOsh = modeling.createConfigurationDocumentOSH('mssql server startup configuration.txt', 'virtual', data, sqlServerid, modeling.MIME_TEXT_PLAIN) return configFileOsh
def createHttpContextOsh(apacheOsh, webgateHttpContextOsh, uri, default_address, resultsVector): """ Create Http Context under apache for the given uri. Create httpcontext.xml configuration document for Http Context. Create c-p link from webgate Http Context to the new Http Context """ logger.debug('add oam uri to result vector: ', uri) uri_pattern = re.compile(r"^(?P<protocol>http|https)://(?P<ip>[\w\.\-]+)(:(?P<port>\d+))?(?P<root>/.*?)?$") match = uri_pattern.match(uri) if not match: if uri[0] != '/': uri = '/%s' % uri uri = 'http://%s%s' % (default_address, uri) logger.debug('use absolute uri: ', uri) match = uri_pattern.match(uri) if match: protocol = match.group('protocol') ip = match.group('ip') port = match.group('port') root = match.group('root') or '/' compositeKey = "_".join([root, ip, port or '']) logger.debug('compositeKey:', compositeKey) httpContextOsh = ObjectStateHolder('httpcontext') httpContextOsh.setAttribute('data_name', compositeKey) httpContextOsh.setAttribute('httpcontext_webapplicationcontext', root) if ip and netutils.isValidIp(ip): httpContextOsh.setAttribute('httpcontext_webapplicationip', ip) elif ip: httpContextOsh.setAttribute('httpcontext_webapplicationhost', ip) if protocol: httpContextOsh.setAttribute('applicationresource_type', protocol) httpContextOsh.setContainer(apacheOsh) contextConfigOsh = modeling.createConfigurationDocumentOSH('httpcontext.txt', '', uri, httpContextOsh) contextConfigLinkOsh = modeling.createLinkOSH('usage', httpContextOsh, contextConfigOsh) httpConfigCPLinkOsh = modeling.createLinkOSH('consumer_provider', webgateHttpContextOsh, httpContextOsh) resultsVector.add(httpContextOsh) resultsVector.add(contextConfigOsh) resultsVector.add(contextConfigLinkOsh) resultsVector.add(httpConfigCPLinkOsh) else: logger.debug('Skip invalid uri %s' % uri) return resultsVector
def parsePortRules(output): lines = re.split('(\r+\n\r?)', output) rulePattern = re.compile(r'(.{15})\s(.{5})\s(.{5})\s(.{4})\s(.{8})\s(.{3})\s(.{4})\s(.*)') index = 0 document_data = '' for line in lines: ruleProps = rulePattern.match(line) if ruleProps: index += 1 ServingIP = ruleProps.group(1).strip() StartPort = ruleProps.group(2).strip() EndPort = ruleProps.group(3).strip() Protocol = ruleProps.group(4).strip() FilteringMode = ruleProps.group(5).strip() LoadWeight = ruleProps.group(7).strip() Affinity = ruleProps.group(8).strip() document_data = appendPortRuleProps(ServingIP, StartPort, EndPort, Protocol, FilteringMode, LoadWeight, Affinity, document_data, index) return modeling.createConfigurationDocumentOSH('Port Rule.txt', None, document_data)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ip = Framework.getDestinationAttribute('ip_address') credential_id = Framework.getDestinationAttribute('credential_id') version = Framework.getDestinationAttribute('version') cmdb_id = Framework.getDestinationAttribute('cmdb_id') protocol = ProtocolManager.getProtocolById(credential_id) host = protocol.getProtocolAttribute('host') port = protocol.getProtocolAttribute('protocol_port') protocolName = ClientsConsts.HTTP_PROTOCOL_NAME if (host and ip != host) or not port: msg = errormessages.makeErrorMessage(protocolName, 'Invalid ip address or missing port in HTTP credential', pattern=errormessages.ERROR_OPERATION_FAILED) errobj = errorobject.createError(errorcodes.OPERATION_FAILED, [protocolName], msg) logger.reportErrorObject(errobj) else: props = Properties() props.setProperty(CollectorsConstants.ATTR_CREDENTIALS_ID, credential_id) props.setProperty('autoAcceptCerts', 'true') props.setProperty('host', ip) try: httpClient = Framework.createClient(props) builder = PolicyBuilder(ip, port, version, httpClient) doc = builder.createPolicyDoc() oamServerOSH = modeling.createOshByCmdbIdString('running_software', cmdb_id) policyOSH = modeling.createConfigurationDocumentOSH('policy.xml', '', doc, oamServerOSH) linkOSH = modeling.createLinkOSH('composition', oamServerOSH, policyOSH) OSHVResult.add(oamServerOSH) OSHVResult.add(policyOSH) OSHVResult.add(linkOSH) except UnauthorizedException, e: msg = 'Failed to authenticate: ' + e.getMessage() errobj = errorobject.createError(errorcodes.INVALID_USERNAME_PASSWORD, [protocolName], msg) logger.reportErrorObject(errobj) except JException, e: msg = 'URL is not accessable: ' + e.getMessage() errobj = errorobject.createError(errorcodes.CONNECTION_FAILED, [protocolName], msg) logger.reportErrorObject(errobj)
def discoverSupportpkgs(sapUtils, systemName, systemOsh): '@types: SapUtils, str, osh -> oshv' logger.info("Discover packages") supportpkgs = sapUtils.getSupportPackages(systemName) logger.debug('Found ', len(supportpkgs), ' support packages.') vector = ObjectStateHolderVector() configurationContent = '' for pkg in supportpkgs: packageType = pkg.getProperty('Type') if packageType == 'AOP' or packageType == 'COP': pkg.setProperty('Type', getSupportPackageTypeText(packageType)) configurationContent += sapUtils.formatElemString(pkg) if configurationContent: configFileOsh = modeling.createConfigurationDocumentOSH( 'support_packages.txt', '<sap database>', configurationContent, systemOsh, modeling.MIME_TEXT_PLAIN, None, 'List of support packages') vector.add(configFileOsh) return vector
def report(self, webSphereConfig, resultVector, webServerOsh): self._resolveHostNameToIp(webSphereConfig) for route in webSphereConfig.routes: clusterName = route.clusterName cluster = webSphereConfig.clustersByName.get(clusterName) if not cluster: continue uriGroupName = route.uriGroupName uriGroup = webSphereConfig.uriGroupsByName.get(uriGroupName) for server in cluster.serversByName.values(): for transport in server.transports: if transport.hostIp and transport.port: self._reportDependentWebSphere(server, transport, webServerOsh, resultVector) if uriGroup is not None: for uri in uriGroup.uris: normalizedUri = self._getNormalizedUri( uri.name) if not normalizedUri: continue httpContextOsh = self._createHttpContext( normalizedUri, transport, server.name, webServerOsh) if httpContextOsh is not None: contextConfigOsh = modeling.createConfigurationDocumentOSH( 'httpcontext.txt', '', self._getContextContent( normalizedUri, transport), httpContextOsh) contextConfigLinkOsh = modeling.createLinkOSH( 'usage', httpContextOsh, contextConfigOsh) resultVector.add(contextConfigOsh) resultVector.add(contextConfigLinkOsh) resultVector.add(httpContextOsh)
def buildConfigFile(self, config_file): """ :param config_file: Cofiguration File information :type config_file: iis.ConfigFile :return: ObjectStateHolder :rtype: ObjectStateHolder """ configLocation = config_file.fullpath matches = re.match('.*\\\\(.*)',configLocation) name = 'web.config' if matches: name = matches.group(1) logger.debug("reporting config file:", name) content = config_file.content lastModificationDate = config_file.last_modified_time return modeling.createConfigurationDocumentOSH(name, configLocation, content, None, modeling.MIME_TEXT_XML, lastModificationDate, "IIS configuration file")
def DiscoveryMain(Framework): """ Discovers MySQL instances and replication topology """ OshVResult = ObjectStateHolderVector() processPath = Framework.getDestinationAttribute('processPath') if not processPath: logger.error('Process path is empty') return OshVResult ipaddress = Framework.getDestinationAttribute('ip_address') dbport = Framework.getDestinationAttribute('dbport') protocol = Framework.getDestinationAttribute('Protocol') dbsid = Framework.getDestinationAttribute('dbsid') processParams = Framework.getDestinationAttribute('processParams') mySqlDiscoverer = None try: try: mySqlDiscoverer = MySqlDiscoverer(Framework, processPath, processParams) cnfPath = mySqlDiscoverer.findConfigPath() if cnfPath: logger.info('MySQL config path %s' % cnfPath) mysqlOsh, hostOsh = mySqlDiscoverer.createDbOsh(dbsid, dbport, ipaddress) myCnfContent, myCnfSize = mySqlDiscoverer.getConfigContent() if cnfPath[0] == '"': cnfPath = cnfPath[1:-1] configFileName = os.path.basename(cnfPath) configFileContent = "\n".join(myCnfContent) configFileOsh = modeling.createConfigurationDocumentOSH(configFileName, cnfPath, configFileContent, mysqlOsh, modeling.MIME_TEXT_PLAIN, None, 'MySQL configuration file') mySqlDiscoverer.setAttribute(mysqlOsh, 'server_id', ARGS_MAPPING) mySqlDiscoverer.setAttribute(mysqlOsh, 'database_datadir', ARGS_MAPPING) mySqlDiscoverer.setAttribute(mysqlOsh, 'database_max_connections', ARGS_MAPPING) addToOshVector(OshVResult, [hostOsh, mysqlOsh, configFileOsh]) mysqlReplicationOshs = mySqlDiscoverer.discoverReplication(mysqlOsh) addToOshVector(OshVResult, mysqlReplicationOshs) except JavaException, ex: strException = ex.getMessage() errormessages.resolveAndReport(strException, protocol, Framework) except: strException = str(sys.exc_info()[1]) errormessages.resolveAndReport(strException, protocol, Framework)
def buildFirewallConfig(config, container_osh): ''' @param config: discovered firewall config @type config: instance of FirewallConfig @param container_osh: OSH allowed to be a container for configuration_document @type container_osh: OSH @return: configuretion_document OSH ''' content = '' for key in config.type_to_rules_dict.keys(): content += '%s\n' % key logger.debug('Building %s' % key) for obj in config.type_to_rules_dict.get(key): attrs = vars(obj) logger.debug(attrs) if attrs: content += '%s\n' % ('\n'.join(['%s = %s' % (key, value) for key, value in attrs.items()])) config_osh = modeling.createConfigurationDocumentOSH(name = config.name, path=config.name, content = content, containerOSH = container_osh ) return config_osh
def getDatabaseProperties(self,databases,dbList,discoverConfigs=1): oshv = ObjectStateHolderVector() if not discoverConfigs: return oshv query = Util.replace(Queries.DATABASE_CONFIG_FILE.toString(),dbList) rs = self.connection.getTable(query) logger.debug("get db properties") while rs.next(): dataBasePropsList=[] dbName = rs.getString("name") database = databases.get(dbName) for key in VALUES: value = rs.getString('_'+key) if value: dataBasePropsList.append("%s=%s\n" % (key, value)) data = ''.join(dataBasePropsList) configFileOsh = modeling.createConfigurationDocumentOSH('mssql database configuration.txt', 'virtual', data, database, modeling.MIME_TEXT_PLAIN) oshv.add(configFileOsh) logger.debug("get db properties: ", oshv.toXmlString()) rs.close() return oshv
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() oracleId = Framework.getDestinationAttribute('id') credentialsId = Framework.getDestinationAttribute('credentialsId') instanceName = Framework.getDestinationAttribute('sid') protocolDbSid = Framework.getProtocolProperty(credentialsId, CollectorsConstants.SQL_PROTOCOL_ATTRIBUTE_DBSID, 'NA') try: #in some cases sid does not coinside to the instance name, so real sid should be used #e.g. when sid is written down in a world unique identifiing string format <instance name>.fulldomainname oracleClient = None if protocolDbSid and protocolDbSid != 'NA' and protocolDbSid != instanceName: try: props = Properties() props.setProperty(Protocol.SQL_PROTOCOL_ATTRIBUTE_DBSID, protocolDbSid) oracleClient = Framework.createClient(props) except: logger.debug('Failed to connect using sid defined in creds. Will try instance name as sid.') oracleClient = None if not oracleClient: props = Properties() props.setProperty(Protocol.SQL_PROTOCOL_ATTRIBUTE_DBSID, instanceName) oracleClient = Framework.createClient(props) try: configFileContent = getConfigFileContent(oracleClient) finally: oracleClient.close() oracleOsh = modeling.createOshByCmdbIdString('oracle', oracleId) configFileOsh = modeling.createConfigurationDocumentOSH('init_parameters.ora', 'NA', configFileContent, oracleOsh, modeling.MIME_TEXT_PLAIN, None, FILE_DESCRIPTION) OSHVResult.add(configFileOsh) except Exception, ex: logger.debugException('') strException = ex.getMessage() errormessages.resolveAndReport(strException, SQL_PROTOCOL_NAME, Framework)
def parsePortRules(output): lines = re.split('(\r+\n\r?)', output) rulePattern = re.compile( r'(.{15})\s(.{5})\s(.{5})\s(.{4})\s(.{8})\s(.{3})\s(.{4})\s(.*)') index = 0 document_data = '' for line in lines: ruleProps = rulePattern.match(line) if ruleProps: index += 1 ServingIP = ruleProps.group(1).strip() StartPort = ruleProps.group(2).strip() EndPort = ruleProps.group(3).strip() Protocol = ruleProps.group(4).strip() FilteringMode = ruleProps.group(5).strip() LoadWeight = ruleProps.group(7).strip() Affinity = ruleProps.group(8).strip() document_data = appendPortRuleProps(ServingIP, StartPort, EndPort, Protocol, FilteringMode, LoadWeight, Affinity, document_data, index) return modeling.createConfigurationDocumentOSH('Port Rule.txt', None, document_data)
def discoverRules(self, nameToVirtualServerHelper, nameToPool): queryBuilder = SnmpQueryBuilder('10.8.2.1') queryBuilder.addQueryElement(1, 'serverName') queryBuilder.addQueryElement(2, 'ruleName') ruleToServerEntries = self.snmpAgent.getSnmpData(queryBuilder) ruleNameToServerName = {} for ruleToServerEntry in ruleToServerEntries: ruleNameToServerName[ruleToServerEntry.ruleName] = ruleToServerEntry.serverName queryBuilder = SnmpQueryBuilder('8.1.2.1') queryBuilder.addQueryElement(1, 'name') queryBuilder.addQueryElement(2, 'definition') #Type is currently not used, consider about adding it to description queryBuilder.addQueryElement(3, 'type') rules = self.snmpAgent.getSnmpData(queryBuilder) for rule in rules: try: virtualServerHelper = nameToVirtualServerHelper[ruleNameToServerName[rule.name]] virtualServerOsh = virtualServerHelper.getOsh() ruleOsh = modeling.createConfigurationDocumentOSH(rule.name, '', rule.definition, virtualServerOsh) virtualServerHelper.addOsh(ruleOsh) lines = rule.definition.splitlines() lines = [line.strip() for line in lines if line and line.strip()] for line in lines: if not line.startswith('#') and not re.search(';\s*\#', line): poolRef = re.match("pool\s+(\S+)", line) if poolRef: poolName = poolRef.group(1) logger.debug('Found pool ' + poolName + ' in rule ' + rule.name) if nameToPool.has_key(poolName): virtualServerHelper.linkToContainingCluster(nameToPool[poolName], poolName) except: errorMsg = 'Failed to obtain virtual server for rule %s' % rule.name errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION_NO_PROTOCOL, ['virtual server for rule %s' % rule.name], errorMsg) logger.debugException(errorMsg) logger.reportWarningObject(errobj)
def report(self, webSphereConfig, resultVector, webServerOsh): self._resolveHostNameToIp(webSphereConfig) for route in webSphereConfig.routes: clusterName = route.clusterName cluster = webSphereConfig.clustersByName.get(clusterName) if not cluster: continue uriGroupName = route.uriGroupName uriGroup = webSphereConfig.uriGroupsByName.get(uriGroupName) for server in cluster.serversByName.values(): for transport in server.transports: if transport.hostIp and transport.port: self._reportDependentWebSphere(server, transport, webServerOsh, resultVector) if uriGroup is not None: for uri in uriGroup.uris: normalizedUri = self._getNormalizedUri(uri.name) if not normalizedUri: continue httpContextOsh = self._createHttpContext(normalizedUri, transport, server.name, webServerOsh) if httpContextOsh is not None: contextConfigOsh = modeling.createConfigurationDocumentOSH('httpcontext.txt', '', self._getContextContent( normalizedUri, transport), httpContextOsh) contextConfigLinkOsh = modeling.createLinkOSH('usage', httpContextOsh, contextConfigOsh) resultVector.add(contextConfigOsh) resultVector.add(contextConfigLinkOsh) resultVector.add(httpContextOsh)
def getDatabaseProperties(self, databases, dbList, discoverConfigs=1): oshv = ObjectStateHolderVector() if not discoverConfigs: return oshv query = Util.replace(Queries.DATABASE_CONFIG_FILE.toString(), dbList) rs = self.connection.getTable(query) logger.debug("get db properties") while rs.next(): dataBasePropsList = [] dbName = rs.getString("name") database = databases.get(dbName) for key in VALUES: value = rs.getString('_' + key) if value: dataBasePropsList.append("%s=%s\n" % (key, value)) data = ''.join(dataBasePropsList) configFileOsh = modeling.createConfigurationDocumentOSH( 'mssql database configuration.txt', 'virtual', data, database, modeling.MIME_TEXT_PLAIN) oshv.add(configFileOsh) logger.debug("get db properties: ", oshv.toXmlString()) rs.close() return oshv
def getBackupFiles(self,databases,dbList,hostId,oshvResult): result = HashMap() query = Util.replace(Queries.DATABASE_BACKUP_FILES,dbList) rs = self.connection.getTable(query) disks = ArrayList() while rs.next(): currentDbName = rs.getString("name") path = rs.getString("path") if path is not None: #extract the path path = Util.replaceFileSeparator(path) disk = Util.getDisk(path,hostId) disks.add(disk) fileName = Util.getFileFromPath(path) path = Util.getPath(path) configFileOsh = modeling.createConfigurationDocumentOSH(fileName, path, None, hostId) result.put(currentDbName, configFileOsh) itr = disks.iterator() while itr.hasNext(): oshvResult.add(itr.next()) rs.close() return result
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 report(self, cluster): ''' Main report method for creation of generic Service Guard Topology @param cluster: instance of Cluster Data Object ''' vector = ObjectStateHolderVector() clusterOsh = cluster.build() vector.add(clusterOsh) configFileOsh = modeling.createConfigurationDocumentOSH( 'cmviewcl.properties', '', cluster.propertiesFileContent, clusterOsh) vector.add(configFileOsh) quorumServer = cluster.quorumServer # report Quorum Server in 'UP' status if (quorumServer and quorumServer.status == QuorumServer.Status.UP): reportTopology = self.__quorumServerReporter.reportTopology try: qsVector = reportTopology(quorumServer, clusterOsh)[3] vector.addAll(qsVector) except Exception: logger.warnException("Failed to report Quorum Server") clusterIpOsh = None if cluster.ipAddress: clusterIpOsh = modeling.createIpOSH(cluster.ipAddress) if clusterIpOsh: vector.add(clusterIpOsh) nodeToClusterSoftwareOshMap = {} nodeNameToNodeOsh = {} #creating cluster Nodes and linking them to cluster for clusterNode in cluster.nodes: nodeOsh = modeling.createHostOSH(clusterNode.ipAddress) vector.add(nodeOsh) nodeNameToNodeOsh[clusterNode.name] = nodeOsh clusterSoftwareOsh = modeling.createClusterSoftwareOSH( nodeOsh, 'HP Service Guard Cluster SW', cluster.version) vector.add(clusterSoftwareOsh) memberLinkOsh = modeling.createLinkOSH('member', clusterOsh, clusterSoftwareOsh) vector.add(memberLinkOsh) if clusterNode.propertiesFileContent: configfileOsh = self.createConfigFileOsh( clusterNode.name, clusterNode.propertiesFileContent, clusterSoftwareOsh) vector.add(configfileOsh) nodeToClusterSoftwareOshMap[ clusterNode.name] = clusterSoftwareOsh for package in cluster.packages: clusteredServiceOsh = self.createClusteredServiceOsh( package.name, cluster.name) package.osh = clusteredServiceOsh containedLinkOsh = modeling.createLinkOSH('contained', clusterOsh, clusteredServiceOsh) vector.add(clusteredServiceOsh) vector.add(containedLinkOsh) if clusterIpOsh is not None: containedLinkOSH = modeling.createLinkOSH( 'contained', clusteredServiceOsh, clusterIpOsh) vector.add(containedLinkOSH) packageOsh = self.createPackageOsh(package.name, clusteredServiceOsh) vector.add(packageOsh) if package.packageIp: resourceOsh = self.createIpResourceOsh(package.packageIp, packageOsh) vector.add(resourceOsh) packageIpOsh = modeling.createIpOSH(package.packageIp) linkOsh = modeling.createLinkOSH('containment', clusteredServiceOsh, packageIpOsh) vector.add(packageIpOsh) vector.add(linkOsh) if package.additionalIpList: for packageIp in package.additionalIpList: if packageIp: resourceOsh = self.createIpResourceOsh( packageIp.ipAddress, packageOsh, packageIp.fqdn) vector.add(resourceOsh) #fix start packageIpOsh = modeling.createIpOSH( packageIp.ipAddress) linkOsh = modeling.createLinkOSH( 'containment', clusteredServiceOsh, packageIpOsh) vector.add(packageIpOsh) vector.add(linkOsh) #fix end configFileOsh = self.createConfigFileOsh( package.name, package.propertiesFileContent, packageOsh) if configFileOsh: vector.add(configFileOsh) for network in package.ipNetworkList: network.build() networkOsh = network.osh if networkOsh: dependLinkOsh = modeling.createLinkOSH( 'depend', packageOsh, networkOsh) vector.add(networkOsh) vector.add(dependLinkOsh) for packageNodeInfo in package.distrNodeInfoList: clusterSoftwareOsh = nodeToClusterSoftwareOshMap.get( packageNodeInfo.name, None) if clusterSoftwareOsh: if packageNodeInfo.status in ('primary', 'alternate'): currOwnerOsh = modeling.createLinkOSH( 'potentially_run', clusterSoftwareOsh, clusteredServiceOsh) currOwnerOsh.setAttribute('data_name', packageNodeInfo.status) isOwner = 0 if packageNodeInfo.status == 'primary': isOwner = 1 currOwnerOsh.setBoolAttribute('is_owner', isOwner) vector.add(currOwnerOsh) if packageNodeInfo.isCurrent: if package.mountPoints: for mountPoint in package.mountPoints: if mountPoint and mountPoint.strip( ) and nodeNameToNodeOsh.get( packageNodeInfo.name): clusteredFsOsh = self.createFileSystemOsh( mountPoint, clusteredServiceOsh) localFsOsh = self.createFileSystemOsh( mountPoint, nodeNameToNodeOsh.get( packageNodeInfo.name)) linkOsh = modeling.createLinkOSH( 'usage', clusteredFsOsh, localFsOsh) vector.add(clusteredFsOsh) vector.add(localFsOsh) vector.add(linkOsh) runOsh = modeling.createLinkOSH( 'run', clusterSoftwareOsh, clusteredServiceOsh) vector.add(runOsh) return vector
def report(self, cluster): ''' Main report method for creation of generic Service Guard Topology @param cluster: instance of Cluster Data Object ''' vector = ObjectStateHolderVector() clusterOsh = cluster.build() vector.add(clusterOsh) configFileOsh = modeling.createConfigurationDocumentOSH( 'cmviewcl.properties', '', cluster.propertiesFileContent, clusterOsh) vector.add(configFileOsh) quorumServer = cluster.quorumServer # report Quorum Server in 'UP' status if (quorumServer and quorumServer.status == QuorumServer.Status.UP): reportTopology = self.__quorumServerReporter.reportTopology try: qsVector = reportTopology(quorumServer, clusterOsh)[3] vector.addAll(qsVector) except Exception: logger.warnException("Failed to report Quorum Server") clusterIpOsh = None if cluster.ipAddress: clusterIpOsh = modeling.createIpOSH(cluster.ipAddress) if clusterIpOsh: vector.add(clusterIpOsh) nodeToClusterSoftwareOshMap = {} nodeNameToNodeOsh = {} #creating cluster Nodes and linking them to cluster for clusterNode in cluster.nodes: nodeOsh = modeling.createHostOSH(clusterNode.ipAddress) vector.add(nodeOsh) nodeNameToNodeOsh[clusterNode.name] = nodeOsh clusterSoftwareOsh = modeling.createClusterSoftwareOSH(nodeOsh, 'HP Service Guard Cluster SW', cluster.version) vector.add(clusterSoftwareOsh) memberLinkOsh = modeling.createLinkOSH('member', clusterOsh, clusterSoftwareOsh) vector.add(memberLinkOsh) if clusterNode.propertiesFileContent: configfileOsh = self.createConfigFileOsh(clusterNode.name, clusterNode.propertiesFileContent, clusterSoftwareOsh) vector.add(configfileOsh) nodeToClusterSoftwareOshMap[clusterNode.name] = clusterSoftwareOsh for package in cluster.packages: clusteredServiceOsh = self.createClusteredServiceOsh(package.name, cluster.name) package.osh = clusteredServiceOsh containedLinkOsh = modeling.createLinkOSH('contained', clusterOsh, clusteredServiceOsh) vector.add(clusteredServiceOsh) vector.add(containedLinkOsh) if clusterIpOsh is not None: containedLinkOSH = modeling.createLinkOSH('contained', clusteredServiceOsh, clusterIpOsh) vector.add(containedLinkOSH) packageOsh = self.createPackageOsh(package.name, clusteredServiceOsh) vector.add(packageOsh) if package.packageIp: resourceOsh = self.createIpResourceOsh(package.packageIp, packageOsh) vector.add(resourceOsh) packageIpOsh = modeling.createIpOSH(package.packageIp) linkOsh = modeling.createLinkOSH('containment', clusteredServiceOsh, packageIpOsh) vector.add(packageIpOsh) vector.add(linkOsh) if package.additionalIpList: for packageIp in package.additionalIpList: if packageIp: resourceOsh = self.createIpResourceOsh(packageIp.ipAddress, packageOsh, packageIp.fqdn) vector.add(resourceOsh) #fix start packageIpOsh = modeling.createIpOSH(packageIp.ipAddress) linkOsh = modeling.createLinkOSH('containment', clusteredServiceOsh, packageIpOsh) vector.add(packageIpOsh) vector.add(linkOsh) #fix end configFileOsh = self.createConfigFileOsh(package.name, package.propertiesFileContent, packageOsh) if configFileOsh: vector.add(configFileOsh) for network in package.ipNetworkList: network.build() networkOsh = network.osh if networkOsh: dependLinkOsh = modeling.createLinkOSH('depend', packageOsh, networkOsh) vector.add(networkOsh) vector.add(dependLinkOsh) for packageNodeInfo in package.distrNodeInfoList: clusterSoftwareOsh = nodeToClusterSoftwareOshMap.get(packageNodeInfo.name, None) if clusterSoftwareOsh: if packageNodeInfo.status in ('primary', 'alternate'): currOwnerOsh = modeling.createLinkOSH('potentially_run', clusterSoftwareOsh, clusteredServiceOsh) currOwnerOsh.setAttribute('data_name', packageNodeInfo.status) isOwner = 0 if packageNodeInfo.status == 'primary': isOwner = 1 currOwnerOsh.setBoolAttribute('is_owner', isOwner) vector.add(currOwnerOsh) if packageNodeInfo.isCurrent: if package.mountPoints: for mountPoint in package.mountPoints: if mountPoint and mountPoint.strip() and nodeNameToNodeOsh.get(packageNodeInfo.name): clusteredFsOsh = self.createFileSystemOsh(mountPoint, clusteredServiceOsh) localFsOsh = self.createFileSystemOsh(mountPoint, nodeNameToNodeOsh.get(packageNodeInfo.name)) linkOsh = modeling.createLinkOSH('usage', clusteredFsOsh, localFsOsh) vector.add(clusteredFsOsh) vector.add(localFsOsh) vector.add(linkOsh) runOsh = modeling.createLinkOSH('run', clusterSoftwareOsh, clusteredServiceOsh) vector.add(runOsh) return vector
def buildConfigFile(self, configFileContent, databaseOsh): return modeling.createConfigurationDocumentOSH('MaxDB Config', 'MaxDB Config', configFileContent, databaseOsh)
def _reportNodeDetails(node, content, containerOsh): r'@types: ms_cluster.Node, str -> ObjectStateHolder' return modeling.createConfigurationDocumentOSH( 'MSCS_%s_properties.properties' % node.name, None, content, containerOsh, modeling.MIME_TEXT_PLAIN, None, 'Cluster properties output', None, 'UTF-8')
def parseCfgFileData(data, installPath, sarmLogFolder, shellUtils, webserverOSH, OSHVResult, HOST_ID, Framework): # create siebel web server extension siebelwseOSH = ObjectStateHolder('siebel_wse') siebelwseOSH.setContainer(webserverOSH) siebelwseOSH.setAttribute('data_name', 'Siebel WSE') siebelwseOSH.setAttribute('install_path', installPath) # try to get some general info on the SWE try: parseWSEDefaults(data, siebelwseOSH) except: logger.debug('failed getting wse defaults') OSHVResult.add(siebelwseOSH) configFileOsh = modeling.createConfigurationDocumentOSH('eapps.cfg', installPath, data, siebelwseOSH, modeling.MIME_TEXT_PLAIN, None, "Siebel Webserver Extention file") OSHVResult.add(configFileOsh) mapKeyToAppServers = None enableVirtualHosts = getAttribute(data, 'EnableVirtualHosts') if (enableVirtualHosts.lower() == 'true'): virtualHostsFile = getAttribute(data, 'VirtualHostsFile') if virtualHostsFile != None: virtualHostsFileData = None try: virtualHostsFileData = shellUtils.safecat(virtualHostsFile) if not virtualHostsFileData: raise ValueError except: logger.warn("Failed reading virtual host file '%s'" % virtualHostsFile) else: pattern = Pattern('([^\s]*)[\\\/]([^\s.]*).([^\s]*)') matcher = pattern.matcher(virtualHostsFile) if matcher.find()== 1: path = matcher.group(1) filename = matcher.group(2) extension = matcher.group(3) configFileName = "%s.%s" % (filename, extension) configFileOsh = modeling.createConfigurationDocumentOSH(configFileName, path, virtualHostsFileData, siebelwseOSH, modeling.MIME_TEXT_PLAIN, None, 'Load Balancer configuration file') OSHVResult.add(configFileOsh) mapKeyToAppServers = getAttributes(virtualHostsFileData,'VirtualServer') # get web applications data apps = getApps(data) gatewayIpToOsh = {} siteNameToOsh = {} for app in apps: appName = app[app.find('[/')+2:app.find(']')] connStr = getAttribute(app, 'ConnectString') # sample line: siebel.TCPIP.None.None://sblgw:2320/siebel/CRAObjMgr_cht/sblapp1_AS # sample line: siebel.TCPIP.None.None://cannon:2320/siebel/ERMObjMgr_chs/cannon gtwyHost = '' gtwyPort = '' siebelSite = '' componentName = '' appSvrName = '' appSvrIP = '' ip = '' tokens = connStr.split('/') numOfTokens = len(tokens) if numOfTokens > 2: if (enableVirtualHosts.lower() == 'true'): appServers = mapKeyToAppServers.get(tokens[2]) if appServers != None: serversStr = appServers.split(';') for serverStr in serversStr: if serverStr != '': serverStrTokens = serverStr.split(':') if appSvrName != '': appSvrName += ',' if appSvrIP != '': appSvrIP += ',' serverName = serverStrTokens[1] appSvrName += serverName appSvrIP += netutils.getHostAddress(serverName, serverName) else: gtwyConn = tokens[2].split(':') gtwyHost = gtwyConn[0] gtwyPort = gtwyConn[1] if not netutils.isValidIp(gtwyHost): ip = resolveHostname(gtwyHost, shellUtils, '') else: ip = gtwyHost if numOfTokens > 3: siebelSite = tokens[3] if numOfTokens > 4: componentName = tokens[4] if numOfTokens > 5: appSvrName = tokens[5] else: if appSvrIP == '': appSvrIP = ip gtwyHost = None if gtwyHost and ip and not gatewayIpToOsh.has_key(ip): gatewayOsh = createGatewayOsh(ip, gtwyPort, OSHVResult, Framework) OSHVResult.add(gatewayOsh) routeLinkOSH = modeling.createLinkOSH('depend', gatewayOsh, siebelwseOSH) OSHVResult.add(routeLinkOSH) gatewayIpToOsh[ip] = gatewayOsh if siebelSite and not siteNameToOsh.has_key(siebelSite): logger.debug('found siebel site:', siebelSite) siteOSH = ObjectStateHolder('siebel_site') siteOSH.setAttribute('gateway_address', ip) siteOSH.setAttribute('data_name', siebelSite) modeling.setAppSystemVendor(siteOSH) OSHVResult.add(siteOSH) siteNameToOsh[siebelSite] = siteOSH # create a siebel application object webappOSH = ObjectStateHolder('siebel_web_app') webappOSH.setAttribute('data_name', appName) webappOSH.setAttribute('site', siebelSite) webappOSH.setAttribute('app_srv_name', appSvrName) webappOSH.setAttribute('app_srv_ip', appSvrIP) webappOSH.setAttribute('component_name', componentName) # application contained in webserver extension webappOSH.setContainer(siebelwseOSH) OSHVResult.add(webappOSH)
def _reportGroupDetails(group, content, containerOsh): r'@types: ResourceGroup, str, ObjectStateHolder -> ObjectStateHolder' return modeling.createConfigurationDocumentOSH( "MSCS_group_properties.properties", None, content, containerOsh, modeling.MIME_TEXT_PLAIN, None, 'Cluster group prop output', None, 'UTF-8')
targetNamespace = defintion.getTargetNamespace() if wsdl_url == None and namespaceURI != None: wsdl_url = namespaceURI + '?WSDL' wsOSH = ObjectStateHolder('webservice') wsOSH.setAttribute('data_name', targetNamespace) wsOSH.setAttribute('service_name', serviceName) if wsdl_url: wsOSH.setAttribute('wsdl_url', wsdl_url) OSHVResult.add(wsOSH) if wsdl_url_data: configFileName = "%s.xml" % serviceName cfOSH = modeling.createConfigurationDocumentOSH( configFileName, wsdl_url, wsdl_url_data, wsOSH, modeling.MIME_TEXT_XML, None, "This document holds the content of the WSDL file") OSHVResult.add(cfOSH) # Add import CFs for importWsdldName in importWsdldNames: currData = importWsdldNameToData[importWsdldName] configFileName = "%s.xml" % importWsdldName cfOSH = modeling.createConfigurationDocumentOSH( configFileName, importWsdldName, currData, wsOSH, modeling.MIME_TEXT_XML, None, "This document holds the content of the WSDL file") OSHVResult.add(cfOSH) if containerOSH != None: dependWsToUrlOSH = modeling.createLinkOSH('depend', wsOSH,
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