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
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
Exemple #3
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
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
def downloadScanFile(Framework):
    remoteScanFileLocation = getScanFilelocation(Framework)
    if not InventoryUtils.isPathValid(remoteScanFileLocation):
        logger.debug('No scan file yet. Scanner is still running.')
        Framework.reportError(inventoryerrorcodes.INVENTORY_DISCOVERY_SCANFILE_NOTREADY, ['Empty'])
        Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
        # get scanner status information
        retrieveScannerStatus(Framework, 0)
        return

    if retrieveScannerStatus(Framework, 1):
        Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
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.')
def downloadScanFile(Framework):
    remoteScanFileLocation = getScanFilelocation(Framework)
    if not InventoryUtils.isPathValid(remoteScanFileLocation):
        logger.debug('No scan file yet. Scanner is still running.')
        Framework.reportError(
            inventoryerrorcodes.INVENTORY_DISCOVERY_SCANFILE_NOTREADY,
            ['Empty'])
        Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
        # get scanner status information
        retrieveScannerStatus(Framework, 0)
        return

    if retrieveScannerStatus(Framework, 1):
        Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
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.'
        )