def doDiscovery(Framework, shell, ip, credentialId, codepage, shellName, warningsList, errorsList, uduid = None):
    vector = ObjectStateHolderVector()
    try:
        try:
            languageName = shell.osLanguage.bundlePostfix

            langBund = Framework.getEnvironmentInformation().getBundle('langNetwork', languageName)
                             
            remoteHostnames = dns_resolver.NsLookupDnsResolver(shell).resolve_hostnames(ip)
            remoteHostFqdn = None 
            if remoteHostnames:
                remoteHostFqdn = remoteHostnames[0]
            shellObj = createShellObj(shell, ip, langBund, languageName, codepage, remoteHostFqdn)
            try:
                vector.addAll(discover(shell, shellObj, ip, langBund, Framework, uduid))
            finally:
                # create shell OSH if connection established
                if shellObj and not vector.size():
                    hostOsh = modeling.createHostOSH(ip)
                    shellObj.setContainer(hostOsh)
                    vector.add(shellObj)
        except Exception, ex:
            strException = ex.getMessage()
            errormessages.resolveAndAddToObjectsCollections(strException, shellName, warningsList, errorsList)
        except:
            msg = str(sys.exc_info()[1])
            logger.debugException('')
            errormessages.resolveAndAddToObjectsCollections(msg, shellName, warningsList, errorsList)
Exemplo n.º 2
0
def getShellUtils(Framework, shellName, credentials, ip, codepage,
                  warningsList, errorsList):
    failedPorts = []
    #check which credential is good for the shell:
    client = None
    for credentialId in credentials:
        try:
            port = None
            props = Properties()
            props.setProperty(BaseAgent.ENCODING, codepage)
            props.setProperty(CollectorsConstants.ATTR_CREDENTIALS_ID,
                              credentialId)
            logger.debug('try credential %s' % credentialId)
            client = Framework.createClient(props)
            shellUtils = shellutils.ShellUtils(client, None, shellName)
            if shellUtils:
                return (shellUtils, credentialId)
        except IOException, ioEx:
            strException = str(ioEx.getMessage())
            errormessages.resolveAndAddToObjectsCollections(
                strException, shellName, warningsList, errorsList)
            if client:
                client.close()
            # we failed to connect - add the problematic port to failedPorts list
            if port:
                failedPorts.append(port)
        except (UnsupportedEncodingException, UnsupportedCharsetException), ex:
            strException = str(ex.getClass().getName())
            shouldStop = errormessages.resolveAndAddToObjectsCollections(
                strException, shellName, warningsList, errorsList)
            if client:
                client.close()
            if shouldStop:
                return (None, None)
def getShellUtils(Framework, shellName, credentials, ip, codepage, warningsList, errorsList):
    failedPorts = []
    #check which credential is good for the shell:
    client = None
    for credentialId in credentials:
        try:
            port = None
            props = Properties()
            props.setProperty(BaseAgent.ENCODING, codepage)
            props.setProperty(CollectorsConstants.ATTR_CREDENTIALS_ID, credentialId)
            logger.debug('try credential %s' % credentialId)
            client = Framework.createClient(props)
            shellUtils = shellutils.ShellUtils(client, None, shellName)
            if shellUtils:
                return (shellUtils, credentialId)
        except IOException, ioEx:
            strException = str(ioEx.getMessage())
            errormessages.resolveAndAddToObjectsCollections(strException, shellName, warningsList, errorsList)
            if client:
                client.close()
            # we failed to connect - add the problematic port to failedPorts list
            if port:
                failedPorts.append(port)
        except (UnsupportedEncodingException, UnsupportedCharsetException), ex:
            strException = str(ex.getClass().getName())
            shouldStop = errormessages.resolveAndAddToObjectsCollections(strException, shellName, warningsList, errorsList)
            if client:
                client.close()
            if shouldStop:
                return (None, None)
Exemplo n.º 4
0
def processException(errorsList, warnList, msg = None): 
    excInfo = logger.prepareJythonStackTrace('')
    logger.error('AS400 Discovery Exception: <%s>' % excInfo)
    if msg:
        excInfo = msg
    else:
        excInfo = str(sys.exc_info()[1])
    errormessages.resolveAndAddToObjectsCollections(excInfo, protocolName, warnList, errorsList)
Exemplo n.º 5
0
def createClient(Framework, shellName, credentials, ip, codepage, warningsList,
                 errorsList):
    'Framework, str, list(str), str, str, list(ErrorObject), list(ErrorObject) -> BaseClient or None'
    # this list will contain ports to which we tried to connect, but failed
    # this is done for not connecting to same ports with different credentials
    # and failing because of some IOException...
    failedPorts = []
    client = None
    # check which credential is good for the shell
    str = lambda x: u'%s' % x
    for credentialId in credentials:
        try:
            port = None

            if shellName and shellName != ClientsConsts.NTCMD_PROTOCOL_NAME and shellName != ClientsConsts.DDM_AGENT_PROTOCOL_NAME:
                # get port details - this is for not failing to connect to same port
                # by different credentials
                port = Framework.getProtocolProperty(
                    credentialId, CollectorsConstants.PROTOCOL_ATTRIBUTE_PORT)
                # do not try to connect to same port if we already failed:
                if port in failedPorts:
                    continue
            props = Properties()
            props.setProperty(CollectorsConstants.DESTINATION_DATA_IP_ADDRESS,
                              ip)
            props.setProperty(BaseAgent.ENCODING, codepage)
            props.setProperty(CollectorsConstants.ATTR_CREDENTIALS_ID,
                              credentialId)
            return Framework.createClient(props)
        except IOException, ioEx:
            strException = str(ioEx.getMessage())
            shouldStop = errormessages.resolveAndAddToObjectsCollections(
                strException, shellName, warningsList, errorsList)
            if client:
                client.close()
            # we failed to connect - add the problematic port to failedPorts list
            if port and shouldStop:
                failedPorts.append(port)
        except (UnsupportedEncodingException,
                UnsupportedCharsetException), enEx:
            strException = str(enEx.getClass().getName())
            shouldStop = errormessages.resolveAndAddToObjectsCollections(
                strException, shellName, warningsList, errorsList)
            if client:
                client.close()
            if shouldStop:
                if port:
                    failedPorts.append(port)
                else:
                    return None
Exemplo n.º 6
0
def createClientFromLastState(Framework, lastState, warningsList, errorsList):
    client = None
    shellName = None
    str = lambda x: u'%s' % x
    try:
        shellName = getShellNameOfLastState(Framework, lastState)
        if not shellName:
            logger.debug('No shellname found for credential id '+lastState+'.')
            return None
        return Framework.createClient(lastState)
    except (UnsupportedEncodingException, UnsupportedCharsetException) , enEx:
        strException = str(enEx.getClass().getName())
        errormessages.resolveAndAddToObjectsCollections(strException, shellName, warningsList, errorsList)
        if client:
            client.close()
Exemplo n.º 7
0
def createClientFromLastState(Framework, lastState, warningsList, errorsList):
    client = None
    shellName = None
    str = lambda x: u'%s' % x
    try:
        shellName = getShellNameOfLastState(Framework, lastState)
        if not shellName:
            logger.debug('No shellname found for credential id ' + lastState +
                         '.')
            return None
        return Framework.createClient(lastState)
    except (UnsupportedEncodingException, UnsupportedCharsetException), enEx:
        strException = str(enEx.getClass().getName())
        errormessages.resolveAndAddToObjectsCollections(
            strException, shellName, warningsList, errorsList)
        if client:
            client.close()
Exemplo n.º 8
0
def DiscoveryMain(Framework):
    warningsList = []
    errorsList = []
    vector = ObjectStateHolderVector()
    ip_address = Framework.getDestinationAttribute('ip_address')
    ip_domain = Framework.getDestinationAttribute('ip_domain')
    protocolName = cim.Protocol.DISPLAY

    credentials = netutils.getAvailableProtocols(Framework, cim.Protocol.FULL,
                                                 ip_address, ip_domain)
    credentials = smis_discoverer.getSmisCredentials(credentials, Framework)
    if len(credentials) == 0:
        msg = errormessages.makeErrorMessage(
            protocolName, pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(
            errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolName], msg)
        warningsList.append(errobj)
        logger.debug(msg)

    smisNamespaces = smis_discoverer.getSmisNamespaces(Framework)
    if not smisNamespaces:
        msg = errormessages.makeErrorMessage(protocolName,
                                             "No SMI-S namespaces found")
        errobj = errorobject.createError(
            errorcodes.INTERNAL_ERROR_WITH_PROTOCOL_DETAILS,
            [cim.Protocol.DISPLAY, msg], msg)
        errorsList.append(errobj)
        logger.reportErrorObject(errobj)
        return vector

    for credential in credentials:
        testedNamespace = None
        for namespaceObject in smisNamespaces:
            try:

                testedNamespace = cim_discover.testConnectionWithNamespace(
                    Framework, ip_address, credential, namespaceObject)
                break
            except JException, ex:
                msg = ex.getMessage()
                msg = cim_discover.translateErrorMessage(msg)
                errormessages.resolveAndAddToObjectsCollections(
                    msg, protocolName, warningsList, errorsList)
            except:
Exemplo n.º 9
0
def createClient(Framework, shellName, credentials, ip, codepage, warningsList, errorsList):
    'Framework, str, list(str), str, str, list(ErrorObject), list(ErrorObject) -> BaseClient or None'
    # this list will contain ports to which we tried to connect, but failed
    # this is done for not connecting to same ports with different credentials
    # and failing because of some IOException...
    failedPorts = []
    client = None
    # check which credential is good for the shell
    str = lambda x: u'%s' % x
    for credentialId in credentials:
        try:
            port = None

            if shellName and shellName != ClientsConsts.NTCMD_PROTOCOL_NAME and shellName != ClientsConsts.DDM_AGENT_PROTOCOL_NAME:
                # get port details - this is for not failing to connect to same port
                # by different credentials
                port = Framework.getProtocolProperty(credentialId, CollectorsConstants.PROTOCOL_ATTRIBUTE_PORT)
                # do not try to connect to same port if we already failed:
                if port in failedPorts:
                    continue
            props = Properties()
            props.setProperty(CollectorsConstants.DESTINATION_DATA_IP_ADDRESS, ip)
            props.setProperty(BaseAgent.ENCODING, codepage)
            props.setProperty(CollectorsConstants.ATTR_CREDENTIALS_ID, credentialId)
            return Framework.createClient(props)
        except IOException, ioEx:
            strException = str(ioEx.getMessage())
            shouldStop = errormessages.resolveAndAddToObjectsCollections(strException, shellName, warningsList, errorsList)
            if client:
                client.close()
            # we failed to connect - add the problematic port to failedPorts list
            if port and shouldStop:
                failedPorts.append(port)
        except (UnsupportedEncodingException, UnsupportedCharsetException) , enEx:
            strException = str(enEx.getClass().getName())
            shouldStop = errormessages.resolveAndAddToObjectsCollections(strException, shellName, warningsList, errorsList)
            if client:
                client.close()
            if shouldStop:
                if port:
                    failedPorts.append(port)
                else:
                    return None
Exemplo n.º 10
0
def doDiscovery(Framework,
                shell,
                ip,
                credentialId,
                codepage,
                shellName,
                warningsList,
                errorsList,
                uduid=None):
    vector = ObjectStateHolderVector()
    try:
        try:
            languageName = shell.osLanguage.bundlePostfix

            langBund = Framework.getEnvironmentInformation().getBundle(
                'langNetwork', languageName)

            remoteHostnames = dns_resolver.NsLookupDnsResolver(
                shell).resolve_hostnames(ip)
            remoteHostFqdn = None
            if remoteHostnames:
                remoteHostFqdn = remoteHostnames[0]
            shellObj = createShellObj(shell, ip, langBund, languageName,
                                      codepage, remoteHostFqdn)
            try:
                vector.addAll(
                    discover(shell, shellObj, ip, langBund, Framework, uduid))
            finally:
                # create shell OSH if connection established
                if shellObj and not vector.size():
                    hostOsh = modeling.createHostOSH(ip)
                    shellObj.setContainer(hostOsh)
                    vector.add(shellObj)
        except Exception, ex:
            strException = ex.getMessage()
            errormessages.resolveAndAddToObjectsCollections(
                strException, shellName, warningsList, errorsList)
        except:
            msg = str(sys.exc_info()[1])
            logger.debugException('')
            errormessages.resolveAndAddToObjectsCollections(
                msg, shellName, warningsList, errorsList)
Exemplo n.º 11
0
def mainFunction(Framework):
    warningsList = []
    errorsList = []
    _vector = ObjectStateHolderVector()
    ip_address = Framework.getDestinationAttribute('ip_address')
    macAddress = Framework.getDestinationAttribute('ip_mac_address')
    ip_domain = Framework.getDestinationAttribute('ip_domain')
    host_cmdbid = Framework.getDestinationAttribute('host_cmdbid')
    host_key = Framework.getDestinationAttribute('host_key')
    host_macs = Framework.getTriggerCIDataAsList('mac_addrs')
    ucmdb_version = modeling.CmdbClassModel().version()

    ip_address = __getIpObjectFromDestinationData(ip_address, macAddress)

    credentials = netutils.getAvailableProtocols(Framework, ClientsConsts.WMI_PROTOCOL_NAME, str(ip_address), ip_domain)
    if len(credentials) == 0:
        msg = errormessages.makeErrorMessage(protocolName, pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolName], msg)
        warningsList.append(errobj)
        logger.debug(msg)
        return (_vector, warningsList, errorsList)

    for credential in credentials:
        client = None
        try:
            debug_string = ip_domain + "\\" + str(ip_address)
            props = Properties()
            props.setProperty(CollectorsConstants.DESTINATION_DATA_IP_ADDRESS, str(ip_address))
            logger.debug('try to get wmi agent for: ', debug_string)
            client = Framework.createClient(credential, props)
            logger.debug('got wmi agent for: ', debug_string)

            hostForLinkOSH = modeling.createHostOSH(str(ip_address))

            # create wmi OSH
            wmiOSH = modeling.createWmiOSH(str(ip_address))
            wmiOSH.setAttribute('credentials_id', client.getCredentialId())
            wmiOSH.setContainer(hostForLinkOSH)

            _vector = doWMI(client, wmiOSH, ip_address, ip_domain, hostForLinkOSH, host_cmdbid, host_key, host_macs, ucmdb_version)

            if _vector.size() > 0:
                Framework.saveState(credential)
                del warningsList[:]
                del errorsList[:]
                break
        except Exception, ex:
            strException = str(ex.getMessage())
            shouldStop = errormessages.resolveAndAddToObjectsCollections(strException, protocolName, warningsList, errorsList)
            if shouldStop:
                break
        except:
Exemplo n.º 12
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    protocol = Framework.getDestinationAttribute('Protocol')
    ipList = Framework.getTriggerCIDataAsList('ip_address')
    hostId = Framework.getDestinationAttribute('id')
    hostOSH = modeling.createOshByCmdbId('host', hostId)

    clientShUtils = None
    errorsList = []
    warningsList = []

    #the job triggered on windows with more than one IP, so at least two IP available
    #so we can connect to cluster IP and communicate with some other machine
    #in that case we have to check is connected IP a cluster IP and reconnect by dedicated one
    for ip in ipList:
        try:
            props = Properties()
            props.setProperty(CollectorsConstants.DESTINATION_DATA_IP_ADDRESS,
                              ip)
            client = Framework.createClient(props)
            clientShUtils = shellutils.ShellUtils(client)
            discoveryNLB(clientShUtils, OSHVResult, hostOSH, Framework, ip)
            errorsList = []
            warningsList = []
            break
        except ConnectedToClusterIpException:
            try:
                clientShUtils and clientShUtils.closeClient()
            except:
                logger.debugException("")
                logger.error('Unable to close shell')
            clientShUtils = None
        except NoNlbControlUtilityException, ex:
            logger.reportWarning('No NLB control utility found')
            break
        except JavaException, ex:
            strException = ex.getMessage()
            errormessages.resolveAndAddToObjectsCollections(
                strException, protocol, warningsList, errorsList)
Exemplo n.º 13
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    protocolType = Framework.getParameter('protocolType')
    if protocolType is None:
        raise Exception, 'Mandatory parameter protocolType is not set'

    #find protocols for desired DB type
    acceptedProtocols = []
    protocols = Framework.getAvailableProtocols(
        ClientsConsts.SQL_PROTOCOL_NAME)
    for protocol in protocols:
        protocolDbType = Framework.getProtocolProperty(
            protocol, CollectorsConstants.SQL_PROTOCOL_ATTRIBUTE_DBTYPE, NA)
        if re.match(protocolType, protocolDbType, re.IGNORECASE):
            acceptedProtocols.append(protocol)
    if len(acceptedProtocols) == 0:
        Framework.reportWarning(
            'Protocol not defined or IP out of protocol network range')
        logger.error(
            'Protocol not defined or IP out of protocol network range')
        return OSHVResult

    connectionData = getConnectionData(Framework, protocolType,
                                       acceptedProtocols)
    reportedSids = []
    warningsList = []
    errorsList = []
    for connectionDataItem in connectionData:
        protocolId, ipAddressList, destinationPortList, sidList = connectionDataItem
        logger.debug('Connecting by protocol %s' % protocolId)
        errList = []
        oshVector = connectByProtocol(Framework, protocolId, ipAddressList,
                                      destinationPortList, sidList,
                                      protocolType, reportedSids, errList)
        if oshVector.size() > 0:
            OSHVResult.addAll(oshVector)
        for error in errList:
            if errormessages.resolveAndAddToObjectsCollections(
                    error, ClientsConsts.SQL_PROTOCOL_NAME, warningsList,
                    errorsList):
                break
    reportError = OSHVResult.size() == 0
    if reportError:
        Framework.reportError('Failed to connect using all protocols')
        logger.error('Failed to connect using all protocols')
        reportErrors(errorsList)
        reportErrors(warningsList)
#    else:
#        reportWarnings(errorsList)
#        reportWarnings(warningsList)
    return OSHVResult
Exemplo n.º 14
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    protocol = Framework.getDestinationAttribute('Protocol')
    ipList = Framework.getTriggerCIDataAsList('ip_address')
    hostId = Framework.getDestinationAttribute('id')
    hostOSH = modeling.createOshByCmdbId('host', hostId)

    clientShUtils = None
    errorsList = []
    warningsList= []

    #the job triggered on windows with more than one IP, so at least two IP available
    #so we can connect to cluster IP and communicate with some other machine
    #in that case we have to check is connected IP a cluster IP and reconnect by dedicated one
    for ip in ipList:
        try:
            props = Properties()
            props.setProperty(CollectorsConstants.DESTINATION_DATA_IP_ADDRESS, ip)
            client = Framework.createClient(props)
            clientShUtils = shellutils.ShellUtils(client)
            discoveryNLB(clientShUtils, OSHVResult, hostOSH, Framework, ip)
            errorsList = []
            warningsList= []
            break
        except ConnectedToClusterIpException:
            try:
                clientShUtils and clientShUtils.closeClient()
            except:
                logger.debugException("")
                logger.error('Unable to close shell')
            clientShUtils = None
        except NoNlbControlUtilityException, ex:
            logger.reportWarning('No NLB control utility found')
            break
        except JavaException, ex:
            strException = ex.getMessage()
            errormessages.resolveAndAddToObjectsCollections(strException, protocol, warningsList, errorsList)
Exemplo n.º 15
0
def DiscoveryMain(Framework):
    warningsList = []
    errorsList = []
    vector = ObjectStateHolderVector()
    ip_address = Framework.getDestinationAttribute('ip_address')
    ip_domain = Framework.getDestinationAttribute('ip_domain')
    protocolName = cim.Protocol.DISPLAY
    
    credentials = netutils.getAvailableProtocols(Framework, cim.Protocol.FULL, ip_address, ip_domain)
    credentials = smis_discoverer.getSmisCredentials(credentials, Framework)
    if len(credentials) == 0:
        msg = errormessages.makeErrorMessage(protocolName, pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolName], msg)
        warningsList.append(errobj)
        logger.debug(msg)
    
    smisNamespaces = smis_discoverer.getSmisNamespaces(Framework)
    if not smisNamespaces:
        msg = errormessages.makeErrorMessage(protocolName, "No SMI-S namespaces found")
        errobj = errorobject.createError(errorcodes.INTERNAL_ERROR_WITH_PROTOCOL_DETAILS, [cim.Protocol.DISPLAY, msg], msg)
        errorsList.append(errobj)
        logger.reportErrorObject(errobj)
        return vector
    
    for credential in credentials:
        testedNamespace = None
        for namespaceObject in smisNamespaces:
            try:
    
                testedNamespace = cim_discover.testConnectionWithNamespace(Framework, ip_address, credential, namespaceObject)
                break
            except JException, ex:
                msg = ex.getMessage()
                msg = cim_discover.translateErrorMessage(msg)
                errormessages.resolveAndAddToObjectsCollections(msg, protocolName, warningsList, errorsList)
            except:
Exemplo n.º 16
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    protocolType = Framework.getParameter('protocolType')
    if protocolType is None:
        raise Exception, 'Mandatory parameter protocolType is not set'

    #find protocols for desired DB type
    acceptedProtocols = []
    protocols = Framework.getAvailableProtocols(ClientsConsts.SQL_PROTOCOL_NAME)
    for protocol in protocols:
        protocolDbType = Framework.getProtocolProperty(protocol, CollectorsConstants.SQL_PROTOCOL_ATTRIBUTE_DBTYPE, NA)
        if re.match(protocolType, protocolDbType, re.IGNORECASE):
            acceptedProtocols.append(protocol)
    if len(acceptedProtocols) == 0:
        Framework.reportWarning('Protocol not defined or IP out of protocol network range')
        logger.error('Protocol not defined or IP out of protocol network range')
        return OSHVResult

    connectionData = getConnectionData(Framework, protocolType, acceptedProtocols)
    reportedSids = []
    warningsList = []
    errorsList = []
    for connectionDataItem in connectionData:
        protocolId, ipAddressList, destinationPortList, sidList = connectionDataItem
        logger.debug('Connecting by protocol %s' % protocolId)
        errList = []
        oshVector = connectByProtocol(Framework, protocolId, ipAddressList, destinationPortList, sidList, protocolType, reportedSids, errList)
        if oshVector.size() > 0:
            OSHVResult.addAll(oshVector)
        for error in errList:
            if errormessages.resolveAndAddToObjectsCollections(error, ClientsConsts.SQL_PROTOCOL_NAME, warningsList, errorsList):
                break
    reportError = OSHVResult.size() == 0
    if reportError:
        Framework.reportError('Failed to connect using all protocols')
        logger.error('Failed to connect using all protocols')
        reportErrors(errorsList)
        reportErrors(warningsList)
#    else:
#        reportWarnings(errorsList)
#        reportWarnings(warningsList)
    return OSHVResult
Exemplo n.º 17
0
            try:
                clientShUtils and clientShUtils.closeClient()
            except:
                logger.debugException("")
                logger.error('Unable to close shell')
            clientShUtils = None
        except NoNlbControlUtilityException, ex:
            logger.reportWarning('No NLB control utility found')
            break
        except JavaException, ex:
            strException = ex.getMessage()
            errormessages.resolveAndAddToObjectsCollections(
                strException, protocol, warningsList, errorsList)
        except:
            strException = logger.prepareJythonStackTrace('')
            errormessages.resolveAndAddToObjectsCollections(
                strException, protocol, warningsList, errorsList)
    try:
        clientShUtils and clientShUtils.closeClient()
    except:
        logger.debugException("")
        logger.error('Unable to close shell')

    for errobj in warningsList:
        logger.reportWarningObject(errobj)
    for errobj in errorsList:
        logger.reportErrorObject(errobj)

    if OSHVResult.size() == 0:
        logger.reportWarning('No NLB instances found')

    return OSHVResult
            errormessages.resolveAndAddToObjectsCollections(strException, shellName, warningsList, errorsList)
            if client:
                client.close()
            # we failed to connect - add the problematic port to failedPorts list
            if port:
                failedPorts.append(port)
        except (UnsupportedEncodingException, UnsupportedCharsetException), ex:
            strException = str(ex.getClass().getName())
            shouldStop = errormessages.resolveAndAddToObjectsCollections(strException, shellName, warningsList, errorsList)
            if client:
                client.close()
            if shouldStop:
                return (None, None)
        except Exception, ex:
            strException = str(ex.getMessage())
            shouldStop = errormessages.resolveAndAddToObjectsCollections(strException, shellName, warningsList, errorsList)
            if client:
                client.close()
            if shouldStop:
                return (None, None)
        except:
            if client:
                client.close()
            excInfo = str(sys.exc_info()[1])
            errormessages.resolveAndAddToObjectsCollections(excInfo, shellName,
                                                 warningsList, errorsList)
    return (None, None)


def createShellObj(shellUtils, ip, langBund, language, codePage, hostFqdn=None):
    regGlobalIp = langBund.getString('global_reg_ip')
Exemplo n.º 19
0
def DiscoveryMain(Framework):
    SHELL_CLIENT_PROTOCOLS = _getSupportedShellProtocols(Framework)

    ip = Framework.getDestinationAttribute('ip_address')
    domain = Framework.getDestinationAttribute('ip_domain')
    codepage = Framework.getCodePage()
    useLastState = Framework.getParameter('useLastSuccessConnection')

    vector = ObjectStateHolderVector()
    warningsList = []
    errorsList = []

    # preparing empty dictionary for storing credentials later
    credentialsByType = {}

    # take the latest used credentials if any
    lastState = None
    if useLastState and useLastState.lower() == 'true':
        lastState = Framework.loadState()

    if lastState:
        credentialsByType[None] = [lastState]

    # try to get ip address by mac address from ARP Cache
    macAddress = Framework.getDestinationAttribute('ip_mac_address')
    foundIp = clientdiscoveryutils.getIPAddressOnlyFromMacAddress(macAddress)
    if foundIp:
        ip = foundIp

    # Gather credentials for protocols
    for clientType in SHELL_CLIENT_PROTOCOLS:
        # getting an ordered list of credentials for the given client type and storing them in the credentials dictionary
        protocols = netutils.getAvailableProtocols(Framework, clientType, ip, domain)
        if protocols:
            credentialsByType[clientType] = protocols

    ##########################################################################################################
    ##################################Start Special processing for Universal Discovery Agent##################
    # take Universal Discovery Agent credentials if new Universal Discovery Agent installed on that IP

    connectedDDMAgentCredentials = None
    if useLastState and useLastState.lower() == 'true':
        connectedDDMAgentCredentials = Framework.loadGlobalState(ip)

    client = None
    udaNotAlive = 0

    if connectedDDMAgentCredentials:
        logger.debug('Found global state credentials ', connectedDDMAgentCredentials, ' of installed agent on ip:', ip)
        client = createClient(Framework, ClientsConsts.DDM_AGENT_PROTOCOL_NAME, [connectedDDMAgentCredentials], ip, codepage, warningsList, errorsList)
        # If we are successfully connected
        if client:
            logger.debug('Succeeded to connect with global state credentials ', client.getCredentialId(), ' of installed agent')
            Framework.saveState(client.getCredentialId())
        else:
            logger.debug('Failed to connect with global state credentials ', connectedDDMAgentCredentials, ' on ip:', ip)
            udaNotAlive = 1
            #AgentUtils.clearGlobalState(Framework)
    # only for case where no connection established before
    if not client:
        # checks whether there are credential for specified protocol
        if credentialsByType:
            if lastState:
                client = createClientFromLastState(Framework, lastState, warningsList, errorsList)
                if not client:
                    logger.debug('Failed to create client using last state properties. Will try to connect using other credentials.')
            if not client:
                for clientType in SHELL_CLIENT_PROTOCOLS:
                    credentials = credentialsByType.get(clientType)
                    if credentials:
                        client = createClient(Framework, clientType, credentials, ip, codepage, warningsList, errorsList)
                        if client:
                            warningsList = []
                            errorsList = []
                            # save credentials id for further reuse
                            Framework.saveState(client.getCredentialId())
                            break
        else:
            for shellType in SHELL_CLIENT_PROTOCOLS:
                msg = errormessages.makeErrorMessage(shellType, pattern=errormessages.ERROR_NO_CREDENTIALS)
                errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [shellType], msg)
                warningsList.append(errobj)

    if not client:
        Framework.clearState()
    else:
        # successfully connected, do discovery
        shell = None
        clientType = client.getClientType()

        connectedOSCredentialID = None
        try:
            try:
                shellFactory = shellutils.ShellFactory()
                shell = shellFactory.createShell(client, clientType)

                connectedOSCredentialID = ConnectedOSCredentialFinder.findCredential(Framework, shell, client,
                    errorsList, warningsList)

                # If we got a default value, we just pass None later
                # Else - we need to signal the existing client which can be only UDA by now that it has a credential
                # to take sudo password from, if it needs it
                if (not connectedOSCredentialID
                    or connectedOSCredentialID == ConnectedOSCredentialFinder.NO_CONNECTED_CRED_ID):
                    connectedOSCredentialID = None
                else:
                    try:
                        client.setConnectedShellCredentialID(connectedOSCredentialID)
                    except:
                        logger.warn('Failed to setConnectedShellCredentialID, sudo commands may not work in this run')

                vector.addAll(doDiscovery(Framework, shell, client, ip, codepage, connectedOSCredentialID))
            except (Exception, JException), jex:
                msg = str(jex)
                logger.debugException(msg)
                errormessages.resolveAndAddToObjectsCollections(msg,
                                        clientType, warningsList, errorsList)
        finally:
            if udaNotAlive and client:
                logger.debug('find another shell can be connected. ', shell)
                logger.debug('Removing the connected uda shell because it failed to connect')

                agentOsh = ObjectStateHolder(ClientsConsts.DDM_AGENT_PROTOCOL_NAME)

                agentOsh.setAttribute('application_ip', ip)
                agentOsh.setAttribute('data_name', ClientsConsts.DDM_AGENT_PROTOCOL_NAME)

                #agentOsh.setAttribute('application_port', shell.getPort())
                agentOsh.setContainer(modeling.createHostOSH(ip))
                Framework.deleteObject(agentOsh)
                Framework.flushObjects()

                Framework.clearGlobalState(ip)
            if shell:
                try:
                    shell.closeClient()
                except:
                    errobj = errorobject.createError(errorcodes.CLIENT_NOT_CLOSED_PROPERLY, None, "Client was not closed properly")
                    warningsList.append(errobj)
                    logger.warnException('')
            # close client anyway
            if client and client.close(): pass
            # create shell OSH if connection established but discovery failed
            if not vector.size():
                logger.warn('Discovery failed, though shell object will be created')
                hostOsh = modeling.createHostOSH(ip, filter_client_ip=True)
                if hostOsh:
                    languageName = None
                    langBund = Framework.getEnvironmentInformation().getBundle('langNetwork', languageName)
                    shellOsh = createShellObj(client, client, ip, langBund, languageName, codepage, connectedShellCredId=connectedOSCredentialID)
                    shellOsh.setContainer(hostOsh)

                    vector.add(shellOsh)
                else:
                    logger.warn('Failed to create node and shell since IP is of a Client range type, not enough data for reconciliation.')

    for errobj in warningsList:
        logger.reportWarningObject(errobj)
    for errobj in errorsList:
        logger.reportErrorObject(errobj)

    return vector
Exemplo n.º 20
0
def _getDocument(framework, httpEndpoint):
    address = httpEndpoint.getAddress()
    port = httpEndpoint.getPort()
    document = None
    errors = []
    warnings = []
    protocolName = 'sapjmxprotocol'
    protocolLabel = errormessages.protocolNames[protocolName]
    protocols = framework.getAvailableProtocols(address, protocolName)
    if not protocols:
        msg = errormessages.makeErrorMessage(protocolName,
                                             pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP,
                                         [protocolLabel], msg)
        warnings.append(errobj)
    else:
        for protocol in protocols:
            logger.debug('Using protocol %s' % protocol)

            with _create_client(framework.createClient, 'http',
                                protocol, address, port) as httpClient:
                protocol_type = framework.getDestinationAttribute('ip_service_name')
                if not protocol_type:
                    try:
                        protocol_type = framework.getProtocolProperty(protocol, 'protocol')
                    except:
                        protocol_type = 'http'
                if protocol_type in ('http', 'sap_http'):
                    sapMonitoringCommands = sap_jee_discoverer.SapMonitoringCommandsPlain
                elif protocol_type == 'sap_jmx':
                    sapMonitoringCommands = sap_jee_discoverer.SapMonitoringCommands
                else:
                    sapMonitoringCommands = sap_jee_discoverer.SapMonitoringCommandsHttps
                    
                for sapMonitoringCommand in sapMonitoringCommands:
                    try:
                        cmd = sapMonitoringCommand()
                        urlDomainPart = _getUrlDomainByIp(address)
                        result = cmd.getSystemInfo(urlDomainPart, port) | HttpExecutorCmdlet(httpClient)

                        document = result | command.cmdlet.produceResult
                        if document:
                            return document, [], []
                    except UnauthorizedException, ex:
                        msg = errormessages.makeErrorMessage(protocolName,
                                                 pattern=errormessages.ERROR_HTTP_UNAUTHORIZED)
                        errobj = errorobject.createError(errorcodes.HTTP_UNAUTHORIZED,
                                             [protocolLabel], msg)
                        warnings.append(errobj)

                    except PageNotFoundException, ex:
                        msg = errormessages.makeErrorMessage(protocolName,
                                                 pattern=errormessages.ERROR_HTTP_PAGE_NOT_FOUND)
                        errobj = errorobject.createError(errorcodes.HTTP_PAGE_NOT_FOUND,
                                             [protocolLabel], msg)
                        warnings.append(errobj)

                    except SSLHandshakeException, ex:
                        msg = ex.getMessage()
                        msg = removeIp(msg, ' to ')
                        errobj = errormessages.resolveError(msg, protocolName)
                        warnings.append(errobj)

                    except SAXParseException, ex:
                        msg = errormessages.makeErrorMessage(protocolName,
                                                 pattern=errormessages.ERROR_INVALID_RESPONSE)
                        errobj = errorobject.createError(errorcodes.INVALID_RESPONSE,
                                             [protocolLabel], msg)
                        errors.append(errobj)

                    except (JException, Exception), ex:
                        msg = str(ex)
                        errormessages.resolveAndAddToObjectsCollections(msg,
                                                                        protocolName,
                                                                        errors,
                                                                        warnings)
Exemplo n.º 21
0
    for credential in credentials:
        testedNamespace = None
        for namespaceObject in smisNamespaces:
            try:

                testedNamespace = cim_discover.testConnectionWithNamespace(
                    Framework, ip_address, credential, namespaceObject)
                break
            except JException, ex:
                msg = ex.getMessage()
                msg = cim_discover.translateErrorMessage(msg)
                errormessages.resolveAndAddToObjectsCollections(
                    msg, protocolName, warningsList, errorsList)
            except:
                trace = logger.prepareJythonStackTrace('')
                errormessages.resolveAndAddToObjectsCollections(
                    trace, protocolName, warningsList, errorsList)

        if testedNamespace is not None:
            hostOsh = modeling.createHostOSH(ip_address)
            smisOsh = cim.createCimOsh(ip_address, hostOsh, credential,
                                       smis.CimCategory.SMIS)
            smisOsh.setStringAttribute('application_category', 'Storage')
            vector.add(hostOsh)
            vector.add(smisOsh)
            warningsList = []
            errorsList = []
            break

    if vector.size() <= 0:
        Framework.clearState()
        if (len(warningsList) == 0) and (len(errorsList) == 0):
Exemplo n.º 22
0
def DiscoveryMain(Framework):
    SHELL_CLIENT_PROTOCOLS = _getSupportedShellProtocols(Framework)

    ip = Framework.getDestinationAttribute('ip_address')
    domain = Framework.getDestinationAttribute('ip_domain')
    codepage = Framework.getCodePage()
    useLastState = Framework.getParameter('useLastSuccessConnection')

    vector = ObjectStateHolderVector()
    warningsList = []
    errorsList = []

    # preparing empty dictionary for storing credentials later
    credentialsByType = {}

    # take the latest used credentials if any
    lastState = None
    if useLastState and useLastState.lower() == 'true':
        lastState = Framework.loadState()

    if lastState:
        credentialsByType[None] = [lastState]

    # try to get ip address by mac address from ARP Cache
    macAddress = Framework.getDestinationAttribute('ip_mac_address')
    foundIp = clientdiscoveryutils.getIPAddressOnlyFromMacAddress(macAddress)
    if foundIp:
        ip = foundIp

    # Gather credentials for protocols
    for clientType in SHELL_CLIENT_PROTOCOLS:
        # getting an ordered list of credentials for the given client type and storing them in the credentials dictionary
        protocols = netutils.getAvailableProtocols(Framework, clientType, ip,
                                                   domain)
        if protocols:
            credentialsByType[clientType] = protocols

    ##########################################################################################################
    ##################################Start Special processing for Universal Discovery Agent##################
    # take Universal Discovery Agent credentials if new Universal Discovery Agent installed on that IP

    connectedDDMAgentCredentials = None
    if useLastState and useLastState.lower() == 'true':
        connectedDDMAgentCredentials = Framework.loadGlobalState(ip)

    client = None
    udaNotAlive = 0

    if connectedDDMAgentCredentials:
        logger.debug('Found global state credentials ',
                     connectedDDMAgentCredentials,
                     ' of installed agent on ip:', ip)
        client = createClient(Framework, ClientsConsts.DDM_AGENT_PROTOCOL_NAME,
                              [connectedDDMAgentCredentials], ip, codepage,
                              warningsList, errorsList)
        # If we are successfully connected
        if client:
            logger.debug('Succeeded to connect with global state credentials ',
                         client.getCredentialId(), ' of installed agent')
            Framework.saveState(client.getCredentialId())
        else:
            logger.debug('Failed to connect with global state credentials ',
                         connectedDDMAgentCredentials, ' on ip:', ip)
            udaNotAlive = 1
            #AgentUtils.clearGlobalState(Framework)
    # only for case where no connection established before
    if not client:
        # checks whether there are credential for specified protocol
        if credentialsByType:
            if lastState:
                client = createClientFromLastState(Framework, lastState,
                                                   warningsList, errorsList)
                if not client:
                    logger.debug(
                        'Failed to create client using last state properties. Will try to connect using other credentials.'
                    )
            if not client:
                for clientType in SHELL_CLIENT_PROTOCOLS:
                    credentials = credentialsByType.get(clientType)
                    if credentials:
                        client = createClient(Framework, clientType,
                                              credentials, ip, codepage,
                                              warningsList, errorsList)
                        if client:
                            warningsList = []
                            errorsList = []
                            # save credentials id for further reuse
                            Framework.saveState(client.getCredentialId())
                            break
        else:
            for shellType in SHELL_CLIENT_PROTOCOLS:
                msg = errormessages.makeErrorMessage(
                    shellType, pattern=errormessages.ERROR_NO_CREDENTIALS)
                errobj = errorobject.createError(
                    errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [shellType],
                    msg)
                warningsList.append(errobj)

    if not client:
        Framework.clearState()
    else:
        # successfully connected, do discovery
        shell = None
        clientType = client.getClientType()

        connectedOSCredentialID = None
        try:
            try:
                shellFactory = shellutils.ShellFactory()
                shell = shellFactory.createShell(client, clientType)

                connectedOSCredentialID = ConnectedOSCredentialFinder.findCredential(
                    Framework, shell, client, errorsList, warningsList)

                # If we got a default value, we just pass None later
                # Else - we need to signal the existing client which can be only UDA by now that it has a credential
                # to take sudo password from, if it needs it
                if (not connectedOSCredentialID or connectedOSCredentialID
                        == ConnectedOSCredentialFinder.NO_CONNECTED_CRED_ID):
                    connectedOSCredentialID = None
                else:
                    try:
                        client.setConnectedShellCredentialID(
                            connectedOSCredentialID)
                    except:
                        logger.warn(
                            'Failed to setConnectedShellCredentialID, sudo commands may not work in this run'
                        )

                vector.addAll(
                    doDiscovery(Framework, shell, client, ip, codepage,
                                connectedOSCredentialID))
            except (Exception, JException), jex:
                msg = str(jex)
                logger.debugException(msg)
                errormessages.resolveAndAddToObjectsCollections(
                    msg, clientType, warningsList, errorsList)
        finally:
            if udaNotAlive and client:
                logger.debug('find another shell can be connected. ', shell)
                logger.debug(
                    'Removing the connected uda shell because it failed to connect'
                )

                agentOsh = ObjectStateHolder(
                    ClientsConsts.DDM_AGENT_PROTOCOL_NAME)

                agentOsh.setAttribute('application_ip', ip)
                agentOsh.setAttribute('data_name',
                                      ClientsConsts.DDM_AGENT_PROTOCOL_NAME)

                #agentOsh.setAttribute('application_port', shell.getPort())
                agentOsh.setContainer(modeling.createHostOSH(ip))
                Framework.deleteObject(agentOsh)
                Framework.flushObjects()

                Framework.clearGlobalState(ip)
            if shell:
                try:
                    shell.closeClient()
                except:
                    errobj = errorobject.createError(
                        errorcodes.CLIENT_NOT_CLOSED_PROPERLY, None,
                        "Client was not closed properly")
                    warningsList.append(errobj)
                    logger.warnException('')
            # close client anyway
            if client and client.close(): pass
            # create shell OSH if connection established but discovery failed
            if not vector.size():
                logger.warn(
                    'Discovery failed, though shell object will be created')
                hostOsh = modeling.createHostOSH(ip, filter_client_ip=True)
                if hostOsh:
                    languageName = None
                    langBund = Framework.getEnvironmentInformation().getBundle(
                        'langNetwork', languageName)
                    shellOsh = createShellObj(
                        client,
                        client,
                        ip,
                        langBund,
                        languageName,
                        codepage,
                        connectedShellCredId=connectedOSCredentialID)
                    shellOsh.setContainer(hostOsh)

                    vector.add(shellOsh)
                else:
                    logger.warn(
                        'Failed to create node and shell since IP is of a Client range type, not enough data for reconciliation.'
                    )

    for errobj in warningsList:
        logger.reportWarningObject(errobj)
    for errobj in errorsList:
        logger.reportErrorObject(errobj)

    return vector
Exemplo n.º 23
0
            # create wmi OSH
            wmiOSH = modeling.createWmiOSH(str(ip_address))
            wmiOSH.setAttribute('credentials_id', client.getCredentialId())
            wmiOSH.setContainer(hostForLinkOSH)

            _vector = doWMI(client, wmiOSH, ip_address, ip_domain, hostForLinkOSH, host_cmdbid, host_key, host_macs, ucmdb_version)

            if _vector.size() > 0:
                Framework.saveState(credential)
                del warningsList[:]
                del errorsList[:]
                break
        except Exception, ex:
            strException = str(ex.getMessage())
            shouldStop = errormessages.resolveAndAddToObjectsCollections(strException, protocolName, warningsList, errorsList)
            if shouldStop:
                break
        except:
            trace = logger.prepareJythonStackTrace('')
            errormessages.resolveAndAddToObjectsCollections(trace, protocolName, warningsList, errorsList)
        if client != None:
            client.close()
    if (_vector.size() <= 0):
                Framework.clearState()
                if (len(warningsList) == 0) and (len(errorsList) == 0):
                        msg = errormessages.makeErrorMessage(protocolName, pattern=errormessages.ERROR_GENERIC)
                        logger.debug(msg)
                        errobj = errorobject.createError(errorcodes.INTERNAL_ERROR_WITH_PROTOCOL, [protocolName], msg)
                        errorsList.append(errobj)
    return (_vector, warningsList, errorsList)
Exemplo n.º 24
0
                    except:
                        logger.warn('Failed to setConnectedShellCredentialID, sudo commands may not work in this run')

                logger.debug("Successfully connected, start to do host connection")
                OSHVResult.addAll(doDiscovery(Framework, shell, client, ip, codepage, connectedOSCredentialID,
                                              credentialId, warningsList, errorsList))

                for osh in OSHVResult:
                    if osh.getAttributeValue('host_iscomplete') == 1:
                        logger.debug("found host OSH:", osh)
                        hostOsh = osh

            except (Exception, JException), jex:
                msg = str(jex)
                logger.debugException(msg)
                errormessages.resolveAndAddToObjectsCollections(msg, clientType, warningsList, errorsList)
                #todo: add error message here for asm trouble shooting

        finally:
            if udaNotAlive and client:
                logger.debug('find another shell can be connected. ', shell)
                logger.debug('Removing the connected uda shell because it failed to connect')

                agentOsh = ObjectStateHolder(ClientsConsts.DDM_AGENT_PROTOCOL_NAME)

                agentOsh.setAttribute('application_ip', ip)
                agentOsh.setAttribute('data_name', ClientsConsts.DDM_AGENT_PROTOCOL_NAME)

                #agentOsh.setAttribute('application_port', shell.getPort())
                agentOsh.setContainer(modeling.createHostOSH(ip))
                Framework.deleteObject(agentOsh)
Exemplo n.º 25
0
            if client:
                client.close()
            # we failed to connect - add the problematic port to failedPorts list
            if port:
                failedPorts.append(port)
        except (UnsupportedEncodingException, UnsupportedCharsetException), ex:
            strException = str(ex.getClass().getName())
            shouldStop = errormessages.resolveAndAddToObjectsCollections(
                strException, shellName, warningsList, errorsList)
            if client:
                client.close()
            if shouldStop:
                return (None, None)
        except Exception, ex:
            strException = str(ex.getMessage())
            shouldStop = errormessages.resolveAndAddToObjectsCollections(
                strException, shellName, warningsList, errorsList)
            if client:
                client.close()
            if shouldStop:
                return (None, None)
        except:
            if client:
                client.close()
            excInfo = str(sys.exc_info()[1])
            errormessages.resolveAndAddToObjectsCollections(
                excInfo, shellName, warningsList, errorsList)
    return (None, None)


def createShellObj(shellUtils,
                   ip,
Exemplo n.º 26
0
                logger.debug(
                    "Successfully connected, start to do host connection")
                OSHVResult.addAll(
                    doDiscovery(Framework, shell, client, ip, codepage,
                                connectedOSCredentialID, credentialId,
                                warningsList, errorsList))

                for osh in OSHVResult:
                    if osh.getAttributeValue('host_iscomplete') == 1:
                        logger.debug("found host OSH:", osh)
                        hostOsh = osh

            except (Exception, JException), jex:
                msg = str(jex)
                logger.debugException(msg)
                errormessages.resolveAndAddToObjectsCollections(
                    msg, clientType, warningsList, errorsList)
                #todo: add error message here for asm trouble shooting

        finally:
            if udaNotAlive and client:
                logger.debug('find another shell can be connected. ', shell)
                logger.debug(
                    'Removing the connected uda shell because it failed to connect'
                )

                agentOsh = ObjectStateHolder(
                    ClientsConsts.DDM_AGENT_PROTOCOL_NAME)

                agentOsh.setAttribute('application_ip', ip)
                agentOsh.setAttribute('data_name',
                                      ClientsConsts.DDM_AGENT_PROTOCOL_NAME)
Exemplo n.º 27
0
        except ConnectedToClusterIpException:
            try:
                clientShUtils and clientShUtils.closeClient()
            except:
                logger.debugException("")
                logger.error('Unable to close shell')
            clientShUtils = None
        except NoNlbControlUtilityException, ex:
            logger.reportWarning('No NLB control utility found')
            break
        except JavaException, ex:
            strException = ex.getMessage()
            errormessages.resolveAndAddToObjectsCollections(strException, protocol, warningsList, errorsList)
        except:
            strException = logger.prepareJythonStackTrace('')
            errormessages.resolveAndAddToObjectsCollections(strException, protocol, warningsList, errorsList)
    try:
        clientShUtils and clientShUtils.closeClient()
    except:
        logger.debugException("")
        logger.error('Unable to close shell')

    for errobj in warningsList:
        logger.reportWarningObject(errobj)
    for errobj in errorsList:
        logger.reportErrorObject(errobj)

    if OSHVResult.size() == 0:
        logger.reportWarning('No NLB instances found')

    return OSHVResult