Exemplo n.º 1
0
def _discoverDatabase(client, baseTopology):
    r'@types: BaseSapJmxClient, BaseTopology -> oshv'
    logger.info("Discover DB information")
    vector = ObjectStateHolderVector()
    try:
        dbInfo = _getDatabase(client)
    except (Exception, JException):
        logger.warnException("Failed to get DB info using new MBean model")
    else:
        if dbInfo:
            try:
                logger.info("Resolve DB address: ", dbInfo.hostname)
                dnsResolver = netutils.JavaDnsResolver()
                ips = dnsResolver.resolveIpsByHostname(dbInfo.hostname)
                hostReporter = sap.HostReporter(sap.HostBuilder())
                hostOsh, hVector = hostReporter.reportHostWithIps(*ips)
                vector.addAll(hVector)
                hVector.clear()
            except netutils.ResolveException:
                logger.warn("DB won't be reported as DB addr is not resolved")
            else:
                try:
                    logger.info("Discovered: ", dbInfo)
                    systemOsh = baseTopology.systemOsh
                    vector.addAll(sap_db.report_db_info(dbInfo, systemOsh, hostOsh))
                except ValueError, ve:
                    logger.warn("%s: %s" % (ve, dbInfo.type))
Exemplo n.º 2
0
    def discoverJvmByServerRuntime(self, serverRuntime):
        '@types: jee_discoverer.ServerRuntime -> jee.Jvm'
        jvm = jee.Jvm('jvm')
        javaPath = serverRuntime.findJavaCommandPath()
        try:
            if javaPath:
                jvm = self.getJVMInfo(_quotePathIfHasSpaces(javaPath))
        except:
            logger.warnException('Failed to get JVM information')
#        Need to expand if the path is only 'java' or else like that
#        if javaPath:
#            jvm.resourcePath = javaPath
        initialPermSize = serverRuntime.getJvmInitialPermSize()
        if initialPermSize:
            jvm.initialPermSizeInBytes.set(1024*1024*long(initialPermSize))

        maxPermSize = serverRuntime.getJvmMaxPermSize()
        if maxPermSize:
            jvm.maxPermSizeInBytes.set(1024*1024* long(maxPermSize))

        initialHeapSize = serverRuntime.getJvmInitialHeapSize()
        if initialHeapSize:
            jvm.initialHeapSizeInBytes.set(1024*1024*long(initialHeapSize))

        maxHeapSize = serverRuntime.getJvmMaxHeapSize()
        if maxHeapSize:
            jvm.maxHeapSizeInBytes.set(1024*1024*long(maxHeapSize))

        jvm.osVersion = str(self._getShell().getOsVersion()).strip()
        jvm.osType = self._getShell().getOsType()
        return jvm
Exemplo n.º 3
0
    def getBindings(self, binding_str):
        binding_elements = binding_str.split(',')
        bindings = []
        try:
            for binding_element in binding_elements:
                if '/' not in binding_element:
                    continue
                protocol, address = binding_element.split('/')
                parts = address.split(':')
                if len(parts) == 3:
                    ip, port, hostname = parts
                    ips = []
                    if not ip or ip == '*':
                        if self.ips:
                            ips = self.ips
                    else:
                        ips = [ip]
                    endpoints = []
                    for ip in ips:
                        endpoint = netutils.Endpoint(
                            port,
                            netutils.ProtocolType.TCP_PROTOCOL,
                            ip,
                            portType=protocol)
                        endpoints.append(endpoint)
                    binding = (hostname, protocol, endpoints)
                    bindings.append(binding)

            logger.debug('Get bindings of site:', bindings)
        except:
            logger.warnException('Failed to get binding info')
        return bindings
Exemplo n.º 4
0
 def _findModule(self, name, path, moduleType, jndiNameToName=None):
     module = jee_discoverer.BaseApplicationDiscovererByShell._findModule(
         self, name, path, moduleType)
     if moduleType == jee_constants.ModuleType.EJB:
         files = filter(
             lambda file: re.match(
                 WebsphereJndiBindingParser.EJB_BINDING_DESCRIPTOR_PATTERN,
                 file.getName(), re.IGNORECASE), module.getConfigFiles())
         if files:
             try:
                 logger.debug(
                     'Parsing JNDI binding descriptor file %s for %s' %
                     (files[0].name, module))
                 bindingDescriptor = self.__jndiBindingParser.parseEjbModuleBindingDescriptor(
                     files[0].content)
                 if bindingDescriptor:
                     for entry in module.getEntrieRefs():
                         jndiName = bindingDescriptor.getJndiName(entry)
                         if jndiName:
                             entry.setJndiName(jndiName)
                             if jndiNameToName and (
                                     jndiName in jndiNameToName.keys()):
                                 entry.setNameInNamespace(
                                     jndiNameToName[jndiName])
                                 logger.debug(
                                     'Found object name for %s:%s' %
                                     (repr(entry),
                                      jndiNameToName[jndiName]))
                             logger.debug('Found JNDI name for %s:%s' %
                                          (repr(entry), jndiName))
             except (Exception, JException):
                 logger.warnException(
                     'Failed to process EJB binding for %s:%s' %
                     (moduleType, module.getName()))
     return module
Exemplo n.º 5
0
def discoverSwitches(client, ips_set, allowDnsLookup, ignoreNodesWithoutIP):
    '''
    @types: Client, set[IPAddress], bool, bool -> generator

    @return: generator of tuples witch such elements
        storage array osh
        list[tuple[Port, osh]]
        list[tuple[Hba, osh]]
        list[tuple[LogicalVolume, osh]]
    @types: Client, set[IPAddress], bool, bool  -> iterable[osh]

    '''
    try:
        switches = _query_switches(client)
    except (Exception, JException):
        logger.warnException("Failed to get switches")
    else:
        for switch in switches:
            ips = _discover_switch_ips(switch, ips_set, allowDnsLookup)
            if ips:
                # change address of switch to IP as reporting depends on it
                switch = switch._replace(address=first(ips))
                each(ips_set.add, ips)
            elif ignoreNodesWithoutIP:
                logger.debug("%s is ignored due to missing IPs" % str(switch))
                continue

            switch_osh = _build_fc_switch_osh(switch)
            port_to_osh = _discoverPortsPerSwitch(client, switch, switch_osh)
            ip_oshs = chain(*[_report_ips(switch_osh, ip) for ip in ips])
            yield switch, switch_osh, port_to_osh, ip_oshs
Exemplo n.º 6
0
    def _findWebModule(self, name, path):
        r''' Module detected by presence of file 'WEB-INF/web.xml' in specified path
        @types: str, str -> jee.WebModule
        @raise ValueError: JEE descriptor is not found
        '''
        webModule = jee.WebModule(name)

        logger.info("Find WAR descriptor files for '%s'" % name)
        path = self.getLayout().path().normalizePath(path)
        files = self.getLayout().findWebDescriptorFiles(path)

        # split descriptors by type - jee or runtime
        jeeDescriptors, runtimeDescriptors = self._splitDescriptorFilesByType(files, 'web.xml')
        if jeeDescriptors:
            try:
                logger.info('Get WEB deployment descriptor content')
                file = self.getLayout().getFileContent(jeeDescriptors[0].path)
                webModule.addConfigFiles(jee.createXmlConfigFile(file))
                descriptor = self._getDescriptorParser().parseWebApplicationDescriptor(file.content)
                for servlet in descriptor.getServlets():
                    webModule.addEntry(servlet)
            except (Exception, JException):
                logger.warnException("Failed to process web.xml")
            # process runtime descriptor files
            for file in runtimeDescriptors:
                try:
                    fileWithContent = self.getLayout().getFileContent(file.path)
                    webModule.addConfigFiles(jee.createXmlConfigFile(fileWithContent))
                except (Exception, JException):
                    logger.warnException("Failed to load content for runtime descriptor: %s" % file.name)
        else:
            raise ValueError("JEE descriptor is not found")
        return webModule
Exemplo n.º 7
0
def DiscoveryMain(Framework):
    Framework = jee_connection.EnhancedFramework(Framework)
    isAppResourcesDiscoveryEnabled = _asBoolean(Framework.getParameter('discoverAppResources'))
    isJmsResourcesDiscoveryEnabled = _asBoolean(Framework.getParameter('discoverJMSResources'))

    platform = jee.Platform.JBOSS
    try:
        r'''In addition to the credentials we have to specify port number and
        version of the platform.
        Credentials may be defined without such information that is very important
        for establishing connections
        '''
        port = entity.WeakNumeric(int)
        port.set(Framework.getDestinationAttribute('port'))
        version = Framework.getDestinationAttribute('version')

        properties = Properties()
        properties.put(CollectorsConstants.PROTOCOL_ATTRIBUTE_PORT, str(port.value()))
        properties.put(AgentConstants.VERSION_PROPERTY, version)

        client = Framework.createClient(properties)

        jmxProvider = jmx.Provider(client)
    except (Exception, JException), exc:
        logger.warnException("Failed to establish connection")
        jee_connection.reportError(Framework, str(exc), platform.getName())
def discoverLparPhysScsiAndRaid(shell, physicalVolumesDict):
    scsiList = []
    physVolumes = []
    output = ""
    for hdisk in physicalVolumesDict.keys():
        try:
            output = ibm_hmc_lib.executeCommand(shell, 'lspath -l %s -F"name:parent"' % hdisk)
        except ValueError, ex:
            logger.warn(str(ex))
            continue
        (hdisks, devices) = parseHdiskToScsiCorres(output, "\:+")
        for i in range(len(devices)):
            deviceName = devices[i]
            physicalVolume = physicalVolumesDict.get(hdisks[i])
            if physicalVolume:
                command = "lscfg | grep %s" % deviceName
                try:
                    output = shell.execAlternateCmds(command, "ioscli " + command, "/usr/ios/cli/ioscli " + command)
                    if output:
                        physicalPath = re.match('\+\s+scsi1\s+([\w\.\-]+)\s+', output.strip())
                        if physicalPath:
                            localSlotNumber = re.match(".*-[Cc](\d+)", physicalPath.group(1).strip()) or re.match(".*-[Pp](\d+)", physicalPath.group(1).strip())
                            if localSlotNumber:
                                scsi = storage_topology.ScsiAdapter()
                                scsi.physicalPath = physicalPath.group(1).strip()
                                scsi.slotNumber = localSlotNumber.group(1).strip()
                                physicalVolume.scsiAdapterSlotNumber = scsi.slotNumber
                                physVolumes.append(physicalVolume)
                                scsiList.append(scsi)
                except:
                    logger.warnException("Failed to discover physical SCSI and RAID.")
Exemplo n.º 9
0
def DiscoveryMain(Framework):
    Framework = jee_connection.EnhancedFramework(Framework)
    port = entity.WeakNumeric(int)
    port.set(Framework.getDestinationAttribute('port'))
    version = Framework.getDestinationAttribute('version')

    resultVector = ObjectStateHolderVector()
    isAppResourcesDiscoveryEnabled = Boolean.valueOf(Framework.getParameter('discoverAppResources'))
    isJMSResourcesDiscoveryEnabled = Boolean.valueOf(Framework.getParameter('discoverJMSResources'))
    discoverDeployedOnlyApplications = Boolean.valueOf(Framework.getParameter("discoverDeployedOnlyApplications"))
    protocolType = (Framework.getDestinationAttribute('protocol') or
                    ClientsConsts.HTTP_PROTOCOL_NAME)

    properties = Properties()
    properties.put(CollectorsConstants.PROTOCOL_ATTRIBUTE_PORT, str(port.value()))
    properties.put(AgentConstants.VERSION_PROPERTY, version)
    properties.put(AgentConstants.PROP_WEBLOGIC_PROTOCOL, protocolType)

    platform = jee.Platform.WEBLOGIC

    try:
        client = Framework.createClient(properties)
    except (Exception, JException), exc:
        logger.warnException("Failed to establish connection")
        jee_connection.reportError(Framework, str(exc), platform.getName())
Exemplo n.º 10
0
 def wrapper(*args, **kwargs):
     try:
         return fn(*args, **kwargs)
     except ex:
         import logger
         logger.warnException(str(sys.exc_info()[1]))
         return fallbackFn(*args, **kwargs)
Exemplo n.º 11
0
 def findFilesRecursively(self, baseDirPath, filters, fileAttrs=None):
     r'''@types: str, list(FileFilterByPattern), list(str) -> list(file_topology.File)
     @raise ValueError: No filters (FileFilterByPattern) specified to make a recursive file search
     '''
     # if filter is not specified - recursive search query becomes not deterministic
     if not filters:
         raise ValueError(
             "No filters (FileFilterByPattern) specified to make a recursive file search"
         )
     # if file attributes are note specified - default set is name and path
     fileAttrs = fileAttrs or [
         file_topology.FileAttrs.NAME, file_topology.FileAttrs.PATH
     ]
     paths = []
     for filterObj in filters:
         try:
             paths.extend(
                 self._findFilesRecursively(baseDirPath,
                                            filterObj.filePattern))
         except file_topology.PathNotFoundException, pnfe:
             logger.warn(str(pnfe))
         except (Exception, JException):
             # TBD: not sure whether we have to swallow such exceptions
             logger.warnException(
                 "Failed to find files for filter with file pattern %s"
                 % filterObj.filePattern)
Exemplo n.º 12
0
def _readUpdatedIdsFromFile(filePath):
    ''' string -> map(string, string) '''
    updatedIds = {}
    file = None
    try:
        try:
            file = open(filePath)
            entry = 1
            while (entry):
                try:
                    entry = file.readline() or None
                    if entry:
                        tokens = entry.split(':')
                        if tokens and len(tokens) == 2:
                            cmdbId = tokens[0] and tokens[0].strip()
                            nnmId = tokens[1] and tokens[1].strip()
                            if cmdbId and nnmId:
                                updatedIds[cmdbId] = nnmId
                except:
                    logger.warnException('Failed to read entry from file: %s' % filePath)
                    entry = None
        except:
            logger.warn('Error reading file [%s]. Integration will update all the IDs and create a new file.' % filePath)

    finally:
        if file is not None:
            file.close()

    return updatedIds
Exemplo n.º 13
0
 def _retrieveConfigFile(self, path, fileSystem):
     try:
         fileObject = fileSystem.getFileContent(path)
         if fileObject and fileObject.content:
             return fileObject
     except:
         logger.warnException(" ... Failed to retrieve content of file by path: %s" % path)
Exemplo n.º 14
0
def getLanguage(framework):

    language = None
    try:
        defaultClient = None
        try:
            factory = hyperv.WmiClientFactory(framework)
            defaultClient = factory.createClient()
            if defaultClient is not None:
                wmiProvider = wmiutils.WmiAgentProvider(defaultClient)
                languageDiscoverer = wmiutils.LanguageDiscoverer(wmiProvider)
                language = languageDiscoverer.getLanguage()
        finally:
            if defaultClient is not None:
                try:
                    defaultClient.close()
                except:
                    pass
    except:
        logger.warnException("Exception while determining OS language")

    if language is None:
        logger.warn("Failed to determine language of target system, default language is used")
        language = wmiutils.DEFAULT_LANGUAGE
    
    return language
Exemplo n.º 15
0
 def discoverAllProcesses(self):
     '@types: -> list(process.Process)'
     try:
         return self.findAllProcessesByWmi()
     except (Exception, JException):
         logger.warnException("Failed to discovery processes by SNMP")
     return []
Exemplo n.º 16
0
 def process(self, context, filter=DEFAULT_FILTER):
     acceptedPlugins = filter.filterPlugins(
         self.idToPluginDescriptor.values())
     logger.debug("Accepted plugins in chain: %d" % len(acceptedPlugins))
     for pluginDescriptor in acceptedPlugins:
         pluginId = pluginDescriptor.getId()
         logger.debug("Executing plug-in with ID '%s'" % pluginId)
         try:
             plugin = self.__instantiatePlugin(pluginDescriptor)
             if plugin:
                 if plugin.isApplicable(context):
                     plugin.process(context)
                 else:
                     logger.debug("Plug-in with ID '%s' is not applicable" %
                                  pluginId)
             else:
                 logger.warn("Failed to instantiate plug-in with ID '%s'" %
                             pluginId)
                 logger.reportWarning("Failed to instantiate plug-in")
         except PluginUncheckedException, ex:
             raise ex.__class__(ex)
         except (Exception, JavaException), e:
             logger.warnException(
                 "Exception during processing of plug-in with ID '%s'\n" %
                 pluginId)
             if isinstance(e, JavaException):
                 msg = e.getMessage()
             else:
                 msg = e.message
             logger.reportWarning(
                 "Exception during processing of plug-in:%s" % msg)
Exemplo n.º 17
0
    def discoverEarApplication(self, name, path, jndiNameToName = None):
        application = jee_discoverer.BaseApplicationDiscovererByShell.discoverEarApplication(self, name, path, jndiNameToName)
        # app scope jdbc & jms
        files = filter(lambda f: re.match(self._getDescriptorParser().WEBLOGIC_APPLICATION_FILE_NAME, f.getName(), re.IGNORECASE),
                           application.getConfigFiles())
        if files:
            try:
                logger.debug('Parsing weblogic application file %s for %s' % (files[0].name, application))
                application_resources = self._getDescriptorParser().parseWeblogicApplicationDescriptor(files[0].content)
                # jdbc & jms
                for resource_type in ('JDBC', 'JMS'):
                    for config in application_resources.getResourceByType(resource_type):
                        config_file = config['path']
                        if not self.getLayout().path().isAbsolute( config_file ):
                            config_file = self.getLayout().path().join(path, config_file)
                        config_file = self.getLayout().path().normalizePath(config_file)
                        try:
                            logger.debug('Parsing %s config file %s for %s' % (resource_type, config_file, application))
                            fileWithContent = self.getLayout().getFileContent(config_file)
                            application.addConfigFiles(jee.createXmlConfigFile(fileWithContent))
                        except (Exception, JException):
                            logger.warnException(
                                "Failed to load content for %s descriptor: %s" % (resource_type, config_file))
            except (Exception, JException):
                logger.warnException('Failed to process weblogic application file %s for %s' % (files[0].name, application))

        return application
Exemplo n.º 18
0
    def _findModule(self, name, path, moduleType, jndiNameToName = None):
        module = jee_discoverer.BaseApplicationDiscovererByShell._findModule(self, name, path, moduleType)
        # Add Bean-Jndi relation
        if moduleType == jee_constants.ModuleType.EJB:
            files = filter(lambda f: re.match(self._getDescriptorParser().WEBLOGIC_EJB_DESCRIPTOR_FILE_NAME, f.getName(), re.IGNORECASE),
                           module.getConfigFiles())
            if files:
                try:
                    logger.debug('Parsing JNDI binding descriptor file %s for %s' % (files[0].name, module))
                    bindingDescriptor = self._getDescriptorParser().parseWeblogicEjbModuleDescriptor(files[0].content)
                    if bindingDescriptor:
                        for entry in module.getEntrieRefs():
                            jndiName = bindingDescriptor.getJndiName(entry.getName())
                            if jndiName:
                                entry.setJndiName(jndiName)
                                if jndiNameToName and (jndiName in jndiNameToName.keys()):
                                    entry.setNameInNamespace(jndiNameToName[jndiName])
                                    logger.debug('Found object name for %s:%s' % (repr(entry), jndiNameToName[jndiName]))
                                logger.debug('Found JNDI name for %s:%s' % (repr(entry), jndiName))
                except (Exception, JException):
                    logger.warnException('Failed to process EJB binding for %s:%s' % (moduleType, module.getName()))
        # Add webservice
        files = filter(lambda f: re.match(self._getDescriptorParser().WEBSERVICE_DESCRIPTOR_FILE_NAME, f.getName(), re.IGNORECASE),
                       module.getConfigFiles())
        if files:
            try:
                logger.debug('Parsing Webservice descriptor file %s for %s' % (files[0].name, module))
                webservice = self._getDescriptorParser().parseWebserviceDescriptor(files[0].content)
                if webservice:
                    logger.debug('Found Webservice %s for %s' % (webservice, module.getName()))
                    module.addWebServices(webservice)
            except (Exception, JException):
                logger.warnException('Failed to process Webservice for %s:%s' % (moduleType, module.getName()))

        return module
 def process(self, context):
     client = context.client
     applicationOsh = context.application.getOsh()
     process = context.application.getProcess(EX_2003_MAIN_PROCESS) 
     if not process:
         process = context.application.getProcess(EX_2007_MAIN_PROCESS)
     
     fullFileName = process.executablePath
     if fullFileName:  
         fileVer = None
         try:
             fileVer = file_ver_lib.getWindowsWMIFileVer(client, fullFileName)
         except:
             logger.warnException('Get version info using WMI failed')
             
         if fileVer:
             truncatedVersion = re.match('(\d+\.\d+).*',fileVer)
             version = truncatedVersion.group(1)
             if truncatedVersion and FILE_VERSION_TO_PRODUCT_VERSION.has_key(version):
                 applicationOsh.setAttribute("application_version_number", FILE_VERSION_TO_PRODUCT_VERSION[version])
             else:
                 logger.warn('Unknown product version %s' % fileVer)
         else: 
             logger.warn('For file %s no version found.' % fullFileName)
     else:
         logger.warn('Process %s full path is not available.' % process.getName())
Exemplo n.º 20
0
    def get_db_datasources(self, content):
        from NTCMD_IIS import NamedDbDataSource, DbDataSource

        dbDataSources = []
        if content:
            try:
                document = SAXBuilder(0).build(StringReader(content))
                results = document.getRootElement().getChildren('connectionStrings')
                if results:
                    for result in results:
                        connectionEntries = result.getChildren('add')
                        for connectionEntry in connectionEntries:
                            connectionString = connectionEntry.getAttributeValue('connectionString')
                            if connectionString:
                                match = re.search("dsn\s*=\s*([a-zA-Z_0-9]+);?.*", connectionString, re.I)
                                if match:
                                    dataSource = NamedDbDataSource(match.group(1))
                                else:
                                    dataSource = DbDataSource(connectionString)
                                if dataSource.isValidDataSource():
                                    dbDataSources.append(dataSource)
                                else:
                                    logger.debug('DB Source did not validate')
            except:
                logger.warnException('Failed getting connection info.')
        return dbDataSources
Exemplo n.º 21
0
 def __discoverInterfaceStates(self, interface):
     ''' Discover interface states - aliases and linked IPs
     Interface -> list(_InterfaceState)'''
     logger.debug("Discover interface states for %s" % interface)
     interfaceStates = []
     try:
         for state in self.getStatesOfInterfaces():
             if (self.__isAliasedStateOf(interface, state)
                 or state.interface.name == interface.name):
                 if interface.name == state.interface.name:
                     logger.debug('Found state %s, ip %s ' % (interface, state.ip))
                     ips = state.ip
                     if ips:
                         for ip in ips:
                             self.__networking().addIpAndNetwork(ip.ip, ip.netmask, interface.name)
                 else:
                     aliasInterface = None
                     try:
                         aliasInterface = self.__getOrAddInterface(state.interface)
                         if (not aliasInterface._hasRole(AliasRole)):
                             aliasRole = AliasRole()
                             aliasRole.parentInterface = interface
                             aliasInterface._addRole(aliasRole)
                             logger.debug('Found alias %s, ip %s ' % (aliasInterface, state.ip))
                         logger.debug('Adding new IP address to interface %s, %s' %(aliasInterface.name, state.ip))
                         ips = state.ip
                         if ips:
                             for ip in ips:
                                 self.__networking().addIpAndNetwork(ip.ip, ip.netmask, aliasInterface.name)
                     except Exception, e:
                         logger.warnException('Failed to add alias for interface %s' % aliasInterface)
                 interfaceStates.append(state)
     except Exception, e:
         logger.warn(str(e))
Exemplo n.º 22
0
    def __parseInterfacesInLanscanOutput(self, output):
        '''str -> map(str, networking.Interface)

        # Expected format for HP-UX lanscan command --
        #0/0/0/1/0 0x00306E4989E7 0    UP    lan0 snap0       1    ETHER       Yes   119
        #0/0/12/0/0 0x00306E4C999B 1    UP    lan1 snap1       2    ETHER       Yes   119
        #0/0/14/0/0 0x00306E4A4773 2    UP    lan2 snap2       3    ETHER       Yes   119
        '''
        nameToInterface = {}

        #The first two lines are skipped because they contain output header
        for line in output.split('\n'):
            properties = line.strip().split()
            if len(properties) > 3:
                status = properties[3]
                # get only  live interfaces with valid hardware path
                if status.lower() == 'up':
                    hwPath = properties[0]
                    name = properties[4]
                    index = self.__getDevNameAndIndex(name)[1]
                    # check whether parsing is correct
                    try:
                        if index == int(properties[2]):
                            # strip 0x from the mac
                            macStr = properties[1]
                            mac = self.__parseLanscanMacString(macStr) or index
                            hpuxRole = _HpuxInterfaceRole(hardwarePath = hwPath)
                            nic = Interface(name = name, index = index, mac = mac)
                            if self.__getSystemVersion() in ['10.20']:
                                nic.serviceIndex = properties[6]
                            nic._addRole(hpuxRole)
                            nameToInterface[name] = nic
                    except:
                        logger.warnException('Wrong line format: %s' % line)
        return nameToInterface
Exemplo n.º 23
0
 def process(self, context, filter = DEFAULT_FILTER):
     acceptedPlugins = filter.filterPlugins(self.idToPluginDescriptor.values())
     logger.debug("Accepted plugins in chain: %d" % len (acceptedPlugins))
     for pluginDescriptor in acceptedPlugins:
         pluginId = pluginDescriptor.getId()
         logger.debug("Executing plug-in with ID '%s'" % pluginId)
         try:
             plugin = self.__instantiatePlugin(pluginDescriptor)
             if plugin:
                 if plugin.isApplicable(context):
                     plugin.process(context)
                 else:
                     logger.debug("Plug-in with ID '%s' is not applicable" % pluginId)
             else:
                 logger.warn("Failed to instantiate plug-in with ID '%s'" % pluginId)
                 logger.reportWarning("Failed to instantiate plug-in")
         except PluginUncheckedException, ex:
             raise ex.__class__(ex)
         except (Exception, JavaException), e:
             logger.warnException("Exception during processing of plug-in with ID '%s'\n" % pluginId)
             if isinstance(e, JavaException):
                 msg = e.getMessage()
             else:
                 msg = e.message
             logger.reportWarning("Exception during processing of plug-in:%s" % msg)
Exemplo n.º 24
0
def _updateNnmNode(nnmConnection, nnmStub, cmdbId, nnmId, framework):
    ''' NnmConnection, Stub, string, string, Framework -> None '''
    if not nnmConnection.version in [-1, 8, 9]: raise ValueError("Invalid NNM version %s" % nnmConnection.version)

    customAttributes = [CustomAttribute("UCMDB_ID", cmdbId)]
    caarray = CustomAttributeArray(customAttributes)
    try:
        if nnmConnection.version in [-1, 9]:
            nnmStub.addCustomAttributes(nnmId, caarray)
        else:
            nnmStub.updateCustomAttributes(nnmId, caarray)

    except:
        stacktrace = traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])
        err = stacktrace[2]
        if re.search('Connection refused', err):
            logger.errorException('Failed to update NNM server')
            raise NnmException('Failed to update NNM server')

        elif re.search('addCustomAttributes', err) and nnmConnection.version == -1:
            raise UnsupportedNnmMethodException()

        else:
            logger.warnException('Failed to update node with id %s in NNM server for UCMDB ID %s' % (nnmId, cmdbId))
            framework.reportWarning("Failed to update node with in NNM server")
Exemplo n.º 25
0
    def process(self, context):
        client = context.client
        applicationOsh = context.application.getOsh()
        process = context.application.getProcess(EX_2003_MAIN_PROCESS)
        if not process:
            process = context.application.getProcess(EX_2007_MAIN_PROCESS)

        fullFileName = process.executablePath
        if fullFileName:
            fileVer = None
            try:
                fileVer = file_ver_lib.getWindowsWMIFileVer(
                    client, fullFileName)
            except:
                logger.warnException('Get version info using WMI failed')

            if fileVer:
                truncatedVersion = re.match('(\d+\.\d+).*', fileVer)
                version = truncatedVersion.group(1)
                if truncatedVersion and FILE_VERSION_TO_PRODUCT_VERSION.has_key(
                        version):
                    applicationOsh.setAttribute(
                        "application_version_number",
                        FILE_VERSION_TO_PRODUCT_VERSION[version])
                else:
                    logger.warn('Unknown product version %s' % fileVer)
            else:
                logger.warn('For file %s no version found.' % fullFileName)
        else:
            logger.warn('Process %s full path is not available.' %
                        process.getName())
Exemplo n.º 26
0
    def getCatalogsByNameForOrganization(self, organizationInstance,
                                         vcloudClient):
        from com.vmware.vcloud.sdk import Catalog
        from com.vmware.vcloud.sdk import VCloudException
        catalogsByName = {}
        try:
            _catalogRefs = organizationInstance.getCatalogRefs()
            if _catalogRefs.isEmpty():
                return catalogsByName

            for reference in _catalogRefs:
                catalogInstance = Catalog.getCatalogByReference(
                    vcloudClient, reference)
                catalogResource = catalogInstance.getResource()
                catalogName = catalogResource.getName()

                catalog = vcloud.Catalog(catalogName)
                catalog.setInstance(catalogInstance)
                catalog.description = catalogResource.getDescription()
                catalog.isPublished = catalogResource.isIsPublished()
                catalog.uuid = _getUuidFromResource(catalogResource)

                catalogsByName[catalogName] = catalog
        except VCloudException:
            logger.warnException("Failed to read catalogs")

        return catalogsByName
Exemplo n.º 27
0
def DiscoveryMain(Framework):
    Framework = jee_connection.EnhancedFramework(Framework)
    port = entity.WeakNumeric(int)
    port.set(Framework.getDestinationAttribute('port'))
    version = Framework.getDestinationAttribute('version')

    resultVector = ObjectStateHolderVector()
    isAppResourcesDiscoveryEnabled = Boolean.valueOf(
        Framework.getParameter('discoverAppResources'))
    isJMSResourcesDiscoveryEnabled = Boolean.valueOf(
        Framework.getParameter('discoverJMSResources'))
    discoverDeployedOnlyApplications = Boolean.valueOf(
        Framework.getParameter("discoverDeployedOnlyApplications"))
    protocolType = (Framework.getDestinationAttribute('protocol')
                    or ClientsConsts.HTTP_PROTOCOL_NAME)

    properties = Properties()
    properties.put(CollectorsConstants.PROTOCOL_ATTRIBUTE_PORT,
                   str(port.value()))
    properties.put(AgentConstants.VERSION_PROPERTY, version)
    properties.put(AgentConstants.PROP_WEBLOGIC_PROTOCOL, protocolType)

    platform = jee.Platform.WEBLOGIC

    try:
        client = Framework.createClient(properties)
    except (Exception, JException), exc:
        logger.warnException("Failed to establish connection")
        jee_connection.reportError(Framework, str(exc), platform.getName())
Exemplo n.º 28
0
 def getCatalogsByNameForOrganization(self, organizationInstance, vcloudClient):
     from com.vmware.vcloud.sdk import Catalog
     from com.vmware.vcloud.sdk import VCloudException
     catalogsByName = {}
     try:
         _catalogRefs = organizationInstance.getCatalogRefs()
         if _catalogRefs.isEmpty():
             return catalogsByName
         
         for reference in _catalogRefs:
             catalogInstance = Catalog.getCatalogByReference(vcloudClient, reference)
             catalogResource = catalogInstance.getResource()
             catalogName = catalogResource.getName()
             
             catalog = vcloud.Catalog(catalogName)
             catalog.setInstance(catalogInstance)
             catalog.description = catalogResource.getDescription()
             catalog.isPublished = catalogResource.isIsPublished()
             catalog.uuid = _getUuidFromResource(catalogResource)
             
             catalogsByName[catalogName] = catalog
     except VCloudException:
         logger.warnException("Failed to read catalogs")
     
     return catalogsByName
Exemplo n.º 29
0
    def getBindings(self, binding_str):
        binding_elements = binding_str.split(",")
        bindings = []
        try:
            for binding_element in binding_elements:
                if "/" not in binding_element:
                    continue
                protocol, address = binding_element.split("/")
                parts = address.split(":")
                if len(parts) == 3:
                    ip, port, hostname = parts
                    ips = []
                    if not ip or ip == "*":
                        if self.ips:
                            ips = self.ips
                    else:
                        ips = [ip]
                    endpoints = []
                    for ip in ips:
                        endpoint = netutils.Endpoint(port, netutils.ProtocolType.TCP_PROTOCOL, ip, portType=protocol)
                        endpoints.append(endpoint)
                    binding = (hostname, protocol, endpoints)
                    bindings.append(binding)

            logger.debug("Get bindings of site:", bindings)
        except:
            logger.warnException("Failed to get binding info")
        return bindings
Exemplo n.º 30
0
 def getLayer2PerVlan(self):
     self.get_fdb_id()
     try:
         aList = self.snmpClient.executeQuery(
             self.DOT1Q_TP_FDB_PORT %
             (self.fdb_id, int(self.fdb_id) +
              1)).asTable()  #@@CMD_PERMISION snmp protocol execution
         if len(aList) == 0 and (
                 self.device_type_str.find('hp') != -1
                 or self.device_type_str.find('procurve') != -1):
             #old HP ProCurve switches use HP private MIBs
             aList = self.snmpClient.executeQuery(
                 self.HP_TP_FDB_PORT %
                 (self.vlan_id, int(self.vlan_id) +
                  1)).asTable()  #@@CMD_PERMISION snmp protocol execution
         if aList:
             for i in xrange(len(aList)):
                 (a, b) = aList[i]
                 aList[i] = (a.upper(), b.upper())
     except:
         logger.warnException('error retrieving TP info')
     else:
         for x in aList:
             if (self.swPortTermMacs.has_key(x[1])):
                 portMacList = self.swPortTermMacs.get(x[1])
                 portMacList.append(x[0])
             else:
                 portMacList = [x[0]]
             self.swPortTermMacs.update({x[1]: portMacList})
Exemplo n.º 31
0
    def get_db_datasources(self, content):
        from NTCMD_IIS import NamedDbDataSource, DbDataSource

        dbDataSources = []
        if content:
            try:
                document = SAXBuilder(0).build(StringReader(content))
                results = document.getRootElement().getChildren("connectionStrings")
                if results:
                    for result in results:
                        connectionEntries = result.getChildren("add")
                        for connectionEntry in connectionEntries:
                            connectionString = connectionEntry.getAttributeValue("connectionString")
                            if connectionString:
                                match = re.search("dsn\s*=\s*([a-zA-Z_0-9]+);?.*", connectionString, re.I)
                                if match:
                                    dataSource = NamedDbDataSource(match.group(1))
                                else:
                                    dataSource = DbDataSource(connectionString)
                                if dataSource.isValidDataSource():
                                    dbDataSources.append(dataSource)
                                else:
                                    logger.debug("DB Source did not validate")
            except:
                logger.warnException("Failed getting connection info.")
        return dbDataSources
Exemplo n.º 32
0
    def __parseInterfacesInLanscanOutput(self, output):
        '''str -> map(str, networking.Interface)

        # Expected format for HP-UX lanscan command --
        #0/0/0/1/0 0x00306E4989E7 0    UP    lan0 snap0       1    ETHER       Yes   119
        #0/0/12/0/0 0x00306E4C999B 1    UP    lan1 snap1       2    ETHER       Yes   119
        #0/0/14/0/0 0x00306E4A4773 2    UP    lan2 snap2       3    ETHER       Yes   119
        '''
        nameToInterface = {}

        #The first two lines are skipped because they contain output header
        for line in output.split('\n'):
            properties = line.strip().split()
            if len(properties) > 3:
                status = properties[3]
                # get only  live interfaces with valid hardware path
                if status.lower() == 'up':
                    hwPath = properties[0]
                    name = properties[4]
                    index = self.__getDevNameAndIndex(name)[1]
                    # check whether parsing is correct
                    try:
                        if index == int(properties[2]):
                            # strip 0x from the mac
                            macStr = properties[1]
                            mac = self.__parseLanscanMacString(macStr) or index
                            hpuxRole = _HpuxInterfaceRole(hardwarePath=hwPath)
                            nic = Interface(name=name, index=index, mac=mac)
                            if self.__getSystemVersion() in ['10.20']:
                                nic.serviceIndex = properties[6]
                            nic._addRole(hpuxRole)
                            nameToInterface[name] = nic
                    except:
                        logger.warnException('Wrong line format: %s' % line)
        return nameToInterface
Exemplo n.º 33
0
 def discoverAllProcesses(self):
     '@types: -> list(process.Process)'
     try:
         return self.findAllProcessesByWmi()
     except (Exception, JException):
         logger.warnException("Failed to discovery processes by SNMP")
     return []
Exemplo n.º 34
0
def discoverLdomTopology(shell, ldmCli):
    '''
    Main method to discover LDOMs topology
    '''

    domainsByName = getBindings(shell, ldmCli)

    _controlDomains = filter(ldom.isControlDomain, domainsByName.values())
    if not _controlDomains: raise ValueError("Control domain not found")
    controlDomain = _controlDomains[0]

    guestDomains = filter(lambda d: not ldom.isControlDomain(d), domainsByName.values())

    logger.debug("Found %s bound guest domains" % len(guestDomains))

    topology = ldom.LdomTopology()
    topology.controlDomain = controlDomain
    topology.guestDomains = guestDomains
    topology.numberOfThreads = getLdomServerVirtualCPUCount(shell)
    logger.debug("Found %s virtual CPUs" % topology.numberOfThreads)
    topology.memorySize = getLdomServerMemorySize(shell)
    logger.debug("Found %sM total memorys" % topology.memorySize)
    hostname = solaris_networking.getHostname(shell)
    if not hostname: raise ValueError("Failed to discover hostname of control domain")
    controlDomain._hostname = hostname
    hostmodel = getHostModel(shell)
    if not hostmodel:
        logger.warn("Failed to discover model of control domain")
    else:
        controlDomain.model = hostmodel
    networking = discoverNetworking(shell)
    topology.networking = networking

    try:
        interfaceNamesBySwitchId = getVirtualSwitchInterfaceNames(shell)
        updateSwitchesWithInterfaces(controlDomain, interfaceNamesBySwitchId)
    except:
        logger.warn("Cannot find swith id with interface")

    hostKey = _findHostKeyForControlDomain(networking)
    if hostKey:
        controlDomain._hostKey = hostKey
    else:
        logger.warn("Cannot find host key for control domain")

    for guestDomain in guestDomains:
        hostKey = _findHostKeyForGuestDomain(guestDomain)
        if hostKey:
            guestDomain._hostKey = hostKey
        else:
            logger.warn("Cannot find host key for domain '%s'" % guestDomain.getName())

    try:
        cpus = discoverCpus(shell)
        topology.cpus = cpus
    except:
        logger.warnException('Failed to discover CPUs')

    return topology
Exemplo n.º 35
0
 def _retrieveConfigFile(self, path, fileSystem):
     try:
         fileObject = fileSystem.getFileContent(path)
         if fileObject and fileObject.content:
             return fileObject
     except:
         logger.warnException(
             " ... Failed to retrieve content of file by path: %s" % path)
Exemplo n.º 36
0
 def _parseStartDate(self, date):
     r'@types: str -> java.util.Date or None'
     try:
         dateFormat = SimpleDateFormat("HHmmss yyyyMMdd")
         return dateFormat.parse(date)
     except:
         logger.warnException('Failed to convert start date: %s'
                              ' to HHmmss yyyyMMdd' % date)
Exemplo n.º 37
0
 def _parseStartDate(self, date):
     r'@types: str -> java.util.Date or None'
     try:
         dateFormat = SimpleDateFormat("HHmmss yyyyMMdd")
         return dateFormat.parse(date)
     except:
         logger.warnException('Failed to convert start date: %s'
                              ' to HHmmss yyyyMMdd' % date)
Exemplo n.º 38
0
 def discoverNetworking(self):
     '''Discover information about all networking
      -> networking.UnixNetworking
     '''
     logger.debug('Discover whole networking')
     try:
         self.discoverLinkAggregations()
     except Exception, e:
         logger.warnException(str(e))
    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
Exemplo n.º 40
0
 def _parseLocation(self, location, parseRuleContexts):
     if location:
         expression = Expression(location)
         expression.parse(parseRuleContexts)
         try:
             parsedLocation = expression.evaluate()
             return parsedLocation
         except:
             logger.warnException(" ... Failed to parse location of config file: %s" % location)
Exemplo n.º 41
0
 def discoverNetworking(self):
     '''Discover information about all networking
      -> networking.UnixNetworking
     '''
     logger.debug('Discover whole networking')
     try:
         self.discoverLinkAggregations()
     except Exception, e:
         logger.warnException(str(e))
Exemplo n.º 42
0
def _discoverRegionsWithZones(service):
    r"@types: AmazonEC2 -> list(aws.Region)"
    logger.info("Discover REGIONS and ZONES")
    discoverer = Ec2Discoverer(service)
    regionByName = {}
    try:
        regionByName = _applyMapping(aws.Region.getName, discoverer.getRegions())
    except JException, je:
        logger.warnException("Failed to discover regions: %s" % je)
Exemplo n.º 43
0
    def _findModule(self, name, path, moduleType, jndiNameToName=None):
        module = jee_discoverer.BaseApplicationDiscovererByShell._findModule(
            self, name, path, moduleType)
        # Add Bean-Jndi relation
        if moduleType == jee_constants.ModuleType.EJB:
            files = filter(
                lambda f: re.match(
                    self.
                    _getDescriptorParser().WEBLOGIC_EJB_DESCRIPTOR_FILE_NAME,
                    f.getName(), re.IGNORECASE), module.getConfigFiles())
            if files:
                try:
                    logger.debug(
                        'Parsing JNDI binding descriptor file %s for %s' %
                        (files[0].name, module))
                    bindingDescriptor = self._getDescriptorParser(
                    ).parseWeblogicEjbModuleDescriptor(files[0].content)
                    if bindingDescriptor:
                        for entry in module.getEntrieRefs():
                            jndiName = bindingDescriptor.getJndiName(
                                entry.getName())
                            if jndiName:
                                entry.setJndiName(jndiName)
                                if jndiNameToName and (
                                        jndiName in jndiNameToName.keys()):
                                    entry.setNameInNamespace(
                                        jndiNameToName[jndiName])
                                    logger.debug(
                                        'Found object name for %s:%s' %
                                        (repr(entry),
                                         jndiNameToName[jndiName]))
                                logger.debug('Found JNDI name for %s:%s' %
                                             (repr(entry), jndiName))
                except (Exception, JException):
                    logger.warnException(
                        'Failed to process EJB binding for %s:%s' %
                        (moduleType, module.getName()))
        # Add webservice
        files = filter(
            lambda f: re.match(
                self._getDescriptorParser().WEBSERVICE_DESCRIPTOR_FILE_NAME,
                f.getName(), re.IGNORECASE), module.getConfigFiles())
        if files:
            try:
                logger.debug('Parsing Webservice descriptor file %s for %s' %
                             (files[0].name, module))
                webservice = self._getDescriptorParser(
                ).parseWebserviceDescriptor(files[0].content)
                if webservice:
                    logger.debug('Found Webservice %s for %s' %
                                 (webservice, module.getName()))
                    module.addWebServices(webservice)
            except (Exception, JException):
                logger.warnException('Failed to process Webservice for %s:%s' %
                                     (moduleType, module.getName()))

        return module
Exemplo n.º 44
0
def createURLOSHV(urlString, framework = None):
    OSHVResult = ObjectStateHolderVector()    
    
    #urlOSH2 = modeling.createOshByCmdbIdString('uri_endpoint', urlId)       
    logger.debug("Starting URL discovery on '%s'" % urlString)
    #urlString = urlString[1:len(urlString)-1]
    if not urlString:
        return OSHVResult
    
    try:
    
        urlString = str(urlString).replace("\\", "//")
        
        urlObject = URL(urlString)
        hostname = urlObject.getHost()
    
        if not hostname:
            raise MalformedURLException("Hostname is not defined in URL '%s'" % urlString)
    
        urlObjectResolver = URLObjectResolver(urlObject)
        protocol = urlObjectResolver.getProtocolFromUrlObject()
        
        if not protocol:
            raise Exception("Failed to resolve the http/https protocol from specified URL")
    
        port = urlObjectResolver.getPortFromUrlObject()
        
        if not port:
            raise Exception("Failed to resolve the port number from specified URL")
    
        # get topology
        # create business element CI and attach the url as configuration document CI to it 
    
        ips = urlObjectResolver.getIpFromUrlObject()
        
        for ipAddress in ips:
            logger.debug('%s: Reporting ip address: %s' % (urlString, ipAddress))
            if not ipAddress or not netutils.isValidIp(ipAddress) or netutils.isLocalIp(ipAddress):
                raise Exception("Failed to resolve the IP address of server from specified URL")
    
            
            hostOSH, ipOSH, OSHVResult2 = createIPEndpointOSHV(framework, ipAddress, port, protocol, hostname)     
            OSHVResult.addAll(OSHVResult2)
            # create UriEndpoint and relations between business element and UriEndpoint
            urlOSH = modeling.createUrlOsh(hostOSH, urlString, None)
            #urlOSH.setCmdbObjectId(urlOSH2.getCmdbObjectId())            
            OSHVResult.add(urlOSH)
            OSHVResult.add(modeling.createLinkOSH('dependency', urlOSH, ipOSH)) 
           
                        
            #create Web Server
    except:
        logger.warnException("Error creating URL OSH for %s" % urlString)


    return OSHVResult
Exemplo n.º 45
0
def DiscoveryMain(Framework):
    logger.debug("Atrium DiscoveryMain starting...")
    preLoadLibrary()
    #ID cache is a local file stored on the Probe. It contains a dictionary from UCMDB id to Atrium id.
    #This dictionary is used to be able to delete CI's in Atrium by UCMDB ID.
    idCachePath = r'%s\%s' % (adapterResWorkDir, 'id_cache.txt')
    if os.path.isfile(idCachePath):
        f = open(idCachePath, 'r')
        for line in f.readlines():
            if line.strip():
                elements = line.strip().split(':')
                id_cache[elements[0]] = elements[1]
        f.close()

    # Get debugMode, smartUpdateIgnoreFields, sortCSVFields properties from push.properties
    (debugMode, smartUpdateIgnoreFields, sortCSVFields, testConnNameSpace, testConnClass) = getPushProperties()

    # smart update function to not push data out to Remedy/Atrium if fields being pushed are unchanged, these are ignored
    smartUpdateIgnoreFieldsList = cleanCsvStrToList(smartUpdateIgnoreFields)
    sortCSVFieldsList           = cleanCsvStrToList(sortCSVFields)

    # Destination Parameters
    testConnection    = Framework.getDestinationAttribute('testConnection') or 'false'
    logger.debug("test connection = %s" % testConnection)

    # Protocol Information
    CONTEXT = processProtocol(Framework)

    # Validate/create necessary directories
    if validateAdapterDirs():

        if testConnection == 'true':
            success = testRemedyAtriumConnection(CONTEXT, testConnNameSpace, testConnClass)
            if not success:
                logger.warnException(CONNECTION_FAILED)
                raise Exception, CONNECTION_FAILED
                return
            else:
                logger.debug("Test connection was successful")
                return

        # Get add/update result objects from the Framework
        addResult     = Framework.getDestinationAttribute('addResult')
        updateResult  = Framework.getDestinationAttribute('updateResult')
        deleteResult  = Framework.getDestinationAttribute('deleteResult')

        # Process the XML results and push to Remedy/Atrium
        addStatus     = processInboundXml("add",    addResult,    CONTEXT, debugMode, smartUpdateIgnoreFieldsList, sortCSVFieldsList)
        updateStatus  = processInboundXml("update", updateResult, CONTEXT, debugMode, smartUpdateIgnoreFieldsList, sortCSVFieldsList)
        deleteStatus  = processInboundXml("delete", deleteResult, CONTEXT, debugMode, smartUpdateIgnoreFieldsList, sortCSVFieldsList)

    f = open(idCachePath, 'w')
    for mamId in id_cache.keys():
        atriumId = id_cache[mamId]
        f.write('%s:%s\n' % (mamId, atriumId))
    f.close()
Exemplo n.º 46
0
def _discoverRegionsWithZones(service):
    r'@types: AmazonEC2 -> list(aws.Region)'
    logger.info('Discover REGIONS and ZONES')
    discoverer = Ec2Discoverer(service)
    regionByName = {}
    try:
        regionByName = _applyMapping(aws.Region.getName,
                                     discoverer.getRegions())
    except JException, je:
        logger.warnException("Failed to discover regions: %s" % je)
Exemplo n.º 47
0
def __getFileLastModificationTimeByOsType(shell, fileName, osType):
    if osType and __LAST_UPDATE_TIME_HANDLERS.has_key(osType):
        handlers = __LAST_UPDATE_TIME_HANDLERS[osType]
        for handler in handlers:
            try:
                return handler(shell, fileName)
            except:
                logger.warnException("Failed getting last modification time for file '%s'\n" % fileName)
    else:
        raise ValueError("Unknown osType %s" % osType)
Exemplo n.º 48
0
 def process(self, context):
     CentralComponentPlugin.process(self, context)
     # discover attribute `enque/server/replication` in profile
     shell = context.client
     is_replicated = None
     try:
         is_replicated = _get_enqueue_replicated_flag(shell, self._pf_path)
         is_replicated = bool(is_replicated)
     except (JException, Exception), e:
         logger.warnException(str(e))
Exemplo n.º 49
0
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)
Exemplo n.º 50
0
 def getProtocolProperty(self, protocol, propertyName, defaultValue=None):
     ''' Get protocol property or default value if failed to get property
     @types: ProtocolObject, str, Object -> Object
     '''
     try:
         value = protocol.getProtocolAttribute(propertyName)
     except:
         logger.warnException('Failed to get property %s in credentials %s' % (propertyName, protocol))
         value = defaultValue
     return value
Exemplo n.º 51
0
def executeCommand(shell, command):
    try:
        for preffix in virshPathList:
            output = shell.execCmd('%s%s' % (preffix, command))
            if output and shell.getLastCmdReturnCode() == 0:
                if output.find('No results') == -1:
                    return output
        raise ValueError, "Failed to execute command: %s" % command
    except:
        logger.warnException('')
        raise ValueError, "Failed to execute command: %s" % command
Exemplo n.º 52
0
def _discoverBasedOnProfiles(sapUtils, oshPerInstance, system, systemOsh, discoverSapProfiles):
    profiles_result = None
    profiles_warning = None
    
    try:
        profiles_result = _discoverBasedOnProfilesUnsafe(sapUtils, oshPerInstance, system, systemOsh, discoverSapProfiles)
    except SapSystemInconsistentDataException:
        raise flow.DiscoveryException('SAP System Name in triggered data is different from the one provided by destination. Assuming false trigger. No Topology will be reported.')
    except (Exception, JException), e:
        profiles_warning = '"Failed to discover profiles"'
        logger.warnException("%s. %s" % (profiles_warning, e))
Exemplo n.º 53
0
 def _parseLocation(self, location, parseRuleContexts):
     if location:
         expression = Expression(location)
         expression.parse(parseRuleContexts)
         try:
             parsedLocation = expression.evaluate()
             return parsedLocation
         except:
             logger.warnException(
                 " ... Failed to parse location of config file: %s" %
                 location)
Exemplo n.º 54
0
def discover_profiles(sap_utils):
    '''
    @return: default profile pair (path and content) and list of pairs of
            instance profiles
    @types: SapUtils -> tuple[tuple[str, str]?, list[tuple[str, str]]]
    '''
    try:
        profiles = get_profiles(sap_utils)
        default_pfs, other_pfs = partition(is_default_pf, profiles)
        return first(default_pfs), other_pfs
    except (Exception, JException), e:
        logger.warnException("Failed to discover profiles. %s" % e)