コード例 #1
0
def processProtocol(Framework):
    credentials_id = Framework.getDestinationAttribute('credentialsId')
    targetHost = Framework.getDestinationAttribute('host')
    targetPort = Framework.getDestinationAttribute('port')

    targetUser = None
    targetPass = None
    caLibDir = None
    caProtocol = ProtocolDictionaryManager.getProtocolById(credentials_id)
    if caProtocol != None:
        caProtocolName = caProtocol.getProtocolName()
        if isNoneOrEmpty(caProtocolName) or caProtocolName != 'cacmdbprotocol':
            raise Exception, "Protocol [%s] not defined" % caProtocolName
            return 1
        else:
            targetUser = caProtocol.getProtocolAttribute(
                'protocol_username', '')
            targetPass = caProtocol.getProtocolAttribute(
                'protocol_password', '')

    if isNoneOrEmpty(targetUser) or isNoneOrEmpty(targetHost):
        raise Exception, "No username defined. "
        return None
    conn = Connection(targetHost, targetPort, targetUser, targetPass, caLibDir)
    return conn
コード例 #2
0
ファイル: pushToAtrium.py プロジェクト: ddonnelly19/dd-git
def processProtocol(Framework):
    credentials_id    = Framework.getDestinationAttribute('credentialsId')
    targetHost        = Framework.getDestinationAttribute('host')
    targetPort        = Framework.getDestinationAttribute('port')
    if not isNoneOrEmpty(targetPort):
        try:
            targetPort = int(targetPort)
        except:
            targetPort = 0

    targetUser        = None
    targetPass        = None
    timeout           = 30      #seconds
    remedyProtocol    = ProtocolDictionaryManager.getProtocolById(credentials_id)
    if remedyProtocol != None:
        remedyProtocolName = remedyProtocol.getProtocolName()
        if isNoneOrEmpty(remedyProtocolName) or remedyProtocolName != 'remedyprotocol':
            raise Exception, "Protocol [%s] not defined" % remedyProtocolName
            return 1
        else:
            targetUser  = remedyProtocol.getProtocolAttribute('remedyprotocol_user', '')
            targetPass  = remedyProtocol.getProtocolAttribute('remedyprotocol_password', '')
            try:
                timeout = int(remedyProtocol.getProtocolAttribute('protocol_timeout'))
                timeout = timeout / 1000
            except:
                timeout = 30


    if isNoneOrEmpty(targetUser) or isNoneOrEmpty(targetHost):
        raise Exception, "No username and/or target server defined. "
        return None
    CONTEXT = ARServerUser(targetUser, targetPass, "", targetHost, targetPort)
    #CONTEXT.setTimeoutNormal(timeout)
    return CONTEXT
コード例 #3
0
def _nnmServerConnect(credId, ip, Framework):
    r'''@types: str, str, Framework -> Result
    @raise java.lang.Exception on connection failure
    @raise Exception on connection failure
    '''

    protocol = ProtocolDictionaryManager.getProtocolById(credId)

    port = protocol.getProtocolAttribute('nnmprotocol_port')
    username = protocol.getProtocolAttribute('nnmprotocol_user')
    password = protocol.getProtocolAttribute('nnmprotocol_password')
    nnmprotocol = protocol.getProtocolAttribute('nnmprotocol_protocol')

    logger.debug('NNM Check Credentials: Server: %s, Port: %s, Username: %s'\
                                                        % (ip, port, username))

    # try getting 5 node objects for the test
    api = NNM_Integration_Utils.NNMiApi(ip, port, username, password,
                                        "5", "5", nnmprotocol, Framework)
    filters = api.getFilters()
    found = 0
    ndStub = api.getStub(NNM_Integration_Utils.NnmServicesEnum().Node)
    for filter_ in filters:
        allNodesArray = ndStub.getNodes(filter_)
        allNodes = allNodesArray.getItem()
        if allNodes != None:
            found = 1
        else:
            break
    if found:
        logger.debug("Retrieved %s Node Objects" % (len(allNodes)))
    else:
        logger.debug('Did not find any Node objects')

    return Result(True)
コード例 #4
0
def getNnmProtocol(Framework, cmdbServerIp):
    ''' Framework, string -> protocol
    @raise MissingNnmProtocolException in case no NNM protocol is defined
    '''
    credentialsId = Framework.getParameter('credentialsId')
    protocols = []
    if credentialsId:
        protocolObject = ProtocolDictionaryManager.getProtocolById(credentialsId)
        if protocolObject:
            protocols.append(protocolObject)
        else:
            logger.warn("Failed to get Protocol by provided credentialsId")
    else:
        protocols = ProtocolDictionaryManager.getProtocolParameters(NNM_PROTOCOL, cmdbServerIp)

    if not protocols:
        raise MissingNnmProtocolException('NNM Protocol is not defined')

    if len(protocols) > 1:
        logger.warn('More than one set of credentials found, the first one is used')

    return protocols[0]
def createCMDBConnection(i__LocalShell):

    logger.info('************* START createCMDBConnection *************')
    l__HostName = CollectorsParameters.getValue(
        CollectorsParameters.KEY_SERVER_NAME)
    l__HTTPPort = int(
        CollectorsParameters.getValue(
            CollectorsParameters.KEY_SERVER_PORT_HTTP))
    l__HTTPSPort = int(
        CollectorsParameters.getValue(
            CollectorsParameters.KEY_SERVER_PORT_HTTPS))

    l__ProtocolParameters = ProtocolDictionaryManager.getProtocolParameters(
        'genericprotocol', netutils.resolveIP(i__LocalShell, l__HostName))

    l__UserName = ''

    for l__Protocol in l__ProtocolParameters:
        if l__Protocol.getProtocolAttribute(
                'protocol_username') == C__INTEGRATION_USER:
            l__UserName = l__Protocol.getProtocolAttribute('protocol_username')
            l__UserPassword = l__Protocol.getProtocolAttribute(
                'protocol_password')
            break

    if not l__UserName:
        logger.error('Error Username Protocol not initialized')
        return None

    #logger.debug('Accessing uCMDB = ',(l__HostName, l__HTTPPort, l__UserName))
    # try http first
    try:
        logger.debug('Attempting HTTP connection')
        l__Provider = UcmdbServiceFactory.getServiceProvider(
            'http', l__HostName, l__HTTPPort)
    except:
        logger.debug('HTTP connection failed, trying HTTPS')
        UcmdbServiceFactory.initSSL()
        l__Provider = UcmdbServiceFactory.getServiceProvider(
            'https', l__HostName, l__HTTPSPort)

    l__Credentials = l__Provider.createCredentials(l__UserName,
                                                   l__UserPassword)
    l__ClientContext = l__Provider.createClientContext("UD")
    o__UcmdbService = l__Provider.connect(l__Credentials, l__ClientContext)
    logger.info('************* END createCMDBConnection *************')
    return o__UcmdbService
コード例 #6
0
ファイル: pushToAtrium.py プロジェクト: deezeesms/dd-git
def processProtocol(Framework):
    credentials_id = Framework.getDestinationAttribute('credentialsId')
    targetHost = Framework.getDestinationAttribute('host')
    targetPort = Framework.getDestinationAttribute('port')
    if not isNoneOrEmpty(targetPort):
        try:
            targetPort = int(targetPort)
        except:
            targetPort = 0

    targetUser = None
    targetPass = None
    timeout = 30  #seconds
    remedyProtocol = ProtocolDictionaryManager.getProtocolById(credentials_id)
    if remedyProtocol != None:
        remedyProtocolName = remedyProtocol.getProtocolName()
        if isNoneOrEmpty(
                remedyProtocolName) or remedyProtocolName != 'remedyprotocol':
            raise Exception, "Protocol [%s] not defined" % remedyProtocolName
            return 1
        else:
            targetUser = remedyProtocol.getProtocolAttribute(
                'remedyprotocol_user', '')
            targetPass = remedyProtocol.getProtocolAttribute(
                'remedyprotocol_password', '')
            try:
                timeout = int(
                    remedyProtocol.getProtocolAttribute('protocol_timeout'))
                timeout = timeout / 1000
            except:
                timeout = 30

    if isNoneOrEmpty(targetUser) or isNoneOrEmpty(targetHost):
        raise Exception, "No username and/or target server defined. "
        return None
    CONTEXT = ARServerUser(targetUser, targetPass, "", targetHost, targetPort)
    #CONTEXT.setTimeoutNormal(timeout)
    return CONTEXT
コード例 #7
0
def processProtocol(Framework):
    credentials_id    = Framework.getDestinationAttribute('credentialsId')
    targetHost        = Framework.getDestinationAttribute('host')
    targetPort        = Framework.getDestinationAttribute('port')

    targetUser        = None
    targetPass        = None
    caLibDir          = None
    caProtocol        = ProtocolDictionaryManager.getProtocolById(credentials_id)
    if caProtocol != None:
        caProtocolName = caProtocol.getProtocolName()
        if isNoneOrEmpty(caProtocolName) or caProtocolName != 'cacmdbprotocol':
            raise Exception, "Protocol [%s] not defined" % caProtocolName
            return 1
        else:
            targetUser = caProtocol.getProtocolAttribute('protocol_username', '')
            targetPass = caProtocol.getProtocolAttribute('protocol_password', '')

    if isNoneOrEmpty(targetUser) or isNoneOrEmpty(targetHost):
        raise Exception, "No username defined. "
        return None
    conn = Connection(targetHost, targetPort, targetUser, targetPass, caLibDir)
    return conn
コード例 #8
0
ファイル: pushDBScript.py プロジェクト: deezeesms/dd-git
def DiscoveryMain(Framework):

    addResult = Framework.getTriggerCIData('addResult')
    updateResult = Framework.getTriggerCIData('updateResult')
    deleteResult = Framework.getTriggerCIData('deleteResult')
    addRefResult = Framework.getTriggerCIData('referencedAddResult')
    updateRefResult = Framework.getTriggerCIData('referencedUpdateResult')
    deleteRefResult = Framework.getTriggerCIData('referencedDeleteResult')


    logger.info('addResult: ')
    logger.info(addResult)
    logger.info('updateResult: ')
    logger.info(updateResult)
    logger.info('deleteResult: ')
    logger.info(deleteResult)
    saxBuilder = SAXBuilder()
    addXml = saxBuilder.build(StringReader(addResult))
    updateXml = saxBuilder.build(StringReader(updateResult))
    deleteXml = saxBuilder.build(StringReader(deleteResult))
    addRefXml = saxBuilder.build(StringReader(addRefResult))
    updateRefXml = saxBuilder.build(StringReader(updateRefResult))
    deleteRefXml = saxBuilder.build(StringReader(deleteRefResult))

    objectMappings = HashMap()
    linkMappings = HashMap()

    #The update status is used to report status of CIs and Links.
    updateStatus = ReplicationActionDataFactory.createUpdateStatus();

    credentialsId = str(Framework.getTriggerCIData('credentialsId'))
    serverName = Framework.getTriggerCIData('ip_address')
    port = Integer.valueOf(Framework.getTriggerCIData('port'))
    customerId = Framework.getTriggerCIData('customerId')
    isTestConnection = Framework.getTriggerCIData('testConnection')
    protocol = ProtocolDictionaryManager.getProtocolById(credentialsId)
    userName = protocol.getProtocolAttribute('protocol_username')
    password = protocol.getProtocolAttribute('protocol_password')
    dbType = Framework.getTriggerCIData('dbtype')

    conn = None
    if(dbType == 'Oracle'):
        #The SID is under Schema Name / SID in the integration point parameters.
        sid = Framework.getTriggerCIData('schemaName')
        conn = createOracleConnection(serverName, port, sid, userName, password)
    elif(dbType == 'SQLServer'):
        schemaName = Framework.getTriggerCIData('schemaName')
        conn = createSQLServerConnection(serverName, port, schemaName,userName, password)

    client = SQLClient(conn)

    allChildren = addXml.getRootElement().getChild('data')
    doAction(client, allChildren, objectMappings, linkMappings, addRefXml, ADD, updateStatus)

    allChildren = updateXml.getRootElement().getChild('data')
    doAction(client, allChildren, objectMappings, linkMappings, updateRefXml, UPDATE, updateStatus)

    allChildren = deleteXml.getRootElement().getChild('data')
    doAction(client, allChildren, objectMappings, linkMappings, deleteRefXml, DELETE, updateStatus)

    client.closeConnection()

    result = DataPushResultsFactory.createDataPushResults(objectMappings, linkMappings, updateStatus);
    return result
コード例 #9
0
 def __getProtocol(self):
     return ProtocolDictionaryManager.getProtocolById(self.credentialsId)
コード例 #10
0
 def __getProtocol(self):
     return ProtocolDictionaryManager.getProtocolById(self.__credentialsId)
コード例 #11
0
ファイル: pushDBScript.py プロジェクト: ddonnelly19/dd-git
def DiscoveryMain(Framework):

    addResult = Framework.getTriggerCIData("addResult")
    updateResult = Framework.getTriggerCIData("updateResult")
    deleteResult = Framework.getTriggerCIData("deleteResult")
    addRefResult = Framework.getTriggerCIData("referencedAddResult")
    updateRefResult = Framework.getTriggerCIData("referencedUpdateResult")
    deleteRefResult = Framework.getTriggerCIData("referencedDeleteResult")

    logger.info("addResult: ")
    logger.info(addResult)
    logger.info("updateResult: ")
    logger.info(updateResult)
    logger.info("deleteResult: ")
    logger.info(deleteResult)
    saxBuilder = SAXBuilder()
    addXml = saxBuilder.build(StringReader(addResult))
    updateXml = saxBuilder.build(StringReader(updateResult))
    deleteXml = saxBuilder.build(StringReader(deleteResult))
    addRefXml = saxBuilder.build(StringReader(addRefResult))
    updateRefXml = saxBuilder.build(StringReader(updateRefResult))
    deleteRefXml = saxBuilder.build(StringReader(deleteRefResult))

    objectMappings = HashMap()
    linkMappings = HashMap()

    # The update status is used to report status of CIs and Links.
    updateStatus = ReplicationActionDataFactory.createUpdateStatus()

    credentialsId = str(Framework.getTriggerCIData("credentialsId"))
    serverName = Framework.getTriggerCIData("ip_address")
    port = Integer.valueOf(Framework.getTriggerCIData("port"))
    customerId = Framework.getTriggerCIData("customerId")
    isTestConnection = Framework.getTriggerCIData("testConnection")
    protocol = ProtocolDictionaryManager.getProtocolById(credentialsId)
    userName = protocol.getProtocolAttribute("protocol_username")
    password = protocol.getProtocolAttribute("protocol_password")
    dbType = Framework.getTriggerCIData("dbtype")

    conn = None
    if dbType == "Oracle":
        # The SID is under Schema Name / SID in the integration point parameters.
        sid = Framework.getTriggerCIData("schemaName")
        conn = createOracleConnection(serverName, port, sid, userName, password)
    elif dbType == "SQLServer":
        schemaName = Framework.getTriggerCIData("schemaName")
        conn = createSQLServerConnection(serverName, port, schemaName, userName, password)

    client = SQLClient(conn)

    allChildren = addXml.getRootElement().getChild("data")
    doAction(client, allChildren, objectMappings, linkMappings, addRefXml, ADD, updateStatus)

    allChildren = updateXml.getRootElement().getChild("data")
    doAction(client, allChildren, objectMappings, linkMappings, updateRefXml, UPDATE, updateStatus)

    allChildren = deleteXml.getRootElement().getChild("data")
    doAction(client, allChildren, objectMappings, linkMappings, deleteRefXml, DELETE, updateStatus)

    client.closeConnection()

    result = DataPushResultsFactory.createDataPushResults(objectMappings, linkMappings, updateStatus)
    return result
コード例 #12
0
def DiscoveryMain(Framework):
    # Prepare the maps to store the mappings of IDs
    objectMappings = HashMap()
    linkMappings = HashMap()
    try:
        ucmdbUpdateResult = None
        mamIdToSysIdMap = HashMap() #Stores mapping between UCMDB mamId to ServiceNow sys_id

        logger.debug('========================================================')
        logger.debug('Starting Push to Service-Now...')


        credentialsId = str(Framework.getDestinationAttribute('credentialsId'))
        credential = ProtocolDictionaryManager.getProtocolById(credentialsId)
        username = credential.getProtocolAttribute('protocol_username')
        password = credential.getProtocolAttribute('protocol_password')

        host = Framework.getDestinationAttribute('ServiceNowDomain') or 'service-now.com'
        protocol = Framework.getDestinationAttribute('protocol') or 'https'
        if protocol == 'http':
            port = Framework.getDestinationAttribute('port') or '80'
        else:
            port = Framework.getDestinationAttribute('port') or '443'
        instance = Framework.getDestinationAttribute('ServiceNowInstance') or 'demo'
        proxyServer = Framework.getDestinationAttribute('ProxyServer') or None
        proxyPort = Framework.getDestinationAttribute('ProxyPort') or None
        importSetsInUse = Framework.getDestinationAttribute('ImportSetsInUse') or 'false'

        insertMultiple = Framework.getDestinationAttribute('InsertMultiple') or 'false'
        insertMultipleBulkSize = Framework.getDestinationAttribute('InsertMultipleBulkSize') or '50'
        retryCount = Framework.getDestinationAttribute('RetryCount') or '3'
        retryDelaySeconds = Framework.getDestinationAttribute('RetryDelaySeconds') or '5'
        global  IS_INSERT_MULTIPLE, INSERT_MULTIPLE_BULK_SIZE, RETRY_COUNT, RETRY_DELAY_SECONDS, FAIL_BULK
        failBulk = Framework.getDestinationAttribute('FailBulk') or 'true'
        FAIL_BULK = failBulk == 'true'
        IS_INSERT_MULTIPLE = insertMultiple == 'true'
        INSERT_MULTIPLE_BULK_SIZE = int (insertMultipleBulkSize)
        RETRY_COUNT = int (retryCount)
        RETRY_DELAY_SECONDS = int (retryDelaySeconds)
        logger.debug('Parameters: IS_INSERT_MULTIPLE:%s, INSERT_MULTIPLE_BULK_SIZE:%s, RETRY_COUNT:%s, RETRY_DELAY_SECONDS:%s'
                     % (INSERT_MULTIPLE_BULK_SIZE, INSERT_MULTIPLE_BULK_SIZE, RETRY_COUNT, RETRY_DELAY_SECONDS))
        debugPrint(1, '[DiscoveryMain] Service-Now URL: <%s://%s.%s:%s>, using proxy <%s:%s>' % (protocol, instance, host, port, proxyServer, proxyPort))

        ## Are Service Now Web Service Import Sets in use?  
        importSetUse = 0
        if importSetsInUse and importSetsInUse.lower().strip() in ['yes', 'y', '1', 'true']:
            importSetUse = 1

        #Connection parameter to ServiceNow
        SNConnPropMap = HashMap()
        SNConnPropMap.put('host', host)
        SNConnPropMap.put('port', port)
        SNConnPropMap.put('instance', instance)
        SNConnPropMap.put('protocol', protocol)
        SNConnPropMap.put('username', username)
        SNConnPropMap.put('password', password)
        SNConnPropMap.put('proxyServer', proxyServer)
        SNConnPropMap.put('proxyPort', proxyPort)

        # get add/update/delete result objects from the Framework
        addResult = Framework.getTriggerCIData('addResult')
        updateResult = Framework.getTriggerCIData('updateResult')
        deleteResult = Framework.getTriggerCIData('deleteResult')

        debugPrint(3, '****************************************************************')
        debugPrint(3, '************************* addResult ****************************')
        debugPrint(3, addResult)
        debugPrint(3, '****************************************************************')
        debugPrint(3, '************************* updateResult *************************')
        debugPrint(3, updateResult)
        debugPrint(3, '****************************************************************')
        debugPrint(3, '************************* deleteResult *************************')
        debugPrint(3, deleteResult)
        debugPrint(3, '****************************************************************')

        saxBuilder = SAXBuilder()
        addXml = saxBuilder.build(StringReader(addResult))
        updateXml = saxBuilder.build(StringReader(updateResult))
        deleteXml = saxBuilder.build(StringReader(deleteResult))

        proceedToNext = 1

        resultCountMap = HashMap()
        resultCountMap.put('add_ci', 0)
        resultCountMap.put('update_ci', 0)
        resultCountMap.put('delete_ci', 0)
        resultCountMap.put('add_rel', 0)
        resultCountMap.put('update_rel', 0)
        resultCountMap.put('delete_rel', 0)

        if addXml:
            debugPrint(1, '[DiscoveryMain] ========== Process items to add ==========')
            allObjectChildren = addXml.getRootElement().getChild('data').getChild('objects').getChildren('Object')
            proceedToNext = processCIs(allObjectChildren, SNConnPropMap, objectMappings, resultCountMap, mamIdToSysIdMap, importSetUse)

            if proceedToNext:
                allLinkChildren = addXml.getRootElement().getChild('data').getChild('links').getChildren('link')
                processRelations(allLinkChildren, SNConnPropMap, linkMappings, resultCountMap, mamIdToSysIdMap, importSetUse)
            else:
                Framework.reportError('[DiscoveryMain] Error adding CIs...please check probe logs!')
                return ucmdbUpdateResult
        else:
            logger.info("[DiscoveryMain] No data to add")

        if proceedToNext:
            if updateXml:
                debugPrint(1, '[DiscoveryMain] ========== Process updated items ==========')
                allObjectChildren = updateXml.getRootElement().getChild('data').getChild('objects').getChildren('Object')
                processCIs(allObjectChildren, SNConnPropMap, objectMappings, resultCountMap, mamIdToSysIdMap, importSetUse)

                allLinkChildren = updateXml.getRootElement().getChild('data').getChild('links').getChildren('link')
                processRelations(allLinkChildren, SNConnPropMap, linkMappings, resultCountMap, mamIdToSysIdMap, importSetUse)
            else:
                logger.info("[DiscoveryMain] No data to update")

            if deleteXml:
                debugPrint(1, '[DiscoveryMain] ========== Process deleted items ==========')
                allObjectChildren = deleteXml.getRootElement().getChild('data').getChild('objects').getChildren('Object')
                processCIs(allObjectChildren, SNConnPropMap, objectMappings, resultCountMap, mamIdToSysIdMap, importSetUse)

                allLinkChildren = deleteXml.getRootElement().getChild('data').getChild('links').getChildren('link')
                processRelations(allLinkChildren, SNConnPropMap, linkMappings, resultCountMap, mamIdToSysIdMap, importSetUse)
            else:
                logger.info("[DiscoveryMain] No data to delete")


        debugPrint(1, '[DiscoveryMain] --------------------------------------------------------')
        logger.info('[DiscoveryMain] CIs added <%s>, updated <%s>, deleted <%s>' % (resultCountMap.get('add_ci'), resultCountMap.get('update_ci'), resultCountMap.get('delete_ci')))
        logger.info('[DiscoveryMain] Relationships added <%s>, updated <%s>, deleted <%s>' % (resultCountMap.get('add_rel'), resultCountMap.get('update_rel'), resultCountMap.get('delete_rel')))
        debugPrint(1, '[DiscoveryMain] ========================================================')
        debugPrint(5, '[DiscoveryMain] MAPPING: CIs: ', objectMappings, ', links: ', linkMappings)
        logger.debug('Finished Push to Service-Now!')
        logger.debug('========================================================')
    except:
        excInfo = logger.prepareJythonStackTrace('')
        logger.warn('[DiscoveryMain] Exception: <%s>' % excInfo)
        logger.reportError('[DiscoveryMain] Exception: <%s>' % excInfo)
        debugPrint(5, '[DiscoveryMain] MAPPING after exception: CIs: ', objectMappings, ', links: ', linkMappings)

    return DataPushResultsFactory.createDataPushResults(objectMappings, linkMappings)