def determineVersion(installRootDirPath, parser, fs):
    r'''@types: str, websphere_discoverer.ProductInfoParser, file_system.FileSystem -> websphere_discoverer.ProductInformation or None
    @resource-file:ND.product
    @resource-file:BASE.product
    @resource-file:WAS.product

    First check this xml files
        <installRootDirPath>/properties\version\ND.product - for Network Deployment
        <installRootDirPath>/properties\version\BASE.product - for Base stand-alone
        <installRootDirPath>/properties\version\BASE.product + ND.product - for Base federated to ND
        <installRootDirPath>/properties\version\WAS.product

    '''
    logger.debug('*** START: determineVesion')
    pathUtil = file_system.getPath(fs)
    propertiesDirPath = pathUtil.join(installRootDirPath, 'properties', 'version')
    productInformation = None
    try:
        files = fs.getFiles(propertiesDirPath, filters = [file_system.ExtensionsFilter(['product'])],
                                           fileAttrs = [file_topology.FileAttrs.NAME,
                                                        file_topology.FileAttrs.PATH])
    except (Exception, JException):
        logger.warnException("Failed to determine platform version as failed to get product files in specified root path")
    else:
        for productFile in files:
            if not (re.search('WAS.product', productFile.path)): # Daniel La (JDS) 16/05/14 - added to ONLY process WAS.product files - IAG ticket SD2798346
                continue
            try:
                file = fs.getFile(productFile.path, [file_topology.FileAttrs.NAME,
                                                    file_topology.FileAttrs.PATH,
                                                    file_topology.FileAttrs.CONTENT
                                                     ])
            except (Exception, JException):
                logger.warnException("Failed to get product file")
            else:
                productInformation = parser.parseProductConfig(file.content)
                logger.debug('*** productInformation found: ', productInformation)
                break
    # if version is not determined, so we will guess it based on the presence
    # of 'profiles' directory in the installation root directory
    if productInformation is None:
        logger.debug('*** productinfo is none')
        pathUtil = file_system.getPath(fs)
        try:
            pathUtil.join(installRootDirPath, 'profiles')
        except (Exception, JException):
            logger.warnException('Failed to find profiles directory in the install root directory.')
            logger.info("Profiles directory appeared starting from the 6th version, so we make an attempt to discover WebSphere 5th")
            productInformation = websphere_discoverer.ProductInformation(version = 5)
        else:
            logger.info("Profiles directory appeared starting from the 6th version, so we make an attempt to discovery WebSphere 6th")
            productInformation = websphere_discoverer.ProductInformation(version = 6)
    logger.debug('*** END: determineVesion')
    return productInformation
예제 #2
0
def determineVersion(installRootDirPath, parser, fs):
    r'''@types: str, websphere_discoverer.ProductInfoParser, file_system.FileSystem -> websphere_discoverer.ProductInformation or None
    @resource-file:ND.product
    @resource-file:BASE.product
    @resource-file:WAS.product

    First check this xml files
        <installRootDirPath>/properties\version\ND.product - for Network Deployment
        <installRootDirPath>/properties\version\BASE.product - for Base stand-alone
        <installRootDirPath>/properties\version\BASE.product + ND.product - for Base federated to ND
        <installRootDirPath>/properties\version\WAS.product

    '''
    pathUtil = file_system.getPath(fs)
    if installRootDirPath:
        propertiesDirPath = pathUtil.join(installRootDirPath, 'properties', 'version')
    productInformation = None
    try:
        files = fs.getFiles(propertiesDirPath, filters = [file_system.ExtensionsFilter(['product'])],
                                           fileAttrs = [file_topology.FileAttrs.NAME,
                                                        file_topology.FileAttrs.PATH])
    except (Exception, JException):
        logger.warnException("Failed to determine platform version as failed to get product files in specified root path")
    else:
        for productFile in files:
            try:
                file = fs.getFile(productFile.path, [file_topology.FileAttrs.NAME,
                                                    file_topology.FileAttrs.PATH,
                                                    file_topology.FileAttrs.CONTENT
                                                     ])
            except (Exception, JException):
                logger.warnException("Failed to get product file")
            else:
                productInformation = parser.parseProductConfig(file.content)
                break
    # if version is not determined, so we will guess it based on the presence
    # of 'profiles' directory in the installation root directory
    if productInformation is None:
        pathUtil = file_system.getPath(fs)
        productName = 'IBM WebSphere Application Server'
        try:
            pathUtil.join(installRootDirPath, 'profiles')
        except (Exception, JException):
            logger.warnException('Failed to find profiles directory in the install root directory.')
            logger.info("Profiles directory appeared starting from the 6th version, so we make an attempt to discover WebSphere 5th")
            productInformation = websphere_discoverer.ProductInformation(productName, version = '5.x')
        else:
            logger.info("Profiles directory appeared starting from the 6th version, so we make an attempt to discovery WebSphere 6th")
            productInformation = websphere_discoverer.ProductInformation(productName, version = '6.x')
    return productInformation
예제 #3
0
def findHdbsqlPathBySid(fs, installationPath, dbSid, is_cmd_exist, shell_executor):
    binName = _HDBSQL_BINARY_NAME
    if fs._shell.isWinOs():
        binName = '%s.exe' % binName

    pathTool = file_system.getPath(fs)

    alternatives = (
                    file_system.Path(installationPath, pathTool) + _HDBCLIENT_FOLDER_NAME + binName,
                    file_system.Path('/usr/sap', pathTool) + _HDBCLIENT_FOLDER_NAME + binName,
                    file_system.Path('/usr/sap', pathTool) + dbSid + _HDBCLIENT_FOLDER_NAME + binName,
                    file_system.Path('/usr/sap', pathTool) + dbSid + 'exe' + 'linuxx86_64' + 'hdb' + binName,
                    file_system.Path('/usr/sap', pathTool) + dbSid + r'SYS' + r'global' + _HDBCLIENT_FOLDER_NAME + binName,
                    file_system.Path('/sapmnt', pathTool) + dbSid + _HDBCLIENT_FOLDER_NAME + binName,
                    file_system.Path('/sapmnt', pathTool) + dbSid + r'global' + _HDBCLIENT_FOLDER_NAME + binName,
                    )

    alternatives = imap(shell_interpreter.normalizePath, alternatives)
    binpath = findFirst(Sfn(fs.exists), alternatives)
    if not binpath:
        bin_in_path = is_cmd_exist(binName) | shell_executor
        if not bin_in_path:
            raise NoHdbsqlException('Hdbsql binary not found')
        binpath = binName
    return binpath
예제 #4
0
 def __init__(self, fs):
     r'''@types: file_system.FileSystem
     @raise ValueError: Path manipulation approach is not specified
     '''
     self.__fs = fs
     pathUtil = file_system.getPath(fs)
     if not pathUtil:
         raise ValueError("Path manipulation approach is not specified")
     self.__pathUtil = pathUtil
예제 #5
0
def _discover_msg_hostname(shell, pf_path):
    r'''Read DEFAULT profile to get message server hostname as usually this
    information resides there
    @types: Shell, str -> str?'''
    fs = file_system.createFileSystem(shell)
    pathtools = file_system.getPath(fs)
    system, _ = sap_discoverer.parsePfDetailsFromPath(pf_path)
    rootPath = sap_discoverer.findSystemBasePath(pf_path, system.getName())
    layout = sap_discoverer.Layout(pathtools, rootPath)
    default_pf_path = layout.getDefaultProfileFilePath()
    try:
        content = shell.safecat(default_pf_path)
    except (JException, Exception), e:
        logger.warn("Failed to get profile content: %s" % e)
예제 #6
0
def findDbmCliPath(fs, mainProcessPath):
    '''
    checks existence of dbmcli commands in following paths:
    /sapdb/<SID>/db/pgm/
    /sapdb/<SID>/db/bin/
    /sapdb/programs/bin/
    /sapdb/clients/<SID>/bin/
    Main process "kernel" has following path:
    /sapdb/<SID>/db/pgm/kernel
    @types: file_system.FileSystem, mainProcessPath -> str:

    '''
    if mainProcessPath:
        possibleDbmcliPaths = []
        pathTool = file_system.getPath(fs)
        # expecting /sapdb/<SID>/db/pgm/kernel
        pathList = mainProcessPath.split(fs.FileSeparator)
        if fs._shell.isWinOs():
            dbmCliBin = 'dbmcli.exe'
        else:
            dbmCliBin = 'dbmcli'
        if (len(pathList) >= 5 and pathList[-2] == 'pgm'
                and pathList[-3] == 'db'):
            # get maxDB home dir from kernel process:
            maxDbSid = pathList[-4]
            logger.debug('Found maxDB instance %s from kernel process path' %
                         maxDbSid)
            # get maxDB base dir from kernel process:
            maxDbHomeDir = pathTool.dirName(
                pathTool.dirName(
                    pathTool.dirName(pathTool.dirName(mainProcessPath))))
            logger.debug(
                'Found maxDB home folder %s from kernel process path' %
                maxDbHomeDir)
            possibleDbmcliPaths = (pathTool.join(maxDbHomeDir, maxDbSid, 'db',
                                                 'pgm', dbmCliBin),
                                   pathTool.join(maxDbHomeDir, maxDbSid, 'db',
                                                 'bin', dbmCliBin),
                                   pathTool.join(maxDbHomeDir, 'programs',
                                                 'bin', dbmCliBin),
                                   pathTool.join(maxDbHomeDir, 'clients',
                                                 maxDbSid, 'bin', dbmCliBin))
        else:
            mainProcessPath = pathTool.dirName(mainProcessPath).strip('" ')
            path_ = file_system.Path(mainProcessPath, pathTool) + dbmCliBin
            path_ = shell_interpreter.normalizePath(path_)
            possibleDbmcliPaths = (path_, )

    return findFirst(fs.exists, possibleDbmcliPaths) or __DEFAULT_DBMCLI_PATH
예제 #7
0
    def process(self, context):
        r'''
         @types: applications.ApplicationSignatureContext
        '''
        shell = context.client
        fs = file_system.createFileSystem(shell)

        config = None
        configPath = getVsConfigPathFromCmdline(self._vscanRfcProcess.commandLine)

        try:
            config = fs.getFile(configPath, [file_topology.FileAttrs.NAME, file_topology.FileAttrs.PATH,
                                             file_topology.FileAttrs.CONTENT])
        except file_topology.PathNotFoundException:
            logger.debugException('Failed to get config file for virus scan')

        configOsh = modeling.createConfigurationDocumentOshByFile(config, context.application.applicationOsh)
        context.resultsVector.add(configOsh)

        pathUtils = file_system.getPath(fs)
        exePath = (self._vscanRfcProcess.executablePath
                   and pathUtils.isAbsolute(self._vscanRfcProcess.executablePath)
                   and self._vscanRfcProcess.executablePath
                   or  _discoverProcessExecutablePath(shell, self._vscanRfcProcess))
        if exePath:
            logger.debug('vscan_rfc executable path: %s' % exePath)
            vscanRfcCmd = vscan_rfc(exePath)
            vsiVersion = vscanRfcCmd.version() | cmdlet.executeCommand(shell) | cmdlet.produceResult
            if vsiVersion:
                softwareBuilder = SoftwareBuilder()
                softwareBuilder.updateVersion(context.application.applicationOsh, vsiVersion.kernelRelease)
                softwareBuilder.updateVsiVersion(context.application.applicationOsh, vsiVersion.vsiVersion)
                appVersionDescription = 'Versiontext: %s. Build release: %s. Build date: %s. Build platform: %s' % (vsiVersion.versionText, vsiVersion.buildRelease, vsiVersion.buildDate, vsiVersion.buildPlatform)

                softwareBuilder.updateVersionDescription(context.application.applicationOsh, appVersionDescription)
        else:
            logger.debug('Failed to discover path to vscan_rfc executable. No version info discovered.')
        appSignature = context.application.getApplicationComponent().getApplicationSignature()
        adjoinedTopologyCookie = _getOrCreateAdjoinedTopologyCookie(appSignature)

        adjoinedTopologyCookie.virusScanOsh = context.application.applicationOsh

        adjoinedTopologyReporter = _VirusScanAdjoinedTopologyReporter()
        if adjoinedTopologyReporter.isDataEnough(adjoinedTopologyCookie):
            context.resultsVector.addAll(adjoinedTopologyReporter.reportApplicationComponentsLinks(adjoinedTopologyCookie.virusScanOsh, \
                                              adjoinedTopologyCookie.sapGatewayOsh))
        else:
            logger.debug('Data is not enough for building adjoined topology from VirusScanPlugin')
예제 #8
0
def DiscoveryMain(Framework):
    Framework = jee_connection.EnhancedFramework(Framework)
    platform = jee.Platform.WEBSPHERE
    shell = None
    try:
        try:
            # ======================= Establish connection =====================
            client = Framework.createClient()
            shell = shellutils.ShellFactory().createShell(client)
            # create FS
            fs = _createFileSystemRecursiveSearchEnabled(file_system.createFileSystem(shell))
            pathUtil = file_system.getPath(fs)
        except (Exception, JException), exc:
            logger.warnException(str(exc))
            jee_connection.reportError(Framework, str(exc), platform.getName())
        else:
예제 #9
0
def DiscoveryMain(Framework):
    Framework = jee_connection.EnhancedFramework(Framework)
    platform = jee.Platform.WEBSPHERE
    shell = None
    try:
        try:
            # ======================= Establish connection =====================
            client = Framework.createClient()
            shell = shellutils.ShellFactory().createShell(client)
            # create FS
            fs = _createFileSystemRecursiveSearchEnabled(
                file_system.createFileSystem(shell))
            pathUtil = file_system.getPath(fs)
        except (Exception, JException), exc:
            logger.warnException(str(exc))
            jee_connection.reportError(Framework, str(exc), platform.getName())
        else:
예제 #10
0
    def process(self, context):
        r'''
         @types: applications.ApplicationSignatureContext
        '''
        shell = context.client
        siaCommandline = self._siaProcess.commandLine

        fs = file_system.createFileSystem(shell)

        pathTool = file_system.getPath(fs)
        boeHome = _parseBOEHomePath(pathTool, self._siaProcess.executablePath)
        productIdPath = _composeProductIdPath(pathTool, boeHome)
        version = None
        try:
            version = _getProductVerisonFromProductId(shell, productIdPath)
        except Exception, e:
            logger.warn("Failed to get version from product ID: %s" % e)
예제 #11
0
    def process(self, context):
        r'''
         @types: applications.ApplicationSignatureContext
        '''
        shell = context.client
        siaCommandline = self._siaProcess.commandLine

        fs = file_system.createFileSystem(shell)

        pathTool = file_system.getPath(fs)
        boeHome = _parseBOEHomePath(pathTool, self._siaProcess.executablePath)
        productIdPath = _composeProductIdPath(pathTool, boeHome)
        version = None
        try:
            version = _getProductVerisonFromProductId(shell, productIdPath)
        except Exception, e:
            logger.warn("Failed to get version from product ID: %s" % e)
 def process(self, context):
     shell = context.client
     fs = file_system.createFileSystem(shell)
     path_util = file_system.getPath(fs)
     application = context.application
     osh = application.getOsh()
     process = application.getMainProcesses()[0]
     cmd_line = process.commandLine
     jvm_cmd_line_descriptor = jee.JvmCommandLineDescriptor(cmd_line)
     cmd_line_elements = jvm_cmd_line_descriptor.parseElements()
     java_options = filter(self.__is_java_option, cmd_line_elements)
     parse_fn = partiallyApply(self.parse_server_name, fptools._, path_util)
     server_name = first(keep(parse_fn, java_options))
     logger.debug('server name: %s' % server_name)
     if server_name is not None:
         osh.setAttribute('j2eeserver_servername', server_name)
         #TODO: replace to jee.ServerTopologyBuilder._composeFullName
         osh.setAttribute('j2eeserver_fullname', server_name)
     modeling.setAppServerType(osh)
 def process(self, context):
     shell = context.client
     fs = file_system.createFileSystem(shell)
     path_util = file_system.getPath(fs)
     application = context.application
     osh = application.getOsh()
     process = application.getMainProcesses()[0]
     cmd_line = process.commandLine
     jvm_cmd_line_descriptor = jee.JvmCommandLineDescriptor(cmd_line)
     cmd_line_elements = jvm_cmd_line_descriptor.parseElements()
     java_options = filter(self.__is_java_option, cmd_line_elements)
     parse_fn = partiallyApply(self.parse_server_name, fptools._, path_util)
     server_name = first(keep(parse_fn, java_options))
     logger.debug('server name: %s' % server_name)
     if server_name is not None:
         osh.setAttribute('j2eeserver_servername', server_name)
         #TODO: replace to jee.ServerTopologyBuilder._composeFullName
         osh.setAttribute('j2eeserver_fullname', server_name)
     modeling.setAppServerType(osh)
예제 #14
0
def findDbmCliPath(fs, mainProcessPath):
    """
    checks existence of dbmcli commands in following paths:
    /sapdb/<SID>/db/pgm/
    /sapdb/<SID>/db/bin/
    /sapdb/programs/bin/
    /sapdb/clients/<SID>/bin/
    Main process "kernel" has following path:
    /sapdb/<SID>/db/pgm/kernel
    @types: file_system.FileSystem, mainProcessPath -> str:

    """
    if mainProcessPath:
        possibleDbmcliPaths = []
        pathTool = file_system.getPath(fs)
        # expecting /sapdb/<SID>/db/pgm/kernel
        pathList = mainProcessPath.split(fs.FileSeparator)
        if fs._shell.isWinOs():
            dbmCliBin = "dbmcli.exe"
        else:
            dbmCliBin = "dbmcli"
        if len(pathList) >= 5 and pathList[-2] == "pgm" and pathList[-3] == "db":
            # get maxDB home dir from kernel process:
            maxDbSid = pathList[-4]
            logger.debug("Found maxDB instance %s from kernel process path" % maxDbSid)
            # get maxDB base dir from kernel process:
            maxDbHomeDir = pathTool.dirName(pathTool.dirName(pathTool.dirName(pathTool.dirName(mainProcessPath))))
            logger.debug("Found maxDB home folder %s from kernel process path" % maxDbHomeDir)
            possibleDbmcliPaths = (
                pathTool.join(maxDbHomeDir, maxDbSid, "db", "pgm", dbmCliBin),
                pathTool.join(maxDbHomeDir, maxDbSid, "db", "bin", dbmCliBin),
                pathTool.join(maxDbHomeDir, "programs", "bin", dbmCliBin),
                pathTool.join(maxDbHomeDir, "clients", maxDbSid, "bin", dbmCliBin),
            )
        else:
            mainProcessPath = pathTool.dirName(mainProcessPath).strip('" ')
            path_ = file_system.Path(mainProcessPath, pathTool) + dbmCliBin
            path_ = shell_interpreter.normalizePath(path_)
            possibleDbmcliPaths = (path_,)

    return findFirst(fs.exists, possibleDbmcliPaths) or __DEFAULT_DBMCLI_PATH
예제 #15
0
    def process(self, context):
        r'''
        @types: applications.ApplicationSignatureContext
        '''
        # ==================== DISCOVERY
        vec = context.resultsVector
        shell = context.client
        pathtools = file_system.getPath(file_system.createFileSystem(shell))
        # x) get process related application
        application = context.application
        connIp = application.getConnectionIp()
        # x) get web dispatcher process
        process = application.getMainProcesses()[0]
        # x) determine version
        _discoverVersion(process, shell, application.getOsh())
        # x) for the process read profile specified in command line
        pfFile = _discoverPfFile(process, shell, pathtools)
        # object version of the profile
        if not pfFile:
            logger.warn("Failed to get content of instance profile")
            return
        vec.add(_reportPfFile(pfFile, application.getOsh()))
        # x) instance profile
        defaultPf, instPf = _discoverPf(pfFile, shell, pathtools)
        # x) served systems

        processOsh = process.getOsh()
        if defaultPf and defaultPf.getMessageServerEndpoint():
            msgEndp = defaultPf.getMessageServerEndpoint()
            # make unknown served system where external is message server
            unknown = sap_webdisp.UnknownSystem()
            msgMetaDataSource = sap_webdisp.MessagingServerSource(msgEndp)
            served = sap_webdisp.ServedSystem(unknown, (msgMetaDataSource, ))
            vec.addAll(_reportSystems((served, ), processOsh, shell, connIp))
        if instPf:
            servedSystems = _discoverServedSystems(instPf, shell, pathtools)
            serverOsh = application.getOsh()
            vec.addAll(_reportWdEndpoints(instPf, serverOsh, shell, connIp))
            vec.addAll(
                _reportSystems(servedSystems, processOsh, shell, connIp,
                               serverOsh))
    def process(self, context):
        r'''
         @types: applications.ApplicationSignatureContext
        '''
        shell = context.client
        if not isinstance(shell, shellutils.Shell):
            raise ValueError("Shell is required")
        dataServiceOsh = context.application.applicationOsh
        fs = file_system.createFileSystem(shell)

        pathTool = file_system.getPath(fs)
        binFolder = pathTool.dirName(self._jobServiceProcess.executablePath)
        configPath = pathTool.join(binFolder, r'DSConfig.txt')

        cat = getSafeCatCmd(shell)
        grep = getGrepCmd(shell)
        version = None
        try:
            version = _getProductVerisonFromDSConfig(shell, configPath)
        except Exception, e:
            logger.warn('Failed to get BOBJ data services version: %s' % e)
예제 #17
0
def findBinPathBySid(binName, mainProcessPath, dbSid, fs):
    if fs._shell.isWinOs():
        binName = '%s.exe' % binName

    alternatives = ()
    if mainProcessPath:
        pathTool = file_system.getPath(fs)
        maxDbHomePath = getMaxDbHomeDir(mainProcessPath, dbSid)
        if maxDbHomePath:
            alternatives = (file_system.Path(maxDbHomePath, pathTool) +
                            'programs' + 'bin' + binName,
                            file_system.Path(maxDbHomePath, pathTool) +
                            'globalprograms' + 'bin' + binName)
        else:
            mainProcessFolder = pathTool.dirName(mainProcessPath).strip('" ')
            alternatives = (file_system.Path(mainProcessFolder, pathTool) +
                            binName, )

    alternatives = (shell_interpreter.normalizePath(path_)
                    for path_ in alternatives)
    return findFirst(Sfn(fs.exists), alternatives) or binName
예제 #18
0
def getDomainRootDirPath(shell, fs, process, getParentProcessByPid):
    r'@types: Shell, FileSystem, Process, (long -> Process) -> str or None'
    # find root directory for the process
    # Root directory may be specified as property in command line
    # -Dweblogic.RootDirectory
    cmdLineDescriptor = jee.JvmCommandLineDescriptor(process.commandLine)
    rootDirPath = cmdLineDescriptor.extractProperty('weblogic\.RootDirectory')
    if not rootDirPath:
        # If property is not specified - find out working directory for the process
        if shell.isWinOs():
            # In Windows root directory path can be extracted from the startup script of the.
            # Command line with path to startup script can be found in the
            # parent process for current weblogic process
            parentProcess = getParentProcessByPid(process.getParentPid())
            if parentProcess:
                startupScriptPath = _extractStartupScriptfromCmdPath(
                    parentProcess.commandLine, fs)
                logger.debug("startupScriptPath:", startupScriptPath)
                if startupScriptPath:
                    path = file_system.getPath(fs)
                    rootDirPath = path.dirName(startupScriptPath)
        else:
            rootDirPath = safeFunc(
                getWorkingDirByReadlinkInProc,
                fallbackFn=safeFunc(
                    getWorkingDirByCwd,
                    fallbackFn=safeFunc(
                        getWorkingDirByPwdx,
                        fallbackFn=safeFunc(getWorkingDirByPwdInProc))))(
                            shell, process.getPid())

    if rootDirPath:
        rootDirPath = rootDirPath.strip()
        # check if path ends with bin (in versions starting from 9th)
        if rootDirPath.endswith('bin'):
            rootDirPath = path.dirName(rootDirPath)
        return rootDirPath
    raise ValueError(
        "Domain root directory path cannot be found from the runtime information."
    )
예제 #19
0
def findBinPathBySid(binName, mainProcessPath, dbSid, fs):
    if fs._shell.isWinOs():
        binName = '%s.exe' % binName

    alternatives = ()
    if mainProcessPath:
        pathTool = file_system.getPath(fs)
        maxDbHomePath = getMaxDbHomeDir(mainProcessPath, dbSid)
        if maxDbHomePath:
            alternatives = (
                            file_system.Path(maxDbHomePath, pathTool) + 'programs' + 'bin' + binName,
                            file_system.Path(maxDbHomePath, pathTool) + 'globalprograms' + 'bin' + binName
                            )
        else:
            mainProcessFolder = pathTool.dirName(mainProcessPath).strip('" ')
            alternatives = (
                            file_system.Path(mainProcessFolder, pathTool) + binName,
                            )

    alternatives = (shell_interpreter.normalizePath(path_)
                                        for path_ in alternatives)
    return findFirst(Sfn(fs.exists), alternatives) or binName
    def process(self, context):
        r'''
        @types: applications.ApplicationSignatureContext
        '''
        # ==================== DISCOVERY
        vec = context.resultsVector
        shell = context.client
        pathtools = file_system.getPath(file_system.createFileSystem(shell))
        # x) get process related application
        application = context.application
        connIp = application.getConnectionIp()
        # x) get web dispatcher process
        process = application.getMainProcesses()[0]
        # x) determine version
        _discoverVersion(process, shell, application.getOsh())
        # x) for the process read profile specified in command line
        pfFile = _discoverPfFile(process, shell, pathtools)
        # object version of the profile
        if not pfFile:
            logger.warn("Failed to get content of instance profile")
            return
        vec.add(_reportPfFile(pfFile, application.getOsh()))
        # x) instance profile
        defaultPf, instPf = _discoverPf(pfFile, shell, pathtools)
        # x) served systems

        processOsh = process.getOsh()
        if defaultPf and defaultPf.getMessageServerEndpoint():
            msgEndp = defaultPf.getMessageServerEndpoint()
            # make unknown served system where external is message server
            unknown = sap_webdisp.UnknownSystem()
            msgMetaDataSource = sap_webdisp.MessagingServerSource(msgEndp)
            served = sap_webdisp.ServedSystem(unknown, (msgMetaDataSource,))
            vec.addAll(_reportSystems((served,), processOsh, shell, connIp))
        if instPf:
            servedSystems = _discoverServedSystems(instPf, shell, pathtools)
            serverOsh = application.getOsh()
            vec.addAll(_reportWdEndpoints(instPf, serverOsh, shell, connIp))
            vec.addAll(_reportSystems(servedSystems, processOsh, shell, connIp, serverOsh))
예제 #21
0
def getDomainRootDirPath(shell, fs, process, getParentProcessByPid):
    r'@types: Shell, FileSystem, Process, (long -> Process) -> str or None'
    # find root directory for the process
    # Root directory may be specified as property in command line
    # -Dweblogic.RootDirectory
    cmdLineDescriptor = jee.JvmCommandLineDescriptor(process.commandLine)
    rootDirPath = cmdLineDescriptor.extractProperty('weblogic\.RootDirectory')
    if not rootDirPath:
        # If property is not specified - find out working directory for the process
        if shell.isWinOs():
            # In Windows root directory path can be extracted from the startup script of the.
            # Command line with path to startup script can be found in the
            # parent process for current weblogic process
            parentProcess = getParentProcessByPid(process.getParentPid())
            if parentProcess:
                startupScriptPath = _extractStartupScriptfromCmdPath(parentProcess.commandLine, fs)
                logger.debug("startupScriptPath:", startupScriptPath)
                if startupScriptPath:
                    path = file_system.getPath(fs)
                    rootDirPath = path.dirName(startupScriptPath)
        else:
            rootDirPath = safeFunc(getWorkingDirByReadlinkInProc,
                              fallbackFn = safeFunc(getWorkingDirByCwd,
                                   fallbackFn = safeFunc(getWorkingDirByPwdx,
                                         fallbackFn=safeFunc(getWorkingDirByPwdInProc)
                                         )
                              )
                          )(shell, process.getPid())

    if rootDirPath:
        rootDirPath = rootDirPath.strip()
        # check if path ends with bin (in versions starting from 9th)
        if rootDirPath.endswith('bin'):
            rootDirPath = path.dirName(rootDirPath)
        return rootDirPath
    raise ValueError("Domain root directory path cannot be found from the runtime information.")
예제 #22
0
 def __init__(self, fs):
     r'@types: file_system.FileSystem'
     self.__fs = fs
     self.__pathUtil = file_system.getPath(fs)
예제 #23
0
    def process(self, context):
        r'''
        @types: applications.ApplicationSignatureContext
        '''
        # ==================== DISCOVERY
        shell = context.client
        fs = file_system.createFileSystem(shell)
        pathtools = file_system.getPath(fs)
        # 1) get process related application
        application = context.application
        connectionIp = application.getConnectionIp()
        # 2) find out process where path to the instance profile is stored
        logger.info(" Get executable path of main process ")
        mainProcess = application.getMainProcesses()[0]
        # 3)
        logger.info("Found out path to instance profile")
        instanceProfilePath = self.__getProfilePath(mainProcess)
        # 4)
        logger.info("Instance profile path: ", instanceProfilePath, ". Get content")
        getContent = fptools.safeFunc(self.__getContent, Exception)
        profileFile = (instanceProfilePath and getContent(shell, pathtools, instanceProfilePath))
        if not profileFile:
            logger.warn("Failed to get content of instance profile")
            return
        # 5) parse content using instance and default profile parsers
        logger.info("Make configuration parsing")
        iniParser = sap_discoverer.IniParser()
        instancePfParser = sap_discoverer.InstanceProfileParser(iniParser)
        try:
            instanceProfile = instancePfParser.parseContent(profileFile.content)
        except Exception:
            logger.warnException("Failed to parse instance profile")
        else:
            traceConfig = None
            runtimeConfig = None
            sapInstance = instanceProfile.instance
            sapInstance = sap.Instance(sapInstance.name + sapInstance.number,
                                       sapInstance.number,
                                       sapInstance.hostname)

            # 6) Process runtime.properties that contains information about
            #    Solution Manager and SLD if present
            logger.info("Create agent layout")
            logger.info("Get content of runtime properties")
            agentLayout = fptools.safeFunc(sap_smd_discoverer.createAgentLayoutFromBinPath)(
                (pathtools.isAbsolute(mainProcess.executablePath)
                 and mainProcess.executablePath
                 or discoverExecutablePath(shell, mainProcess)
                 ),
                    fs,
                    pathtools
                )
            if agentLayout:
                propertiesFile = getContent(shell, pathtools, agentLayout.getRuntimePropertiesPath())
                if propertiesFile:
                    parser = sap_smd_discoverer.RuntimePropertiesParser(
                        sap_discoverer.IniParser())
                    try:
                        runtimeConfig = parser.parse(propertiesFile.content)
                    except Exception:
                        logger.warnException("Failed to parse runtime properties")

                logger.info("Find out version information")
                devSmdAgentFile = getContent(shell, pathtools, agentLayout.getDevSmdAgentConfigFile())
                if devSmdAgentFile:
                    configParser = sap_smd_discoverer.DevSmdAgentConfigParser()
                    # find config with corresponding PID (of main process)
                    hasMainProcessPid = lambda c, pid = mainProcess.getPid(): c.pid == pid
                    traceConfig = fptools.findFirst(hasMainProcessPid,
                                                    configParser.parse(devSmdAgentFile.content))
                    if not traceConfig:
                        logger.warn("Failed to find trace information for the main process")

            # === REPORT ===
            smdAgentOsh = application.getOsh()
            vector = context.resultsVector
            endpointReporter = netutils.EndpointReporter(netutils.ServiceEndpointBuilder())
            configFileReporter = file_topology.Reporter(file_topology.Builder())
            linkReporter = sap.LinkReporter()
            smdAgentBuilder = sap_smd.Builder()
            softwareBuilder = sap.SoftwareBuilder()
            softwareReporter = sap.SoftwareReporter(sap.SoftwareBuilder())
            resolverByShell = netutils.DnsResolverByShell(shell)
            processOsh = mainProcess.getOsh()

            # x) update name of application using instance name
            softwareBuilder.updateName(smdAgentOsh, sapInstance.getName())
            # x) configuration files related to running_software
            vector.add(configFileReporter.report(profileFile, smdAgentOsh))

            if traceConfig:
                # x) update version information in application
                smdAgentOsh = softwareBuilder.updateVersionInfo(
                    smdAgentOsh, traceConfig.versionInfo)
                if traceConfig.jstartVersionInfo:
                    smdAgentOsh = smdAgentBuilder.updateJstartVersionInfo(
                        smdAgentOsh, traceConfig.jstartVersionInfo)

            # x) show relation between agent and
            # - SMD server / no enough information /
            # - message server of SCS OR Solution Manager, represented as agent connection endpoint
            # - SLD
            if propertiesFile and runtimeConfig:
                # x) report properties file as configuration document
                vector.add(configFileReporter.report(propertiesFile, smdAgentOsh))
                # x) Report relation between agent and SLD server and SolMan
                # Resolve endpoint addresses
                # make function that will accept endpoint only
                resolveEndpointFn = fptools.partiallyApply(
                    self.__resolveEndpointAddress,
                    fptools.safeFunc(resolverByShell.resolveIpsByHostname, []),
                    fptools._
                )
                # - SLD relation
                if runtimeConfig.sldEndpoint:
                    for endpoint in resolveEndpointFn(runtimeConfig.sldEndpoint):
                        sldHostOsh = endpointReporter.reportHostFromEndpoint(endpoint)
                        vector.add(sldHostOsh)
                        sldEndpointOsh = endpointReporter.reportEndpoint(endpoint, sldHostOsh)
                        vector.add(sldEndpointOsh)
                        # this unknown server type must be SLD server
                        sldOsh = softwareReporter.reportUknownSoftware(sldHostOsh)
                        vector.add(sldOsh)
                        vector.add(linkReporter.reportUsage(sldOsh, sldEndpointOsh))
                        # report link between process and SLD server endpoint
                        vector.add(linkReporter.reportClientServerRelation(processOsh, sldEndpointOsh))

                # - Solution Manager relation
                agentConnectionEndpoint = runtimeConfig.getAgentConnecitonEndpoint()
                if agentConnectionEndpoint:
                    for endpoint in resolveEndpointFn(agentConnectionEndpoint):
                        hostOsh = endpointReporter.reportHostFromEndpoint(endpoint)
                        vector.add(hostOsh)
                        endpointOsh = endpointReporter.reportEndpoint(endpoint, hostOsh)
                        vector.add(endpointOsh)
                        softwareOsh = softwareReporter.reportUknownSoftware(hostOsh)
                        vector.add(softwareOsh)
                        vector.add(linkReporter.reportUsage(softwareOsh, endpointOsh))
                        # report link between process and SolMan end-point
                        vector.add(linkReporter.reportClientServerRelation(processOsh, endpointOsh))
예제 #24
0
def determineVersion(installRootDirPath, parser, fs):
    r'''@types: str, websphere_discoverer.ProductInfoParser, file_system.FileSystem -> websphere_discoverer.ProductInformation or None
    @resource-file:ND.product
    @resource-file:BASE.product
    @resource-file:WAS.product

    First check this xml files
        <installRootDirPath>/properties\version\ND.product - for Network Deployment
        <installRootDirPath>/properties\version\BASE.product - for Base stand-alone
        <installRootDirPath>/properties\version\BASE.product + ND.product - for Base federated to ND
        <installRootDirPath>/properties\version\WAS.product

    '''
    pathUtil = file_system.getPath(fs)
    if installRootDirPath:
        propertiesDirPath = pathUtil.join(installRootDirPath, 'properties',
                                          'version')
    productInformation = None
    try:
        files = fs.getFiles(
            propertiesDirPath,
            filters=[file_system.ExtensionsFilter(['product'])],
            fileAttrs=[
                file_topology.FileAttrs.NAME, file_topology.FileAttrs.PATH
            ])
    except (Exception, JException):
        logger.warnException(
            "Failed to determine platform version as failed to get product files in specified root path"
        )
    else:
        for productFile in files:
            try:
                file = fs.getFile(productFile.path, [
                    file_topology.FileAttrs.NAME, file_topology.FileAttrs.PATH,
                    file_topology.FileAttrs.CONTENT
                ])
            except (Exception, JException):
                logger.warnException("Failed to get product file")
            else:
                productInformation = parser.parseProductConfig(file.content)
                break
    # if version is not determined, so we will guess it based on the presence
    # of 'profiles' directory in the installation root directory
    if productInformation is None:
        pathUtil = file_system.getPath(fs)
        productName = 'IBM WebSphere Application Server'
        try:
            pathUtil.join(installRootDirPath, 'profiles')
        except (Exception, JException):
            logger.warnException(
                'Failed to find profiles directory in the install root directory.'
            )
            logger.info(
                "Profiles directory appeared starting from the 6th version, so we make an attempt to discover WebSphere 5th"
            )
            productInformation = websphere_discoverer.ProductInformation(
                productName, version='5.x')
        else:
            logger.info(
                "Profiles directory appeared starting from the 6th version, so we make an attempt to discovery WebSphere 6th"
            )
            productInformation = websphere_discoverer.ProductInformation(
                productName, version='6.x')
    return productInformation
예제 #25
0
 def __init__(self, fs):
     r'@types: file_system.FileSystem'
     self.__fs = fs
     self.__pathUtil = file_system.getPath(fs)
예제 #26
0
    def process(self, context):
        r''' @types: applications.ApplicationSignatureContext '''
        # ------------------------------------------------------------ DISCOVERY
        "SAP TREX plug-in DISCOVERY start" | info
        shell = context.client
        fs = file_system.createFileSystem(shell)
        pathtools = file_system.getPath(fs)
        # x) get process related application
        hostOsh = context.hostOsh
        application = context.application
        destinationIp = application.getConnectionIp()
        "x) Find TREX Daemon process that has profile path as parameter" | info
        mainProcess = findFirst(isMainTrexProcess,
                                context.application.getProcesses())
        profilePath = sap_discoverer.getProfilePathFromCommandline(
            mainProcess.commandLine)
        "x) Read profile content: %s" % profilePath | info
        getFileContent = Sfn(
            Fn(self.__getFileWithContent, shell, pathtools, __))
        profileFile = profilePath and getFileContent(profilePath)
        if not profileFile:
            "Plug-in flow broken. Failed to read instance profile\
content based on path from the TREXDaemon command line"                                                        | warn
            return

        "x) Instance profile parsing" | info
        sapIniParser = sap_discoverer.IniParser()
        instanceProfileParser = sap_discoverer.InstanceProfileParser(
            sapIniParser)
        defaultProfileParser = sap_trex_discoverer.DefaultProfileParser(
            sapIniParser)
        try:
            resultAsIni = instanceProfileParser.parseAsIniResult(
                profileFile.content)
            instanceProfile = instanceProfileParser.parse(resultAsIni)
            defaultProfile = defaultProfileParser.parse(resultAsIni)
        except Exception:
            logger.warnException("Failed to parse instance profile")
            return

        rfcConfigs = []
        trexSystem = defaultProfile.getSystem()
        trexInstance = instanceProfile.getInstance()
        trexInstanceName = trexInstance.getName() + trexInstance.getNumber()

        isBiaProduct = 0
        versionInfo = None
        #        # master by default, if topology file is not found that means
        #        # that current one is the only instance
        #        isMaster = 1

        trexTopology = None

        "x) Initialize TREX instance layout" | debug
        systemName = trexSystem.getName()
        systemBasePath = sap_discoverer.findSystemBasePath(
            mainProcess.getExecutablePath(), systemName)
        if systemBasePath:
            systemLayout = sap_trex_discoverer.SystemLayout(
                pathtools, systemBasePath, systemName)
            'System path: %s' % systemLayout.getRootPath() | info
            instancePath = systemLayout.composeInstanceDirPath(
                trexInstanceName)
            'Instance path: %s' % instancePath | debug
            instanceLayout = sap_trex_discoverer.InstanceLayout(
                pathtools, instancePath, trexInstanceName)

            "x) Get content of default profile as it contains information about product"
            "x) Determine whether we deal with BIA based on version information" | debug
            defaultProfilePath = systemLayout.getDefaultProfileFilePath()
            defaultProfileFile = getFileContent(defaultProfilePath)
            try:
                resultAsIni = instanceProfileParser.parseAsIniResult(
                    defaultProfileFile.content)
                defaultProfile = defaultProfileParser.parse(resultAsIni)
            except Exception:
                logger.warnException("Failed to parse default profile")
            else:
                isBiaProduct = defaultProfile.getProductType(
                ) == sap_trex.Product.BIA
            (isBiaProduct and "BIA" or "non-BIA", "product detected") | info

            # get instance host name from profile name
            instanceHostname = None
            try:
                destinationSystem = sap_discoverer.parseSapSystemFromInstanceProfileName(
                    profileFile.getName())
            except Exception:
                msg = "Failed to parse instance hostname from profile file name"
                logger.debugException(msg)
            else:
                instanceHostname = first(
                    destinationSystem.getInstances()).getHostname()

            "x) Discover whole topology from (topology.ini)" | info
            # topology.ini file location and format differs depending on the
            # product:
            # -a) BIA (has plain-ini file at <SID>/sys/global/trex/data/topology.ini
            # -b) TREX (has several places where topology.ini can be stored)
            discoverTopologyIniFilePath = fptools.safeFunc(
                sap_trex_discoverer.discoverTopologyIniFilePath)
            topologyFilePath = (isBiaProduct
                                and systemLayout.getTopologyIniPath()
                                or discoverTopologyIniFilePath(
                                    fs, instanceLayout, instanceHostname))

            topologyFile = topologyFilePath and getFileContent(
                topologyFilePath)
            if topologyFile:
                try:
                    configParser = sap_trex_discoverer.TopologyConfigParser()
                    trexTopology = sap_trex_discoverer.TrexTopologyConfig(
                        configParser.parse(topologyFile.content))
                    # find instance between master end-points


#                    landscapeSnapshot = topology.getGlobals().getLandscapeSnapshot()
#                    masterEndpoints = landscapeSnapshot.getMasterEndpoints()
#                    activeMasterEndpoints = landscapeSnapshot.getActiveMasterEndpoints()
#                    topologyNodes = topology.getHostNodes()
##
#                    isEndpointWithInstanceHostname = (lambda
#                        ep, hostname = instanceHostname: ep.getAddress() == hostname)
#                    isMaster = len(filter(isEndpointWithInstanceHostname,
#                           landscapeSnapshot.getMasterEndpoints()))
#                    "host role is %s" % (isMaster and "master" or "slave") | info
                except:
                    logger.warnException(
                        "Failed to parse topology configuration")
            else:
                logger.warn(
                    "Failed to get content for the topology configuration")

            "x) Discover TREX version information from saptrexmanifest.mf" | info
            # read version info from manifest file
            manifestFile = getFileContent(instanceLayout.getManifestFilePath())
            if manifestFile:
                manifestParser = sap_trex_discoverer.SapTrexManifestParser(
                    sapIniParser)
                versionInfo = manifestParser.parseVersion(manifestFile.content)
            else:
                'Failed to discover version from manifest file' | warn
                'Second attept to get version from updateConfig.ini file' | info
                profileSystem = Sfn(
                    sap_discoverer.parseSapSystemFromInstanceProfileName)(
                        profileFile.getName())
                if profileSystem:
                    hostname = first(
                        profileSystem.getInstances()).getHostname()
                    updateConfigFile = getFileContent(
                        instanceLayout.composeUpdateConfigIniFilePath(
                            hostname))
                    versionInfo = updateConfigFile and sap.VersionInfo(
                        updateConfigFile.content.strip())

            "x) Discover served systems ( in case if RFC configuration established )" | info
            rfcServerIniFilePath = (
                isBiaProduct and systemLayout.getRfcServerConfigFilePath()
                or instanceLayout.composeTrexRfcServerIniFilePath(
                    instanceHostname))

            rfcServerIniFile = getFileContent(rfcServerIniFilePath)
            if rfcServerIniFile:
                rfcConfigs = filter(None, (fptools.safeFunc(
                    sap_trex_discoverer.parseConnectionsInRfcServerIni)(
                        rfcServerIniFile.content)))

        # -------------------------------------------------------- REPORTING
        "SAP TREX plug-in REPORTING start" | info
        trexOsh = application.getOsh()
        vector = context.resultsVector
        configFileReporter = file_topology.Reporter(file_topology.Builder())
        trexReporter = sap_trex.Reporter(sap_trex.Builder())
        linkReporter = sap.LinkReporter()
        softwareBuilder = sap.SoftwareBuilder()
        "x) - report profile content as configuration document for the application" | info
        vector.add(configFileReporter.report(profileFile, trexOsh))
        ("x) - report %s" % trexSystem) | info
        trexSystemOsh = trexReporter.reportSystem(trexSystem)
        vector.add(trexSystemOsh)
        vector.add(linkReporter.reportMembership(trexSystemOsh, trexOsh))
        "x) - report instance name and version" | info
        softwareBuilder.updateName(trexOsh, trexInstanceName)
        "x) report instance number: %s" % trexInstance.getNumber() | info
        instanceBuilder = sap_trex.Builder()
        instanceBuilder.updateInstanceNumber(trexOsh, trexInstance.getNumber())
        if versionInfo:
            softwareBuilder.updateVersionInfo(trexOsh, versionInfo)
        if isBiaProduct:
            softwareBuilder.updateDiscoveredProductName(
                trexOsh, sap_trex.Product.BIA.instanceProductName)
        "x) report RFC connections" | info
        dnsResolver = netutils.DnsResolverByShell(shell, destinationIp)
        vector.addAll(reportRfcConfigs(rfcConfigs, dnsResolver, hostOsh))

        "x) report all topology nodes" | info
        if trexTopology:
            reportHostNode = fptools.partiallyApply(reportTrexHostNode,
                                                    fptools._, trexTopology,
                                                    isBiaProduct)
            vectors = map(reportHostNode, trexTopology.getHostNodes())
            fptools.each(vector.addAll, vectors)
예제 #27
0
def DiscoveryMain(Framework):
    OshvResult = ObjectStateHolderVector()
    hostOsh = None

    ## Destination data
    hostId = Framework.getDestinationAttribute('hostId') or None
    processRootId = Framework.getDestinationAttribute('processRootId') or None
    processPath = Framework.getDestinationAttribute('processPath') or None
    processCmdLine = Framework.getDestinationAttribute('processCmdLine') or None
    protocol = Framework.getDestinationAttribute('Protocol')
    ipAddress = Framework.getDestinationAttribute('ip_address')
    raw_paths = Framework.getParameter('emsadmin_tool_absolute_paths') or ''
    default_paths = [x.strip() for x in raw_paths.split(',')]
    ## Pattern parameters
    isJmsQueueDiscoveryEnabled = Boolean.valueOf(Framework.getParameter('discover_queues'))
    isJmsTopicDiscoveryEnabled = Boolean.valueOf(Framework.getParameter('discover_topics'))

    ## Container HOST OSH
    if hostId:
        hostOsh = modeling.createOshByCmdbIdString('host', hostId.strip())
        OshvResult.add(hostOsh)
        logger.debug('[' + __name__ + ':DiscoveryMain] Got HOSTID <%s>' % hostId)

    ## EMS OSH
    if processRootId:
        processOsh = modeling.createOshByCmdbIdString('process', processRootId.strip())
        OshvResult.add(processOsh)
        logger.debug('[' + __name__ + ':DiscoveryMain] Got Process ID <%s>' % processRootId)
    else:
        errMsg = "Invalid Tibco EMS Server CI ID received from server. This EMS server will not be processed"
        logger.error(errMsg)
        logger.reportError(errMsg)
        return OshvResult

    emsTopology = []
    # Attempt to create a shell client
    try:
        client = Framework.createClient()
        shell = shellutils.ShellFactory().createShell(client)
        fallbackDnsResolver = tibco_discoverer.FallbackResolver([netutils.JavaDnsResolver(), netutils.DnsResolverByShell(shell)])
        dnsResolver = tibco_discoverer.CachedResolver(fallbackDnsResolver)

        fs = file_system.createFileSystem(shell)
        emsShellDiscoverer = tibco_discoverer.EmsDiscovererByShell(shell, fs)

        pathUtils = file_system.getPath(fs)
        emsPath = "%s/" % pathUtils.dirName(processPath)
        default_paths.insert(0, emsPath)
        # find out whether emsadmin tool exists and config path present in command line
        for ems_path in default_paths:
            configPath = emsShellDiscoverer.discoverConfigPath(ems_path, processCmdLine)
            if configPath:
                emsPath = ems_path
                logger.debug('Found ems admin utility path %s' % emsPath)
                logger.debug('Found ems config file path %s' % configPath)
                break
        if not emsPath:
            raise ValueError('Failed to discover ems admin utility path. No discovery possible.')
        listenUrls = emsShellDiscoverer.getListenUrls(configPath)
        credList = Framework.getAvailableProtocols(ipAddress, tibco.TIBCO_PROTOCOL)
        # Check if exists any credentials for TIBCO
        if credList:
            for cred in credList:
                for listenUrl in listenUrls:
                    try:
                        emsAdminCommand = tibco_discoverer.EmsAdminCommand(client, cred, emsPath, listenUrl)
                        if testConnection(emsAdminCommand):
                            emsDiscoverer = tibco_discoverer.EmsDiscovererByAdminCommand(emsAdminCommand)
                            emsServer = emsDiscoverer.getEmsServerInfo()
                            jmsServer = emsDiscoverer.extractJmsServerInfoFromUrl(listenUrl)

                            if jmsServer:
                                hostname = jmsServer.hostname
                                try:
                                    ip = dnsResolver.resolveIpsByHostname(hostname)
                                    jmsServer.hostname = netutils.getLowestIp(ip)
                                except:
                                    logger.debug("Cannot resolve %s host" % hostname)
                            if emsServer:
                                emsQueues = isJmsQueueDiscoveryEnabled and emsDiscoverer.getQueues()
                                emsTopics = isJmsTopicDiscoveryEnabled and emsDiscoverer.getTopics()
                            destinations = []
                            if emsQueues or emsTopics:
                                emsQueues and destinations.extend(emsQueues)
                                emsTopics and destinations.extend(emsTopics)
                            emsDataItem = tibco_discoverer.EmsTopology(emsServer, jmsServer, destinations)
                            emsTopology.append(emsDataItem)
                    except tibco_discoverer.TibcoDiscovererException, ex:
                        reportError(str(ex), tibco.TIBCO_PROTOCOL, Framework)
                    except Exception, ex:
                        reportError(str(ex), protocol, Framework)
                    except JException, ex:
                        msg = ex.getMessage()
                        logger.debugException(msg)
                        errormessages.resolveAndReport(msg, protocol, Framework)
예제 #28
0
 def __init__(self, shell, fs):
     r'@types: shelltuils.Shell'
     assert shell
     self.__fs = fs
     self.__pathUtils = file_system.getPath(self.__fs)
예제 #29
0
 def __init__(self, shell, fs):
     r'@types: shelltuils.Shell'
     assert shell
     self.__fs = fs
     self.__pathUtils = file_system.getPath(self.__fs)
예제 #30
0
    def process(self, context):
        r''' @types: applications.ApplicationSignatureContext '''
        # ------------------------------------------------------------ DISCOVERY
        "SAP TREX plug-in DISCOVERY start" | info
        shell = context.client
        fs = file_system.createFileSystem(shell)
        pathtools = file_system.getPath(fs)
        # x) get process related application
        hostOsh = context.hostOsh
        application = context.application
        destinationIp = application.getConnectionIp()
        "x) Find TREX Daemon process that has profile path as parameter" | info
        mainProcess = findFirst(isMainTrexProcess, context.application.getProcesses())
        profilePath = sap_discoverer.getProfilePathFromCommandline(mainProcess.commandLine)
        "x) Read profile content: %s" % profilePath | info
        getFileContent = Sfn(Fn(self.__getFileWithContent, shell, pathtools, __))
        profileFile = profilePath and getFileContent(profilePath)
        if not profileFile:
            "Plug-in flow broken. Failed to read instance profile\
content based on path from the TREXDaemon command line" | warn
            return

        "x) Instance profile parsing" | info
        sapIniParser = sap_discoverer.IniParser()
        instanceProfileParser = sap_discoverer.InstanceProfileParser(sapIniParser)
        defaultProfileParser = sap_trex_discoverer.DefaultProfileParser(sapIniParser)
        try:
            resultAsIni = instanceProfileParser.parseAsIniResult(profileFile.content)
            instanceProfile = instanceProfileParser.parse(resultAsIni)
            defaultProfile = defaultProfileParser.parse(resultAsIni)
        except Exception:
            logger.warnException("Failed to parse instance profile")
            return

        rfcConfigs = []
        trexSystem = defaultProfile.getSystem()
        trexInstance = instanceProfile.getInstance()
        trexInstanceName = trexInstance.getName() + trexInstance.getNumber()

        isBiaProduct = 0
        versionInfo = None
#        # master by default, if topology file is not found that means
#        # that current one is the only instance
#        isMaster = 1

        trexTopology = None

        "x) Initialize TREX instance layout" | debug
        systemName = trexSystem.getName()
        systemBasePath = sap_discoverer.findSystemBasePath(
                            mainProcess.getExecutablePath(), systemName )
        if systemBasePath:
            systemLayout = sap_trex_discoverer.SystemLayout(pathtools, systemBasePath, systemName)
            'System path: %s' % systemLayout.getRootPath() | info
            instancePath = systemLayout.composeInstanceDirPath(trexInstanceName)
            'Instance path: %s' % instancePath | debug
            instanceLayout = sap_trex_discoverer.InstanceLayout(pathtools, instancePath, trexInstanceName)

            "x) Get content of default profile as it contains information about product"
            "x) Determine whether we deal with BIA based on version information" | debug
            defaultProfilePath = systemLayout.getDefaultProfileFilePath()
            defaultProfileFile = getFileContent(defaultProfilePath)
            try:
                resultAsIni = instanceProfileParser.parseAsIniResult(defaultProfileFile.content)
                defaultProfile = defaultProfileParser.parse(resultAsIni)
            except Exception:
                logger.warnException("Failed to parse default profile")
            else:
                isBiaProduct = defaultProfile.getProductType() == sap_trex.Product.BIA
            (isBiaProduct and "BIA" or "non-BIA", "product detected") | info

            # get instance host name from profile name
            instanceHostname = None
            try:
                destinationSystem = sap_discoverer.parseSapSystemFromInstanceProfileName(profileFile.getName())
            except Exception:
                msg = "Failed to parse instance hostname from profile file name"
                logger.debugException(msg)
            else:
                instanceHostname = first(destinationSystem.getInstances()).getHostname()

            "x) Discover whole topology from (topology.ini)" | info
            # topology.ini file location and format differs depending on the
            # product:
            # -a) BIA (has plain-ini file at <SID>/sys/global/trex/data/topology.ini
            # -b) TREX (has several places where topology.ini can be stored)
            discoverTopologyIniFilePath = fptools.safeFunc(sap_trex_discoverer.discoverTopologyIniFilePath)
            topologyFilePath = (isBiaProduct
                and systemLayout.getTopologyIniPath()
                or  discoverTopologyIniFilePath(fs, instanceLayout, instanceHostname))

            topologyFile = topologyFilePath and getFileContent(topologyFilePath)
            if topologyFile:
                try:
                    configParser = sap_trex_discoverer.TopologyConfigParser()
                    trexTopology = sap_trex_discoverer.TrexTopologyConfig(
                                configParser.parse(topologyFile.content))
                    # find instance between master end-points
#                    landscapeSnapshot = topology.getGlobals().getLandscapeSnapshot()
#                    masterEndpoints = landscapeSnapshot.getMasterEndpoints()
#                    activeMasterEndpoints = landscapeSnapshot.getActiveMasterEndpoints()
#                    topologyNodes = topology.getHostNodes()
##
#                    isEndpointWithInstanceHostname = (lambda
#                        ep, hostname = instanceHostname: ep.getAddress() == hostname)
#                    isMaster = len(filter(isEndpointWithInstanceHostname,
#                           landscapeSnapshot.getMasterEndpoints()))
#                    "host role is %s" % (isMaster and "master" or "slave") | info
                except:
                    logger.warnException("Failed to parse topology configuration")
            else:
                logger.warn("Failed to get content for the topology configuration")

            "x) Discover TREX version information from saptrexmanifest.mf" | info
            # read version info from manifest file
            manifestFile = getFileContent(instanceLayout.getManifestFilePath())
            if manifestFile:
                manifestParser = sap_trex_discoverer.SapTrexManifestParser(sapIniParser)
                versionInfo = manifestParser.parseVersion(manifestFile.content)
            else:
                'Failed to discover version from manifest file' | warn
                'Second attept to get version from updateConfig.ini file' | info
                profileSystem = Sfn(sap_discoverer.parseSapSystemFromInstanceProfileName)(profileFile.getName())
                if profileSystem:
                    hostname = first(profileSystem.getInstances()).getHostname()
                    updateConfigFile = getFileContent(instanceLayout.composeUpdateConfigIniFilePath(hostname))
                    versionInfo = updateConfigFile and sap.VersionInfo(updateConfigFile.content.strip())

            "x) Discover served systems ( in case if RFC configuration established )" | info
            rfcServerIniFilePath = (isBiaProduct
                    and systemLayout.getRfcServerConfigFilePath()
                    or instanceLayout.composeTrexRfcServerIniFilePath(instanceHostname))

            rfcServerIniFile = getFileContent(rfcServerIniFilePath)
            if rfcServerIniFile:
                rfcConfigs = filter(None, (fptools.safeFunc(
                    sap_trex_discoverer.parseConnectionsInRfcServerIni)
                        (rfcServerIniFile.content)))

        # -------------------------------------------------------- REPORTING
        "SAP TREX plug-in REPORTING start" | info
        trexOsh = application.getOsh()
        vector = context.resultsVector
        configFileReporter = file_topology.Reporter(file_topology.Builder())
        trexReporter = sap_trex.Reporter(sap_trex.Builder())
        linkReporter = sap.LinkReporter()
        softwareBuilder = sap.SoftwareBuilder()
        "x) - report profile content as configuration document for the application" | info
        vector.add(configFileReporter.report(profileFile, trexOsh))
        ("x) - report %s" % trexSystem) | info
        trexSystemOsh = trexReporter.reportSystem(trexSystem)
        vector.add(trexSystemOsh)
        vector.add(linkReporter.reportMembership(trexSystemOsh, trexOsh))
        "x) - report instance name and version" | info
        softwareBuilder.updateName(trexOsh, trexInstanceName)
        "x) report instance number: %s" % trexInstance.getNumber() | info
        instanceBuilder = sap_trex.Builder()
        instanceBuilder.updateInstanceNumber(trexOsh, trexInstance.getNumber())
        if versionInfo:
            softwareBuilder.updateVersionInfo(trexOsh, versionInfo)
        if isBiaProduct:
            softwareBuilder.updateDiscoveredProductName(trexOsh,
                                    sap_trex.Product.BIA.instanceProductName)
        "x) report RFC connections" | info
        dnsResolver = netutils.DnsResolverByShell(shell, destinationIp)
        vector.addAll(reportRfcConfigs(rfcConfigs, dnsResolver, hostOsh))

        "x) report all topology nodes" | info
        if trexTopology:
            reportHostNode = fptools.partiallyApply(reportTrexHostNode,
                                     fptools._, trexTopology, isBiaProduct)
            vectors = map(reportHostNode, trexTopology.getHostNodes())
            fptools.each(vector.addAll, vectors)
예제 #31
0
    def process(self, context):
        r'''
        @types: applications.ApplicationSignatureContext
        '''
        # ==================== DISCOVERY
        shell = context.client
        fs = file_system.createFileSystem(shell)
        pathtools = file_system.getPath(fs)
        # 1) get process related application
        application = context.application
        connectionIp = application.getConnectionIp()
        # 2) find out process where path to the instance profile is stored
        logger.info(" Get executable path of main process ")
        mainProcess = application.getMainProcesses()[0]
        # 3)
        logger.info("Found out path to instance profile")
        instanceProfilePath = self.__getProfilePath(mainProcess)
        # 4)
        logger.info("Instance profile path: ", instanceProfilePath,
                    ". Get content")
        getContent = fptools.safeFunc(self.__getContent, Exception)
        profileFile = (instanceProfilePath
                       and getContent(shell, pathtools, instanceProfilePath))
        if not profileFile:
            logger.warn("Failed to get content of instance profile")
            return
        # 5) parse content using instance and default profile parsers
        logger.info("Make configuration parsing")
        iniParser = sap_discoverer.IniParser()
        instancePfParser = sap_discoverer.InstanceProfileParser(iniParser)
        try:
            instanceProfile = instancePfParser.parseContent(
                profileFile.content)
        except Exception:
            logger.warnException("Failed to parse instance profile")
        else:
            traceConfig = None
            runtimeConfig = None
            sapInstance = instanceProfile.instance
            sapInstance = sap.Instance(sapInstance.name + sapInstance.number,
                                       sapInstance.number,
                                       sapInstance.hostname)

            # 6) Process runtime.properties that contains information about
            #    Solution Manager and SLD if present
            logger.info("Create agent layout")
            logger.info("Get content of runtime properties")
            agentLayout = fptools.safeFunc(
                sap_smd_discoverer.createAgentLayoutFromBinPath)(
                    (pathtools.isAbsolute(mainProcess.executablePath)
                     and mainProcess.executablePath
                     or discoverExecutablePath(shell, mainProcess)), fs,
                    pathtools)
            if agentLayout:
                propertiesFile = getContent(
                    shell, pathtools, agentLayout.getRuntimePropertiesPath())
                if propertiesFile:
                    parser = sap_smd_discoverer.RuntimePropertiesParser(
                        sap_discoverer.IniParser())
                    try:
                        runtimeConfig = parser.parse(propertiesFile.content)
                    except Exception:
                        logger.warnException(
                            "Failed to parse runtime properties")

                logger.info("Find out version information")
                devSmdAgentFile = getContent(
                    shell, pathtools, agentLayout.getDevSmdAgentConfigFile())
                if devSmdAgentFile:
                    configParser = sap_smd_discoverer.DevSmdAgentConfigParser()
                    # find config with corresponding PID (of main process)
                    hasMainProcessPid = lambda c, pid=mainProcess.getPid(
                    ): c.pid == pid
                    traceConfig = fptools.findFirst(
                        hasMainProcessPid,
                        configParser.parse(devSmdAgentFile.content))
                    if not traceConfig:
                        logger.warn(
                            "Failed to find trace information for the main process"
                        )

            # === REPORT ===
            smdAgentOsh = application.getOsh()
            vector = context.resultsVector
            endpointReporter = netutils.EndpointReporter(
                netutils.ServiceEndpointBuilder())
            configFileReporter = file_topology.Reporter(
                file_topology.Builder())
            linkReporter = sap.LinkReporter()
            smdAgentBuilder = sap_smd.Builder()
            softwareBuilder = sap.SoftwareBuilder()
            softwareReporter = sap.SoftwareReporter(sap.SoftwareBuilder())
            resolverByShell = netutils.DnsResolverByShell(shell)
            processOsh = mainProcess.getOsh()

            # x) update name of application using instance name
            softwareBuilder.updateName(smdAgentOsh, sapInstance.getName())
            # x) configuration files related to running_software
            vector.add(configFileReporter.report(profileFile, smdAgentOsh))

            if traceConfig:
                # x) update version information in application
                smdAgentOsh = softwareBuilder.updateVersionInfo(
                    smdAgentOsh, traceConfig.versionInfo)
                if traceConfig.jstartVersionInfo:
                    smdAgentOsh = smdAgentBuilder.updateJstartVersionInfo(
                        smdAgentOsh, traceConfig.jstartVersionInfo)

            # x) show relation between agent and
            # - SMD server / no enough information /
            # - message server of SCS OR Solution Manager, represented as agent connection endpoint
            # - SLD
            if propertiesFile and runtimeConfig:
                # x) report properties file as configuration document
                vector.add(
                    configFileReporter.report(propertiesFile, smdAgentOsh))
                # x) Report relation between agent and SLD server and SolMan
                # Resolve endpoint addresses
                # make function that will accept endpoint only
                resolveEndpointFn = fptools.partiallyApply(
                    self.__resolveEndpointAddress,
                    fptools.safeFunc(resolverByShell.resolveIpsByHostname, []),
                    fptools._)
                # - SLD relation
                if runtimeConfig.sldEndpoint:
                    for endpoint in resolveEndpointFn(
                            runtimeConfig.sldEndpoint):
                        sldHostOsh = endpointReporter.reportHostFromEndpoint(
                            endpoint)
                        vector.add(sldHostOsh)
                        sldEndpointOsh = endpointReporter.reportEndpoint(
                            endpoint, sldHostOsh)
                        vector.add(sldEndpointOsh)
                        # this unknown server type must be SLD server
                        sldOsh = softwareReporter.reportUknownSoftware(
                            sldHostOsh)
                        vector.add(sldOsh)
                        vector.add(
                            linkReporter.reportUsage(sldOsh, sldEndpointOsh))
                        # report link between process and SLD server endpoint
                        vector.add(
                            linkReporter.reportClientServerRelation(
                                processOsh, sldEndpointOsh))

                # - Solution Manager relation
                agentConnectionEndpoint = runtimeConfig.getAgentConnecitonEndpoint(
                )
                if agentConnectionEndpoint:
                    for endpoint in resolveEndpointFn(agentConnectionEndpoint):
                        hostOsh = endpointReporter.reportHostFromEndpoint(
                            endpoint)
                        vector.add(hostOsh)
                        endpointOsh = endpointReporter.reportEndpoint(
                            endpoint, hostOsh)
                        vector.add(endpointOsh)
                        softwareOsh = softwareReporter.reportUknownSoftware(
                            hostOsh)
                        vector.add(softwareOsh)
                        vector.add(
                            linkReporter.reportUsage(softwareOsh, endpointOsh))
                        # report link between process and SolMan end-point
                        vector.add(
                            linkReporter.reportClientServerRelation(
                                processOsh, endpointOsh))