Exemplo n.º 1
0
def unInstallAgent(Framework):
    protocolName = Framework.getProperty(InventoryUtils.STATE_PROPERTY_CONNECTED_SHELL_PROTOCOL_NAME)
    logger.debug('Protocal name: ', protocolName)

    client = Framework.getConnectedClient()
    uduid = InventoryUtils.getUduid(client)
    logger.debug('UD_UNIQUE_ID: ', uduid)
    Framework.setProperty(InventoryUtils.ATTR_UD_UNIQUE_ID, uduid)

    if protocolName == ClientsConsts.DDM_AGENT_PROTOCOL_NAME:
        # Should release lock first if there will be no connected credential after agent uninstallation.
        logger.debug('The connected credential is UDA. Try to release lock first.')
        LockUtils.releaseScannerLock(Framework)

    if AgentUtils.isAgentInstalled(Framework):
        logger.debug('There is an agent in remote machine.')
        # Run uninstall command.
        shouldStop = AgentUtils.agentUnInstallRoutine(Framework)
        if shouldStop != 0:
            Framework.setStepExecutionStatus(WorkflowStepStatus.FATAL_FAILURE)
            logger.debug('Failed to uninstall agent.')
    else:
        logger.debug('There is no agent in remote machine. The job will be done.')
        reason = 'There is no agent in remote machine'
        Framework.setProperty(InventoryUtils.generateSkipStep('Check Agent UnInstalled'), reason)
    Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
Exemplo n.º 2
0
def unInstallAgent(Framework):
    protocolName = Framework.getProperty(
        InventoryUtils.STATE_PROPERTY_CONNECTED_SHELL_PROTOCOL_NAME)
    logger.debug('Protocal name: ', protocolName)

    client = Framework.getConnectedClient()
    uduid = InventoryUtils.getUduid(client)
    logger.debug('UD_UNIQUE_ID: ', uduid)
    Framework.setProperty(InventoryUtils.ATTR_UD_UNIQUE_ID, uduid)

    if protocolName == ClientsConsts.DDM_AGENT_PROTOCOL_NAME:
        # Should release lock first if there will be no connected credential after agent uninstallation.
        logger.debug(
            'The connected credential is UDA. Try to release lock first.')
        LockUtils.releaseScannerLock(Framework)

    if AgentUtils.isAgentInstalled(Framework):
        logger.debug('There is an agent in remote machine.')
        # Run uninstall command.
        shouldStop = AgentUtils.agentUnInstallRoutine(Framework)
        if shouldStop != 0:
            Framework.setStepExecutionStatus(WorkflowStepStatus.FATAL_FAILURE)
            logger.debug('Failed to uninstall agent.')
    else:
        logger.debug(
            'There is no agent in remote machine. The job will be done.')
        reason = 'There is no agent in remote machine'
        Framework.setProperty(
            InventoryUtils.generateSkipStep('Check Agent UnInstalled'), reason)
    Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
Exemplo n.º 3
0
def getScanFilelocation(Framework):
    try:
        client = Framework.getConnectedClient()
    except:
        logger.warn(
            "Connect failed during [Check Scanner Finished], parking for next try "
        )
        return None

    #on previous Download Scan File step execution we can already obtain remote scan file path
    #but failed to copy it to base dir. That is why we can try to get it from properties
    remoteScanFileLocation = Framework.getProperty(
        InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_FILE_LOCATION)
    if not InventoryUtils.isPathValid(remoteScanFileLocation):
        options = LockUtils.getClientOptionsMap(client)
        remoteScanFileLocation = options.get(
            InventoryUtils.AGENT_OPTION_DISCOVERY_SCANFILENAME)
        if InventoryUtils.isPathValid(remoteScanFileLocation):
            Framework.setProperty(
                InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_FILE_LOCATION,
                remoteScanFileLocation)
            logger.debug(
                'Got agent option ' +
                InventoryUtils.AGENT_OPTION_DISCOVERY_SCANFILENAME + ' ',
                remoteScanFileLocation)
        else:
            logger.debug('Remote scan file location from agent options:',
                         remoteScanFileLocation)
    else:
        logger.debug('Got scan file location from properties ',
                     remoteScanFileLocation)
    return remoteScanFileLocation
Exemplo n.º 4
0
def getRemoteScanLogFilelocation(Framework):
    client = Framework.getConnectedClient()
    remoteScanLogFileLocation = Framework.getProperty(InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_LOG_FILE_LOCATION)
    if not InventoryUtils.isPathValid(remoteScanLogFileLocation):
        options = LockUtils.getClientOptionsMap(client)
        remoteScanLogFileLocation = options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCANLOGFILENAME)
        if InventoryUtils.isPathValid(remoteScanLogFileLocation):
            Framework.setProperty(
                InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_LOG_FILE_LOCATION, remoteScanLogFileLocation
            )
            logger.debug(
                "Got agent option " + InventoryUtils.AGENT_OPTION_DISCOVERY_SCANLOGFILENAME + " ",
                remoteScanLogFileLocation,
            )
        else:
            logger.debug("Remote scan log file location from agent options:", remoteScanLogFileLocation)
    else:
        logger.debug("Got scan log file location from properties ", remoteScanLogFileLocation)

    if remoteScanLogFileLocation is None:
        remoteScanFileLocation = Framework.getProperty(InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_FILE_LOCATION)
        if remoteScanFileLocation is not None:
            remoteScanLogFileLocation = os.path.splitext(remoteScanFileLocation)[0] + ".log"

    return remoteScanLogFileLocation
Exemplo n.º 5
0
def UDUniqueIDCheck(Framework):
    ipTaggingList = Framework.getTriggerCIDataAsList('ipTaggingList')
    hasShortIp = 0
    for tagging in ipTaggingList:
        if tagging == '1':
            hasShortIp = 1
            break

    if not hasShortIp:
        Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
        return

    nodeGUID = Framework.getDestinationAttribute('nodeGUID')

    client = Framework.getConnectedClient()
    client_options = LockUtils.getClientOptionsMap(client)
    logger.debug("Get client options map for GUID:", client_options)
    remoteGUID = client_options.get(InventoryUtils.AGENT_OPTION_CALLHOME_GUID)

    if nodeGUID and nodeGUID != 'NA' and remoteGUID and nodeGUID == remoteGUID or isScanOverdue(
            Framework):  #Go discovery if the nodes are same or overdue scan
        Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
    else:
        Framework.reportWarning(
            "GUID is different, may be they are different hosts!")
        Framework.setStepExecutionStatus(WorkflowStepStatus.CANCEL)
Exemplo n.º 6
0
def retrieveScannerStatus(Framework, success=1):
    client = Framework.getConnectedClient()
    options = LockUtils.getClientOptionsMap(client)
    completionCode = options.get(
        InventoryUtils.AGENT_OPTION_DISCOVERY_SCAN_EXITCODE)
    status = options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCAN_STATUS)
    # just put the information into Framework to avoid duplicate log
    Framework.setProperty(
        "scanner_state_process_id",
        options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCAN_PID))
    Framework.setProperty(
        "scanner_status_exit_code",
        options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCAN_EXITCODE))
    Framework.setProperty(
        "scanner_status_scanner_stage",
        options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCAN_STAGE))
    Framework.setProperty("scanner_status_retrieve_status", str(success))
    Framework.setProperty("scanner_status_retrieve_date", Date())
    # record Scanner status here
    recordScannerStatus(Framework, success)
    completion = ""
    if (completionCode is not None) and len(completionCode):
        completion = InventoryUtils.SCANNER_EXIT_CODE_MAPPING.get(
            str(completionCode))
        if (str(completionCode) != '0' and str(completionCode) != '11'
                and str(completionCode) != '10'
                and str(completionCode) != '7'):
            # If the scanner exits with fatal failure, download the scanner log file before the entire workflow exits
            DownloadScanFile.downloadScanLogFile(Framework)

            Framework.setStepExecutionStatus(WorkflowStepStatus.FATAL_FAILURE)
            Framework.reportError(
                inventoryerrorcodes.INVENTORY_DISCOVERY_SCANNER_STATUS_FAILED,
                [completion, status])
            return 0
        elif str(completionCode) != '0':
            Framework.reportWarning(completion)
    else:
        pid = options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCAN_PID)
        if not pid:
            startTime = Framework.getProperty(
                "START_TIME_OF_SCANNER_STATUS_CHECKING")
            if not startTime:
                Framework.setProperty("START_TIME_OF_SCANNER_STATUS_CHECKING",
                                      System.currentTimeMillis())
            else:
                startTime = long(startTime)
                now = System.currentTimeMillis()
                if (now - startTime) > maxWaitingTimeForScannerStartUp:
                    Framework.setStepExecutionStatus(
                        WorkflowStepStatus.FATAL_FAILURE)
                    Framework.reportError(
                        "Scanner can't be executed. Check if the scanner can run on the target host."
                    )
                    return 0
    return 1
Exemplo n.º 7
0
def releaseResources(Framework):
	logger.debug('Releasing resources')
	# we try to remove lock if lock was acquired and not unlocked yet
	logger.debug('Releasing scanner node lock if not unlocked yet')
	logger.debug('LockUtils.ScannerNodeSetLock in Framework: ', Framework.getProperty(LockUtils.ScannerNodeSetLock))
	logger.debug('LockUtils.ScannerNodeUnSetLock in Framework: ', Framework.getProperty(LockUtils.ScannerNodeUnSetLock))
	if Framework.getProperty(LockUtils.ScannerNodeSetLock) and not Framework.getProperty(LockUtils.ScannerNodeUnSetLock):
		if InventoryUtils.ensureConnection(Framework):
			LockUtils.releaseScannerLock(Framework)
		else:
			logger.debug('Failed to remove lock as failed to connect to host')
	else:
		logger.debug('Not removing lock as lock was not acquired or already unlocked')
	if Framework.getProperty(InventoryUtils.STATE_PROPERTY_CLEAN_UP_STATE_FINALLY):
		logger.debug('Clear up state saved in DB')
		Framework.clearState()
		Framework.setProperty(InventoryUtils.STATE_PROPERTY_CLEAN_UP_STATE_FINALLY, '')
	logger.debug('Releasing shell connection to the remote node if not released yet')
	InventoryUtils.releaseConnection(Framework)
def releaseScannerLock(Framework):
    logger.debug('Finally, Starting Unlock Scanner Node')
    if not LockUtils.releaseScannerLock(Framework):
        Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
    else:
        logger.debug('Unlock Scanner Node finished')
        Framework.setProperty(LockUtils.ScannerNodeUnSetLock, LockUtils.ScannerNodeUnSetLock)
        Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
    logger.debug('Releasing connection after unlock scan node')
    InventoryUtils.releaseConnection(Framework)
Exemplo n.º 9
0
def runScanner(Framework):
    client = Framework.getConnectedClient()

    scannersConfigFile = Framework.getConfigFile(
        CollectorsConstants.SCANNERSBYPLATFORM_FILE_NAME)

    platform = Framework.getProperty(InventoryUtils.STATE_PROPERTY_PLATFORM)
    architecture = Framework.getProperty(
        InventoryUtils.STATE_PROPERTY_ARCHITECTURE)
    logger.debug('Platform:', platform, ' architecture ', architecture)

    scannerPlatformConfig = scannersConfigFile.getPlatformConfiguration(
        platform, architecture)

    BASEDIR = Framework.getProperty(
        InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR)

    lockValue = Framework.getProperty(LockUtils.ScannerNodeLock)

    client_options = LockUtils.getClientOptionsMap(client)

    logger.debug('Settings agent options')
    options = HashMap()
    options.put(InventoryUtils.AGENT_OPTION_DISCOVERY_SCANFILENAME, '')
    options.put(LockUtils.ScannerNodeLock, lockValue)
    options.put(InventoryUtils.STATE_PROPERTY_EXECUTION_STARTED,
                str(System.currentTimeMillis()))

    logger.debug('Agent option ',
                 InventoryUtils.AGENT_OPTION_DISCOVERY_SCANFILENAME, ':', '')
    logger.debug('Agent option ', LockUtils.ScannerNodeLock, ':', lockValue)
    logger.debug('Agent option ',
                 InventoryUtils.STATE_PROPERTY_EXECUTION_STARTED, ':',
                 str(System.currentTimeMillis()))

    filterOptionsByBlackList(
        client_options)  #filter the options of client by black list
    client_options.putAll(options)
    client.setOptionsMap(client_options, 1)

    shell = shellutils.ShellUtils(client, skip_set_session_locale=True)

    shell.execCmd('cd ' + BASEDIR)

    runScannerCommand = scannerPlatformConfig.getRunScannerCommand()
    logger.debug('Launching scanner on remote machine')
    commandLine = runScannerCommand.getCommand()
    commandLine = updateCmdWithLogLevel(commandLine, Framework)
    commandLine = updateCmdForDeltaScanning(commandLine, Framework)
    commandLine = InventoryUtils.handleBaseDirPath(Framework, commandLine)
    commandLine = updateWithPrePostScriptCmd(Framework, commandLine)
    logger.debug('Scanner execution command:', commandLine)
    shell.execCmd(commandLine)
    logger.debug('Scanner Launched on remote machine')
    Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
Exemplo n.º 10
0
def releaseScannerLock(Framework):
    logger.debug('Finally, Starting Unlock Scanner Node')
    if not LockUtils.releaseScannerLock(Framework):
        Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
    else:
        logger.debug('Unlock Scanner Node finished')
        Framework.setProperty(LockUtils.ScannerNodeUnSetLock,
                              LockUtils.ScannerNodeUnSetLock)
        Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
    logger.debug('Releasing connection after unlock scan node')
    InventoryUtils.releaseConnection(Framework)
Exemplo n.º 11
0
def checkScanFileExistance(Framework):
	# this step is always finished with success since we DON'T require scan file from previous execution, just nice to have
	Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
	DownloadScanFileBeforeExecution = Boolean.parseBoolean(Framework.getParameter('DownloadScanFileBeforeExecution'))
	if DownloadScanFileBeforeExecution:
		try:
			client = Framework.getConnectedClient()
			options = LockUtils.getClientOptionsMap(client)
			previousExecutionStarted = options.get(InventoryUtils.STATE_PROPERTY_EXECUTION_STARTED)
			
			if (previousExecutionStarted is None) or (len(previousExecutionStarted.strip()) == 0):
				logger.debug('Previous execution timestamp no found, continuing with workflow')
				return
				
			remoteScanFileLocation = options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCANFILENAME)
			if not InventoryUtils.isPathValid(remoteScanFileLocation):
				logger.debug('No scan file path found on remote machine, continuing with workflow')
				return
			
			lastSuccessExecuton = Framework.getState().getJobLastSuccessfulRun()
			
			logger.debug('Last success execution ' + str(lastSuccessExecuton))
			logger.debug('Remote scan file execution ' + str(previousExecutionStarted))

			if long(lastSuccessExecuton) > long(previousExecutionStarted):
				logger.debug('Scan file on probe side is newer than on remote machine, skipping downloading')
				return
				
			logger.debug('Last success execution ' + str(lastSuccessExecuton) + ' older than scan file on remote machine ' + str(remoteScanFileLocation) + '. Going to download scan file:' + str(remoteScanFileLocation))

			tempScanFileFolder = CollectorsParameters.PROBE_MGR_TEMPDOWNLOAD + Framework.getDiscoveryJobId() + CollectorsParameters.FILE_SEPARATOR
			File(tempScanFileFolder).mkdirs()
			
			extension = InventoryUtils.getFileExtension(remoteScanFileLocation)
			tempScanFileName = InventoryUtils.generateScanFileName(Framework, extension)

			tempScanFile = File(tempScanFileFolder, tempScanFileName)
			tempScanFilePath = tempScanFile.getCanonicalPath()
			
			logger.debug('Try to download scan file to the:', tempScanFilePath)

			if not InventoryUtils.copyRemoteFileToLocal(Framework, remoteScanFileLocation, tempScanFilePath, 0):
				logger.debug('Failed to download scan file before current execution')
			
			Framework.setProperty(InventoryUtils.STATE_PROPERTY_TEMP_SCAN_FILE, tempScanFilePath)
		except:
			reason = str(sys.exc_info()[1])
			logger.debug('Failed to check/download scan file from previous execution. Reason:', reason)
	else:
		logger.debug('Even not checking whether scan file exists on remote machine or not.')
Exemplo n.º 12
0
def acquireScannerLock(Framework):
	lockValue = LockUtils.acquireScannerLock(Framework)
	if lockValue is None:
		errorMessage = 'Found existing lock on remote machine, lock scanner node failed.'
		logger.debug(errorMessage)
		Framework.reportError(inventoryerrorcodes.INVENTORY_DISCOVERY_FAILED_LOCKED, ['found existing lock on remote machine'])
		Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
	elif lockValue == LockUtils.ScannerNodeLockedByCallHome:
		Framework.setStepExecutionStatus(WorkflowStepStatus.CANCEL)
	else:
		logger.debug('Lock was acquired with value:', lockValue)
		Framework.setProperty(LockUtils.ScannerNodeSetLock, LockUtils.ScannerNodeSetLock)
		Framework.setProperty(LockUtils.ScannerNodeLock, lockValue)
		Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
Exemplo n.º 13
0
def UDUniqueIDCheck(Framework):

    nodeGUID = Framework.getDestinationAttribute('nodeGUID')

    client = Framework.getConnectedClient()
    client_options = LockUtils.getClientOptionsMap(client)
    logger.debug("Get client options map for UdUid:", client_options)
    remoteGUID = client_options.get(InventoryUtils.AGENT_OPTION_CALLHOME_GUID)

    if (nodeGUID and nodeGUID != 'NA' and remoteGUID and nodeGUID == remoteGUID):
        Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
    else:
        logger.debug("node UdUid:", nodeGUID)
        Framework.reportWarning("GUID is different, may be they are different hosts!")
        Framework.setStepExecutionStatus(WorkflowStepStatus.CANCEL)
Exemplo n.º 14
0
def runScanner(Framework):
    client = Framework.getConnectedClient()

    scannersConfigFile = Framework.getConfigFile(CollectorsConstants.SCANNERSBYPLATFORM_FILE_NAME)

    platform = Framework.getProperty(InventoryUtils.STATE_PROPERTY_PLATFORM)
    architecture = Framework.getProperty(InventoryUtils.STATE_PROPERTY_ARCHITECTURE)
    logger.debug('Platform:', platform, ' architecture ', architecture)

    scannerPlatformConfig = scannersConfigFile.getPlatformConfiguration(platform, architecture)

    BASEDIR = Framework.getProperty(InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR)

    lockValue = Framework.getProperty(LockUtils.ScannerNodeLock)

    client_options = LockUtils.getClientOptionsMap(client)

    logger.debug('Settings agent options')
    options = HashMap()
    options.put(InventoryUtils.AGENT_OPTION_DISCOVERY_SCANFILENAME, '')
    options.put(LockUtils.ScannerNodeLock, lockValue)
    options.put(InventoryUtils.STATE_PROPERTY_EXECUTION_STARTED, str(System.currentTimeMillis()))

    logger.debug('Agent option ', InventoryUtils.AGENT_OPTION_DISCOVERY_SCANFILENAME, ':', '')
    logger.debug('Agent option ', LockUtils.ScannerNodeLock, ':', lockValue)
    logger.debug('Agent option ', InventoryUtils.STATE_PROPERTY_EXECUTION_STARTED, ':', str(System.currentTimeMillis()))

    filterOptionsByBlackList(client_options) #filter the options of client by black list
    client_options.putAll(options)
    client.setOptionsMap(client_options, 1)

    shell = shellutils.ShellUtils(client, skip_set_session_locale=True)

    shell.execCmd('cd ' + BASEDIR)

    runScannerCommand = scannerPlatformConfig.getRunScannerCommand()
    logger.debug('Launching scanner on remote machine')
    commandLine = runScannerCommand.getCommand()
    commandLine = updateCmdWithLogLevel(commandLine, Framework)
    commandLine = updateCmdForDeltaScanning(commandLine, Framework)
    commandLine = InventoryUtils.handleBaseDirPath(Framework, commandLine)
    commandLine = updateWithPrePostScriptCmd(Framework, commandLine)
    logger.debug('Scanner execution command:', commandLine)
    shell.execCmd(commandLine)
    logger.debug('Scanner Launched on remote machine')
    Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
Exemplo n.º 15
0
def UDUniqueIDCheck(Framework):

    nodeGUID = Framework.getDestinationAttribute('nodeGUID')

    client = Framework.getConnectedClient()
    client_options = LockUtils.getClientOptionsMap(client)
    logger.debug("Get client options map for UdUid:", client_options)
    remoteGUID = client_options.get(InventoryUtils.AGENT_OPTION_CALLHOME_GUID)

    if (nodeGUID and nodeGUID != 'NA' and remoteGUID
            and nodeGUID == remoteGUID):
        Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
    else:
        logger.debug("node UdUid:", nodeGUID)
        Framework.reportWarning(
            "GUID is different, may be they are different hosts!")
        Framework.setStepExecutionStatus(WorkflowStepStatus.CANCEL)
Exemplo n.º 16
0
def acquireScannerLock(Framework):
    lockValue = LockUtils.acquireScannerLock(Framework)
    if lockValue is None:
        errorMessage = 'Found existing lock on remote machine, lock scanner node failed.'
        logger.debug(errorMessage)
        Framework.reportError(
            inventoryerrorcodes.INVENTORY_DISCOVERY_FAILED_LOCKED,
            ['found existing lock on remote machine'])
        Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
    elif lockValue == LockUtils.ScannerNodeLockedByCallHome:
        Framework.setStepExecutionStatus(WorkflowStepStatus.CANCEL)
    else:
        logger.debug('Lock was acquired with value:', lockValue)
        Framework.setProperty(LockUtils.ScannerNodeSetLock,
                              LockUtils.ScannerNodeSetLock)
        Framework.setProperty(LockUtils.ScannerNodeLock, lockValue)
        Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
Exemplo n.º 17
0
def releaseScannerLock(Framework):
    logger.debug('Starting Unlock Scanner Node step')
    logger.debug("Start checking ud_unique_id...")
    client = Framework.getConnectedClient()
    if client:
        uduid = InventoryUtils.getUduid(
            client,
            InventoryUtils.isStampEnabled(Framework, client.getIpAddress()))
        Framework.setProperty(InventoryUtils.ATTR_UD_UNIQUE_ID, uduid)
    if not LockUtils.releaseScannerLock(Framework):
        Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
    else:
        logger.debug('Unlock Scanner Node step finished')
        Framework.setProperty(LockUtils.ScannerNodeUnSetLock,
                              LockUtils.ScannerNodeUnSetLock)
        Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
    logger.debug('Releasing connection after unlock scan node')
    InventoryUtils.releaseConnection(Framework)
Exemplo n.º 18
0
def getRemoteScanLogFilelocation(Framework):
    client = Framework.getConnectedClient()
    remoteScanLogFileLocation = Framework.getProperty(InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_LOG_FILE_LOCATION)
    if not InventoryUtils.isPathValid(remoteScanLogFileLocation):
        options = LockUtils.getClientOptionsMap(client)
        remoteScanLogFileLocation = options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCANLOGFILENAME)
        if InventoryUtils.isPathValid(remoteScanLogFileLocation):
            Framework.setProperty(InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_LOG_FILE_LOCATION, remoteScanLogFileLocation)
            logger.debug('Got agent option ' + InventoryUtils.AGENT_OPTION_DISCOVERY_SCANLOGFILENAME + ' ', remoteScanLogFileLocation)
        else:
            logger.debug('Remote scan log file location from agent options:', remoteScanLogFileLocation)
    else:
        logger.debug('Got scan log file location from properties ', remoteScanLogFileLocation)

    if remoteScanLogFileLocation is None:
        remoteScanFileLocation = Framework.getProperty(InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_FILE_LOCATION)
        if remoteScanFileLocation is not None:
            remoteScanLogFileLocation = os.path.splitext(remoteScanFileLocation)[0] + '.log'

    return remoteScanLogFileLocation
Exemplo n.º 19
0
def getScanFilelocation(Framework):
    try:
        client = Framework.getConnectedClient()
    except:
        logger.warn("Connect failed during [Check Scanner Finished], parking for next try ")
        return None

    #on previous Download Scan File step execution we can already obtain remote scan file path
    #but failed to copy it to base dir. That is why we can try to get it from properties
    remoteScanFileLocation = Framework.getProperty(InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_FILE_LOCATION)
    if not InventoryUtils.isPathValid(remoteScanFileLocation):
        options = LockUtils.getClientOptionsMap(client)
        remoteScanFileLocation = options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCANFILENAME)
        if InventoryUtils.isPathValid(remoteScanFileLocation):
            Framework.setProperty(InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_FILE_LOCATION, remoteScanFileLocation)
            logger.debug('Got agent option ' + InventoryUtils.AGENT_OPTION_DISCOVERY_SCANFILENAME + ' ', remoteScanFileLocation)
        else:
            logger.debug('Remote scan file location from agent options:', remoteScanFileLocation)
    else:
        logger.debug('Got scan file location from properties ', remoteScanFileLocation)
    return remoteScanFileLocation
Exemplo n.º 20
0
def retrieveScannerStatus(Framework, success = 1):
    client = Framework.getConnectedClient()
    options = LockUtils.getClientOptionsMap(client)
    completionCode = options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCAN_EXITCODE)
    status = options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCAN_STATUS)
    # just put the information into Framework to avoid duplicate log
    Framework.setProperty("scanner_state_process_id", options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCAN_PID))
    Framework.setProperty("scanner_status_exit_code", options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCAN_EXITCODE))
    Framework.setProperty("scanner_status_scanner_stage", options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCAN_STAGE))
    Framework.setProperty("scanner_status_retrieve_status", str(success))
    Framework.setProperty("scanner_status_retrieve_date", Date())
    # record Scanner status here
    recordScannerStatus(Framework, success)
    completion = ""
    if (completionCode is not None) and len(completionCode):
        completion = InventoryUtils.SCANNER_EXIT_CODE_MAPPING.get(str(completionCode))
        if (str(completionCode) != '0' and str(completionCode) != '11' and str(completionCode) != '10' and str(completionCode) != '7'):
            # If the scanner exits with fatal failure, download the scanner log file before the entire workflow exits
            DownloadScanFile.downloadScanLogFile(Framework)

            Framework.setStepExecutionStatus(WorkflowStepStatus.FATAL_FAILURE)
            Framework.reportError(inventoryerrorcodes.INVENTORY_DISCOVERY_SCANNER_STATUS_FAILED, [completion, status])
            return 0
        elif str(completionCode) != '0':
            Framework.reportWarning(completion)
    else:
        pid = options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCAN_PID)
        if not pid:
            startTime = Framework.getProperty("START_TIME_OF_SCANNER_STATUS_CHECKING")
            if not startTime:
                Framework.setProperty("START_TIME_OF_SCANNER_STATUS_CHECKING", System.currentTimeMillis())
            else:
                startTime = long(startTime)
                now = System.currentTimeMillis()
                if (now - startTime) > maxWaitingTimeForScannerStartUp:
                    Framework.setStepExecutionStatus(WorkflowStepStatus.FATAL_FAILURE)
                    Framework.reportError("Scanner can't be executed. Check if the scanner can run on the target host.")
                    return 0
    return 1
Exemplo n.º 21
0
def UDUniqueIDCheck(Framework):
	ipTaggingList = Framework.getTriggerCIDataAsList('ipTaggingList')
	hasShortIp = 0
	for tagging in ipTaggingList:
		if tagging == '1':
			hasShortIp = 1
			break

	if not hasShortIp:
		Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
		return

	nodeGUID = Framework.getDestinationAttribute('nodeGUID')

	client = Framework.getConnectedClient()
	client_options = LockUtils.getClientOptionsMap(client)
	logger.debug("Get client options map for GUID:", client_options)
	remoteGUID = client_options.get(InventoryUtils.AGENT_OPTION_CALLHOME_GUID)

	if nodeGUID and nodeGUID != 'NA' and remoteGUID and nodeGUID == remoteGUID or isScanOverdue(Framework):#Go discovery if the nodes are same or overdue scan
		Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
	else:
		Framework.reportWarning("GUID is different, may be they are different hosts!")
		Framework.setStepExecutionStatus(WorkflowStepStatus.CANCEL)
Exemplo n.º 22
0
def checkScanFileExistance(Framework):
    # this step is always finished with success since we DON'T require scan file from previous execution, just nice to have
    Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
    DownloadScanFileBeforeExecution = Boolean.parseBoolean(
        Framework.getParameter('DownloadScanFileBeforeExecution'))
    if DownloadScanFileBeforeExecution:
        try:
            client = Framework.getConnectedClient()
            options = LockUtils.getClientOptionsMap(client)
            previousExecutionStarted = options.get(
                InventoryUtils.STATE_PROPERTY_EXECUTION_STARTED)

            if (previousExecutionStarted is None) or (len(
                    previousExecutionStarted.strip()) == 0):
                logger.debug(
                    'Previous execution timestamp no found, continuing with workflow'
                )
                return

            remoteScanFileLocation = options.get(
                InventoryUtils.AGENT_OPTION_DISCOVERY_SCANFILENAME)
            if not InventoryUtils.isPathValid(remoteScanFileLocation):
                logger.debug(
                    'No scan file path found on remote machine, continuing with workflow'
                )
                return

            lastSuccessExecuton = Framework.getState().getJobLastSuccessfulRun(
            )

            logger.debug('Last success execution ' + str(lastSuccessExecuton))
            logger.debug('Remote scan file execution ' +
                         str(previousExecutionStarted))

            if long(lastSuccessExecuton) > long(previousExecutionStarted):
                logger.debug(
                    'Scan file on probe side is newer than on remote machine, skipping downloading'
                )
                return

            logger.debug('Last success execution ' + str(lastSuccessExecuton) +
                         ' older than scan file on remote machine ' +
                         str(remoteScanFileLocation) +
                         '. Going to download scan file:' +
                         str(remoteScanFileLocation))

            tempScanFileFolder = CollectorsParameters.PROBE_MGR_TEMPDOWNLOAD + Framework.getDiscoveryJobId(
            ) + CollectorsParameters.FILE_SEPARATOR
            File(tempScanFileFolder).mkdirs()

            extension = InventoryUtils.getFileExtension(remoteScanFileLocation)
            tempScanFileName = InventoryUtils.generateScanFileName(
                Framework, extension)

            tempScanFile = File(tempScanFileFolder, tempScanFileName)
            tempScanFilePath = tempScanFile.getCanonicalPath()

            logger.debug('Try to download scan file to the:', tempScanFilePath)

            if not InventoryUtils.copyRemoteFileToLocal(
                    Framework, remoteScanFileLocation, tempScanFilePath, 0):
                logger.debug(
                    'Failed to download scan file before current execution')

            Framework.setProperty(InventoryUtils.STATE_PROPERTY_TEMP_SCAN_FILE,
                                  tempScanFilePath)
        except:
            reason = str(sys.exc_info()[1])
            logger.debug(
                'Failed to check/download scan file from previous execution. Reason:',
                reason)
    else:
        logger.debug(
            'Even not checking whether scan file exists on remote machine or not.'
        )