Exemplo n.º 1
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    clientId = Framework.getDestinationAttribute('CLIENT_ID')
    clientClass = Framework.getDestinationAttribute('CLIENT_CLASS')
    accDatabaseIds = Framework.getTriggerCIDataAsList('ACC_DB_ID')
    accDatabaseClasses = Framework.getTriggerCIDataAsList('ACC_DB_CLASS')
    serverIds = Framework.getTriggerCIDataAsList('SERVER_ID')
    context = Framework.getDestinationAttribute('CONTEXT')
    SCPId = Framework.getDestinationAttribute('id')

    serverIdsHaveLink = Framework.getTriggerCIDataAsList('SERVER_ID_HAVE_LINK')
    serverIdsShouldHaveLink = Framework.getTriggerCIDataAsList(
        'SERVER_ID_SHOULD_HAVE_LINK')
    serverClassesHaveLink = Framework.getTriggerCIDataAsList(
        'SERVER_CLASS_HAVE_LINK')

    acclinks = 0
    index = 0
    logger.debug("Try to create dependency using database name: ", context)
    for accDatabaseId in accDatabaseIds:
        if accDatabaseId and accDatabaseId != clientId:
            accDatabaseClass = accDatabaseClasses[index]
            logger.debug("Creating CP link to database: ", accDatabaseId)
            OSHVResult.addAll(
                scp.createCPLink(clientId, clientClass, accDatabaseId,
                                 accDatabaseClass, SCPId, context))
            acclinks += 1
        index += 1

    if acclinks == 0:
        logger.debug(
            "No accurate dependency found, using port to do dependency")
        for serverId in serverIds:
            if serverId and serverId != clientId:
                logger.debug("creating cp-link for ci:", serverId)
                OSHVResult.addAll(
                    scp.createCPLink(clientId, clientClass, serverId,
                                     'running_software', SCPId, context))

    logger.debug("check if there is cp link need to be deleted")
    clientOsh = ObjectStateHolder(
        clientClass, CmdbObjectID.Factory.restoreObjectID(clientId))
    scp.deleteDependencies(Framework, clientOsh, serverIdsHaveLink,
                           serverIdsShouldHaveLink, serverClassesHaveLink)

    return OSHVResult
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    ## Write implementation to return new result CIs here...
    clientId = Framework.getDestinationAttribute('CLIENT_ID')
    clientClass = Framework.getDestinationAttribute('CLIENT_CLASS')
    serverIds = Framework.getTriggerCIDataAsList('SERVER_ID')
    serverClasses = Framework.getTriggerCIDataAsList('SERVER_CLASS')
    scpId = Framework.getDestinationAttribute('id')
    serverIdsHaveLink = Framework.getTriggerCIDataAsList('SERVER_ID_HAVE_LINK')
    serverIdsShouldHaveLink = Framework.getTriggerCIDataAsList('SERVER_ID_SHOULD_HAVE_LINK')
    serverClassesHaveLink = Framework.getTriggerCIDataAsList('SERVER_CLASS_HAVE_LINK')

    clientOsh = ObjectStateHolder(clientClass, clientId)
    OSHVResult.add(clientOsh)
    if Framework.getDestinationAttribute('CLIENT_APPLICATION_ID'):
        buildClientOsh(Framework, clientOsh)

    index = -1
    processed = set()
    reference = buildReferenceString(Framework)
    for serverId in serverIds:
        index += 1
        if serverId:
            if serverId in processed:
                logger.debug('Ignore duplication link for id:', serverId)
                continue
            processed.add(serverId)
            if serverId == clientId:
                logger.debug('Ignore self link from id:', serverId)
                continue
            logger.debug("creating cp-link for ci:", serverId)
            serverClass = serverClasses[index] or 'running_software'
            serverOsh = ObjectStateHolder(serverClass, serverId)
            OSHVResult.add(serverOsh)
            OSHVResult.addAll(scp.createCPLinkByOsh(clientOsh, serverOsh, scpId, reference))
            if clientClass == 'business_application':
                containmentLink = modeling.createLinkOSH('containment', clientOsh, serverOsh)
                OSHVResult.add(containmentLink)

    logger.debug("check if there is cp link need to be deleted")

    scp.deleteDependencies(Framework, clientOsh, serverIdsHaveLink, serverIdsShouldHaveLink, serverClassesHaveLink)
    return OSHVResult
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    clientId = Framework.getDestinationAttribute('CLIENT_ID')
    clientClass = Framework.getDestinationAttribute('CLIENT_CLASS')
    accDatabaseIds = Framework.getTriggerCIDataAsList('ACC_DB_ID')
    accDatabaseClasses = Framework.getTriggerCIDataAsList('ACC_DB_CLASS')
    serverIds = Framework.getTriggerCIDataAsList('SERVER_ID')
    context = Framework.getDestinationAttribute('CONTEXT')
    SCPId = Framework.getDestinationAttribute('id')

    serverIdsHaveLink = Framework.getTriggerCIDataAsList('SERVER_ID_HAVE_LINK')
    serverIdsShouldHaveLink = Framework.getTriggerCIDataAsList('SERVER_ID_SHOULD_HAVE_LINK')
    serverClassesHaveLink = Framework.getTriggerCIDataAsList('SERVER_CLASS_HAVE_LINK')

    acclinks = 0
    index = 0
    logger.debug("Try to create dependency using database name: ", context)
    for accDatabaseId in accDatabaseIds:
        if accDatabaseId and accDatabaseId != clientId:
            accDatabaseClass = accDatabaseClasses[index]
            logger.debug("Creating CP link to database: ", accDatabaseId)
            OSHVResult.addAll(scp.createCPLink(clientId, clientClass, accDatabaseId, accDatabaseClass, SCPId, context))
            acclinks += 1
        index += 1

    if acclinks == 0:
        logger.debug("No accurate dependency found, using port to do dependency")
        for serverId in serverIds:
            if serverId and serverId != clientId:
                logger.debug("creating cp-link for ci:", serverId)
                OSHVResult.addAll(scp.createCPLink(clientId, clientClass, serverId, 'running_software', SCPId, context))

    logger.debug("check if there is cp link need to be deleted")
    clientOsh = ObjectStateHolder(clientClass, CmdbObjectID.Factory.restoreObjectID(clientId))
    scp.deleteDependencies(Framework, clientOsh, serverIdsHaveLink, serverIdsShouldHaveLink, serverClassesHaveLink)

    return OSHVResult