Esempio n. 1
0
    def servicesPorts(self, onlyKnownPorts=1):
        services = self.Framework.getParameter('services')
        if logger.isDebugEnabled():
            logger.debug('Requested services:', services)
        if (services == None) or (len(services) == 0) or (services == '*'):
            if onlyKnownPorts:
                portsInfo = self.knownPortsConfigFile.getTcpPorts()
                services = ''
                delimiter = ''
                for info in portsInfo:
                    services = services + delimiter + str(info.getPortNumber())
                    delimiter = ','
                if len(services) == 0:
                    return services
            else:
                return ''

        names = services.split(',')
        ports = ''
        delimiter = ''
        for name in names:
            portNums = self.knownPortsConfigFile.getPortByName(name)
            if (portNums == None) or (len(portNums) == 0):
                try:
                    portNums = [Integer.parseInt(name)]
                except:
                    logger.debug('Failed to resolve service port number:',
                                 name)
                    continue
            for portNum in portNums:
                ports = ports + delimiter + str(portNum)
                delimiter = ','
        if logger.isDebugEnabled():
            logger.debug('Requested services ports:', ports)
        return ports
Esempio n. 2
0
    def servicesPorts(self, onlyKnownPorts = 1):
        services = self.Framework.getParameter('services')
        if logger.isDebugEnabled():
            logger.debug('Requested services:', services)
        if (services == None) or (len(services) == 0) or (services == '*'):
            if onlyKnownPorts:
                portsInfo = self.knownPortsConfigFile.getTcpPorts()
                services = ''
                delimiter = ''
                for info in portsInfo:
                    services = services + delimiter + str(info.getPortNumber())
                    delimiter = ','
                if len(services) == 0:
                    return services
            else:
                return ''

        names = services.split(',')
        ports = ''
        delimiter = ''
        for name in names:
            portNums = self.knownPortsConfigFile.getPortByName(name)
            if (portNums == None) or (len(portNums) == 0):
                try:
                    portNums = [Integer.parseInt(name)]
                except:
                    logger.debug('Failed to resolve service port number:', name)
                    continue
            for portNum in portNums:
                ports = ports + delimiter + str(portNum)
                delimiter = ','
        if logger.isDebugEnabled():
            logger.debug('Requested services ports:', ports)
        return ports
Esempio n. 3
0
def shouldDiscoverTCP(Framework):
	from com.hp.ucmdb.discovery.probe.services.netlinks.dal import NetLinksSqlDAO
	executionSignaturePrefix = getExecutionSignaturePrefix(Framework)
	executionSignatureParameters = getExecutionSignatureParameters(Framework)
	executionSignature = executionSignaturePrefix + '->' + executionSignatureParameters
	if logger.isDebugEnabled():
		logger.debug('New processes execution signature:', executionSignature)
	oldExecutionSignature = TcpDbUtils.TCP_EXECUTED_JOBS.put(executionSignaturePrefix, executionSignature)
	if logger.isDebugEnabled():
		if oldExecutionSignature != None:
			logger.debug('Previous processes execution signature:', oldExecutionSignature)
	return NetLinksSqlDAO.shouldExecuteQuery(executionSignature) or (oldExecutionSignature == None) or (oldExecutionSignature != executionSignature)
Esempio n. 4
0
def shouldDiscoverTCP(Framework):
    from com.hp.ucmdb.discovery.probe.services.netlinks.dal import NetLinksSqlDAO
    executionSignaturePrefix = getExecutionSignaturePrefix(Framework)
    executionSignatureParameters = getExecutionSignatureParameters(Framework)
    executionSignature = executionSignaturePrefix + '->' + executionSignatureParameters
    if logger.isDebugEnabled():
        logger.debug('New processes execution signature:', executionSignature)
    oldExecutionSignature = TcpDbUtils.TCP_EXECUTED_JOBS.put(
        executionSignaturePrefix, executionSignature)
    if logger.isDebugEnabled():
        if oldExecutionSignature != None:
            logger.debug('Previous processes execution signature:',
                         oldExecutionSignature)
    return NetLinksSqlDAO.shouldExecuteQuery(executionSignature) or (
        oldExecutionSignature
        == None) or (oldExecutionSignature != executionSignature)
def makeCompGrp(cgObj, cgDataRow, appServerOSH):
	attrNum = len(cgObj)
	cgName = cgObj[0]
	cgAlias = cgObj[1]
	cgDesc = ''
	cgEnabled = ''

	#cgRunState = ''
	# these are not must, so don't fail on them
	if attrNum > 2:
		cgDesc = cgObj[2]
	if attrNum > 3:
		cgEnabled = cgObj[3]

	if logger.isDebugEnabled():
		logger.debug('--------------------------------------------------------')
		logger.debug('data_name = ', cgName)
		logger.debug('alias = ', cgAlias)
		logger.debug('desc = ', cgDesc)
		logger.debug('enabled = ', cgEnabled)
		logger.debug('--------------------------------------------------------')

	compGrpOSH = ObjectStateHolder('siebel_comp_grp')
	compGrpOSH.setAttribute('data_name', cgName)
	compGrpOSH.setAttribute('alias', cgAlias)
	compGrpOSH.setAttribute('desc', cgDesc)
	compGrpOSH.setAttribute('enabled', cgEnabled)

	return compGrpOSH
def processSoftware(keys, buffer, hostOSH, OSHVResults, softNameToInstSoftOSH = None):
    '''
    list(str), str, osh, oshVector, map(str, osh) = None -> bool
    '''
    swList = []
    for key in keys:

        softwareName = None
        softwarePath = None
        softwareVer = None
        softwareInstallDate = None
        softwareProductId = None
        softwareProductCode = None
        softwareVendor = None

        m = re.search('\n\s*DisplayName\s+REG_SZ\s+?([^\n]+)', key)
        if(m):
            softwareName = m.group(1).strip()
        else:
            continue
        m = re.search('\n\s*InstallLocation\s+REG_SZ\s+?([^\n]+)', key)
        if(m):
            softwarePath = m.group(1).strip()
        m = re.search('\n\s*DisplayVersion\s+REG_SZ\s+?([^\n]+)', key)
        if(m):
            softwareVer = m.group(1).strip()
        m = re.search('\n\s*InstallDate\s+REG_SZ\s+?([^\n]+)', key)
        if (m):
            softwareInstallDate = m.group(1).strip()
        m = re.search('\n\s*ProductID\s+REG_SZ\s+?([^\n]+)', key)
        if (m) and m.group(1).strip():
            softwareProductId = m.group(1).strip()
        #in case the has a format of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90120000-0011-0000-0000-0000000FF1CE}_PROPLUS_{297857BF-4011-449B-BD74-DB64D182821C}
        #we report 90120000-0011-0000-0000-0000000FF1CE which is a product code of parent software
        m = re.match(r"\\Uninstall\\?[\w\{\[\( ]*([\dabcdefABCDEF]{8}(\-[\dabcdefABCDEF]{4}){3}-[\dabcdefABCDEF]{12}).*\n", key)
        if (m):
            softwareProductCode= m.group(1).strip()
        m = re.search('\n\s*Publisher\s+REG_SZ\s+?([^\n]+)', key)
        if (m):
            softwareVendor = m.group(1).strip()

        if softwareName:
            if ((softwareName in swList) == 0) :
                swList.append(softwareName)
                softwareOSH = hostresource.makeSoftwareOSH(softwareName, softwarePath, softwareVer, hostOSH, softwareInstallDate, softwareProductId, softwareProductCode, softwareVendor)

                if softNameToInstSoftOSH != None:
                    softNameToInstSoftOSH[softwareName] = softwareOSH

                OSHVResults.add(softwareOSH)
    if logger.isDebugEnabled():
        logger.debug('found ', str(OSHVResults.size()), ' software CIs')
        if OSHVResults.size() == 0:
            logger.debug('buffer: ', buffer)

    return 1
Esempio n. 7
0
def getProcesses(client,
                 nameToHostOSH,
                 OSHVResult,
                 schemaName=None,
                 viewSchemaName=None):
    # [queue id] <--> [ list of process OSH ]
    mapIDToOSH = HashMap()
    objs = __assocWithSchemaName(['FND_CONCURRENT_PROCESSES'], schemaName,
                                 viewSchemaName)
    resultSet = client.executeQuery(
        'SELECT CONCURRENT_QUEUE_ID,OS_PROCESS_ID,NODE_NAME FROM %s WHERE PROCESS_STATUS_CODE=\'A\' or PROCESS_STATUS_CODE=\'C\''
        % objs)  #@@CMD_PERMISION sql protocol execution
    while resultSet.next():
        queueID = resultSet.getString(1)
        PID = resultSet.getString(2)
        host = resultSet.getString(3)
        hostNoDomain = host.split('.')[0]
        if logger.isDebugEnabled():
            logger.debug('-------------------------------------------------')
            logger.debug('queueID = ', queueID)
            logger.debug('PID = ', PID)
            logger.debug('host = ', host)
            logger.debug('hostNoDomain = ', hostNoDomain)
            logger.debug('-------------------------------------------------')
        hostOSH = nameToHostOSH.get(host)
        if hostOSH == None:
            hostOSH = nameToHostOSH.get(hostNoDomain)
        if hostOSH != None:
            processOSH = ObjectStateHolder('process')
            processOSH.setAttribute('process_pid', int(PID))
            processOSH.setContainer(hostOSH)
            OSHVResult.add(processOSH)
            processes = mapIDToOSH.get(queueID)
            if processes == None:
                processes = ArrayList()
                mapIDToOSH.put(queueID, processes)
            processes.add(processOSH)
    if logger.isDebugEnabled():
        logger.debug('-------------------------------------------------')
        logger.debug(mapIDToOSH)
        logger.debug('-------------------------------------------------')
    resultSet.close()
    return mapIDToOSH
Esempio n. 8
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ip = Framework.getDestinationAttribute('ip_address')
    sid = Framework.getDestinationAttribute('sid')
    port = Framework.getDestinationAttribute('port')

    hostId = Framework.getDestinationAttribute('hostId')

    if (ip == None) or (ip == 'NA'):
        #checked and pass all IPs of given host
        ips = Framework.getTriggerCIDataAsList('host_ips')
    else:
        ips = [ip]
    for currIP in ips:
        if len(currIP) == 0:
            continue
        logger.debug('Checking sqlserver with no user on ipaddress:', currIP)
        protocols = Framework.getAvailableProtocols(
            currIP, ClientsConsts.SQL_PROTOCOL_NAME)
        for protocol in protocols:
            dbClient = None
            try:
                try:
                    if dbutils.protocolMatch(
                            Framework, protocol, 'microsoftsqlserver', sid,
                            port) or dbutils.protocolMatch(
                                Framework, protocol, 'microsoftsqlserverntlm',
                                sid, port):
                        props = Properties()
                        props.setProperty('ip_address', currIP)
                        dbClient = Framework.createClient(protocol, props)

                        hostOSH = modeling.createOshByCmdbIdString(
                            'host', hostId)
                        oracleOSH = modeling.createDatabaseOSH(
                            'sqlserver', sid, str(dbClient.getPort()),
                            dbClient.getIpAddress(), hostOSH, protocol, None,
                            dbClient.getTimeout(), dbClient.getDbVersion(),
                            dbClient.getAppVersion())
                        logger.debug(
                            'Successfully connected to sqlserver object ', sid,
                            ' on ', currIP)
                        OSHVResult.add(oracleOSH)
                        #since this is knownn oracle and we found credentials for it we can finish execution
                        return OSHVResult
                except:
                    if logger.isDebugEnabled():
                        logger.debugException(
                            'Unexpected CreateClient() for sqlserver client Exception:'
                        )
            finally:
                if dbClient != None:
                    dbClient.close()
    Framework.reportWarning('Failed to connect using all protocols')
    return OSHVResult
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ip = Framework.getDestinationAttribute("ip_address")
    sid = Framework.getDestinationAttribute("sid")
    port = Framework.getDestinationAttribute("port")

    hostId = Framework.getDestinationAttribute("hostId")

    if (ip == None) or (ip == "NA"):
        # checked and pass all IPs of given host
        ips = Framework.getTriggerCIDataAsList("host_ips")
    else:
        ips = [ip]
    for currIP in ips:
        if len(currIP) == 0:
            continue
        logger.debug("Checking sqlserver with no user on ipaddress:", currIP)
        protocols = Framework.getAvailableProtocols(currIP, ClientsConsts.SQL_PROTOCOL_NAME)
        for protocol in protocols:
            dbClient = None
            try:
                try:
                    if dbutils.protocolMatch(
                        Framework, protocol, "microsoftsqlserver", sid, port
                    ) or dbutils.protocolMatch(Framework, protocol, "microsoftsqlserverntlm", sid, port):
                        props = Properties()
                        props.setProperty("ip_address", currIP)
                        dbClient = Framework.createClient(protocol, props)

                        hostOSH = modeling.createOshByCmdbIdString("host", hostId)
                        oracleOSH = modeling.createDatabaseOSH(
                            "sqlserver",
                            sid,
                            str(dbClient.getPort()),
                            dbClient.getIpAddress(),
                            hostOSH,
                            protocol,
                            None,
                            dbClient.getTimeout(),
                            dbClient.getDbVersion(),
                            dbClient.getAppVersion(),
                        )
                        logger.debug("Successfully connected to sqlserver object ", sid, " on ", currIP)
                        OSHVResult.add(oracleOSH)
                        # since this is knownn oracle and we found credentials for it we can finish execution
                        return OSHVResult
                except:
                    if logger.isDebugEnabled():
                        logger.debugException("Unexpected CreateClient() for sqlserver client Exception:")
            finally:
                if dbClient != None:
                    dbClient.close()
    Framework.reportWarning("Failed to connect using all protocols")
    return OSHVResult
Esempio n. 10
0
def getProcesses(client,nameToHostOSH, OSHVResult, schemaName = None, viewSchemaName = None):
    # [queue id] <--> [ list of process OSH ]
    mapIDToOSH = HashMap()
    objs = __assocWithSchemaName(['FND_CONCURRENT_PROCESSES'], schemaName, viewSchemaName) 
    resultSet = client.executeQuery('SELECT CONCURRENT_QUEUE_ID,OS_PROCESS_ID,NODE_NAME FROM %s WHERE PROCESS_STATUS_CODE=\'A\' or PROCESS_STATUS_CODE=\'C\'' % objs)#@@CMD_PERMISION sql protocol execution
    while resultSet.next():
        queueID = resultSet.getString(1)
        PID = resultSet.getString(2)
        host = resultSet.getString(3)
        hostNoDomain = host.split('.')[0]
        if logger.isDebugEnabled():
            logger.debug('-------------------------------------------------')
            logger.debug('queueID = ', queueID)
            logger.debug('PID = ', PID)
            logger.debug('host = ', host)
            logger.debug('hostNoDomain = ', hostNoDomain)
            logger.debug('-------------------------------------------------') 
        hostOSH = nameToHostOSH.get(host)
        if hostOSH == None:
            hostOSH = nameToHostOSH.get(hostNoDomain)
        if hostOSH != None:
            processOSH = ObjectStateHolder('process')
            processOSH.setAttribute('process_pid', int(PID))
            processOSH.setContainer(hostOSH)
            OSHVResult.add(processOSH)
            processes = mapIDToOSH.get(queueID)
            if processes == None:
                processes = ArrayList()
                mapIDToOSH.put(queueID,processes)
            processes.add(processOSH)
    if logger.isDebugEnabled():    
        logger.debug('-------------------------------------------------')
        logger.debug(mapIDToOSH)
        logger.debug('-------------------------------------------------')
    resultSet.close()
    return mapIDToOSH
Esempio n. 11
0
def DiscoveryMain(Framework):
	OSHVResult = ObjectStateHolderVector()
	ip = Framework.getDestinationAttribute('ip_address')
	sid = Framework.getDestinationAttribute('sid')
	port = Framework.getDestinationAttribute('port')
	
	hostId	  = Framework.getDestinationAttribute('hostId')
	

	if (ip == None) or (ip == 'NA'):
		#checked and pass all IPs of given host
		ips = Framework.getTriggerCIDataAsList('host_ips')
	else:
		ips = [ip]
	for currIP in ips:
		if len(currIP) == 0:
			continue
		logger.debug('Checking oracle with no user on ipaddress:', currIP)
		protocols = Framework.getAvailableProtocols(currIP, ClientsConsts.SQL_PROTOCOL_NAME)
		for protocol in protocols:
			dbClient = None
			try:
				try:
					if dbutils.protocolMatch(Framework, protocol, 'oracle', sid, port):
						props = Properties()
						props.setProperty('ip_address', currIP)
						dbClient = Framework.createClient(protocol, props)

						hostOSH = modeling.createOshByCmdbIdString('host', hostId)
						oracleOSH = modeling.createDatabaseOSH('oracle', sid, str(dbClient.getPort()), dbClient.getIpAddress(), hostOSH, protocol,None, dbClient.getTimeout(),dbClient.getDbVersion(), dbClient.getAppVersion())
						logger.debug('Successfully connected to oracle object ', sid, ' on ', currIP)
						OSHVResult.add(oracleOSH)
						#since this is knownn oracle and we found credentials for it we can finish execution
						return OSHVResult
				except:			
					if logger.isDebugEnabled():
						logger.debugException('Unexpected CreateClient() for oracle client Exception:')
			finally:
				if dbClient != None:
					dbClient.close()
	Framework.reportWarning('Failed to connect using all protocols')
	return OSHVResult
Esempio n. 12
0
    def getRequestedPortsSet(self):
        services = self.Framework.getParameter('P2PServerPorts')
        if logger.isDebugEnabled():
            logger.debug('Requested services:', services)
        if (services == None) or (len(services) == 0) or (services == '*'):
            return None

        names = services.split(',')
        portsSet = HashSet()
        for name in names:
            portNums = self.knownPortsConfigFile.getPortByName(name)
            if portNums == None:
                try:
                    portNums = [Integer.parseInt(name)]
                except:
                    logger.debug('Failed to resolve service port number:', name)
                    continue
            for portNum in portNums:
                portsSet.add(portNum)
        return portsSet
Esempio n. 13
0
    def getKnownListeningPortsSet(self):
        ports = self.Framework.getParameter('knownListeningPorts')
        portsSet = HashSet()
        if logger.isDebugEnabled():
            logger.debug('Known Listening Ports:', ports)
        if (ports == None) or (len(ports) == 0):
            return None
        if (ports == '*'):
            portsSet.add('*')
            return portsSet

        names = ports.split(',')
        for name in names:
            portNums = self.knownPortsConfigFile.getPortByName(name)
            if portNums == None:
                try:
                    portNums = [Integer.parseInt(name)]
                except:
                    logger.debug('Failed to resolve service port number:', name)
                    continue
            for portNum in portNums:
                portsSet.add(portNum)
        return portsSet
Esempio n. 14
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    SYSNAME = Framework.getDestinationAttribute('system_name')
    GET_TX_ACTIVE = Framework.getParameter('getActiveTransactions') == 'true'
    GET_TX_CHANGE = Framework.getParameter('getTransChanges') == 'true'
    GET_TX_ALL = Framework.getParameter('getAllTransactions') == 'true'
    report_app_components = Framework.getParameter('getAppComponents') == 'true'

    properties = Properties()
    instance_number =  Framework.getDestinationAttribute('instance_nr')
    ip_address =  Framework.getDestinationAttribute('ip_address')
    connection_client =  Framework.getDestinationAttribute('connection_client')
    logger.debug('Connecting to a SAP system number:', str(instance_number))
    properties.setProperty(Protocol.SAP_PROTOCOL_ATTRIBUTE_SYSNUMBER, instance_number)
    if (connection_client is not None) and (connection_client != 'NA'):
        logger.debug('Connecting to a SAP system with client:', str(connection_client))
        properties.setProperty(Protocol.SAP_PROTOCOL_ATTRIBUTE_CLIENT, connection_client)
    if GET_TX_CHANGE:
        # get transaction change only parameters
        FROM_DATE = Framework.getParameter('transChangesFromDate')
        FROM_TIME = Framework.getParameter('transChangesFromTime')
        TO_DATE = Framework.getParameter('transChangesToDate')
        TO_TIME = Framework.getParameter('transChangesToTime')
        INTERVAL = Framework.getParameter('transChangesDaysInterval')

        if logger.isDebugEnabled():
            logger.debug('FROM_DATE = ', FROM_DATE)
            logger.debug('FROM_TIME = ', FROM_TIME)
            logger.debug('TO_DATE = ', TO_DATE)
            logger.debug('TO_TIME = ', TO_TIME)

        properties.setProperty(SAPQueryClient.PARAM_FROM_DATE,FROM_DATE)
        properties.setProperty(SAPQueryClient.PARAM_FROM_TIME,FROM_TIME)
        properties.setProperty(SAPQueryClient.PARAM_TO_DATE,TO_DATE)
        properties.setProperty(SAPQueryClient.PARAM_TO_TIME,TO_TIME)
        if ( (INTERVAL != None) and (INTERVAL != '0') and (INTERVAL != '') ):
            properties.setProperty(SAPQueryClient.PARAM_INTERVAL,INTERVAL)

    loadOnInit = 0
    if GET_TX_ACTIVE:
        properties.setProperty(SAPQueryClient.PARAM_FLAG_GET_USERS,'false')
        loadOnInit = 1

    errormsg = ''
    client = None
    try:
        try:
            # create SAP client
            client = Framework.createClient(properties)
            sapUtils = sapappsutils.SapAppsUtils(client, loadOnInit, saputils.SapUtils.NO_LOAD)
        except (NoClassDefFoundError, MissingJarsException, ExceptionInInitializerError):
            errormsg = 'SAP drivers are missing'
            logger.debugException(errormsg)
        except:
            errormsg = 'Connection failed'
            logger.debugException(errormsg)
        else:
            systemOsh, oshs = sap_abap.report_system(SYSNAME, instance_number, ip_address)
            OSHVResult.addAll(oshs)

            # Check if we need to collect all the application component.
            # (we can discover up to 60000 CIs per System - don't discover if it is not needed)
            if not report_app_components:
                logger.debug('Not sending application components to server')

            # build the application hierarchy even if not all of it is sent to the server
            mapDevcToOSH = None
            if GET_TX_CHANGE or GET_TX_ALL or GET_TX_ACTIVE or report_app_components:
                mapDevcToOSH, oshs = buildAppHierarchy(sapUtils, systemOsh, report_app_components)
                OSHVResult.addAll(oshs)

            # Check if we need to collect the changed transactions
            if GET_TX_CHANGE:
                try:
                    logger.debug('Getting transaction change...')
                    transactionChange(sapUtils, mapDevcToOSH, systemOsh, SYSNAME, OSHVResult)
                except NoSuchChangeException:
                    Framework.reportWarning('No changes found in the given time range')
                except:
                    logger.errorException('Failed retrieving transactions change')
                    Framework.reportError('Failed retrieving transactions change')

            # Check if we need to collect all the transactions
            if GET_TX_ALL:
                try:
                    logger.debug('Getting all transactions...')
                    transactions(sapUtils, mapDevcToOSH, systemOsh, SYSNAME, OSHVResult)
                except:
                    logger.errorException('Failed to get transactions')
                    Framework.reportWarning('Failed to get transactions')

            # Check if we need to collect the active transactions
            if GET_TX_ACTIVE:
                try:
                    logger.debug('Getting active transactions...')
                    activeTransactions(sapUtils, mapDevcToOSH, systemOsh, SYSNAME, OSHVResult)
                except:
                    logger.errorException('Failed retrieving active transactions')
                    Framework.reportError('Failed retrieving active transactions')
    finally:
        if client is not None:
            client.close()
        if errormsg:
            Framework.reportError(errormsg)
    return OSHVResult
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    DISCOVERED_IP = Framework.getDestinationAttribute('ip_address')
    DISCOVERED_IP_ID = Framework.getDestinationAttribute('ip_id')
    #    ip = modeling.createOshByCmdbIdString('ip_address', DISCOVERED_IP_ID)
    ucmdbVersion = modeling.CmdbClassModel().version()
    if ucmdbVersion >= 9:
        ipClass = 'ip_address'
    else:
        ipClass = 'ip'

    protocols = Framework.getAvailableProtocols(
        DISCOVERED_IP, ClientsConsts.SNMP_PROTOCOL_NAME)

    if protocols.__len__() == 0:
        errStr = 'No credentials defined for the triggered ip'
        logger.debug(errStr)
        Framework.reportWarning(errStr)
    else:
        for protocol in protocols:
            sysplexNameList = None
            lparIpList = None

            snmpOSH = modeling.createSnmpOSH(DISCOVERED_IP, None)

            client = None
            try:
                client = Framework.createClient(protocol)
                logger.debug('got snmp agent for: ', DISCOVERED_IP)
                isMultiOid = client.supportMultiOid()

                sysplexNameList = client.executeQuery(
                    '1.3.6.1.4.1.2.6.19.2.2.2.41,1.3.6.1.4.1.2.6.19.2.2.2.41,string,1.3.6.1.4.1.2.6.19.2.2.2.40,string'
                )  #@@CMD_PERMISION snmp protocol execution
                sysplexNameList = sysplexNameList.asTable()

                lparIpList = client.executeQuery(
                    '1.3.6.1.2.1.4.20.1.1,1.3.6.1.2.1.4.20.1.2,string'
                )  #@@CMD_PERMISION snmp protocol execution
                lparIpList = lparIpList.asTable()

                mainframeMacList = client.executeQuery(
                    '1.3.6.1.2.1.2.2.1.6,1.3.6.1.2.1.2.2.1.7,hexa'
                )  #@@CMD_PERMISION snmp protocol execution
                mainframeMacList = mainframeMacList.asTable()
                snmpOSH.setAttribute('application_port', client.getPort())

                snmpOSH.setAttribute('application_timeout',
                                     client.getTimeout())
                snmpOSH.setAttribute('snmp_port', client.getPort())
                snmpOSH.setAttribute('credentials_id',
                                     client.getCredentialId())
                snmpOSH.setAttribute('snmp_retry', client.getRetries())
                snmpOSH.setAttribute('snmp_timeout', client.getTimeout())
                if isMultiOid == 1:
                    snmpOSH.setBoolAttribute('snmp_supportmultioid', 1)
                else:
                    snmpOSH.setBoolAttribute('snmp_supportmultioid', 0)
            except:
                logger.debugException('Unexpected SNMP_AGENT Exception:')
                continue

            if client != None:
                client.close()

            mainframeKey = getMainframeKey(mainframeMacList)
            if mainframeKey:
                mainframeOSH = modeling.createCompleteHostOSH(
                    'mainframe', mainframeKey, machineName=mainframeKey)
                modeling.setHostOsFamily(mainframeOSH, 'mainframe')
                OSHVResult.add(mainframeOSH)

                for currSysplex in sysplexNameList:
                    if logger.isDebugEnabled():
                        logger.debug('SYSPLEX : ', currSysplex[1])
                        logger.debug('LPAR : ', currSysplex[2])
                        logger.debug('MainframeKEY : ', mainframeKey)

                    lparKey = mainframeKey + ':' + currSysplex[2]
                    lparOSH = modeling.createCompleteHostOSH(
                        'lpar', lparKey, machineName=currSysplex[2])
                    OSHVResult.add(lparOSH)

                    snmpOSH.setContainer(lparOSH)
                    OSHVResult.add(snmpOSH)

                    # Create contained link between discovered IP and lpar
                    OSHVResult.add(
                        modeling.createLinkOSH(
                            'contained', lparOSH,
                            modeling.createOshByCmdbIdString(
                                ipClass, DISCOVERED_IP_ID)))

                    # Create member link between lpar and Mainframe
                    OSHVResult.add(
                        modeling.createLinkOSH('member', mainframeOSH,
                                               lparOSH))

                    # Create sysplex
                    sysplexOSH = ObjectStateHolder('sysplex')
                    sysplexOSH.setAttribute('data_name', currSysplex[1])
                    OSHVResult.add(sysplexOSH)

                    # Create member link between lpar and sysplex
                    OSHVResult.add(
                        modeling.createLinkOSH('member', sysplexOSH, lparOSH))

                    # Create member link between mainframe and sysplex
                    OSHVResult.add(
                        modeling.createLinkOSH('member', mainframeOSH,
                                               sysplexOSH))

                    # connect all ips to lpar
                    for currLparIp in lparIpList:
                        if netutils.isLocalIp(currLparIp[1]):
                            continue

                        currIpOSH = modeling.createIpOSH(currLparIp[1])
                        OSHVResult.add(currIpOSH)
                        OSHVResult.add(
                            modeling.createLinkOSH('contained', lparOSH,
                                                   currIpOSH))
                break
            else:
                logger.debug("Failed to get Mainframe key.")
        else:
            errormessages.resolveAndReport(
                "Could not perform snmp connection to %s" % DISCOVERED_IP,
                ClientsConsts.SNMP_PROTOCOL_NAME, Framework)

    return OSHVResult
def readPropertiesFile(fname):
    """
    Uses ConfigReader to read all sections in to a dictionary. Each sections options will
    be kept as nested dictionary under each section key.
    e.g.:
    {
        'WHITELIST': {
            '<j2eetype-1>': {
                '<value-1>',
                '<value-2>',
                :
                '<value-n>'
                }
            '<j2eetype-2>': {
                '<value-1>',
                '<value-2>',
                :
                '<value-n>'
                }
    }
    """
    l.debug("looking for file: '%s'", fname)
    if not os.path.isfile(fname):
        l.debug("file not found: '%s'", fname)
        return {}

    # discover comments per regex
    re_comment = re.compile('^\s*#', re.IGNORECASE)
    # discover enumeration on first level: eg "DATASOURCE3"
    re_enumeration = re.compile('^([A-z]+)(\d+)\.', re.IGNORECASE)

    reader = ConfigParser.ConfigParser()
    l.debug("reading file: '%s'", fname)
    reader.read(fname)
    # read all sections and items therein
    allSectionsMap = {}
    sectionNames = reader.sections()
    sectionNames.sort()
    for sectionName in sectionNames:
        if l.isDebugEnabled():
            l.logLF()
            l.debug("found section === %s === ", sectionName)
        sectionMap = {}
        allSectionsMap[sectionName.upper()] = sectionMap

        lastBlockNumber = -1
        expectedBlockNumber = 0
        configBlockNumber = 0
        # read all option lines from current section into sectionMap dictionary
        # eg: "datasource1.connectionpool.reaptime = 7"
        sectionOptions = reader.options(sectionName)
        # in Python 2.1 (WAS8.x) the option() lines of a configParser section may be unsorted!
        # but I cant use default sort, because Datasource1, datasource10 will be sorted before Datasource2
        if l.isHellLevelEnabled():
            for optionKey in sectionOptions:
                l.debug666("read original-ordered section/line: %-20s :  %s",
                           sectionName, optionKey)

        sortedSectionOptions = sorted(sectionOptions,
                                      key=configReaderOptionSort)
        if l.isHellLevelEnabled():
            for optionKey in sortedSectionOptions:
                l.debug666("read num.sorted section/line: %s :\t%s",
                           sectionName, optionKey)

        for optionKey in sortedSectionOptions:
            if (re_comment.search(optionKey)) is not None:
                l.debug666("skipping comment: %s", optionKey)
                continue
            optionValue = reader.get(sectionName, optionKey)

            # now fix the *1st* level of enumeration, if it is not done sequentially.
            # eg. when somebody declares 20 datasources, but deletes the 3rd.
            # This way, one does not need to re-enumerate all the
            # other datasource entries in the config file.
            match = re_enumeration.search(optionKey)
            if (match) is not None:
                configBlockNumber = int(match.group(2))
                if configBlockNumber > lastBlockNumber:
                    # new block found -> increase block counter
                    if l.isDebugEnabled():
                        l.logLF()
                        l.debug("=== read new config block # %d ===",
                                configBlockNumber)
                    expectedBlockNumber = expectedBlockNumber + 1
                    lastBlockNumber = configBlockNumber

                l.debug2("config #:%2d   expected #:%2d", configBlockNumber,
                         expectedBlockNumber)
                # check for non-sequential block numbering!
                if configBlockNumber != expectedBlockNumber:
                    l.debug("FIX block numbering: %d -> %d in option: '%s'",
                            configBlockNumber, expectedBlockNumber, optionKey)
                    optionKey = re_enumeration.sub(
                        lambda m, num=expectedBlockNumber: "%s%s." %
                        (m.group(1), num),
                        optionKey)
                    # and store the original block number in special hash key:
                    originalNumberKey = "%s%d.%s" % (match.group(1),
                                                     expectedBlockNumber,
                                                     "__ORIGINAL_NUMBER")
                    sectionMap[originalNumberKey.upper()] = configBlockNumber

            l.debug("data: %s = %s", optionKey, optionValue)
            # finally, add key to sectionMap hash:
            sectionMap[optionKey.upper()] = optionValue

    return allSectionsMap
Esempio n. 17
0
def transactionChange(sapUtils, mapDevcToOSH, siteOSH, SYSNAME, OSHVResult):
    mapTransportToOSH = HashMap()
    transactionChange = sapUtils.getTransactionChange()
    count = transactionChange.getRowCount()
    for row in range(count):
        # read all fields
        transaction = transactionChange.getCell(row,0)
        devc = transactionChange.getCell(row,1)
        objectName = transactionChange.getCell(row,2)
        objectType = transactionChange.getCell(row,3)
        objectDescription = transactionChange.getCell(row,4)
        changeDescription = transactionChange.getCell(row,5)
        date = transactionChange.getCell(row,6)
        time = transactionChange.getCell(row,7)
        user = transactionChange.getCell(row,8)
        status = transactionChange.getCell(row,9)
        changeRequest = transactionChange.getCell(row,10)
        program = transactionChange.getCell(row,12)
        screen = transactionChange.getCell(row,13)
        programVersion = transactionChange.getCell(row,14)
        targetSystem = transactionChange.getCell(row,15)
        if logger.isDebugEnabled():
            logger.debug('--------------------------------------------')
            logger.debug('changeDescription = ', changeDescription)
            logger.debug('objectType = ', objectType)
            logger.debug('objectName = ', objectName)
            logger.debug('objectDescription = ', objectDescription)
            logger.debug('date = ', date)
            logger.debug('time = ', time)
            logger.debug('user = '******'--------------------------------------------')

        sfDate = SimpleDateFormat('yyyy-MM-dd HH:mm:ss')
        dateObj = sfDate.parse(date + ' ' + time,ParsePosition(0))

        if devc is not None:
            devcOSH = mapDevcToOSH.get(devc)
            if devcOSH != None:

                # In case the application components were filtered then we need to send only the relevant
                # application components for this transport
                addAppCompHierarchy(devcOSH, OSHVResult)
                transactionOSH = buildTransaction(transaction, devc, program, screen, programVersion, devcOSH, siteOSH, SYSNAME, OSHVResult)
                ticketStatus = ''
                #
                # L - Modifiable
                # D - Modifiable, Protected
                if status == 'L' or status == 'D':
                    # (1) = Plan
                    # (9) = Critical
                    ticketStatus = 'In progress'
                else:
                    # (2) = New change
                    # (7) = Major
                    ticketStatus = 'Closed'

                transportOSH = mapTransportToOSH.get(changeRequest)
                if transportOSH == None:
                    transportOSH = buildTransport(changeRequest,dateObj,time,user,targetSystem,changeDescription,ticketStatus, siteOSH, OSHVResult)
                    mapTransportToOSH.put(changeRequest,transportOSH)
                OSHVResult.add(modeling.createLinkOSH('contains',transactionOSH,transportOSH));
                changeOSH = createTransportChange(transaction,objectType,objectName,transportOSH, OSHVResult)
                OSHVResult.add(modeling.createLinkOSH('use',changeOSH,transactionOSH));
            else:
                logger.warn('can not find devclass OSH for [', devc, ']')
Esempio n. 18
0
	def getActiveTransactions(self):
		activeTransactions = []
		whereClauses = ArrayList()
		whereClauses.add("FUNCNAME IN ('SAPWL_TCODE_AGGREGATION','SAPWL_TCODE_AGGREGATION_COPY')");
		result = self.executeQuery("TFDIR", whereClauses, "FUNCNAME")#@@CMD_PERMISION sap protocol execution
		
		functionName = None
		if result.next():
			functionName = result.getString("FUNCNAME")

		if functionName == None:
			logger.warn('getActiveTransactions: active transaction function is not found')
			return activeTransactions
		
		day = self.__client.getProperty('from_date')
		if day == None:
			today = Date()
			sfDate = SimpleDateFormat("yyyyMMdd")
			day = sfDate.format(today)
		elif day.find('/') != -1:
			try:
				sfDate = SimpleDateFormat("MM/dd/yyyy")
				parsedDate = sfDate.parse(day)
				sfDate = SimpleDateFormat("yyyyMMdd")
				day = sfDate.format(parsedDate)
			except:
				logger.reportWarning('Failed to parse date ', day)
				
		logger.debug('Parsed start date:', day)
			

		logger.debug('Active transactions from data:', day)
		mapTransactionToUsers = None
		getUsers = Boolean.parseBoolean(self.__client.getProperty("get_users"))
		if getUsers:
			mapTransactionToUsers = HashMap()
			
			funcParams = HashMap()
			funcParams.put('READ_START_DATE', day)
			funcParams.put('READ_START_TIME', '000000')
			funcParams.put('READ_END_DATE', day)
			funcParams.put('READ_END_TIME', '235959')
			funcParams.put('READ_ONLY_MAINRECORDS', 'X')
			
			logger.debug('executing func:SAPWL_STATREC_FROM_REMOTE_SYS(', str(funcParams),')')
			
			fields = ArrayList()
			fields.add('TCODE')
			fields.add('ACCOUNT')
			usersResult = self.__client.executeFunction('SAPWL_STATREC_FROM_REMOTE_SYS', funcParams, 'NORMAL_RECORDS', fields)
			while usersResult.next():
				transaction = usersResult.getString('TCODE')
				if len(transaction) > 0:
					user = usersResult.getString("ACCOUNT");
					users = mapTransactionToUsers.get(transaction)
					if users == None:
						users = HashMap()
						mapTransactionToUsers.put(transaction,users)
					users.put(user,users);

		self.getSites()
		site = self.getSites().getCell(0,0)
		servers = self.getServers(site)
		numServers = servers.getRowCount()
		transactionToStats = HashMap()
		for j in range(numServers):
			try:
				instance = servers.getCell(j,0);
				logger.debug('getActiveTransactions:executing function[' + functionName + '] for instance [' + instance + ']')
				if functionName == 'SAPWL_TCODE_AGGREGATION_COPY':
					records = self.callSapwlTcodeAggregationCopy(instance,day)
	
					while records.next():
						transaction = (str(records.getString(0))).strip()
						mapUsers = None
						if mapTransactionToUsers != None:
							mapUsers = mapTransactionToUsers.get(transaction)
						if (transaction != None) and (len(transaction) > 0):
							stats = transactionToStats.get(transaction)
							if stats == None:
								stats = TransactionStatistics(transaction)
								transactionToStats.put(transaction,stats)
	
							if mapUsers != None:
								stats.users = ArrayList(mapUsers.keySet())
							if records.next():
								stats.steps = stats.steps + int(float(records.getString(0)))
							if records.next():
								stats.responseTime = stats.responseTime + int(float(records.getString(0)))
							if records.next():
								stats.cpuTime = stats.cpuTime + int(float(records.getString(0)))
							if records.next():
								stats.dbTime = stats.dbTime + int(float(records.getString(0)))
							if records.next():
								stats.guiTime = stats.guiTime + int(float(records.getString(0)))
							if records.next():
								stats.roundTrips = stats.roundTrips + int(float(records.getString(0)))
							if records.next():
								stats.text = (str(records.getString(0))).strip()
				else:
					fields = ArrayList()
					fields.add('ENTRY_ID')
					fields.add('COUNT')
					fields.add('RESPTI')
					fields.add('CPUTI')
					fields.add('DBTIME')
					fields.add('GUITIME')
					fields.add('GUICNT')
					fields.add('TEXT')
					records = self.getApplicationStatistics(functionName, instance, day, fields)

					while records.next():
						entryID = records.getString("ENTRY_ID");
						transaction = self.getTransactionFromEntryID(entryID);
						mapUsers = None
						if mapTransactionToUsers != None:
							mapUsers = mapTransactionToUsers.get(transaction)
						if (transaction != None) and (len(transaction) > 0):
							stats = transactionToStats.get(transaction)
							if(stats == None):
								stats = TransactionStatistics(transaction)
								transactionToStats.put(transaction,stats)

							if(mapUsers != None):
								stats.users = ArrayList(mapUsers.keySet())
							count = records.getString("COUNT")
							stats.steps = stats.steps + int(count)
							stats.responseTime = stats.responseTime + int(records.getString("RESPTI"))
							stats.cpuTime = stats.cpuTime + int(records.getString("CPUTI"))
							stats.dbTime = stats.dbTime + int(records.getString("DBTIME"))
							stats.guiTime = stats.guiTime + int(records.getString("GUITIME"))
							stats.roundTrips = stats.roundTrips + int(records.getString("GUICNT"))
							stats.text = records.getString("TEXT")
			except:
				msg = sys.exc_info()[1]
				strmsg = '%s' % msg
				if strmsg.find('NO_DATA_FOUND') != -1:
					logger.debug(strmsg)
					logger.reportWarning('No data found in the given time range')
				else:
					logger.debugException('Unexpected error getting transactions for function:' + str(functionName))
					logger.reportWarning('Unexpected error getting transactions for function:' + str(functionName) + ':' + strmsg)

		transactions = ArrayList(transactionToStats.keySet())
		logger.debug("getActiveTransactions: Found [" + str(transactions.size()) + "] active transactions")
		if logger.isDebugEnabled():
			logger.debug("getActiveTransactions: transactions = " + str(transactions))
		transactionsInfo = self.getTransactionsInfo(transactions)

		it = transactionToStats.values()
		for stats in it:
			prop = Properties()
			prop.setProperty('data_name', str(stats.transaction))
			prop.setProperty('dialog_steps', str(stats.steps))
			prop.setProperty('total_response_time', str(stats.responseTime))
			prop.setProperty('average_response_time', str(stats.getAverageCPUTime()))
			prop.setProperty('total_cpu_time', str(stats.cpuTime))
			prop.setProperty('average_cpu_time', str(stats.getAverageCPUTime()))
			prop.setProperty('round_trips', str(stats.roundTrips))
			prop.setProperty('total_db_time', str(stats.dbTime))
			prop.setProperty('average_db_time', str(stats.getAverageDBTime()))
			prop.setProperty('total_gui_time', str(stats.guiTime))
			prop.setProperty('average_gui_time', str(stats.getAverageGUITime()))
			prop.setProperty('text', stats.text)
			prop.setProperty('saptransaction_averagedbtime', str(stats.users.size()))

			info = transactionsInfo.get(stats.transaction)
			if info != None:
				prop.setProperty('devclass', info.devclass)
				prop.setProperty('program', info.program)
				prop.setProperty('screen', info.screen)
				prop.setProperty('', info.screen)
			else:
				prop.setProperty('devclass', "")
				prop.setProperty('program', "")
				prop.setProperty('screen', "")
				prop.setProperty('version', "")
				
			activeTransactions.append(prop)
		
		return activeTransactions
Esempio n. 19
0
    def discover_private(self):
        ports = self.servicesPorts(0)
        query = 'select ipaddress, port, Protocol from Port_Process '
        if (ports != None) and (len(ports) > 0):
            query = query + ' where listen and port IN (' + ports + ')'
        logger.debug('ListenPorts,sql:', query)
        conn = self.Framework.getProbeDatabaseConnection('TCPDISCOVERY')
        st = None
        result = None
        try:
            try:
                if logger.isDebugEnabled():
                    logger.debug(query)
                st = conn.createStatement()
                result = st.executeQuery(query)
                dataFound = 0
                while result.next():
                    dataFound = 1
                    address = result.getString('ipaddress');
                    port = result.getInt('port');
                    prot = result.getInt('Protocol');
                    if not self.shouldInclude(address, 1):
                        if logger.isDebugEnabled():
                            logger.debug("ignoring ip out of scope: " + address)
                        continue
                    ipOSH = modeling.createIpOSH(address)
                    self.Framework.sendObject(ipOSH)

                    hostOSH = modeling.createHostOSH(address)
                    portName = self.knownPortsConfigFile.getPortName(prot, port)
                    if portName == None:
                        portName = str(port)

                    portType = modeling.SERVICEADDRESS_TYPE_TCP
                    if prot == modeling.UDP_PROTOCOL:
                        portType = modeling.SERVICEADDRESS_TYPE_UDP

                    serverPortOSH = modeling.createServiceAddressOsh(hostOSH, address, port, portType, portName)
                    containedLinkOSH = modeling.createLinkOSH('contained', hostOSH, ipOSH)
                    self.Framework.sendObject(hostOSH)
                    self.Framework.sendObject(serverPortOSH)
                    self.Framework.sendObject(containedLinkOSH)
                if not dataFound:
                    self.Framework.reportWarning("No data to process, please check if Host Resources jobs had already run")
            except:
                msg = sys.exc_info()[1]
                exInfo = '%s' % msg
                if exInfo.find('ResultSet closed') != -1:
                    error = 'Connection to probe database closed'
                    details = str("Please increase job execution max time and/or configure parameter 'appilog.agent.netflow.heldTimeoutConnection' in DiscoveryProbe.properties file")
                    errobj = errorobject.createError(errorcodes.INTERNAL_ERROR_WITH_PROTOCOL_DETAILS, [error, details], error + details)
                    logger.reportErrorObject(errobj)
                else:
                    errobj = errorobject.createError(errorcodes.FAILED_TO_EXECUTE_SQL, [exInfo], exInfo)
                    logger.reportErrorObject(errobj)
        finally:
            if result != None:
                try:
                    result.close
                except:
                    pass
            conn.close(st)
            conn.close()
def dbg(msg):
    if 1:
        info(msg)
    elif logger.isDebugEnabled():
        logger.debug(msg)
Esempio n. 21
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ObjSHV = ObjectStateHolderVector()
    discInst = RunInstance()
    ipAddressList = Framework.getTriggerCIDataAsList('ip_address')
    credentialsList = Framework.getTriggerCIDataAsList('credentialsId')
    bridgeId = Framework.getDestinationAttribute('bridgeId')
    hostIdList = Framework.getTriggerCIDataAsList('hostId')
    ucmdbVersion = modeling.CmdbClassModel().version()
    
    
    snmpCommunityPostfix = ''
    try:
        snmpCommunityPostfix = Framework.getDestinationAttribute('snmpCommunityPostfix')
        hostModel = Framework.getDestinationAttribute('hostModel')
        hostOs = Framework.getDestinationAttribute('hostOs')
        snmpDescription = Framework.getDestinationAttribute('smpDescription')
    except:
        pass

    SwitchesNumber = len(credentialsList)
    for i in range(SwitchesNumber):
        ipAddress = ipAddressList[i]
        hostId = hostIdList[i]
        credId = credentialsList[i]
        
        properties = Properties()

        if credId and ipAddress:
            properties.setProperty('ip_address', ipAddress)
            properties.setProperty(BaseClient.CREDENTIALS_ID, credId)
        sw = Switch(bridgeId, hostId, ucmdbVersion, Framework)
        if (snmpCommunityPostfix != None) and (snmpCommunityPostfix != ''):
            device_type_str = '%s%s%s' % (hostModel.lower(),
                                          hostOs.lower(),
                                          snmpDescription.lower())
            if device_type_str.find('atalyst')!=-1 or device_type_str.find('cisco')!=-1:
                snmp_version = Framework.getProtocolProperty(credId, "snmpprotocol_version")
                if snmp_version == 'version 3':
                    props = Properties()
                    props.setProperty('ip_address', ipAddress)
                    props.setProperty(BaseClient.CREDENTIALS_ID, credId)
                    client = Framework.createClient(props)
                    vlan_context_dict = snmputils.get_snmp_vlan_context_dict(client)
                    client and client.close()

                    if not vlan_context_dict:
                        raise Exception, "Vlan Conext is not present on the device. No Vlan details might be discovered"
                    
                    vlan_context = vlan_context_dict.get(snmpCommunityPostfix)
                    if not vlan_context:
                        raise Exception, "Failed to find configured Vlan context for Vlan %s. Vlan will be skipped" % snmpCommunityPostfix
                    
                    properties.setProperty(SnmpQueries._postfix, '%s' % vlan_context)
                else:
                    properties.setProperty(SnmpQueries._postfix,'@%s' % snmpCommunityPostfix)
            else:
                sw = QBridgeSwitch(snmpCommunityPostfix, bridgeId, hostId, ucmdbVersion, Framework)
                sw.set_device_type_str(device_type_str)
        if logger.isDebugEnabled():
            logger.debug('ip', ipAddress)
            logger.debug('bridgeMac', bridgeId)
            logger.debug('Postfix', snmpCommunityPostfix)

        try:
            sw.snmpClient = Framework.createClient(properties)
            #SnmpConnectionTester(sw.snmpClient).testSnmpConnection()
            sw.doWork(ObjSHV, discInst)
            OSHVResult.addAll(ObjSHV)
        except:
            logger.debugException('')
            if (snmpCommunityPostfix != None) and (snmpCommunityPostfix != ''):
                logger.error('Failed to discover ip: ', ipAddress, ' on Vlan#: ', snmpCommunityPostfix)
            else:
                logger.error('Failed to discover ip: ', ipAddress )
        if sw.snmpClient != None:
            sw.snmpClient.close()
    return OSHVResult
def processSoftware(keys,
                    buffer,
                    hostOSH,
                    OSHVResults,
                    softNameToInstSoftOSH=None):
    '''
    list(str), str, osh, oshVector, map(str, osh) = None -> bool
    '''
    swList = []
    for key in keys:

        softwareName = None
        softwarePath = None
        softwareVer = None
        softwareInstallDate = None
        softwareProductId = None
        softwareProductCode = None
        softwareVendor = None

        m = re.search('\n\s*DisplayName\s+REG_SZ\s+?([^\n]+)', key)
        if (m):
            softwareName = m.group(1).strip()
        else:
            continue
        m = re.search('\n\s*InstallLocation\s+REG_SZ\s+?([^\n]+)', key)
        if (m):
            softwarePath = m.group(1).strip()
        m = re.search('\n\s*DisplayVersion\s+REG_SZ\s+?([^\n]+)', key)
        if (m):
            softwareVer = m.group(1).strip()
        m = re.search('\n\s*InstallDate\s+REG_SZ\s+?([^\n]+)', key)
        if (m):
            softwareInstallDate = m.group(1).strip()
        m = re.search('\n\s*ProductID\s+REG_SZ\s+?([^\n]+)', key)
        if (m) and m.group(1).strip():
            softwareProductId = m.group(1).strip()
        #in case the has a format of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90120000-0011-0000-0000-0000000FF1CE}_PROPLUS_{297857BF-4011-449B-BD74-DB64D182821C}
        #we report 90120000-0011-0000-0000-0000000FF1CE which is a product code of parent software
        m = re.match(
            r"\\Uninstall\\?[\w\{\[\( ]*([\dabcdefABCDEF]{8}(\-[\dabcdefABCDEF]{4}){3}-[\dabcdefABCDEF]{12}).*\n",
            key)
        if (m):
            softwareProductCode = m.group(1).strip()
        m = re.search('\n\s*Publisher\s+REG_SZ\s+?([^\n]+)', key)
        if (m):
            softwareVendor = m.group(1).strip()

        if softwareName:
            if ((softwareName in swList) == 0):
                swList.append(softwareName)
                softwareOSH = hostresource.makeSoftwareOSH(
                    softwareName, softwarePath, softwareVer, hostOSH,
                    softwareInstallDate, softwareProductId,
                    softwareProductCode, softwareVendor)

                if softNameToInstSoftOSH != None:
                    softNameToInstSoftOSH[softwareName] = softwareOSH

                OSHVResults.add(softwareOSH)
    if logger.isDebugEnabled():
        logger.debug('found ', str(OSHVResults.size()), ' software CIs')
        if OSHVResults.size() == 0:
            logger.debug('buffer: ', buffer)

    return 1
Esempio n. 23
0
def services(client,mapAppIdToOSH,hostToServerOSH,nameToHostOSH,systemOSH, OSHVResult, schemaName = None, viewSchemaName = None):
    mapManagerToOSH = HashMap()
    mapServiceToOSH = HashMap()
    
    #we have no way for now to obtain processes names, and pid is not interesting for us
    #so we don't want to create processes (and can't, since process name is key_attribute)
    #mapProcessIDToOSH = getProcesses(client,nameToHostOSH, OSHVResult)
    mapProcessIDToOSH = HashMap()
    objs = __assocWithSchemaName(['FND_CONCURRENT_QUEUES_VL', 'FND_CP_SERVICES_VL'], schemaName, viewSchemaName) 
    resultSet = client.executeQuery('SELECT Q.CONCURRENT_QUEUE_ID,Q.APPLICATION_ID,Q.CONCURRENT_QUEUE_NAME,Q.MAX_PROCESSES,Q.RUNNING_PROCESSES,Q.TARGET_NODE,Q.USER_CONCURRENT_QUEUE_NAME,Q.DESCRIPTION,S.SERVICE_NAME,S.DESCRIPTION FROM %s Q, %s S WHERE Q.MANAGER_TYPE = S.SERVICE_ID' % objs)#@@CMD_PERMISION sql protocol execution
    while resultSet.next():
        queueId = resultSet.getString(1)
        appId = resultSet.getString(2)
        name = resultSet.getString(3)
        maxProcesses = resultSet.getString(4)
        runningProcesses = resultSet.getString(5)
        host = resultSet.getString(6)
        displayName = resultSet.getString(7)
        description = resultSet.getString(8)
        managerName = resultSet.getString(9)
        managerDescription = resultSet.getString(10)

        if managerName == None:
            continue

        managerOSH = mapManagerToOSH.get(managerName)
        if managerOSH == None:        
            managerOSH = ObjectStateHolder('oracleappservicemanager')
            managerOSH.setAttribute('data_name', managerName)
            if managerDescription != None:
                managerOSH.setAttribute('oracleappservicemanager_description', managerDescription)
            managerOSH.setContainer(systemOSH)
            mapManagerToOSH.put(managerName,managerOSH)
            OSHVResult.add(managerOSH)
    
        if description == None:
            description = ''
        if logger.isDebugEnabled():    
            logger.debug('-------------------------------------------------')
            logger.debug('name = ', name)
            logger.debug('displayName = ', displayName)
            logger.debug('appId = ', appId)
            logger.debug('description = ', description)
            if host != None:
                logger.debug('host = ', host)
            logger.debug('-------------------------------------------------') 
        appOSH = mapAppIdToOSH.get(appId)
        serverOSH = hostToServerOSH.get(host)
        if appOSH != None:
            if (name == None) and (displayName != None):
                name = displayName
            if name != None:
                serviceOSH = ObjectStateHolder('oracleappservice')
                serviceOSH.setAttribute('data_name', name)
                serviceOSH.setAttribute('oracleappservice_displayname', displayName)
                serviceOSH.setAttribute('oracleappservice_description', description)
                serviceOSH.setAttribute('oracleappservice_maxprocesses', int(maxProcesses))
                serviceOSH.setAttribute('oracleappservice_runningprocesses', int(runningProcesses))
                serviceOSH.setContainer(appOSH)
                OSHVResult.add(serviceOSH)
                mapServiceToOSH.put(name,serviceOSH)

                processes = mapProcessIDToOSH.get(queueId)
                if processes != None:
                    logger.debug('Found processes for service [', name, ']')
                    itProcesses = processes.iterator()
                    while itProcesses.hasNext():
                        processOSH = itProcesses.next()
                        resourceOSH = modeling.createLinkOSH('resource', serviceOSH, processOSH)
                        OSHVResult.add(resourceOSH)
                else:
                    logger.debug('No processes found for service [', name, ']')


                if managerOSH != None:
                    memberOSH = modeling.createLinkOSH('member', managerOSH, serviceOSH)
                    OSHVResult.add(memberOSH)

                if serverOSH != None:
                    deployedOSH = modeling.createLinkOSH('deployed', serverOSH, serviceOSH)
                    OSHVResult.add(deployedOSH)
                else:
                    logger.debug('Server not found for host [', host, ']')
    resultSet.close()
Esempio n. 24
0
def transactionChange(sapUtils, mapDevcToOSH, siteOSH, SYSNAME, OSHVResult):
    mapTransportToOSH = HashMap()
    transactionChange = sapUtils.getTransactionChange()
    count = transactionChange.getRowCount()
    for row in range(count):
        # read all fields
        transaction = transactionChange.getCell(row, 0)
        devc = transactionChange.getCell(row, 1)
        objectName = transactionChange.getCell(row, 2)
        objectType = transactionChange.getCell(row, 3)
        objectDescription = transactionChange.getCell(row, 4)
        changeDescription = transactionChange.getCell(row, 5)
        date = transactionChange.getCell(row, 6)
        time = transactionChange.getCell(row, 7)
        user = transactionChange.getCell(row, 8)
        status = transactionChange.getCell(row, 9)
        changeRequest = transactionChange.getCell(row, 10)
        program = transactionChange.getCell(row, 12)
        screen = transactionChange.getCell(row, 13)
        programVersion = transactionChange.getCell(row, 14)
        targetSystem = transactionChange.getCell(row, 15)
        if logger.isDebugEnabled():
            logger.debug('--------------------------------------------')
            logger.debug('changeDescription = ', changeDescription)
            logger.debug('objectType = ', objectType)
            logger.debug('objectName = ', objectName)
            logger.debug('objectDescription = ', objectDescription)
            logger.debug('date = ', date)
            logger.debug('time = ', time)
            logger.debug('user = '******'--------------------------------------------')

        sfDate = SimpleDateFormat('yyyy-MM-dd HH:mm:ss')
        dateObj = sfDate.parse(date + ' ' + time, ParsePosition(0))

        if devc is not None:
            devcOSH = mapDevcToOSH.get(devc)
            if devcOSH != None:

                # In case the application components were filtered then we need to send only the relevant
                # application components for this transport
                addAppCompHierarchy(devcOSH, OSHVResult)
                transactionOSH = buildTransaction(transaction, devc, program,
                                                  screen, programVersion,
                                                  devcOSH, siteOSH, SYSNAME,
                                                  OSHVResult)
                ticketStatus = ''
                #
                # L - Modifiable
                # D - Modifiable, Protected
                if status == 'L' or status == 'D':
                    # (1) = Plan
                    # (9) = Critical
                    ticketStatus = 'In progress'
                else:
                    # (2) = New change
                    # (7) = Major
                    ticketStatus = 'Closed'

                transportOSH = mapTransportToOSH.get(changeRequest)
                if transportOSH == None:
                    transportOSH = buildTransport(changeRequest, dateObj, time,
                                                  user, targetSystem,
                                                  changeDescription,
                                                  ticketStatus, siteOSH,
                                                  OSHVResult)
                    mapTransportToOSH.put(changeRequest, transportOSH)
                OSHVResult.add(
                    modeling.createLinkOSH('contains', transactionOSH,
                                           transportOSH))
                changeOSH = createTransportChange(transaction, objectType,
                                                  objectName, transportOSH,
                                                  OSHVResult)
                OSHVResult.add(
                    modeling.createLinkOSH('use', changeOSH, transactionOSH))
            else:
                logger.warn('can not find devclass OSH for [', devc, ']')
def dbg(msg):
    if 1:
        info(msg)
    elif logger.isDebugEnabled():
        logger.debug(msg)
Esempio n. 26
0
def applications(client,systemOSH,databasesOSH, OSHVResult, schemaName = None, viewSchemaName = None):
    #query information about Oracle Applications products at your site
    mapIdToOSH = HashMap()
    objs = __assocWithSchemaName(['FND_PRODUCT_INSTALLATIONS', 'FND_APPLICATION_VL'], schemaName, viewSchemaName)
    resultSet = client.executeQuery('SELECT * FROM %s P,%s V  WHERE V.APPLICATION_ID = P.APPLICATION_ID' % objs)#@@CMD_PERMISION sql protocol execution
    while resultSet.next():
        id = resultSet.getString(1)
        version = resultSet.getString(8)
        status = resultSet.getString(9)
        tablespace = resultSet.getString(11)
        indexTablespace = resultSet.getString(12)
        tempTablespace = resultSet.getString(13)
        sizing = resultSet.getString(14)
        patchSet = resultSet.getString(17)
        shortName = resultSet.getString(20)
        basePath = resultSet.getString(26)
        description = resultSet.getString(27)
        if patchSet == None:
            patchSet = ''
        if logger.isDebugEnabled():    
            logger.debug('-------------------------------------------------')
            logger.debug('id = ', id)
            logger.debug('version = ', version)
            logger.debug('status = ', status)
            logger.debug('tablespace = ', tablespace)
            logger.debug('indexTablespace = ', indexTablespace)
            logger.debug('tempTablespace = ', tempTablespace)
            logger.debug('sizing = ', sizing)
            logger.debug('patchSet = ', patchSet)
            logger.debug('shortName = ', shortName)
            logger.debug('basepath = ', basePath)
            logger.debug('description = ', description)
            logger.debug('-------------------------------------------------') 
        appOSH = ObjectStateHolder('oracleapplication')
        appOSH.setAttribute('data_name', id)
        if version != None:
            appOSH.setAttribute('oracleapplication_version', version)
        appOSH.setAttribute('oracleapplication_status', getStatusString(status))
        if tablespace != None:
            appOSH.setAttribute('oracleapplication_tablespace', tablespace)
        if indexTablespace != None:
            appOSH.setAttribute('oracleapplication_indextablespace', indexTablespace)
        if tempTablespace != None:
            appOSH.setAttribute('oracleapplication_temptablespace', tempTablespace)
        if sizing != None:
            appOSH.setAttribute('oracleapplication_sizing', int(sizing))
        if patchSet != None:
            appOSH.setAttribute('oracleapplication_patchset', patchSet)
        if shortName != None:
            appOSH.setAttribute('oracleapplication_shortname', shortName)
        if basePath != None:
            appOSH.setAttribute('oracleapplication_basepath', basePath)
        if description != None:
            appOSH.setAttribute('oracleapplication_description', description)
        appOSH.setContainer(systemOSH)
        OSHVResult.add(appOSH)
        mapIdToOSH.put(id,appOSH)
        if databasesOSH != None:
            linkTablespace(appOSH,databasesOSH,tablespace, OSHVResult)
            linkTablespace(appOSH,databasesOSH,indexTablespace, OSHVResult)
            linkTablespace(appOSH,databasesOSH,tempTablespace, OSHVResult)
    # build application dependencies
    resultSet.close()
    objs = __assocWithSchemaName(['FND_PRODUCT_DEPENDENCIES'], schemaName, viewSchemaName)
    resultSet = client.executeQuery('SELECT APPLICATION_ID,REQUIRED_APPLICATION_ID FROM %s' % objs)#@@CMD_PERMISION sql protocol execution        
    while resultSet.next():
        id = resultSet.getString(1)
        requiredId = resultSet.getString(2)
        appOSH = mapIdToOSH.get(id)
        requiredAppOSH = mapIdToOSH.get(requiredId)
        if appOSH != None and requiredAppOSH != None:
            dependOSH = modeling.createLinkOSH('depend', appOSH, requiredAppOSH)
            OSHVResult.add(dependOSH)
        else:
            logger.debug('Applications for ids [', id, '] and/or [', requiredId, '] are not found')
    resultSet.close()
    return     mapIdToOSH
Esempio n. 27
0
    def discover_private(self):
        query = self.buildQuery()

        conn = self.Framework.getProbeDatabaseConnection('TCPDISCOVERY')
        st = None
        result = None
        try:
            st = conn.createStatement()
            result = st.executeQuery(query)

            currDestination = None
            clientsCount = 0
            octetsCount = 0
            packetsCount = 0

            OSHVResult = ObjectStateHolderVector()
            addPortInAnyCase = 0

            dstIpOSH = None
            dstHostOSH = None
            serverPortOsh = None
            portName = -1
            firstTimeSeenPort = 1
            dataFound = 0
            while result.next():
                dataFound = 1
                listen = result.getBoolean('ListenPort')
                if listen:
                    srcAddr = result.getString('SrcAddr')
                    dstAddr = result.getString('DstAddr')
                    dstPort = result.getString('DstPort')
                else:
                    srcAddr = result.getString('DstAddr')
                    dstAddr = result.getString('SrcAddr')
                    dstPort = result.getString('SrcPort')

                if self.ignoreLocalConnections and (srcAddr == dstAddr):
                    continue
                if (not self.shouldInclude(dstAddr, listen)) or self.isIgnoredIp(dstAddr):
                    continue

                srcIgnored = self.isIgnoredIp(srcAddr) or (not self.shouldInclude(srcAddr, not listen))
                protocolNumber = result.getString('Prot')

                destination = dstAddr + ":" + dstPort
                if logger.isDebugEnabled():
                    logger.debug('Current connection:', srcAddr, '->', destination)
                if destination != currDestination:
                    if OSHVResult != None:
                        if addPortInAnyCase or self.matchPortConditions(octetsCount, packetsCount, clientsCount):
                            self.Framework.sendObjects(OSHVResult)

                    currDestination = destination
                    clientsCount = 0
                    octetsCount = 0
                    packetsCount = 0
                    OSHVResult = ObjectStateHolderVector()
                    addPortInAnyCase = self.checkIfAddPortInAnyCase(result)
                    firstTimeSeenPort = 1
                else:
                    firstTimeSeenPort = 0

                if firstTimeSeenPort:
                    dstIpOSH = modeling.createIpOSH(dstAddr)
                    dstHostOSH = modeling.createHostOSH(dstAddr)
                    if not self.onlyHostDependLinks:
                        OSHVResult.add(dstIpOSH)
                    OSHVResult.add(dstHostOSH)
                    portName = ''
                    if int(protocolNumber) == NetlinksServices.UDP_PROTOCOL:
                        portTypeEnum = NetlinksServices.UDP_PORT_TYPE_ENUM
                        portName = self.knownPortsConfigFile.getUdpPortName(int(dstPort))
                    else:
                        portTypeEnum = NetlinksServices.TCP_PORT_TYPE_ENUM
                        portName = self.knownPortsConfigFile.getTcpPortName(int(dstPort))
                    if portName == None:
                        portName = dstPort
                    if logger.isDebugEnabled():
                        logger.debug('Port ', str(dstPort), ' with name ', portName)
                    serverPortOsh = modeling.createServiceAddressOsh(dstHostOSH, dstAddr, int(dstPort), portTypeEnum, portName)
                    OSHVResult.add(serverPortOsh)


                srcIpOSH = None
                srcHostOSH = None
                if not srcIgnored:
                    srcIpOSH = modeling.createIpOSH(srcAddr)
                    srcHostOSH = modeling.createHostOSH(srcAddr)
                    if not self.onlyHostDependLinks:
                        OSHVResult.add(srcIpOSH)
                    OSHVResult.add(srcHostOSH)

                    if not self.onlyHostDependLinks:
                        containedLink = modeling.createLinkOSH('contained', srcHostOSH, srcIpOSH)
                        OSHVResult.add(containedLink)
                        if firstTimeSeenPort:
                            containedLink = modeling.createLinkOSH('contained', dstHostOSH, dstIpOSH)
                            OSHVResult.add(containedLink)

                octets = 0
                packets = 0
                clients = 0
                if self.updateUtilizationInfo:
                    octets = result.getInt('dOctets')
                    packets = result.getInt('dPkts')
                    if self.shouldCountClients:
                        clients = result.getInt('cnt')

                clientsCount = clientsCount + clients
                octetsCount = octetsCount + octets
                packetsCount = packetsCount + packets

                self.createObjects(OSHVResult, dstIpOSH, dstHostOSH, dstPort, serverPortOsh, portName, protocolNumber, srcIpOSH, srcHostOSH, octets, packets, srcIgnored)

            if not dataFound:
                self.Framework.reportWarning("No data to process, please check if Host Resources jobs had already run")
            if addPortInAnyCase or self.matchPortConditions(octetsCount, packetsCount, clientsCount):
                self.Framework.sendObjects(OSHVResult)
        #except JException,ex:
        #    ex.printStackTrace()
        finally:
            if result != None:
                try:
                    result.close
                except:
                    pass
            st.close()
#            conn.close(st)
            conn.close()
Esempio n. 28
0
	def getTransactionsInfo(self, transactions):
		mapTransactionToInfo = HashMap()
		mapProgramToTransaction = HashMap()

		if (transactions == None) or (len(transactions) == 0):
			logger.info("getTransactionsInfo: transactions list is empty")
			return mapTransactionToInfo
		
		transactionsRS = self.__client.executeQuery('TSTC', '', 'TCODE', transactions, 'TCODE,PGMNA,DYPNO')#@@CMD_PERMISION sap protocol execution
		while transactionsRS.next():
			transaction = transactionsRS.getString("TCODE")
			program = transactionsRS.getString("PGMNA")
			screen = transactionsRS.getString("DYPNO")
			if logger.isDebugEnabled():
				logger.debug("-------------------------------------------------------")
				logger.debug("getTransactionsInfo: transaction = " + transaction)
				logger.debug("getTransactionsInfo: program = " + program)
				logger.debug("getTransactionsInfo: screen = " + screen)
				logger.debug("-------------------------------------------------------")

			if (program == None) or (len(program) == 0):
				program = "N/A"
				logger.info("getTransactionsInfo: program for transaction [" + str(transaction) + "] is no available - setting to N/A.")

			info = TransactionInfo(transaction,program,screen)
			mapTransactionToInfo.put(transaction,info)
			transForProgram = mapProgramToTransaction.get(program)
			if transForProgram == None:
				transForProgram = ArrayList()
				mapProgramToTransaction.put(program,transForProgram)
			transForProgram.add(transaction)

		if logger.isDebugEnabled():
			logger.debug("getTransactionsInfo: mapProgramToTransaction = " + str(mapProgramToTransaction))

		if len(mapProgramToTransaction) == 0:
			logger.info("getTransactionsInfo: failed to get programs for transactions " + str(transactions))
			return mapProgramToTransaction

		objNames = ArrayList(mapProgramToTransaction.keySet())
		objNames.addAll(mapTransactionToInfo.keySet())
		
		
		programsRS = self.__client.executeQuery('TADIR', "(OBJECT = 'PROG' OR OBJECT = 'TRAN') AND ", 'OBJ_NAME', objNames, 'OBJECT,OBJ_NAME,VERSID,DEVCLASS')#@@CMD_PERMISION sap protocol execution
		
		while programsRS.next():
			objectType = programsRS.getString("OBJECT")
			if objectType == "PROG":
				program = programsRS.getString("OBJ_NAME")
				version = programsRS.getString("VERSID")
				transForProgram = mapProgramToTransaction.get(program)
				if transForProgram != None:
					
					for ti in transForProgram:
						info = mapTransactionToInfo.get(ti)
						if info == None:
							logger.info("program: Failed to find info for transaction [" + str(transaction) + "]")
						else:
							info.version = version
				else:
					logger.info("getTransactionsInfo: failed getting transactions for program [" + str(program) + "]")
			else: # transaction
				devclass = programsRS.getString("DEVCLASS");
				transaction = programsRS.getString("OBJ_NAME")
				info = mapTransactionToInfo.get(transaction)
				if info == None:
					logger.info("transaction: Failed to find info for transaction [" + str(transaction) + "]")
					info = TransactionInfo(transaction,"N/A","")
					mapTransactionToInfo.put(transaction,info)
				info.devclass = devclass

		if logger.isDebugEnabled():
			logger.debug("--------------------------------------------------")
			logger.debug("getTransactionsInfo: returning transaction info " + str(mapTransactionToInfo))
			logger.debug("--------------------------------------------------")

		return mapTransactionToInfo
Esempio n. 29
0
    def discover_private(self):
        query = self.buildQuery()

        conn = self.Framework.getProbeDatabaseConnection('TCPDISCOVERY')
        st = None
        result = None
        try:
            st = conn.createStatement()
            result = st.executeQuery(query)

            currDestination = None
            clientsCount = 0
            octetsCount = 0
            packetsCount = 0

            OSHVResult = ObjectStateHolderVector()
            addPortInAnyCase = 0

            dstIpOSH = None
            dstHostOSH = None
            serverPortOsh = None
            portName = -1
            firstTimeSeenPort = 1
            dataFound = 0
            while result.next():
                dataFound = 1
                listen = result.getBoolean('ListenPort')
                if listen:
                    srcAddr = result.getString('SrcAddr')
                    dstAddr = result.getString('DstAddr')
                    dstPort = result.getString('DstPort')
                else:
                    srcAddr = result.getString('DstAddr')
                    dstAddr = result.getString('SrcAddr')
                    dstPort = result.getString('SrcPort')

                if self.ignoreLocalConnections and (srcAddr == dstAddr):
                    continue
                if (not self.shouldInclude(
                        dstAddr, listen)) or self.isIgnoredIp(dstAddr):
                    continue

                srcIgnored = self.isIgnoredIp(srcAddr) or (
                    not self.shouldInclude(srcAddr, not listen))
                protocolNumber = result.getString('Prot')

                destination = dstAddr + ":" + dstPort
                if logger.isDebugEnabled():
                    logger.debug('Current connection:', srcAddr, '->',
                                 destination)
                if destination != currDestination:
                    if OSHVResult != None:
                        if addPortInAnyCase or self.matchPortConditions(
                                octetsCount, packetsCount, clientsCount):
                            self.Framework.sendObjects(OSHVResult)

                    currDestination = destination
                    clientsCount = 0
                    octetsCount = 0
                    packetsCount = 0
                    OSHVResult = ObjectStateHolderVector()
                    addPortInAnyCase = self.checkIfAddPortInAnyCase(result)
                    firstTimeSeenPort = 1
                else:
                    firstTimeSeenPort = 0

                if firstTimeSeenPort:
                    dstIpOSH = modeling.createIpOSH(dstAddr)
                    dstHostOSH = modeling.createHostOSH(dstAddr)
                    if not self.onlyHostDependLinks:
                        OSHVResult.add(dstIpOSH)
                    OSHVResult.add(dstHostOSH)
                    portName = ''
                    if int(protocolNumber) == NetlinksServices.UDP_PROTOCOL:
                        portTypeEnum = NetlinksServices.UDP_PORT_TYPE_ENUM
                        portName = self.knownPortsConfigFile.getUdpPortName(
                            int(dstPort))
                    else:
                        portTypeEnum = NetlinksServices.TCP_PORT_TYPE_ENUM
                        portName = self.knownPortsConfigFile.getTcpPortName(
                            int(dstPort))
                    if portName == None:
                        portName = dstPort
                    if logger.isDebugEnabled():
                        logger.debug('Port ', str(dstPort), ' with name ',
                                     portName)
                    serverPortOsh = modeling.createServiceAddressOsh(
                        dstHostOSH, dstAddr, int(dstPort), portTypeEnum,
                        portName)
                    OSHVResult.add(serverPortOsh)

                srcIpOSH = None
                srcHostOSH = None
                if not srcIgnored:
                    srcIpOSH = modeling.createIpOSH(srcAddr)
                    srcHostOSH = modeling.createHostOSH(srcAddr)
                    if not self.onlyHostDependLinks:
                        OSHVResult.add(srcIpOSH)
                    OSHVResult.add(srcHostOSH)

                    if not self.onlyHostDependLinks:
                        containedLink = modeling.createLinkOSH(
                            'contained', srcHostOSH, srcIpOSH)
                        OSHVResult.add(containedLink)
                        if firstTimeSeenPort:
                            containedLink = modeling.createLinkOSH(
                                'contained', dstHostOSH, dstIpOSH)
                            OSHVResult.add(containedLink)

                octets = 0
                packets = 0
                clients = 0
                if self.updateUtilizationInfo:
                    octets = result.getInt('dOctets')
                    packets = result.getInt('dPkts')
                    if self.shouldCountClients:
                        clients = result.getInt('cnt')

                clientsCount = clientsCount + clients
                octetsCount = octetsCount + octets
                packetsCount = packetsCount + packets

                self.createObjects(OSHVResult, dstIpOSH, dstHostOSH, dstPort,
                                   serverPortOsh, portName, protocolNumber,
                                   srcIpOSH, srcHostOSH, octets, packets,
                                   srcIgnored)

            if not dataFound:
                self.Framework.reportWarning(
                    "No data to process, please check if Host Resources jobs had already run"
                )
            if addPortInAnyCase or self.matchPortConditions(
                    octetsCount, packetsCount, clientsCount):
                self.Framework.sendObjects(OSHVResult)
        #except JException,ex:
        #    ex.printStackTrace()
        finally:
            if result != None:
                try:
                    result.close
                except:
                    pass
            st.close()
            #            conn.close(st)
            conn.close()
Esempio n. 30
0
def infrastructure(client, OSHVResult, Framework, schemaName = None, viewSchemaName = None):
    retOSHs = ArrayList(4)
    retOSHs.add(None)
    retOSHs.add(None)
    retOSHs.add(None)
    retOSHs.add(None)

    systemOSH = ObjectStateHolder('oraclesystem')
    systemOSH.setAttribute('data_name', client.getSid())
    systemOSH.setAttribute('oraclesystem_dbaddress', client.getIpAddress())
    modeling.setAppSystemVendor(systemOSH)
    
    webServerOSH = None
    nameToHostOSH = HashMap()
    hostToServerOSH = HashMap()
    hostToIpAddress = HashMap()
    databasesOSH = HashMap()

    resultSet = None
    try:
        objs = __assocWithSchemaName(['FND_OAM_APP_SYS_STATUS'], schemaName, viewSchemaName) 
        # query a special table that holds Applications System Status related information
        resultSet = client.executeQuery('SELECT * FROM %s' % objs)#@@CMD_PERMISION sql protocol execution
    except:
        logger.debugException('SQL query failure. "SELECT * FROM FND_OAM_APP_SYS_STATUS"')
        Framework.reportWarning('No Oracle E-Business Suite components found.')

    if resultSet:
        OSHVResult.add(systemOSH)
        retOSHs.set(0, systemOSH)
    else:
        return None
        
    while resultSet.next():
        name = resultSet.getString(1)
        dbSid = resultSet.getString(4)
        status = resultSet.getString(6)
        host = resultSet.getString(7)
        port = client.getPort()
        
        if logger.isDebugEnabled():
            logger.debug('-----------------------------')
            logger.debug('name = ', name)
            logger.debug('status = ', status)
            if host != None:
                logger.debug('host = ', host)
            else:
                logger.debug('skipping Application system with None host')
                continue
            logger.debug('-----------------------------')
        hostOSH = nameToHostOSH.get(host)
        serverOSH = hostToServerOSH.get(host)
        hostIP = hostToIpAddress.get(host)

        if not hostIP:
            hostIP = netutils.getHostAddress(host, host)

        if hostOSH == None and netutils.isValidIp(hostIP):
            hostOSH = modeling.createHostOSH(hostIP)
            OSHVResult.add(hostOSH)
            nameToHostOSH.put(host,hostOSH)
            hostToIpAddress.put(host,hostIP)

        if hostOSH == None:
            logger.warn('Failed to created host [', host, ']')
            continue

        if serverOSH == None:
            serverOSH = modeling.createJ2EEServer('oracleias', hostIP, None, hostOSH, host)
            OSHVResult.add(serverOSH)
            hostToServerOSH.put(host,serverOSH)
            serverMemberOSH = modeling.createLinkOSH('member', systemOSH, serverOSH)
            OSHVResult.add(serverMemberOSH)
        if name.find('WEB_SERVER') == 0 and host != None:
            webServerOSH = serverOSH
            serverOSH.setBoolAttribute('oracleias_web', 1)
        elif name.find('FORMS_SERVER') == 0 and host != None:
            serverOSH.setBoolAttribute('oracleias_form', 1)
        elif name.find('ADMIN_SERVER') == 0 and host != None:
            serverOSH.setBoolAttribute('oracleias_admin', 1)
        elif name.find('CP_SERVER') == 0 and host != None:            
            serverOSH.setBoolAttribute('oracleias_concurrentprocessing', 1)
        elif name.find('DATABASE') == 0 and host != None:
            dbOSH = modeling.createDatabaseOSH('oracle', dbSid, port, hostIP, hostOSH)
            OSHVResult.add(dbOSH)
            databasesOSH.put(dbSid,dbOSH)
            memberOSH = modeling.createLinkOSH('member', systemOSH, dbOSH)
            OSHVResult.add(memberOSH)
    resultSet.close()
    try:
        systemMetrics(client,systemOSH,webServerOSH, OSHVResult, schemaName, viewSchemaName)
    except:
        logger.debug("Failed to get system metrics")
    retOSHs.set(1, hostToServerOSH)
    retOSHs.set(2, nameToHostOSH)
    retOSHs.set(3, databasesOSH)
    return retOSHs    
Esempio n. 31
0
def applications(client,
                 systemOSH,
                 databasesOSH,
                 OSHVResult,
                 schemaName=None,
                 viewSchemaName=None):
    #query information about Oracle Applications products at your site
    mapIdToOSH = HashMap()
    objs = __assocWithSchemaName(
        ['FND_PRODUCT_INSTALLATIONS', 'FND_APPLICATION_VL'], schemaName,
        viewSchemaName)
    resultSet = client.executeQuery(
        'SELECT * FROM %s P,%s V  WHERE V.APPLICATION_ID = P.APPLICATION_ID' %
        objs)  #@@CMD_PERMISION sql protocol execution
    while resultSet.next():
        id = resultSet.getString(1)
        version = resultSet.getString(8)
        status = resultSet.getString(9)
        tablespace = resultSet.getString(11)
        indexTablespace = resultSet.getString(12)
        tempTablespace = resultSet.getString(13)
        sizing = resultSet.getString(14)
        patchSet = resultSet.getString(17)
        shortName = resultSet.getString(20)
        basePath = resultSet.getString(26)
        description = resultSet.getString(27)
        if patchSet == None:
            patchSet = ''
        if logger.isDebugEnabled():
            logger.debug('-------------------------------------------------')
            logger.debug('id = ', id)
            logger.debug('version = ', version)
            logger.debug('status = ', status)
            logger.debug('tablespace = ', tablespace)
            logger.debug('indexTablespace = ', indexTablespace)
            logger.debug('tempTablespace = ', tempTablespace)
            logger.debug('sizing = ', sizing)
            logger.debug('patchSet = ', patchSet)
            logger.debug('shortName = ', shortName)
            logger.debug('basepath = ', basePath)
            logger.debug('description = ', description)
            logger.debug('-------------------------------------------------')
        appOSH = ObjectStateHolder('oracleapplication')
        appOSH.setAttribute('data_name', id)
        if version != None:
            appOSH.setAttribute('oracleapplication_version', version)
        appOSH.setAttribute('oracleapplication_status',
                            getStatusString(status))
        if tablespace != None:
            appOSH.setAttribute('oracleapplication_tablespace', tablespace)
        if indexTablespace != None:
            appOSH.setAttribute('oracleapplication_indextablespace',
                                indexTablespace)
        if tempTablespace != None:
            appOSH.setAttribute('oracleapplication_temptablespace',
                                tempTablespace)
        if sizing != None:
            appOSH.setAttribute('oracleapplication_sizing', int(sizing))
        if patchSet != None:
            appOSH.setAttribute('oracleapplication_patchset', patchSet)
        if shortName != None:
            appOSH.setAttribute('oracleapplication_shortname', shortName)
        if basePath != None:
            appOSH.setAttribute('oracleapplication_basepath', basePath)
        if description != None:
            appOSH.setAttribute('oracleapplication_description', description)
        appOSH.setContainer(systemOSH)
        OSHVResult.add(appOSH)
        mapIdToOSH.put(id, appOSH)
        if databasesOSH != None:
            linkTablespace(appOSH, databasesOSH, tablespace, OSHVResult)
            linkTablespace(appOSH, databasesOSH, indexTablespace, OSHVResult)
            linkTablespace(appOSH, databasesOSH, tempTablespace, OSHVResult)
    # build application dependencies
    resultSet.close()
    objs = __assocWithSchemaName(['FND_PRODUCT_DEPENDENCIES'], schemaName,
                                 viewSchemaName)
    resultSet = client.executeQuery(
        'SELECT APPLICATION_ID,REQUIRED_APPLICATION_ID FROM %s' %
        objs)  #@@CMD_PERMISION sql protocol execution
    while resultSet.next():
        id = resultSet.getString(1)
        requiredId = resultSet.getString(2)
        appOSH = mapIdToOSH.get(id)
        requiredAppOSH = mapIdToOSH.get(requiredId)
        if appOSH != None and requiredAppOSH != None:
            dependOSH = modeling.createLinkOSH('depend', appOSH,
                                               requiredAppOSH)
            OSHVResult.add(dependOSH)
        else:
            logger.debug('Applications for ids [', id, '] and/or [',
                         requiredId, '] are not found')
    resultSet.close()
    return mapIdToOSH
Esempio n. 32
0
def services(client,
             mapAppIdToOSH,
             hostToServerOSH,
             nameToHostOSH,
             systemOSH,
             OSHVResult,
             schemaName=None,
             viewSchemaName=None):
    mapManagerToOSH = HashMap()
    mapServiceToOSH = HashMap()

    #we have no way for now to obtain processes names, and pid is not interesting for us
    #so we don't want to create processes (and can't, since process name is key_attribute)
    #mapProcessIDToOSH = getProcesses(client,nameToHostOSH, OSHVResult)
    mapProcessIDToOSH = HashMap()
    objs = __assocWithSchemaName(
        ['FND_CONCURRENT_QUEUES_VL', 'FND_CP_SERVICES_VL'], schemaName,
        viewSchemaName)
    resultSet = client.executeQuery(
        'SELECT Q.CONCURRENT_QUEUE_ID,Q.APPLICATION_ID,Q.CONCURRENT_QUEUE_NAME,Q.MAX_PROCESSES,Q.RUNNING_PROCESSES,Q.TARGET_NODE,Q.USER_CONCURRENT_QUEUE_NAME,Q.DESCRIPTION,S.SERVICE_NAME,S.DESCRIPTION FROM %s Q, %s S WHERE Q.MANAGER_TYPE = S.SERVICE_ID'
        % objs)  #@@CMD_PERMISION sql protocol execution
    while resultSet.next():
        queueId = resultSet.getString(1)
        appId = resultSet.getString(2)
        name = resultSet.getString(3)
        maxProcesses = resultSet.getString(4)
        runningProcesses = resultSet.getString(5)
        host = resultSet.getString(6)
        displayName = resultSet.getString(7)
        description = resultSet.getString(8)
        managerName = resultSet.getString(9)
        managerDescription = resultSet.getString(10)

        if managerName == None:
            continue

        managerOSH = mapManagerToOSH.get(managerName)
        if managerOSH == None:
            managerOSH = ObjectStateHolder('oracleappservicemanager')
            managerOSH.setAttribute('data_name', managerName)
            if managerDescription != None:
                managerOSH.setAttribute('oracleappservicemanager_description',
                                        managerDescription)
            managerOSH.setContainer(systemOSH)
            mapManagerToOSH.put(managerName, managerOSH)
            OSHVResult.add(managerOSH)

        if description == None:
            description = ''
        if logger.isDebugEnabled():
            logger.debug('-------------------------------------------------')
            logger.debug('name = ', name)
            logger.debug('displayName = ', displayName)
            logger.debug('appId = ', appId)
            logger.debug('description = ', description)
            if host != None:
                logger.debug('host = ', host)
            logger.debug('-------------------------------------------------')
        appOSH = mapAppIdToOSH.get(appId)
        serverOSH = hostToServerOSH.get(host)
        if appOSH != None:
            if (name == None) and (displayName != None):
                name = displayName
            if name != None:
                serviceOSH = ObjectStateHolder('oracleappservice')
                serviceOSH.setAttribute('data_name', name)
                serviceOSH.setAttribute('oracleappservice_displayname',
                                        displayName)
                serviceOSH.setAttribute('oracleappservice_description',
                                        description)
                serviceOSH.setAttribute('oracleappservice_maxprocesses',
                                        int(maxProcesses))
                serviceOSH.setAttribute('oracleappservice_runningprocesses',
                                        int(runningProcesses))
                serviceOSH.setContainer(appOSH)
                OSHVResult.add(serviceOSH)
                mapServiceToOSH.put(name, serviceOSH)

                processes = mapProcessIDToOSH.get(queueId)
                if processes != None:
                    logger.debug('Found processes for service [', name, ']')
                    itProcesses = processes.iterator()
                    while itProcesses.hasNext():
                        processOSH = itProcesses.next()
                        resourceOSH = modeling.createLinkOSH(
                            'resource', serviceOSH, processOSH)
                        OSHVResult.add(resourceOSH)
                else:
                    logger.debug('No processes found for service [', name, ']')

                if managerOSH != None:
                    memberOSH = modeling.createLinkOSH('member', managerOSH,
                                                       serviceOSH)
                    OSHVResult.add(memberOSH)

                if serverOSH != None:
                    deployedOSH = modeling.createLinkOSH(
                        'deployed', serverOSH, serviceOSH)
                    OSHVResult.add(deployedOSH)
                else:
                    logger.debug('Server not found for host [', host, ']')
    resultSet.close()
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    DISCOVERED_IP = Framework.getDestinationAttribute('ip_address')
    DISCOVERED_IP_ID = Framework.getDestinationAttribute('ip_id')    
#    ip = modeling.createOshByCmdbIdString('ip_address', DISCOVERED_IP_ID)
    ucmdbVersion = modeling.CmdbClassModel().version()
    if ucmdbVersion >= 9:
        ipClass = 'ip_address'
    else:
        ipClass = 'ip'

    protocols = Framework.getAvailableProtocols(DISCOVERED_IP, ClientsConsts.SNMP_PROTOCOL_NAME)

    if protocols.__len__() == 0:
        errStr = 'No credentials defined for the triggered ip'
        logger.debug(errStr)
        Framework.reportWarning(errStr)
    else:
        for protocol in protocols:
            sysplexNameList = None
            lparIpList = None
            
            snmpOSH = modeling.createSnmpOSH(DISCOVERED_IP, None)

            client = None
            try:
                client = Framework.createClient(protocol)
                logger.debug('got snmp agent for: ', DISCOVERED_IP)
                isMultiOid = client.supportMultiOid()
                
                sysplexNameList = client.executeQuery( '1.3.6.1.4.1.2.6.19.2.2.2.41,1.3.6.1.4.1.2.6.19.2.2.2.41,string,1.3.6.1.4.1.2.6.19.2.2.2.40,string' )#@@CMD_PERMISION snmp protocol execution
                sysplexNameList = sysplexNameList.asTable()

                lparIpList = client.executeQuery( '1.3.6.1.2.1.4.20.1.1,1.3.6.1.2.1.4.20.1.2,string' )#@@CMD_PERMISION snmp protocol execution
                lparIpList = lparIpList.asTable()

                mainframeMacList = client.executeQuery( '1.3.6.1.2.1.2.2.1.6,1.3.6.1.2.1.2.2.1.7,hexa' )#@@CMD_PERMISION snmp protocol execution
                mainframeMacList = mainframeMacList.asTable()
                snmpOSH.setAttribute('application_port', client.getPort())
                
                snmpOSH.setAttribute('application_timeout', client.getTimeout())
                snmpOSH.setAttribute('snmp_port', client.getPort())
                snmpOSH.setAttribute('credentials_id', client.getCredentialId())
                snmpOSH.setAttribute('snmp_retry', client.getRetries())
                snmpOSH.setAttribute('snmp_timeout', client.getTimeout())
                if isMultiOid == 1:
                    snmpOSH.setBoolAttribute('snmp_supportmultioid', 1)
                else:
                    snmpOSH.setBoolAttribute('snmp_supportmultioid', 0)
            except:
                logger.debugException('Unexpected SNMP_AGENT Exception:')
                continue

            if client != None:
                client.close()

            mainframeKey = getMainframeKey(mainframeMacList)
            if mainframeKey:
                mainframeOSH = modeling.createCompleteHostOSH('mainframe', mainframeKey, machineName = mainframeKey)
                modeling.setHostOsFamily(mainframeOSH, 'mainframe')
                OSHVResult.add(mainframeOSH)

                for currSysplex in sysplexNameList:
                    if logger.isDebugEnabled():
                        logger.debug( 'SYSPLEX : ', currSysplex[1] )
                        logger.debug( 'LPAR : ', currSysplex[2] )
                        logger.debug( 'MainframeKEY : ', mainframeKey )

                    lparKey = mainframeKey + ':' + currSysplex[2]
                    lparOSH = modeling.createCompleteHostOSH('lpar', lparKey, machineName = currSysplex[2])
                    OSHVResult.add(lparOSH)
                    
                    snmpOSH.setContainer(lparOSH)
                    OSHVResult.add(snmpOSH)

                    # Create contained link between discovered IP and lpar
                    OSHVResult.add(modeling.createLinkOSH('contained', lparOSH, modeling.createOshByCmdbIdString(ipClass, DISCOVERED_IP_ID)))

                    # Create member link between lpar and Mainframe
                    OSHVResult.add(modeling.createLinkOSH('member', mainframeOSH, lparOSH))

                    # Create sysplex
                    sysplexOSH = ObjectStateHolder('sysplex')
                    sysplexOSH.setAttribute('data_name', currSysplex[1])
                    OSHVResult.add(sysplexOSH)

                    # Create member link between lpar and sysplex
                    OSHVResult.add(modeling.createLinkOSH('member', sysplexOSH, lparOSH))

                    # Create member link between mainframe and sysplex
                    OSHVResult.add(modeling.createLinkOSH('member', mainframeOSH, sysplexOSH))

                    # connect all ips to lpar
                    for currLparIp in lparIpList:
                        if netutils.isLocalIp(currLparIp[1]):
                            continue

                        currIpOSH = modeling.createIpOSH(currLparIp[1])
                        OSHVResult.add(currIpOSH)
                        OSHVResult.add(modeling.createLinkOSH('contained', lparOSH, currIpOSH))
                break
            else:
                logger.debug("Failed to get Mainframe key.")
        else:
            errormessages.resolveAndReport("Could not perform snmp connection to %s" % DISCOVERED_IP, ClientsConsts.SNMP_PROTOCOL_NAME, Framework)

    return OSHVResult
Esempio n. 34
0
def infrastructure(client,
                   OSHVResult,
                   Framework,
                   schemaName=None,
                   viewSchemaName=None):
    retOSHs = ArrayList(4)
    retOSHs.add(None)
    retOSHs.add(None)
    retOSHs.add(None)
    retOSHs.add(None)

    systemOSH = ObjectStateHolder('oraclesystem')
    systemOSH.setAttribute('data_name', client.getSid())
    systemOSH.setAttribute('oraclesystem_dbaddress', client.getIpAddress())
    modeling.setAppSystemVendor(systemOSH)

    webServerOSH = None
    nameToHostOSH = HashMap()
    hostToServerOSH = HashMap()
    hostToIpAddress = HashMap()
    databasesOSH = HashMap()

    resultSet = None
    try:
        objs = __assocWithSchemaName(['FND_OAM_APP_SYS_STATUS'], schemaName,
                                     viewSchemaName)
        # query a special table that holds Applications System Status related information
        resultSet = client.executeQuery(
            'SELECT * FROM %s' % objs)  #@@CMD_PERMISION sql protocol execution
    except:
        logger.debugException(
            'SQL query failure. "SELECT * FROM FND_OAM_APP_SYS_STATUS"')
        Framework.reportWarning('No Oracle E-Business Suite components found.')

    if resultSet:
        OSHVResult.add(systemOSH)
        retOSHs.set(0, systemOSH)
    else:
        return None

    while resultSet.next():
        name = resultSet.getString(1)
        dbSid = resultSet.getString(4)
        status = resultSet.getString(6)
        host = resultSet.getString(7)
        port = client.getPort()

        if logger.isDebugEnabled():
            logger.debug('-----------------------------')
            logger.debug('name = ', name)
            logger.debug('status = ', status)
            if host != None:
                logger.debug('host = ', host)
            else:
                logger.debug('skipping Application system with None host')
                continue
            logger.debug('-----------------------------')
        hostOSH = nameToHostOSH.get(host)
        serverOSH = hostToServerOSH.get(host)
        hostIP = hostToIpAddress.get(host)

        if not hostIP:
            hostIP = netutils.getHostAddress(host, host)

        if hostOSH == None and netutils.isValidIp(hostIP):
            hostOSH = modeling.createHostOSH(hostIP)
            OSHVResult.add(hostOSH)
            nameToHostOSH.put(host, hostOSH)
            hostToIpAddress.put(host, hostIP)

        if hostOSH == None:
            logger.warn('Failed to created host [', host, ']')
            continue

        if serverOSH == None:
            serverOSH = modeling.createJ2EEServer('oracleias', hostIP, None,
                                                  hostOSH, host)
            OSHVResult.add(serverOSH)
            hostToServerOSH.put(host, serverOSH)
            serverMemberOSH = modeling.createLinkOSH('member', systemOSH,
                                                     serverOSH)
            OSHVResult.add(serverMemberOSH)
        if name.find('WEB_SERVER') == 0 and host != None:
            webServerOSH = serverOSH
            serverOSH.setBoolAttribute('oracleias_web', 1)
        elif name.find('FORMS_SERVER') == 0 and host != None:
            serverOSH.setBoolAttribute('oracleias_form', 1)
        elif name.find('ADMIN_SERVER') == 0 and host != None:
            serverOSH.setBoolAttribute('oracleias_admin', 1)
        elif name.find('CP_SERVER') == 0 and host != None:
            serverOSH.setBoolAttribute('oracleias_concurrentprocessing', 1)
        elif name.find('DATABASE') == 0 and host != None:
            dbOSH = modeling.createDatabaseOSH('oracle', dbSid, port, hostIP,
                                               hostOSH)
            OSHVResult.add(dbOSH)
            databasesOSH.put(dbSid, dbOSH)
            memberOSH = modeling.createLinkOSH('member', systemOSH, dbOSH)
            OSHVResult.add(memberOSH)
    resultSet.close()
    try:
        systemMetrics(client, systemOSH, webServerOSH, OSHVResult, schemaName,
                      viewSchemaName)
    except:
        logger.debug("Failed to get system metrics")
    retOSHs.set(1, hostToServerOSH)
    retOSHs.set(2, nameToHostOSH)
    retOSHs.set(3, databasesOSH)
    return retOSHs
Esempio n. 35
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    SYSNAME = Framework.getDestinationAttribute('system_name')
    GET_TX_ACTIVE = Framework.getParameter('getActiveTransactions') == 'true'
    GET_TX_CHANGE = Framework.getParameter('getTransChanges') == 'true'
    GET_TX_ALL = Framework.getParameter('getAllTransactions') == 'true'
    report_app_components = Framework.getParameter(
        'getAppComponents') == 'true'

    properties = Properties()
    instance_number = Framework.getDestinationAttribute('instance_nr')
    ip_address = Framework.getDestinationAttribute('ip_address')
    connection_client = Framework.getDestinationAttribute('connection_client')
    logger.debug('Connecting to a SAP system number:', str(instance_number))
    properties.setProperty(Protocol.SAP_PROTOCOL_ATTRIBUTE_SYSNUMBER,
                           instance_number)
    if (connection_client is not None) and (connection_client != 'NA'):
        logger.debug('Connecting to a SAP system with client:',
                     str(connection_client))
        properties.setProperty(Protocol.SAP_PROTOCOL_ATTRIBUTE_CLIENT,
                               connection_client)
    if GET_TX_CHANGE:
        # get transaction change only parameters
        FROM_DATE = Framework.getParameter('transChangesFromDate')
        FROM_TIME = Framework.getParameter('transChangesFromTime')
        TO_DATE = Framework.getParameter('transChangesToDate')
        TO_TIME = Framework.getParameter('transChangesToTime')
        INTERVAL = Framework.getParameter('transChangesDaysInterval')

        if logger.isDebugEnabled():
            logger.debug('FROM_DATE = ', FROM_DATE)
            logger.debug('FROM_TIME = ', FROM_TIME)
            logger.debug('TO_DATE = ', TO_DATE)
            logger.debug('TO_TIME = ', TO_TIME)

        properties.setProperty(SAPQueryClient.PARAM_FROM_DATE, FROM_DATE)
        properties.setProperty(SAPQueryClient.PARAM_FROM_TIME, FROM_TIME)
        properties.setProperty(SAPQueryClient.PARAM_TO_DATE, TO_DATE)
        properties.setProperty(SAPQueryClient.PARAM_TO_TIME, TO_TIME)
        if ((INTERVAL != None) and (INTERVAL != '0') and (INTERVAL != '')):
            properties.setProperty(SAPQueryClient.PARAM_INTERVAL, INTERVAL)

    loadOnInit = 0
    if GET_TX_ACTIVE:
        properties.setProperty(SAPQueryClient.PARAM_FLAG_GET_USERS, 'false')
        loadOnInit = 1

    errormsg = ''
    client = None
    try:
        try:
            # create SAP client
            client = Framework.createClient(properties)
            sapUtils = sapappsutils.SapAppsUtils(client, loadOnInit,
                                                 saputils.SapUtils.NO_LOAD)
        except (NoClassDefFoundError, MissingJarsException,
                ExceptionInInitializerError):
            errormsg = 'SAP drivers are missing'
            logger.debugException(errormsg)
        except:
            errormsg = 'Connection failed'
            logger.debugException(errormsg)
        else:
            systemOsh, oshs = sap_abap.report_system(SYSNAME, instance_number,
                                                     ip_address)
            OSHVResult.addAll(oshs)

            # Check if we need to collect all the application component.
            # (we can discover up to 60000 CIs per System - don't discover if it is not needed)
            if not report_app_components:
                logger.debug('Not sending application components to server')

            # build the application hierarchy even if not all of it is sent to the server
            mapDevcToOSH = None
            if GET_TX_CHANGE or GET_TX_ALL or GET_TX_ACTIVE or report_app_components:
                mapDevcToOSH, oshs = buildAppHierarchy(sapUtils, systemOsh,
                                                       report_app_components)
                OSHVResult.addAll(oshs)

            # Check if we need to collect the changed transactions
            if GET_TX_CHANGE:
                try:
                    logger.debug('Getting transaction change...')
                    transactionChange(sapUtils, mapDevcToOSH, systemOsh,
                                      SYSNAME, OSHVResult)
                except NoSuchChangeException:
                    Framework.reportWarning(
                        'No changes found in the given time range')
                except:
                    logger.errorException(
                        'Failed retrieving transactions change')
                    Framework.reportError(
                        'Failed retrieving transactions change')

            # Check if we need to collect all the transactions
            if GET_TX_ALL:
                try:
                    logger.debug('Getting all transactions...')
                    transactions(sapUtils, mapDevcToOSH, systemOsh, SYSNAME,
                                 OSHVResult)
                except:
                    logger.errorException('Failed to get transactions')
                    Framework.reportWarning('Failed to get transactions')

            # Check if we need to collect the active transactions
            if GET_TX_ACTIVE:
                try:
                    logger.debug('Getting active transactions...')
                    activeTransactions(sapUtils, mapDevcToOSH, systemOsh,
                                       SYSNAME, OSHVResult)
                except:
                    logger.errorException(
                        'Failed retrieving active transactions')
                    Framework.reportError(
                        'Failed retrieving active transactions')
    finally:
        if client is not None:
            client.close()
        if errormsg:
            Framework.reportError(errormsg)
    return OSHVResult
Esempio n. 36
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ObjSHV = ObjectStateHolderVector()
    discInst = RunInstance()
    ipAddressList = Framework.getTriggerCIDataAsList('ip_address')
    credentialsList = Framework.getTriggerCIDataAsList('credentialsId')
    bridgeId = Framework.getDestinationAttribute('bridgeId')
    hostIdList = Framework.getTriggerCIDataAsList('hostId')
    ucmdbVersion = modeling.CmdbClassModel().version()

    snmpCommunityPostfix = ''
    try:
        snmpCommunityPostfix = Framework.getDestinationAttribute(
            'snmpCommunityPostfix')
        hostModel = Framework.getDestinationAttribute('hostModel')
        hostOs = Framework.getDestinationAttribute('hostOs')
        snmpDescription = Framework.getDestinationAttribute('smpDescription')
    except:
        pass

    SwitchesNumber = len(credentialsList)
    for i in range(SwitchesNumber):
        ipAddress = ipAddressList[i]
        hostId = hostIdList[i]
        credId = credentialsList[i]

        properties = Properties()

        if credId and ipAddress:
            properties.setProperty('ip_address', ipAddress)
            properties.setProperty(BaseClient.CREDENTIALS_ID, credId)
        sw = Switch(bridgeId, hostId, ucmdbVersion, Framework)
        if (snmpCommunityPostfix != None) and (snmpCommunityPostfix != ''):
            device_type_str = '%s%s%s' % (hostModel.lower(), hostOs.lower(),
                                          snmpDescription.lower())
            if device_type_str.find('atalyst') != -1 or device_type_str.find(
                    'cisco') != -1:
                snmp_version = Framework.getProtocolProperty(
                    credId, "snmpprotocol_version")
                if snmp_version == 'version 3':
                    props = Properties()
                    props.setProperty('ip_address', ipAddress)
                    props.setProperty(BaseClient.CREDENTIALS_ID, credId)
                    client = Framework.createClient(props)
                    vlan_context_dict = snmputils.get_snmp_vlan_context_dict(
                        client)
                    client and client.close()

                    if not vlan_context_dict:
                        raise Exception, "Vlan Conext is not present on the device. No Vlan details might be discovered"

                    vlan_context = vlan_context_dict.get(snmpCommunityPostfix)
                    if not vlan_context:
                        raise Exception, "Failed to find configured Vlan context for Vlan %s. Vlan will be skipped" % snmpCommunityPostfix

                    properties.setProperty(SnmpQueries._postfix,
                                           '%s' % vlan_context)
                else:
                    properties.setProperty(SnmpQueries._postfix,
                                           '@%s' % snmpCommunityPostfix)
            else:
                sw = QBridgeSwitch(snmpCommunityPostfix, bridgeId, hostId,
                                   ucmdbVersion, Framework)
                sw.set_device_type_str(device_type_str)
        if logger.isDebugEnabled():
            logger.debug('ip', ipAddress)
            logger.debug('bridgeMac', bridgeId)
            logger.debug('Postfix', snmpCommunityPostfix)

        try:
            sw.snmpClient = Framework.createClient(properties)
            #SnmpConnectionTester(sw.snmpClient).testSnmpConnection()
            sw.doWork(ObjSHV, discInst)
            OSHVResult.addAll(ObjSHV)
        except:
            logger.debugException('')
            if (snmpCommunityPostfix != None) and (snmpCommunityPostfix != ''):
                logger.error('Failed to discover ip: ', ipAddress,
                             ' on Vlan#: ', snmpCommunityPostfix)
            else:
                logger.error('Failed to discover ip: ', ipAddress)
        if sw.snmpClient != None:
            sw.snmpClient.close()
    return OSHVResult