Administer > RTSM > RTSM Developer Reference > Creating Discovery and Integration Adapters > Developing Jython Adapters > Finding the Correct Credentials (for Connection Adapters)

Finding the Correct Credentials (for Connection Adapters)

An adapter trying to connect to a remote system needs to try all possible credentials. One of the parameters needed when creating a client is the credentials ID. The connection script gains access to possible credential sets and tries them one by one using the Framework.getAvailableProtocols() method. When one credential set succeeds, the adapter reports a CI connection object on the host of this trigger CI (with the credentials ID that matches the IP) to the RTSM. Subsequent adapters can use this connection object CI directly to connect to the credential set (that is, the adapters do not have to try all possible credentials again).

Note Access to sensitive data (passwords, private keys, and so on) is blocked for the following protocol types:

sshprotocol, ntadminprotocol, as400protocol, vmwareprotocol, wmiprotocol, vcloudprotocol, sapjmxprotocol, websphereprotocol, siebelgtwyprotocol, sapprotocol, ldapprotocol, udaprotocol, ntcmdprotocol, snmpprotocol, jbossprotocol, telnetprotocol, powershellprotocol, sqlprotocol, weblogicprotocol

Utilization of these protocol types should be done by using dedicated clients.

The following example shows how to obtain all entries of the SNMP protocol. Note that here the IP is obtained from the Trigger CI data (# Get the Trigger CI data values).

The connection script requests all possible protocol credentials (# Go over all the protocol credentials) and tries them in a loop until one succeeds (resultVector). For details, see the two-phase connect paradigm entry in Separating Adapters.

Example

import logger
import netutils
import sys
import errorcodes
import errorobject
# Java imports
from java.util import Properties
from com.hp.ucmdb.discovery.common import CollectorsConstants
from appilog.common.system.types.vectors import ObjectStateHolderVector
from com.hp.ucmdb.discovery.library.clients import ClientsConsts
from com.hp.ucmdb.discovery.library.scope import DomainScopeManager
TRUE = 1
FALSE = 0
def mainFunction(Framework, isClient, ip_address = None):
	_vector = ObjectStateHolderVector()
	errStr = ''
       ip_domain  = Framework.getDestinationAttribute('ip_domain')
       # Get the Trigger CI data values
       ip_address = Framework.getDestinationAttribute('ip_address')
if (ip_domain == None):
   ip_domain = DomainScopeManager.getDomainByIp(ip_address, None)
protocols = netutils.getAvailableProtocols(Framework, ClientsConsts.SNMP_PROTOCOL_NAME, ip_address, ip_domain)
if len(protocols) == 0:
    errStr = 'No credentials defined for the triggered ip'
    logger.debug(errStr)
    errObj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [ClientsConsts.SNMP_PROTOCOL_NAME], errStr)
    return (_vector, errObj)
connected = 0
# Go over all the protocol credentials
for protocol in protocols:
    client = None
    try:
        try:
            logger.debug('try to get snmp agent for: %s:%s' % (ip_address, ip_domain))
            if (isClient == TRUE):
                properties = Properties()
                properties.setProperty(CollectorsConstants.DESTINATION_DATA_IP_ADDRESS, ip_address)
                properties.setProperty(CollectorsConstants.DESTINATION_DATA_IP_DOMAIN, ip_domain)
                client = Framework.createClient(protocol, properties)
            else:
                properties = Properties()
                properties.setProperty(CollectorsConstants.DESTINATION_DATA_IP_ADDRESS, ip_address)
                client = Framework.createClient(protocol, properties)
            logger.debug('Running test connection queries')
            testConnection(client)
            Framework.saveState(protocol)
            logger.debug('got snmp agent for: %s:%s' % (ip_address, ip_domain))
            isMultiOid = client.supportMultiOid()
            logger.debug('snmp server isMultiOid state=%s' %isMultiOid)
                   client.close()
                   client = None
        except:
            if client != None:
                client.close()
                client = None
            logger.debugException('Unexpected SNMP_AGENT Exception:')
            lastExceptionStr = str(sys.exc_info()[1]).strip()
    finally:
        if client != None:
            client.close()
            client = None
	return (_vector, error)

Parent topic: Create Jython Code