Esempio n. 1
0
def getInformationFromListeners(client, procToPortDict, dbInstanceDict):
	shell = ShellUtils(client)
	env = oracle_shell_utils.getEnvConfigurator(shell)
	is_fully_discovered = 1
	for pid in procToPortDict.keys():
		processName = (procToPortDict[pid])[dbconnect_utils.PROCESSNAME_INDEX].lower()
		processPath = (procToPortDict[pid])[dbconnect_utils.PATH_INDEX]
		if re.search('tnslsnr', processName) or re.search('tnslistener', processName):
			logger.debug('Found listener with path "%s"' % processPath)
			env.setOracleHomeEnvVar(processPath)
			m = re.match(r"(.+)[\\\/]+tns.*", processPath)
			if m:
				output = shell.execCmd('%s/lsnrctl status' % m.group(1))
				if not(output and shell.getLastCmdReturnCode() == 0):
					is_fully_discovered = 0
#dbDict[sidFound] = ['oracle', tnslsnrPort, ipAddress, installPath, version, statusFlag]
				ip_port, service_instance, version = parseListenerOutput(output)
				for service, instance in service_instance:
					ip = None
					port = None
					if ip_port:
						ip, port = ip_port[0]
					details = dbInstanceDict.get(instance, [])
					if details:
						#instance already found previously
						if details[1] == dbconnect_utils.UNKNOWN:
							details[1] = port
						if details[2] == dbconnect_utils.UNKNOWN:
							details[2] = ip
						details[4] = version
						dbInstanceDict[instance] = details
					else:
						dbInstanceDict[instance] = ['oracle', port, ip, m.group(1), version, dbconnect_utils.UNKNOWN]
	return is_fully_discovered
Esempio n. 2
0
class ShellWithException(object):
    def __init__(self, client):
        self.__shell = ShellUtils(client)

    def __getattr__(self, name):
        return getattr(self.__shell, name)

    def execCmd(self, command, msg):
        output = self.__shell.execCmd(command).strip()
        if self.__shell.getLastCmdReturnCode() != 0 or not output:
            raise DiscoveryException(msg + (' (%s)' % command))
        return output
class ShellWithException(object):
    def __init__(self, client):
        self.__shell = ShellUtils(client)

    def __getattr__(self, name):
        return getattr(self.__shell, name)

    def execCmd(self, command, msg):
        output = self.__shell.execCmd(command).strip()
        if self.__shell.getLastCmdReturnCode() != 0 or not output:
            raise DiscoveryException(msg + (' (%s)' % command))
        return output
def DiscoveryMain(Framework):

	# Create our dynamic SSH credential entry	
	sshCredOSH = ObjectStateHolder('sshprotocol')
	sshCredOSH.setStringAttribute('sshprotocol_authmode','password')
	sshCredOSH.setStringAttribute('protocol_username','root')

	# Enter a real password here instead of <YOUR PASSWORD HERE> string
	sshCredOSH.setBytesAttribute('protocol_password', '<YOUR PASSWORD HERE>')
	
	# List of required attributes to create SQL credential:
	# protocol name - sqlprotocol
	# protocol_port (integer)
	# sqlprotocol_dbname (string) - for use with  db2
	# sqlprotocol_dbsid (string) - for use with oracle, MicrosoftSQLServerNTLM, 
	# sqlprotocol_dbtype (db_types) - can be one of the following: 
	# 	MicrosoftSQLServer, db2, Sybase, oracle, MicrosoftSQLServerNTLM
	
	# List of required attributes to create NTCMD credential:
	# protocol name - ntadminprotocol
	# ntadminprotocol_ntdomain (string) - Windows Domain name

	credentialId = Framework.createDynamicCredential(sshCredOSH)


	# Use our Dynamic credential in order to connect to the remote machine
	client = Framework.createClient(credentialId)
	
	# Create shellUtils
	shellUtils = ShellUtils(client)
	
	# Execute some command
	shellUtils.execCmd('uname -a')


	# Explicitly Release all our used resources
	shellUtils.closeClient()
	Framework.releaseDynamicCredential(credentialId)
def DiscoveryMain(Framework):

    # Create our dynamic SSH credential entry
    sshCredOSH = ObjectStateHolder('sshprotocol')
    sshCredOSH.setStringAttribute('sshprotocol_authmode', 'password')
    sshCredOSH.setStringAttribute('protocol_username', 'root')

    # Enter a real password here instead of <YOUR PASSWORD HERE> string
    sshCredOSH.setBytesAttribute('protocol_password', '<YOUR PASSWORD HERE>')

    # List of required attributes to create SQL credential:
    # protocol name - sqlprotocol
    # protocol_port (integer)
    # sqlprotocol_dbname (string) - for use with  db2
    # sqlprotocol_dbsid (string) - for use with oracle, MicrosoftSQLServerNTLM,
    # sqlprotocol_dbtype (db_types) - can be one of the following:
    # 	MicrosoftSQLServer, db2, Sybase, oracle, MicrosoftSQLServerNTLM

    # List of required attributes to create NTCMD credential:
    # protocol name - ntadminprotocol
    # ntadminprotocol_ntdomain (string) - Windows Domain name

    credentialId = Framework.createDynamicCredential(sshCredOSH)

    # Use our Dynamic credential in order to connect to the remote machine
    client = Framework.createClient(credentialId)

    # Create shellUtils
    shellUtils = ShellUtils(client)

    # Execute some command
    shellUtils.execCmd('uname -a')

    # Explicitly Release all our used resources
    shellUtils.closeClient()
    Framework.releaseDynamicCredential(credentialId)