def backupSWUtilizationConfig(Framework):
    # keep remote ini files
    BASEDIR = AgentPlatformParameters.getAgentConfigurationPath(Framework)

    localDiscusgeFile = File.createTempFile(
        "discusge" + str(System.currentTimeMillis()) +
        Framework.getTriggerCIData('id'), ".ini")
    remoteDiscusgeFile = BASEDIR + "discusge.ini"

    if InventoryUtils.copyRemoteFileToLocal(
            Framework, remoteDiscusgeFile,
            localDiscusgeFile.getCanonicalPath(), 0, 1):
        Framework.setProperty("local_discusge_temp_file",
                              localDiscusgeFile.getCanonicalPath())
    else:
        Framework.reportWarning(
            "backup discusge.ini file in remote server failed, upgrade agent will use default configuration."
        )

    localPluginFile = File.createTempFile(
        "plugin" + str(System.currentTimeMillis()) +
        Framework.getTriggerCIData('id'), ".ini")
    remotePluginFile = BASEDIR + "plugin.ini"

    if InventoryUtils.copyRemoteFileToLocal(Framework, remotePluginFile,
                                            localPluginFile.getCanonicalPath(),
                                            0, 1):
        Framework.setProperty("local_plugin_temp_file",
                              localPluginFile.getCanonicalPath())
    else:
        Framework.reportWarning(
            "backup discusge.ini file in remote server failed, upgrade agent will use default configuration."
        )

    Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
示例#2
0
def downloadRemoteScanFile(Framework):
    remoteScanFileLocation = Framework.getProperty(InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_FILE_LOCATION)

    # download scanner log file before downloading scan file
    downloadScanLogFile(Framework)

    if remoteScanFileLocation is None:
        logger.debug("No scan file to downloaded from current execution")
        return None

    logger.debug("About to download scan file from current execution:", remoteScanFileLocation)
    extension = InventoryUtils.getFileExtension(remoteScanFileLocation)
    localScanFileName = InventoryUtils.generateScanFileName(Framework, extension)

    # folder for scan files
    localScanFileFolderPath = (
        CollectorsParameters.PROBE_MGR_INVENTORY_XMLENRICHER_FILES_FOLDER + XmlEnricherConstants.INCOMING_FOLDER_NAME
    )

    downloadedScanFilesDir = File(localScanFileFolderPath)
    downloadedScanFilesDir.mkdirs()

    # this scan file will be created after downloading from remote machine
    targetScanFile = File(downloadedScanFilesDir, localScanFileName)

    # get file to the local machine
    logger.debug("Scan file to be downloaded to location:", targetScanFile.getCanonicalPath())
    if not InventoryUtils.copyRemoteFileToLocal(Framework, remoteScanFileLocation, targetScanFile.getCanonicalPath()):
        return None
    return targetScanFile
def getLogFileContent(Framework, localFile, remotePath):
    localPath = localFile.getCanonicalPath()
    logger.debug('Going to download remote agent log file ', remotePath,
                 ' to local path:', localPath)
    if not InventoryUtils.copyRemoteFileToLocal(Framework, remotePath,
                                                localPath):
        return

    logger.debug('Start reading content from ' + localPath)
    localClient = None
    try:
        try:
            localClient = Framework.createClient(
                ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME)
            localClient.executeCmd('type "' + localPath + '"')
        except:
            errorMessage = str(sys.exc_info()[1])
            logger.debugException('Failed to load content of file:' +
                                  localPath + ';' + errorMessage)
    finally:
        if localClient is not None:
            try:
                localClient.close()
            except:
                pass
示例#4
0
def downloadRemoteScanFile(Framework):
    remoteScanFileLocation = Framework.getProperty(InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_FILE_LOCATION)

    # download scanner log file before downloading scan file
    downloadScanLogFile(Framework)

    if remoteScanFileLocation is None:
        logger.debug('No scan file to downloaded from current execution')
        return None

    logger.debug('About to download scan file from current execution:', remoteScanFileLocation)
    extension = InventoryUtils.getFileExtension(remoteScanFileLocation)
    localScanFileName = InventoryUtils.generateScanFileName(Framework, extension)

    #folder for scan files
    localScanFileFolderPath = CollectorsParameters.PROBE_MGR_INVENTORY_XMLENRICHER_FILES_FOLDER + XmlEnricherConstants.INCOMING_FOLDER_NAME

    downloadedScanFilesDir = File(localScanFileFolderPath)
    downloadedScanFilesDir.mkdirs()

    #this scan file will be created after downloading from remote machine
    targetScanFile = File(downloadedScanFilesDir, localScanFileName)

    #get file to the local machine
    logger.debug('Scan file to be downloaded to location:', targetScanFile.getCanonicalPath())
    if not InventoryUtils.copyRemoteFileToLocal(Framework, remoteScanFileLocation, targetScanFile.getCanonicalPath()):
        return None
    return targetScanFile
def backupSWUtilizationConfig(Framework):
	# keep remote ini files
	BASEDIR = AgentPlatformParameters.getAgentConfigurationPath(Framework)

	localDiscusgeFile = File.createTempFile("discusge" + str(System.currentTimeMillis()) + Framework.getTriggerCIData('id'), ".ini")
	remoteDiscusgeFile = BASEDIR + "discusge.ini"

	if InventoryUtils.copyRemoteFileToLocal(Framework, remoteDiscusgeFile, localDiscusgeFile.getCanonicalPath(), 0, 1):
		Framework.setProperty("local_discusge_temp_file", localDiscusgeFile.getCanonicalPath())
	else :
		Framework.reportWarning("backup discusge.ini file in remote server failed, upgrade agent will use default configuration.")

	localPluginFile = File.createTempFile("plugin" + str(System.currentTimeMillis()) + Framework.getTriggerCIData('id'), ".ini")
	remotePluginFile = BASEDIR + "plugin.ini"

	if InventoryUtils.copyRemoteFileToLocal(Framework, remotePluginFile, localPluginFile.getCanonicalPath(), 0, 1):
		Framework.setProperty("local_plugin_temp_file", localPluginFile.getCanonicalPath())
	else :
		Framework.reportWarning("backup discusge.ini file in remote server failed, upgrade agent will use default configuration.")

	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.')
示例#7
0
def downloadScanLogFile(Framework):
    needDownloadLog = Framework.getProperty(InventoryUtils.DOWNLOAD_SCANNER_LOG)
    if not needDownloadLog:
        return

    logger.debug('Downloading remote scanner log file to local location')
    try:
        remoteScanLogLocation = getRemoteScanLogFilelocation(Framework)
        localScanLogLocation = getLocalScanLogFileLocation(Framework)
        if (remoteScanLogLocation is None) or (localScanLogLocation is None):
            logger.debug('Download scanner log file failed: remoteScanLogLocation=', remoteScanLogLocation, ', localScanLogLocation=', localScanLogLocation)
            return

        #get file to the local machine
        if not InventoryUtils.copyRemoteFileToLocal(Framework, remoteScanLogLocation, localScanLogLocation):
            return
    except:
        errorMessage = str(sys.exc_info()[1])
        logger.warn('Download scanner log file failed: ', errorMessage)
def getLogFileContent(Framework, localFile, remotePath):
    localPath = localFile.getCanonicalPath()
    logger.debug('Going to download remote agent log file ', remotePath, ' to local path:', localPath)
    if not InventoryUtils.copyRemoteFileToLocal(Framework, remotePath, localPath):
        return

    logger.debug('Start reading content from ' + localPath)
    localClient = None
    try:
        try:
            localClient = Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME)
            localClient.executeCmd('type "' + localPath + '"')
        except:
            errorMessage = str(sys.exc_info()[1])
            logger.debugException('Failed to load content of file:' + localPath + ';' + errorMessage)
    finally:
        if localClient is not None:
            try:
                localClient.close()
            except:
                pass
示例#9
0
def downloadScanLogFile(Framework):
    needDownloadLog = Framework.getProperty(InventoryUtils.DOWNLOAD_SCANNER_LOG)
    if not needDownloadLog:
        return

    logger.debug("Downloading remote scanner log file to local location")
    try:
        remoteScanLogLocation = getRemoteScanLogFilelocation(Framework)
        localScanLogLocation = getLocalScanLogFileLocation(Framework)
        if (remoteScanLogLocation is None) or (localScanLogLocation is None):
            logger.debug(
                "Download scanner log file failed: remoteScanLogLocation=",
                remoteScanLogLocation,
                ", localScanLogLocation=",
                localScanLogLocation,
            )
            return

        # get file to the local machine
        if not InventoryUtils.copyRemoteFileToLocal(Framework, remoteScanLogLocation, localScanLogLocation):
            return
    except:
        errorMessage = str(sys.exc_info()[1])
        logger.warn("Download scanner log file failed: ", errorMessage)
示例#10
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.'
        )