Example #1
0
    def __discoverAliasInfo(self, scope, db2_home, shell, instance_name=None):
        # get version using db2level
        # User scope:
        # %USERPROFILE%\db2cli.ini
        # System scope:
        # < 9.7
        # <db2 home>\db2cli.ini
        # > 9.7
        # %ALLUSERSPROFILE%\IBM\DB2\<instance name>\CFG\db2cli.ini
        executor = db2_base_shell_discoverer.get_command_executor(shell)
        major, minor = db2_base_shell_discoverer.get_version_by_instance_home(
            executor, db2_home)
        iniFile = None
        user_path = r"%USERPROFILE%\db2cli.ini"
        system_path = None
        if major == 9 and minor < 7:
            system_path = r"%s\db2cli.ini" % db2_home
        elif major == 9 and minor >= 7 and instance_name:
            system_path = r"%%ALLUSERSPROFILE%%\IBM\DB2\%s\cfg\db2cli.ini" % instance_name

        fs = file_system.createFileSystem(shell)
        if scope == ScopeEnum.USER:
            iniFile = fs.getFileContent(user_path)
        elif scope == ScopeEnum.SYSTEM and system_path:
            iniFile = fs.getFileContent(system_path)

        if iniFile:
            return self.__parse_db2cli_ini(iniFile.content)

        raise flow.DiscoveryException("Cannot parse db2 information for %s" %
                                      self._name)
    def process(self, context):
        descriptor = context.application.getApplicationComponent().getExplicitPluginById(
            ConfigurationFilesPlugin.PLUGIN_ID
        )
        if not descriptor:
            return

        element = descriptor.getRootElement()
        configElements = element.getChildren(ConfigurationFilesPlugin.ELEMENT_CONFIG_FILE)

        # parse DOM
        paths = ifilter(None, imap(self._getLocationFromElement, configElements))

        # evaluate expressions
        parseRuleContexts = context.application.getParseRuleContexts()
        parseFn = fptools.partiallyApply(self._parseLocation, fptools._, parseRuleContexts)
        parsedPaths = ifilter(None, imap(parseFn, paths))

        # retrieve content
        fileSystem = file_system.createFileSystem(context.client)
        retrieveFn = fptools.partiallyApply(self._retrieveConfigFile, fptools._, fileSystem)
        configFiles = ifilter(None, imap(retrieveFn, parsedPaths))

        # report
        builder = file_topology.Builder()
        reporter = file_topology.Reporter(builder)
        reportFn = fptools.partiallyApply(self._reportConfigFile, fptools._, reporter, context)
        oshs = ifilter(None, imap(reportFn, configFiles))

        for osh in oshs:
            context.resultsVector.add(osh)
Example #3
0
    def discover(self):
        fs = file_system.createFileSystem(self.shell)
        self.configFiles = fs.getFiles(
            F5_CONFIG_DIR, False, [ConfigFileFilter()], [
                FileAttrs.NAME, FileAttrs.PATH, FileAttrs.CONTENT,
                FileAttrs.PERMS, FileAttrs.LAST_MODIFICATION_TIME,
                FileAttrs.OWNER
            ])
        for configFileName in F5_CONFIG_NAMES:
            for configFile in self.configFiles:
                if configFileName == configFile.name:
                    # get all defined nodes
                    self.discoverNodes(configFile.path)
                    self.discoverPools(configFile.path)
                    self.discoverVirtualServers(configFile.path)

        for cluster in self.clusters:
            logger.debug("--" * 20)
            logger.debug("cluster name = ", cluster.getName())
            ipPorts = cluster.getIpPorts()
            for ipPort in ipPorts:
                logger.debug("ipPort (%s, %s)" %
                             (ipPort.getIp(), ipPort.getPort()))
            virtuals = cluster.getVirtualHosts()
            for virtual in virtuals:
                logger.debug("virtual name = ", virtual.getName())
                logger.debug("virtual ipPort(%s, %s)" %
                             (virtual.getIp(), virtual.getPort()))
            logger.debug("--" * 20)
    def __discoverAliasInfo(self, scope, db2_home, shell, instance_name=None):
        # get version using db2level
        # User scope:
        # %USERPROFILE%\db2cli.ini
        # System scope:
        # < 9.7
        # <db2 home>\db2cli.ini
        # > 9.7
        # %ALLUSERSPROFILE%\IBM\DB2\<instance name>\CFG\db2cli.ini
        executor = db2_base_shell_discoverer.get_command_executor(shell)
        major, minor = db2_base_shell_discoverer.get_version_by_instance_home(executor, db2_home)
        iniFile = None
        user_path = r"%USERPROFILE%\db2cli.ini"
        system_path = None
        if major == 9 and minor < 7:
            system_path = r"%s\db2cli.ini" % db2_home
        elif major == 9 and minor >= 7 and instance_name:
            system_path = r"%%ALLUSERSPROFILE%%\IBM\DB2\%s\cfg\db2cli.ini" % instance_name

        fs = file_system.createFileSystem(shell)
        if scope == ScopeEnum.USER:
            iniFile = fs.getFileContent(user_path)
        elif scope == ScopeEnum.SYSTEM and system_path:
            iniFile = fs.getFileContent(system_path)

        if iniFile:
            return self.__parse_db2cli_ini(iniFile.content)

        raise flow.DiscoveryException("Cannot parse db2 information for %s" % self._name)
Example #5
0
 def __getCommandPrefix(self):
     'str -> str'
     if self.shell.is64BitMachine() and file_system.createFileSystem(
             self.shell).exists('%SystemRoot%\\sysnative\\cluster.exe'):
         return '%SystemRoot%\\sysnative\\'
     else:
         return ''
Example #6
0
    def process(self, context):
        descriptor = context.application.getApplicationComponent(
        ).getExplicitPluginById(ConfigurationFilesPlugin.PLUGIN_ID)
        if not descriptor:
            return

        element = descriptor.getRootElement()
        configElements = element.getChildren(
            ConfigurationFilesPlugin.ELEMENT_CONFIG_FILE)

        # parse DOM
        paths = ifilter(None, imap(self._getLocationFromElement,
                                   configElements))

        # evaluate expressions
        parseRuleContexts = context.application.getParseRuleContexts()
        parseFn = fptools.partiallyApply(self._parseLocation, fptools._,
                                         parseRuleContexts)
        parsedPaths = ifilter(None, imap(parseFn, paths))

        # retrieve content
        fileSystem = file_system.createFileSystem(context.client)
        retrieveFn = fptools.partiallyApply(self._retrieveConfigFile,
                                            fptools._, fileSystem)
        configFiles = ifilter(None, imap(retrieveFn, parsedPaths))

        # report
        builder = file_topology.Builder()
        reporter = file_topology.Reporter(builder)
        reportFn = fptools.partiallyApply(self._reportConfigFile, fptools._,
                                          reporter, context)
        oshs = ifilter(None, imap(reportFn, configFiles))

        for osh in oshs:
            context.resultsVector.add(osh)
 def _get_db2_home_path(self, context):
     fileSystem = file_system.createFileSystem(context.client)
     path_tool = file_system.getPathTool(fileSystem)
     if self._main_process.executablePath:
         exe_path = file_system.Path(self._main_process.executablePath,
                                     path_tool)
         return exe_path.get_parent().get_parent()
Example #8
0
 def getConfigFile(self, client, filePath):
     if filePath:
         fs = file_system.createFileSystem(client)
         fileAttributes = []
         fileAttributes.extend(BASE_FILE_ATTRIBUTES)
         fileAttributes.append(FileAttrs.CONTENT)
         file = fs.getFile(filePath, fileAttributes)
         return file.content
Example #9
0
 def getConfigFile(self, client, filePath):
     if filePath:
         fs = file_system.createFileSystem(client)
         fileAttributes = []
         fileAttributes.extend(BASE_FILE_ATTRIBUTES)
         fileAttributes.append(FileAttrs.CONTENT)
         file = fs.getFile(filePath, fileAttributes)
         return file.content
    def get_web_configs(self, physical_path_of_app, shell,
                        webservice_ext_filter):
        fs = file_system.createFileSystem(shell)
        configs = []
        try:
            file_attr = (file_topology.BASE_FILE_ATTRIBUTES + [
                file_topology.FileAttrs.CONTENT,
                file_topology.FileAttrs.LAST_MODIFICATION_TIME
            ])

            logger.debug("try to get webservice from path:",
                         physical_path_of_app)
            files = fs.getFiles(
                physical_path_of_app,
                filters=[file_system.ExtensionsFilter(webservice_ext_filter)],
                fileAttrs=[
                    file_topology.FileAttrs.NAME, file_topology.FileAttrs.PATH
                ])

            for webservicefile in files:
                logger.debug("getting webservice file:", webservicefile.path)
                file = fs.getFile(webservicefile.path, file_attr)
                if file:
                    content = file.content
                    config_file = iis.ConfigFile(
                        webservicefile.path,
                        content,
                        file.lastModificationTime(),
                    )
                    configs.append(config_file)

            webconfig_path = physical_path_of_app + "\web.config"
            logger.debug("try to get web.config file from path:",
                         webconfig_path)
            webconfig = fs.getFile(webconfig_path, file_attr)
            if webconfig:
                content = webconfig.content
                content = content.strip()
                xmlContentStartIndex = content.find('<?xml')
                if xmlContentStartIndex != -1:
                    content = content[xmlContentStartIndex:]

                    # Lazy intilization of old code to prevent cyclic dependencies
                from NTCMD_IIS import WebConfig

                content = WebConfig.replacePasswords(content)

                db_datasources = self.get_db_datasources(content)

                config_file = iis.ConfigFile(webconfig_path, content,
                                             webconfig.lastModificationTime(),
                                             db_datasources)
                configs.append(config_file)
        except:
            logger.debug("Unable to discover %s" % physical_path_of_app)
            #logger.debugException("")
            #logger.reportWarning("Unable to discover some of config files")
        return configs
    def enrichAppServerOsh(self, context, processName):
        r'''Goal of this is to set for reported Weblogic AS
         - administrative domain name
         - application type as Application Server (AS)
         @types: applications.ApplicationSignatureContext, str
        '''
        # @types: ProcessObject
        process = context.application.getProcess(processName)
        # compose function to get process by PID required to get
        # domain root directory path
        appComponent = context.application.getApplicationComponent()
        applicationSignature = appComponent.getApplicationSignature()
        processInfoManager = applicationSignature.getProcessesManager()
        # here it is - function accept PID and returns process or None
        getProcessByPid = (processInfoManager
                           and processInfoManager.getProcessByPid
                           or (lambda *args: None)
        )

        # first of all set application type as AS for the server OSH
        serverOsh = context.application.getOsh()
        modeling.setAppServerType(serverOsh)

        # initialize required data
        loadExternalDtd = 0
        shell = context.client # for shell jobs we have shellutils.Shell instance
        fs = file_system.createFileSystem(shell)

        try:
            # find out path of domain root directory
            domainRootPath = weblogic_by_shell.getDomainRootDirPath(shell, fs, process,
                                               getProcessByPid)
        except:
            logger.debug("Domain root directory path cannot be found from the runtime information.")
            return
        domainLayout = weblogic_discoverer.createDomainLayout(fs, domainRootPath)
        parser = weblogic_discoverer.createDomainConfigParserByLayout(domainLayout, loadExternalDtd)
        try:
            domainDescriptorFile = domainLayout.getFileContent(
                        domainLayout.getDomainConfigFilePath()
            )
            domainDescriptor = parser.parseConfiguration(domainDescriptorFile.content)
        except (Exception, JException):
            logger.warnException("Failed to process config.xml")
        else:
            # get version of the platform
            versionInfo = domainDescriptor.versionInfo
            logger.info("Platform version is %s" % versionInfo)
            domainName = domainDescriptor.getName()
            # update server administrative domain attribute
            modeling.setJ2eeServerAdminDomain(serverOsh, domainName)
            servers = domainDescriptor.getServers()
            for server in servers:
                if server.getName() == serverOsh.getAttributeValue('name'):
                    serverFullName = jee.ServerTopologyBuilder()._composeFullName(server)
                    serverOsh.setAttribute('j2eeserver_fullname', serverFullName)
                    break
def read_pf(shell, pf_path):
    '@types: Shell, str -> tuple[File, sap_discoverer.IniDocument]'
    try:
        pathtool = file_system.getPathTool(file_system.createFileSystem(shell))
        name = pathtool.baseName(pf_path)
        file_ = file_topology.File(name, False)
        file_.content = shell.safecat(pf_path)
        file_.path = pf_path
    except Exception, e:
        logger.warnException("Failed to read profile: %s" % e)
def read_pf(shell, pf_path):
    '@types: Shell, str -> tuple[File, sap_discoverer.IniDocument]'
    try:
        pathtool = file_system.getPathTool(file_system.createFileSystem(shell))
        name = pathtool.baseName(pf_path)
        file_ = file_topology.File(name, False)
        file_.content = shell.safecat(pf_path)
        file_.path = pf_path
    except Exception, e:
        logger.warnException("Failed to read profile: %s" % e)
Example #14
0
 def getConfigFile(self, filePath):
     if not (filePath and filePath.strip()):
         logger.debug('No config file path passes.')
         return None
     fileSystem = file_system.createFileSystem(self.shell)
     fileAttrs = [FileAttrs.NAME, FileAttrs.CONTENT]
     try:
         return fileSystem.getFile(filePath, fileAttrs)
     except (Exception, FsException):
         return None
 def getConfigFile(self, filePath):
     if not (filePath and filePath.strip()):
         logger.debug('No config file path passes.')
         return None
     fileSystem = file_system.createFileSystem(self.shell)
     fileAttrs = [FileAttrs.NAME, FileAttrs.CONTENT]
     try:
         return fileSystem.getFile(filePath, fileAttrs)
     except file_topology.FsException:
         logger.warn("Failed to get content %s" % filePath)
def processGlassfish(context, processName):
    glassfishOsh = context.application.getOsh()

    logger.debug('Started processing')
    process = context.application.getProcess(processName)
    processOriginCmd = process.commandLine
    if processOriginCmd is not None:
        serverName = None
        serverRuntime = None
        if processOriginCmd.find(
                'com.sun.enterprise.glassfish.bootstrap.ASMain') != -1:
            serverRuntime = glassfish_discoverer.createServerRuntimeV3(
                processOriginCmd, None)
            DescriptorClass = glassfish_discoverer.DomainXmlDescriptorV3
        elif processOriginCmd.find('com.sun.enterprise.server.PELaunch') != -1:
            serverRuntime = glassfish_discoverer.createServerRuntimeV2(
                processOriginCmd, None)
            DescriptorClass = glassfish_discoverer.DomainXmlDescriptorV2

        if serverRuntime:
            serverName = serverRuntime.findServerName()
            globalSettings = GeneralSettingsConfigFile.getInstance()
            loadExternalDTD = globalSettings.getPropertyBooleanValue(
                'loadExternalDTD', 0)

            fs = file_system.createFileSystem(context.client)
            layout = glassfish_discoverer.createServerLayout(serverRuntime, fs)
            domainXmlFile = layout.getFile(layout.getDomainXmlPath())

            xPathParser = glassfish_discoverer.XpathParser(loadExternalDTD)
            descriptor = DescriptorClass(xPathParser, domainXmlFile.content)
            domainName = descriptor.findDomainName()

            nodeName = descriptor.findNodeNameByServerName(serverName)

            if serverName and domainName:
                logger.debug('Reporting serverName %s, domainName %s' %
                             (serverName, domainName))
                glassfishOsh.setStringAttribute('j2eeserver_servername',
                                                serverName)
                modeling.setJ2eeServerAdminDomain(glassfishOsh, domainName)
                modeling.setAppServerType(glassfishOsh)
                # server full name
                nodeNamePart = nodeName and '%s_' % nodeName or ''
                fullName = '%s%s' % (nodeNamePart, serverName)
                glassfishOsh.setAttribute('j2eeserver_fullname', fullName)
            else:
                logger.debug(
                    'Glassfish details cannot be acquired, ignoring the application %s, %s'
                    % (serverName, domainName))
        else:
            logger.debug('Server runtime is not created')
    else:
        logger.debug('No process comman line found for pid: %s' %
                     process.getPid())
    def get_web_configs(self, webconfig_path_list, shell, webservice_ext_filter):
        fs = file_system.createFileSystem(shell)
        configs = []
        for webconfig_path in webconfig_path_list:
            try:
                webconfig_path = webconfig_path.find("%") != -1 and shell_interpreter.dereference_string(shell,
                                                                                                         webconfig_path) or webconfig_path
                default_configs = map(
                    lambda obj: obj.find("%") != -1 and shell_interpreter.dereference_string(shell, obj) or obj,
                    self.DEFAULT_WEB_CONFIGURATION_LOCATIONS)
                if not webconfig_path in default_configs and fs.exists(webconfig_path):
                    file_attr = (file_topology.BASE_FILE_ATTRIBUTES +
                                 [file_topology.FileAttrs.CONTENT, file_topology.FileAttrs.LAST_MODIFICATION_TIME])
                    logger.debug("getting config file:", webconfig_path)
                    resource_path = ''
                    match = re.match('(.*)\\\\.*', webconfig_path)
                    if match:
                        resource_path = match.group(1)
                    logger.debug("getting config file path:", resource_path)
                    files = fs.getFiles(resource_path, filters = [file_system.ExtensionsFilter(webservice_ext_filter)],
                                           fileAttrs = [file_topology.FileAttrs.NAME,
                                                        file_topology.FileAttrs.PATH])

                    for webservicefile in files:
                        logger.debug("getting webservice file:", webservicefile.path)
                        file = fs.getFile(webservicefile.path, file_attr)
                        if file:
                            content = file.content
                            config_file = iis.ConfigFile(webservicefile.path, content, file.lastModificationTime(),)
                            configs.append(config_file)

                    webconfig = fs.getFile(webconfig_path, file_attr)
                    if webconfig:
                        content = webconfig.content
                        content = content.strip()
                        xmlContentStartIndex = content.find('<?xml')
                        if xmlContentStartIndex != -1:
                            content = content[xmlContentStartIndex:]

                        # Lazy intilization of old code to prevent cyclic dependencies
                        from NTCMD_IIS import WebConfig

                        content = WebConfig.replacePasswords(content)

                        db_datasources = self.get_db_datasources(content)

                        config_file = iis.ConfigFile(webconfig_path, content, webconfig.lastModificationTime(),
                                                     db_datasources)
                        configs.append(config_file)
            except:
                logger.warn("Unable to discover %s" % webconfig_path)
                logger.debugException("")
                logger.reportWarning("Unable to discover some of config files")
        return configs
def getConfigFile(shell, filePath):
    '@types: str -> File?'
    if not (filePath and filePath.strip()):
        logger.debug('No configuration file path passed')
        return None
    fileSystem = file_system.createFileSystem(shell)
    fileAttrs = [FileAttrs.NAME, FileAttrs.CONTENT]
    try:
        return fileSystem.getFile(filePath, fileAttrs)
    except PathNotFoundException:
        logger.warn("Does not exist: %s" % filePath)
    return None
def getConfigFile(shell, filePath):
    '@types: str -> File?'
    if not (filePath and filePath.strip()):
        logger.debug('No configuration file path passed')
        return None
    fileSystem = file_system.createFileSystem(shell)
    fileAttrs = [FileAttrs.NAME, FileAttrs.CONTENT]
    try:
        return fileSystem.getFile(filePath, fileAttrs)
    except PathNotFoundException:
        logger.warn("Does not exist: %s" % filePath)
    return None
Example #20
0
def DiscoveryMain(Framework):
    Framework = jee_connection.EnhancedFramework(Framework)
    platform = jee.Platform.WEBLOGIC
    try:
        # establish connection
        client = Framework.createClient()
        shell = shellutils.ShellFactory().createShell(client)
        # prepare components for topology discoverer
        fs = file_system.createFileSystem(shell)
        processDiscoverer = process_discoverer.getDiscovererByShell(shell)
    except (Exception, JException), exc:
        logger.warnException(str(exc))
        jee_connection.reportError(Framework, str(exc), platform.getName())
Example #21
0
    def discover(self, name, driverName, scope, shell):
        DSNRegistryEntryDiscoverer.discover(self, name, driverName, scope, shell)
        fs = file_system.createFileSystem(shell)
        path_tool = file_system.getPathTool(fs)
        db2_home_bin = file_system.Path(self._raw_object.Driver, path_tool).get_parent()
        if db2_home_bin:
            self.__db2_home = db2_home_bin.get_parent()

            instance_name = self.__parseInstanceName(driverName)
            self.__address, self.__port, self.__database = self.__discoverAliasInfo(scope, self.__db2_home, shell, instance_name)

        if not self.__address:
            raise flow.DiscoveryException("Address is empty")
Example #22
0
    def discover(self, name, driverName, scope, shell):
        DSNRegistryEntryDiscoverer.discover(self, name, driverName, scope, shell)
        fs = file_system.createFileSystem(shell)
        path_tool = file_system.getPathTool(fs)
        oracle_home_bin = file_system.Path(self._raw_object.Driver, path_tool).get_parent()
        logger.debug("Oracle home bin folder:%s" % oracle_home_bin)
        if oracle_home_bin:
            self.__oracle_home = oracle_home_bin.get_parent()
            logger.debug("Oracle home:%s" % oracle_home_bin)
            self.__address, self.__port, self.__database = self.__discoverAliasInfo(scope, self.__oracle_home, shell)

        if not self.__address:
            raise flow.DiscoveryException("Address is empty")
Example #23
0
def DiscoveryMain(Framework):
    Framework = jee_connection.EnhancedFramework(Framework)
    platform = jee.Platform.WEBLOGIC
    try:
        # establish connection
        client = Framework.createClient()
        shell = shellutils.ShellFactory().createShell(client)
        # prepare components for topology discoverer
        fs = file_system.createFileSystem(shell)
        processDiscoverer = process_discoverer.getDiscovererByShell(shell)
    except (Exception, JException), exc:
        logger.warnException(str(exc))
        jee_connection.reportError(Framework, str(exc), platform.getName())
def createClusterCmd(shell, bundle):
    r'@types: shellutils.Shell, ResourceBundle -> ClusterCmd'
    binPath = ''
    fs = file_system.createFileSystem(shell)
    is64bit = shell.is64BitMachine()
    if is64bit and fs.exists( '%SystemRoot%\\sysnative\\cluster.exe' ):
        #this is a 64 bit destination with cluster.exe present
        binPath = '%SystemRoot%\\sysnative\\'
    elif not is64bit and fs.exists( '%SystemRoot%\\system32\\cluster.exe' ):
        #this ia 32 bit destination with cluster.exe available
        binPath = '%SystemRoot%\\system32\\'

    return ClusterCmd(shell, binPath, bundle)
Example #25
0
def createClusterCmd(shell, bundle):
    r'@types: shellutils.Shell, ResourceBundle -> ClusterCmd'
    binPath = ''
    fs = file_system.createFileSystem(shell)
    is64bit = shell.is64BitMachine()
    if is64bit and fs.exists('%SystemRoot%\\sysnative\\cluster.exe'):
        #this is a 64 bit destination with cluster.exe present
        binPath = '%SystemRoot%\\sysnative\\'
    elif not is64bit and fs.exists('%SystemRoot%\\system32\\cluster.exe'):
        #this ia 32 bit destination with cluster.exe available
        binPath = '%SystemRoot%\\system32\\'

    return ClusterCmd(shell, binPath, bundle)
Example #26
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)
Example #27
0
def DiscoveryMain(Framework):

    rangeString = Framework.getParameter('range')
    probeName = Framework.getDestinationAttribute('probeName')
    nmapLocation = Framework.getParameter('nmap_location') or None

    protocol = Framework.getDestinationAttribute('Protocol')
    try:
        excludePatterns = icmp_utils.preparePatterns(Framework.getParameter('excludePatternsList'))
        client = Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME)
        shell = ShellFactory().createShell(client)
        fs = file_system.createFileSystem(shell)
        try:
            if nmapLocation and fs.isDirectory(nmapLocation):
                path_tool = NtPath()
                nmapLocation = path_tool.join(nmapLocation, nmap.NMAP_EXECUTABLES[1])
        except PathNotFoundException:
            logger.warn("Specified directory \"%s\" is not exists." % nmapLocation)

        if nmapLocation and not nmap.NmapPathValidator.get(fs).validate(nmapLocation):
            logger.warn("Specified Nmap path \"%s\" is not exists. Trying the system path..." % nmapLocation)
            nmapLocation = None

        nmapTool = nmap.getByShell(shell, nmapLocation)
        if not nmapTool.getVersion():
            logger.reportWarning("NMAP command is not installed on the probe machine")
            return ObjectStateHolderVector()
        probeRanges = _buildProbeRanges(Framework, rangeString, probeName)

        logger.info('Start working on total probe ranges: ', len(probeRanges))

        for probeRange in probeRanges:

            logger.debug("Start working on range ", probeRange.toRangeString())
            rangeIps = probeRange.getAllIPs(probeRange.getTotalIPs())
            byExcludePatterns = lambda ip, patterns = excludePatterns: icmp_utils.shouldPingIp(ip, patterns, None)
            filteredIps = filter(byExcludePatterns, rangeIps)

            excludedIpCount = len(rangeIps) - len(filteredIps)
            if excludedIpCount:
                logger.debug("Excluded IP's count: %s " % excludedIpCount)

            try:
                liveIps = nmapTool.doPingScan(filteredIps, issubclass(probeRange.__class__, IPv6Range) or issubclass(probeRange.__class__, IPv6RangeWIthDescription))
            except Exception, ex:
                logger.warn(str(ex))
            else:
                if liveIps:
                    Framework.sendObjects(_reportIpOSHs(liveIps))
        logger.info('Finished working on all Probes Ranges')
 def getGlobalConfigFiles(self, path):
     if path:
         fs = _createFileSystemRecursiveSearchEnabled(file_system.createFileSystem(self.shell))
         fileAttrs = [FileAttrs.NAME, FileAttrs.PATH]
         configFiles = fs.getFiles(path, 1, [FileFilterByPattern('csmconf', lambda x: x.name.lower() == 'csmconf')], fileAttrs)
         result = []
         for configFile in configFiles:
             if configFile.name == 'csmconf':
                 try:
                     file_ = fs.getFile(configFile.path, [FileAttrs.NAME, FileAttrs.CONTENT])
                     result.append(file_)
                 except (Exception, JException):
                     logger.debugException()
         logger.debug(result)
         return result
 def isUsingPowerShellCmdlet(self):
     fs = file_system.createFileSystem(self.__shell)
     is64bit = self.__shell.is64BitMachine()
     if is64bit and fs.exists( '%SystemRoot%\\sysnative\\cluster.exe' ):
         self.bin_path = '%SystemRoot%\\sysnative\\'
     elif not is64bit and fs.exists( '%SystemRoot%\\system32\\cluster.exe' ):
         self.bin_path = '%SystemRoot%\\system32\\'
     if self.bin_path:
         return False
     else:
         output = self.__shell.execCmd('CLUSTER /VER')
         if output and output.strip() and self.__shell.getLastCmdReturnCode() == 0:
             self.bin_path = ""
             return False
     return True
    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')
    def get_web_configs(self, physical_path_of_app, shell, webservice_ext_filter):
        fs = file_system.createFileSystem(shell)
        configs = []
        try:
            file_attr = file_topology.BASE_FILE_ATTRIBUTES + [
                file_topology.FileAttrs.CONTENT,
                file_topology.FileAttrs.LAST_MODIFICATION_TIME,
            ]

            logger.debug("try to get webservice from path:", physical_path_of_app)
            files = fs.getFiles(
                physical_path_of_app,
                filters=[file_system.ExtensionsFilter(webservice_ext_filter)],
                fileAttrs=[file_topology.FileAttrs.NAME, file_topology.FileAttrs.PATH],
            )

            for webservicefile in files:
                logger.debug("getting webservice file:", webservicefile.path)
                file = fs.getFile(webservicefile.path, file_attr)
                if file:
                    content = file.content
                    config_file = iis.ConfigFile(webservicefile.path, content, file.lastModificationTime())
                    configs.append(config_file)

            webconfig_path = physical_path_of_app + "\web.config"
            logger.debug("try to get web.config file from path:", webconfig_path)
            webconfig = fs.getFile(webconfig_path, file_attr)
            if webconfig:
                content = webconfig.content
                content = content.strip()
                xmlContentStartIndex = content.find("<?xml")
                if xmlContentStartIndex != -1:
                    content = content[xmlContentStartIndex:]

                    # Lazy intilization of old code to prevent cyclic dependencies
                from NTCMD_IIS import WebConfig

                content = WebConfig.replacePasswords(content)

                db_datasources = self.get_db_datasources(content)

                config_file = iis.ConfigFile(webconfig_path, content, webconfig.lastModificationTime(), db_datasources)
                configs.append(config_file)
        except:
            logger.debug("Unable to discover %s" % physical_path_of_app)
            # logger.debugException("")
            # logger.reportWarning("Unable to discover some of config files")
        return configs
Example #32
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:
Example #33
0
    def discover(self, name, driverName, scope, shell):
        DSNRegistryEntryDiscoverer.discover(self, name, driverName, scope,
                                            shell)
        fs = file_system.createFileSystem(shell)
        path_tool = file_system.getPathTool(fs)
        db2_home_bin = file_system.Path(self._raw_object.Driver,
                                        path_tool).get_parent()
        if db2_home_bin:
            self.__db2_home = db2_home_bin.get_parent()

            instance_name = self.__parseInstanceName(driverName)
            self.__address, self.__port, self.__database = self.__discoverAliasInfo(
                scope, self.__db2_home, shell, instance_name)

        if not self.__address:
            raise flow.DiscoveryException("Address is empty")
Example #34
0
 def process(self, context):
     r'''
      @types: applications.ApplicationSignatureContext
     '''
     shell = context.client
     kernelProcName = self._getMainProcessName()
     kernelProc = context.application.getProcess(kernelProcName)
     logger.debug('Kernel proc cmdLine: %s' % kernelProc.commandLine)
     fs = file_system.createFileSystem(shell)
     dbmCliWithPath = maxdb_discoverer.findDbmCliPath(fs, kernelProc.commandLine)
     dbmCli = maxdb_discoverer.getDbmCli(shell, dbmCliWithPath)
     appOsh = context.application.applicationOsh
     try:
         allDbEnums = dbmCli.db_enum().process()
     except maxdb_discoverer.DbmCliException, dce:
         logger.debugException(str(dce))
Example #35
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:
Example #36
0
 def process(self, context):
     r'''
      @types: applications.ApplicationSignatureContext
     '''
     shell = context.client
     kernelProcName = self._getMainProcessName()
     kernelProc = context.application.getProcess(kernelProcName)
     logger.debug('Kernel proc cmdLine: %s' % kernelProc.commandLine)
     fs = file_system.createFileSystem(shell)
     dbmCliWithPath = maxdb_discoverer.findDbmCliPath(
         fs, kernelProc.commandLine)
     dbmCli = maxdb_discoverer.getDbmCli(shell, dbmCliWithPath)
     appOsh = context.application.applicationOsh
     try:
         allDbEnums = dbmCli.db_enum().process()
     except maxdb_discoverer.DbmCliException, dce:
         logger.debugException(str(dce))
    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):
        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 processGlassfish(context, processName):
    glassfishOsh = context.application.getOsh()

    logger.debug('Started processing')
    process = context.application.getProcess(processName)
    processOriginCmd = process.commandLine
    if processOriginCmd is not None:
        serverName = None
        serverRuntime = None
        if processOriginCmd.find('com.sun.enterprise.glassfish.bootstrap.ASMain') != -1:
            serverRuntime = glassfish_discoverer.createServerRuntimeV3(processOriginCmd, None)
            DescriptorClass = glassfish_discoverer.DomainXmlDescriptorV3
        elif processOriginCmd.find('com.sun.enterprise.server.PELaunch') != -1:
            serverRuntime = glassfish_discoverer.createServerRuntimeV2(processOriginCmd, None)
            DescriptorClass = glassfish_discoverer.DomainXmlDescriptorV2

        if serverRuntime:
            serverName = serverRuntime.findServerName()
            globalSettings = GeneralSettingsConfigFile.getInstance()
            loadExternalDTD = globalSettings.getPropertyBooleanValue('loadExternalDTD', 0)

            fs = file_system.createFileSystem(context.client)
            layout = glassfish_discoverer.createServerLayout(serverRuntime, fs)
            domainXmlFile = layout.getFile(layout.getDomainXmlPath())

            xPathParser = glassfish_discoverer.XpathParser(loadExternalDTD)
            descriptor = DescriptorClass(xPathParser, domainXmlFile.content)
            domainName = descriptor.findDomainName()

            nodeName = descriptor.findNodeNameByServerName(serverName)

            if serverName and domainName:
                logger.debug('Reporting serverName %s, domainName %s' % (serverName, domainName))
                glassfishOsh.setStringAttribute('j2eeserver_servername', serverName)
                modeling.setJ2eeServerAdminDomain(glassfishOsh, domainName)
                modeling.setAppServerType(glassfishOsh)
                # server full name
                nodeNamePart = nodeName and '%s_' % nodeName or ''
                fullName = '%s%s' % (nodeNamePart, serverName)
                glassfishOsh.setAttribute('j2eeserver_fullname', fullName)
            else:
                logger.debug('Glassfish details cannot be acquired, ignoring the application %s, %s' % (serverName, domainName))
        else:
            logger.debug('Server runtime is not created')
    else:
        logger.debug('No process comman line found for pid: %s' % process.getPid())
Example #40
0
    def __discoverAliasInfo(self, scope, oracle_home, shell):
        #The tnsnames.ora file is under %ORACLE_HOME%\network\admin
        #Try to get this file and parse it.
        oraFile = None
        user_path = r"%USERPROFILE%\tnsnames.ora"
        system_path = None
        system_path = r"%s\network\admin\tnsnames.ora" % oracle_home

        fs = file_system.createFileSystem(shell)
        if scope == ScopeEnum.USER:
            oraFile = fs.getFileContent(user_path)
        elif scope == ScopeEnum.SYSTEM and system_path:
            oraFile = fs.getFileContent(system_path)

        if oraFile:
            return self.__parse_tnsnames_ora(oraFile.content)

        raise flow.DiscoveryException("Cannot parse db2 information for %s" % self._name)
 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)
 def getGlobalConfigFiles(self, path):
     if path:
         fs = _createFileSystemRecursiveSearchEnabled(
             file_system.createFileSystem(self.shell))
         fileAttrs = [FileAttrs.NAME, FileAttrs.PATH]
         configFiles = fs.getFiles(path, 1, [
             FileFilterByPattern('csmconf',
                                 lambda x: x.name.lower() == 'csmconf')
         ], fileAttrs)
         result = []
         for configFile in configFiles:
             if configFile.name == 'csmconf':
                 try:
                     file_ = fs.getFile(configFile.path,
                                        [FileAttrs.NAME, FileAttrs.CONTENT])
                     result.append(file_)
                 except (Exception, JException):
                     logger.debugException()
         logger.debug(result)
         return result
    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)
 def process(self, context):
     application = context.application
     osh = application.getOsh()
     shell = context.client
     fs = file_system.createFileSystem(shell)
     ip = application.getConnectionIp()
     dns_resolver = jee_discoverer.DnsResolverDecorator(
                             netutils.createDnsResolverByShell(shell), ip)
     process = application.getMainProcesses()[0]
     cmd_line = process.commandLine
     server_runtime = jboss_discoverer.createServerRuntime(cmd_line, ip)
     home_dir = server_runtime.findHomeDirPath()
     config = server_runtime.extractOptionValue('--server-config')
     layout = jboss_discoverer.StandaloneModeLayout(fs, home_dir, config)
     loadDtd = 0
     server_config_parser = jboss_discoverer.ServerConfigParserV7(loadDtd)
     standalone_config_path = layout.getStandaloneConfigPath()
     standalone_config_file = layout.getFileContent(standalone_config_path)
     content = standalone_config_file.content
     standalone_config_with_expressions = (
                 server_config_parser.parseStandaloneServerConfig(content))
     server_properties = jboss_discoverer.SystemProperties()
     properties_from_cmd_line = server_runtime.findJbossProperties()
     server_properties.update(properties_from_cmd_line)
     config_props = standalone_config_with_expressions.getSystemProperties()
     server_properties.update(config_props)
     standalone_config = server_config_parser.resolveStandaloneServerConfig(
                      standalone_config_with_expressions, server_properties)
     server_name = standalone_config.getServerName()
     if not server_name:
         try:
             server_name = dns_resolver.resolveHostnamesByIp(ip)[0]
         except netutils.ResolveException:
             server_name = 'Default'
     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.setJ2eeServerAdminDomain(osh, server_name)
     modeling.setAppServerType(osh)
 def process(self, context):
     application = context.application
     osh = application.getOsh()
     shell = context.client
     fs = file_system.createFileSystem(shell)
     ip = application.getConnectionIp()
     dns_resolver = jee_discoverer.DnsResolverDecorator(
         netutils.createDnsResolverByShell(shell), ip)
     process = application.getMainProcesses()[0]
     cmd_line = process.commandLine
     server_runtime = jboss_discoverer.createServerRuntime(cmd_line, ip)
     home_dir = server_runtime.findHomeDirPath()
     config = server_runtime.extractOptionValue('--server-config')
     layout = jboss_discoverer.StandaloneModeLayout(fs, home_dir, config)
     loadDtd = 0
     server_config_parser = jboss_discoverer.ServerConfigParserV7(loadDtd)
     standalone_config_path = layout.getStandaloneConfigPath()
     standalone_config_file = layout.getFileContent(standalone_config_path)
     content = standalone_config_file.content
     standalone_config_with_expressions = (
         server_config_parser.parseStandaloneServerConfig(content))
     server_properties = jboss_discoverer.SystemProperties()
     properties_from_cmd_line = server_runtime.findJbossProperties()
     server_properties.update(properties_from_cmd_line)
     config_props = standalone_config_with_expressions.getSystemProperties()
     server_properties.update(config_props)
     standalone_config = server_config_parser.resolveStandaloneServerConfig(
         standalone_config_with_expressions, server_properties)
     server_name = standalone_config.getServerName()
     if not server_name:
         try:
             server_name = dns_resolver.resolveHostnamesByIp(ip)[0]
         except netutils.ResolveException:
             server_name = 'Default'
     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.setJ2eeServerAdminDomain(osh, server_name)
     modeling.setAppServerType(osh)
    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 discover(self):
        fs = file_system.createFileSystem(self.shell)
        self.configFiles = fs.getFiles(F5_CONFIG_DIR, False, [ConfigFileFilter()],
                                       [FileAttrs.NAME, FileAttrs.PATH, FileAttrs.CONTENT, FileAttrs.PERMS, FileAttrs.LAST_MODIFICATION_TIME,
                                        FileAttrs.OWNER])
        for configFileName in F5_CONFIG_NAMES:
            for configFile in self.configFiles:
                if configFileName == configFile.name:
                    # get all defined nodes
                    self.discoverNodes(configFile.path)
                    self.discoverPools(configFile.path)
                    self.discoverVirtualServers(configFile.path)

        for cluster in self.clusters:
            logger.debug("--" * 20)
            logger.debug("cluster name = ", cluster.getName())
            ipPorts = cluster.getIpPorts()
            for ipPort in ipPorts:
                logger.debug("ipPort (%s, %s)" % (ipPort.getIp(), ipPort.getPort()))
            virtuals = cluster.getVirtualHosts()
            for virtual in virtuals:
                logger.debug("virtual name = ", virtual.getName())
                logger.debug("virtual ipPort(%s, %s)" % (virtual.getIp(), virtual.getPort()))
            logger.debug("--" * 20)
Example #50
0
def DiscoveryMain(Framework):
    ipAddress = Framework.getDestinationAttribute('ip_address')
    discoveredPorts = Framework.getParameter('ports') or None
    useNMap = Framework.getParameter('useNMap') == 'true'
    nmapPath = Framework.getParameter('nmapPath') or None
    scanUDP = Framework.getParameter('scanUDP') == 'true'
    UDPports = Framework.getParameter('UDPports') or None
    UDPports = UDPports and UDPports.strip()
    connectTimeOut = int(Framework.getParameter('connectTimeOut'))

    #if we need to check host's reachability:
    if Framework.getParameter('checkIfIpIsReachable').lower() == 'true':
        if not netutils.pingIp(Framework, ipAddress,
                               Framework.getParameter('pingTimeOut')):
            logger.debug('Could not connect to ', ipAddress, ' by ping')
            msg = 'Target host is not reachable'
            warningObject = errorobject.createError(
                errorcodes.CONNECTION_FAILED_NO_PROTOCOL_WITH_DETAILS,
                ['', msg], msg)
            logger.reportWarningObject(warningObject)
            return

    OSHVResult = ObjectStateHolderVector()
    hostOsh = modeling.createHostOSH(ipAddress)
    OSHVResult.add(hostOsh)

    cfgFile = Framework.getConfigFile(
        CollectorsParameters.KEY_COLLECTORS_SERVERDATA_PORTNUMBERTOPORTNAME)

    onlyKnownPorts = Framework.getParameter('checkOnlyKnownPorts')
    onlyKnownPorts = (onlyKnownPorts and onlyKnownPorts.lower() == 'true')

    portsList = getPorts(discoveredPorts and discoveredPorts.strip(),
                         PortType.TCP, cfgFile, onlyKnownPorts)
    if scanUDP:
        if onlyKnownPorts and not UDPports:
            UDPports = '*'
        portsList.extend(
            getPorts(UDPports, PortType.UDP, cfgFile, onlyKnownPorts))

    portsToDiscover = filter(lambda port: port.isDiscover, portsList)

    isConnectedPortFound = False
    useFallback = False
    if useNMap:
        # Nmap flow supports udp and tcp ports
        client = Framework.createClient(
            ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME)
        try:
            shell = shellutils.ShellFactory().createShell(client)
            fs = file_system.createFileSystem(shell)
            try:
                if nmapPath and fs.isDirectory(nmapPath):
                    path_tool = NtPath()
                    nmapPath = path_tool.join(nmapPath,
                                              nmap.NMAP_EXECUTABLES[1])
            except PathNotFoundException:
                logger.warn("Specified directory \"%s\" is not exists." %
                            nmapPath)

            if nmapPath and not nmap.NmapPathValidator.get(fs).validate(
                    nmapPath):
                logger.warn(
                    "Specified Nmap path \"%s\" is not exists. Trying the system path..."
                    % nmapPath)
                nmapPath = None

            nmapDiscover = nmap.getByShell(shell, nmapPath)

            nmapVersion = nmapDiscover.getVersion()
            if not nmapVersion:
                raise Exception('Cannot get nmap version')
            logger.debug("Found nmap %s" % nmapVersion)
            nmapVersion = float(nmapVersion)
            if nmapVersion < 5.21:
                raise Exception("Not supported version of nmap found.")

            tcpPorts = [
                port.getPortNumber() for port in portsToDiscover
                if port and port.getProtocolName() == 'tcp'
                and port.isIpInRange(ipAddress)
            ]
            udpPorts = [
                port.getPortNumber() for port in portsToDiscover
                if port and port.getProtocolName() == 'udp'
                and port.isIpInRange(ipAddress)
            ]

            discoveredPorts = nmapDiscover.doPortScan(ipAddress, tcpPorts,
                                                      udpPorts)

            portsNameByPortInfo = {}
            for port in portsToDiscover:
                port_names = portsNameByPortInfo.setdefault(
                    (port.getProtocol(), port.getPortNumber()), [])
                port_names.append(port.portName)

            if discoveredPorts:
                isConnectedPortFound = True
                for port_info in discoveredPorts:
                    port_names = portsNameByPortInfo.get(port_info, [])
                    OSHVResult.addAll(
                        reportPort(hostOsh, ipAddress, port_names, *port_info))
        except:
            logger.debugException(
                "Nmap executing failed. Try to use default behavior...")
            logger.reportWarning("Nmap executing failed")
            useFallback = True

    if useFallback or not useNMap:
        # Old flow supports only TCP ports
        for port in portsToDiscover:
            if port.isIpInRange(ipAddress):
                if port.getProtocol() == PortType.UDP.getProtocol():
                    logger.warn(
                        "UDP port scan is not supporting by default behavior. Skipping..."
                    )
                elif port.getProtocol() == PortType.TCP.getProtocol() and (
                        netutils.checkTcpConnectivity(
                            ipAddress, port.getPortNumber(), connectTimeOut)):
                    OSHVResult.addAll(
                        reportPort(hostOsh, ipAddress, [port.portName],
                                   port.getProtocol(), port.getPortNumber()))
                    #we found one connected port -> we need to add hostOsh to OSHVResult
                    isConnectedPortFound = True

    #in case we didn't find any port, return nothing
    if not isConnectedPortFound:
        OSHVResult.clear()
        msg = 'None of specified ports were discovered on destination host'
        warningObject = errorobject.createError(
            errorcodes.CONNECTION_FAILED_NO_PROTOCOL_WITH_DETAILS, ['', msg],
            msg)
        logger.reportWarningObject(warningObject)

    return OSHVResult
Example #51
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)
    def enrichAppServerOsh(self, context, processName):
        r'''Goal of this is to set for reported Weblogic AS
         - administrative domain name
         - application type as Application Server (AS)
         @types: applications.ApplicationSignatureContext, str
        '''
        # @types: ProcessObject
        process = context.application.getProcess(processName)
        # compose function to get process by PID required to get
        # domain root directory path
        appComponent = context.application.getApplicationComponent()
        applicationSignature = appComponent.getApplicationSignature()
        processInfoManager = applicationSignature.getProcessesManager()
        # here it is - function accept PID and returns process or None
        getProcessByPid = (processInfoManager
                           and processInfoManager.getProcessByPid
                           or (lambda *args: None))

        # first of all set application type as AS for the server OSH
        serverOsh = context.application.getOsh()
        modeling.setAppServerType(serverOsh)

        # initialize required data
        loadExternalDtd = 0
        shell = context.client  # for shell jobs we have shellutils.Shell instance
        fs = file_system.createFileSystem(shell)

        try:
            # find out path of domain root directory
            domainRootPath = weblogic_by_shell.getDomainRootDirPath(
                shell, fs, process, getProcessByPid)
        except:
            logger.debug(
                "Domain root directory path cannot be found from the runtime information."
            )
            return
        domainLayout = weblogic_discoverer.createDomainLayout(
            fs, domainRootPath)
        parser = weblogic_discoverer.createDomainConfigParserByLayout(
            domainLayout, loadExternalDtd)
        try:
            domainDescriptorFile = domainLayout.getFileContent(
                domainLayout.getDomainConfigFilePath())
            domainDescriptor = parser.parseConfiguration(
                domainDescriptorFile.content)
        except (Exception, JException):
            logger.warnException("Failed to process config.xml")
        else:
            # get version of the platform
            versionInfo = domainDescriptor.versionInfo
            logger.info("Platform version is %s" % versionInfo)
            domainName = domainDescriptor.getName()
            # update server administrative domain attribute
            modeling.setJ2eeServerAdminDomain(serverOsh, domainName)
            servers = domainDescriptor.getServers()
            for server in servers:
                if server.getName() == serverOsh.getAttributeValue('name'):
                    serverFullName = jee.ServerTopologyBuilder(
                    )._composeFullName(server)
                    serverOsh.setAttribute('j2eeserver_fullname',
                                           serverFullName)
                    break
Example #53
0
def DiscoveryMain(Framework):

    rangeString = Framework.getParameter('range')
    probeName = Framework.getDestinationAttribute('probeName')
    nmapLocation = Framework.getParameter('nmap_location') or None

    protocol = Framework.getDestinationAttribute('Protocol')
    try:
        excludePatterns = icmp_utils.preparePatterns(
            Framework.getParameter('excludePatternsList'))
        client = Framework.createClient(
            ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME)
        shell = ShellFactory().createShell(client)
        fs = file_system.createFileSystem(shell)
        try:
            if nmapLocation and fs.isDirectory(nmapLocation):
                path_tool = NtPath()
                nmapLocation = path_tool.join(nmapLocation,
                                              nmap.NMAP_EXECUTABLES[1])
        except PathNotFoundException:
            logger.warn("Specified directory \"%s\" is not exists." %
                        nmapLocation)

        if nmapLocation and not nmap.NmapPathValidator.get(fs).validate(
                nmapLocation):
            logger.warn(
                "Specified Nmap path \"%s\" is not exists. Trying the system path..."
                % nmapLocation)
            nmapLocation = None

        nmapTool = nmap.getByShell(shell, nmapLocation)
        if not nmapTool.getVersion():
            logger.reportWarning(
                "NMAP command is not installed on the probe machine")
            return ObjectStateHolderVector()
        probeRanges = _buildProbeRanges(Framework, rangeString, probeName)

        logger.info('Start working on total probe ranges: ', len(probeRanges))

        for probeRange in probeRanges:

            logger.debug("Start working on range ", probeRange.toRangeString())
            rangeIps = probeRange.getAllIPs(probeRange.getTotalIPs())
            byExcludePatterns = lambda ip, patterns=excludePatterns: icmp_utils.shouldPingIp(
                ip, patterns, None)
            filteredIps = filter(byExcludePatterns, rangeIps)

            excludedIpCount = len(rangeIps) - len(filteredIps)
            if excludedIpCount:
                logger.debug("Excluded IP's count: %s " % excludedIpCount)

            try:
                liveIps = nmapTool.doPingScan(
                    filteredIps,
                    issubclass(probeRange.__class__, IPv6Range) or issubclass(
                        probeRange.__class__, IPv6RangeWIthDescription))
            except Exception, ex:
                logger.warn(str(ex))
            else:
                if liveIps:
                    Framework.sendObjects(_reportIpOSHs(liveIps))
        logger.info('Finished working on all Probes Ranges')
Example #54
0
 def filesystem(shell):
     return file_system.createFileSystem(shell)