def remove_expired_jobs_and_update_operations(): epoch_time_now = mktime(datetime.now().timetuple()) expired_jobs = get_all_expired_jobs(epoch_time_now) status_code, count, error, generated_ids = ( delete_all_expired_jobs(epoch_time_now) ) jobs_deleted = count msg = 'number of jobs expired: %s' % (str(jobs_deleted)) logger.info(msg) for job in expired_jobs: operation = ( AgentOperation('admin', job[OperationKey.CustomerName], None, None) ) operation.update_operation_expire_time( job[OperationKey.OperationId], job[OperationPerAgentKey.AgentId], job[OperationKey.Operation] ) if job[OperationKey.Plugin] == RV_PLUGIN: collection = AppCollections.UniqueApplications if re.search('^install', job['operation']): app_status = {STATUS: AVAILABLE} if job['operation'] == AgentOperations.INSTALL_CUSTOM_APPS: collection = AppCollections.CustomApps if job['operation'] == AgentOperations.INSTALL_SUPPORTED_APPS: collection = AppCollections.SupportedApps if job['operation'] == AgentOperations.INSTALL_AGENT_UPDATE: collection = AppCollections.vFenseApps elif re.search('^uninstall', job['operation']): app_status = {STATUS: INSTALLED} for app in job[AppsKey.FileData]: update_app_status_by_agentid_and_appid( job[OperationPerAgentKey.AgentId], collection, app[AppsKey.AppId], app_status )
def remove_expired_jobs_and_update_operations(): epoch_time_now = mktime(datetime.now().timetuple()) expired_jobs = get_all_expired_jobs(epoch_time_now) status_code, count, error, generated_ids = ( delete_all_expired_jobs(epoch_time_now)) jobs_deleted = count msg = 'number of jobs expired: %s' % (str(jobs_deleted)) logger.info(msg) for job in expired_jobs: operation = (AgentOperation('admin', job[OperationKey.CustomerName], None, None)) operation.update_operation_expire_time( job[OperationKey.OperationId], job[OperationPerAgentKey.AgentId], job[OperationKey.Operation]) if job[OperationKey.Plugin] == RV_PLUGIN: collection = AppCollections.UniqueApplications if re.search('^install', job['operation']): app_status = {STATUS: AVAILABLE} if job['operation'] == AgentOperations.INSTALL_CUSTOM_APPS: collection = AppCollections.CustomApps if job['operation'] == AgentOperations.INSTALL_SUPPORTED_APPS: collection = AppCollections.SupportedApps if job['operation'] == AgentOperations.INSTALL_AGENT_UPDATE: collection = AppCollections.vFenseApps elif re.search('^uninstall', job['operation']): app_status = {STATUS: INSTALLED} for app in job[AppsKey.FileData]: update_app_status_by_agentid_and_appid( job[OperationPerAgentKey.AgentId], collection, app[AppsKey.AppId], app_status)
def install_apps(self, oper_type, appids, cpu_throttle=CPUThrottleValues.NORMAL, net_throttle=0, restart=RebootValues.NONE, agentids=None, tag_id=None): """This method creates the operation and stores it into the agent queue. Args: oper_type (str): The operation type, etc.. install_os_apps, uninstall appids (list): List of the application ids, that you want to install. Kwargs: cpu_throttle (str): Throttle how much cpu to use while installing the applications. default = normal net_throttle (int): Throttle how much bandwidth is being used, while the agent is downloading the applications. default = 0 (unlimited) restart (str): Choose if you want to restart the system after the application is installed. Examples (none, needed, forced) default = 'none' (do not reboot) agentids (str): List of agent ids. default = None tag_id (str): 36 character UUID of the agent. default = None """ oper_plugin = vFensePlugins.RV_PLUGIN results = { ApiResultKeys.DATA: [], ApiResultKeys.USERNAME: self.username, ApiResultKeys.URI: self.uri, ApiResultKeys.HTTP_METHOD: self.method } performed_on = vFenseObjects.AGENT if tag_id: performed_on = vFenseObjects.TAG if not agentids: agentids = get_agent_ids_from_tag(tag_id) else: agentids += get_agent_ids_from_tag(tag_id) operation = (PatchingOperation( self.username, self.customer_name, )) operation_id = (operation.create_operation(oper_type, oper_plugin, agentids, tag_id, cpu_throttle, net_throttle, restart, performed_on=performed_on)) if operation_id: msg = 'operation created' status_code = GenericCodes.ObjectCreated vfense_status_code = AgentOperationCodes.Created results[ApiResultKeys.GENERATED_IDS] = [operation_id] results[ApiResultKeys.GENERIC_STATUS_CODE] = status_code results[ApiResultKeys.VFENSE_STATUS_CODE] = vfense_status_code results[ApiResultKeys.MESSAGE] = msg for agent_id in agentids: valid_appids = (return_valid_appids_for_agent( appids, agent_id, collection=self.CurrentAppsPerAgentCollection)) pkg_data = [] for app_id in valid_appids: update_app_status_by_agentid_and_appid( agent_id, app_id, CommonAppKeys.PENDING, self.CurrentAppsPerAgentCollection) pkg_data.append(self._get_apps_data(app_id, agent_id)) operation_data = { AgentOperationKey.Operation: oper_type, AgentOperationKey.OperationId: operation_id, AgentOperationKey.Plugin: oper_plugin, AgentOperationKey.Restart: restart, CommonFileKeys.PKG_FILEDATA: pkg_data, OperationPerAgentKey.AgentId: agent_id, AgentOperationKey.CpuThrottle: cpu_throttle, AgentOperationKey.NetThrottle: net_throttle, } self._store_in_agent_queue(operation_data) operation.add_agent_to_install_operation( agent_id, operation_id, pkg_data) else: msg = 'operation failed to create' status_code = GenericFailureCodes.FailedToCreateObject vfense_status_code = ( AgentOperationFailureCodes.FailedToCreateOperation) results[ApiResultKeys.GENERATED_IDS] = [operation_id], results[ApiResultKeys.GENERIC_STATUS_CODE] = status_code results[ApiResultKeys.VFENSE_STATUS_CODE] = vfense_status_code results[ApiResultKeys.MESSAGE] = msg return results
def install_apps( self, oper_type, appids, cpu_throttle=CPUThrottleValues.NORMAL, net_throttle=0, restart=RebootValues.NONE, agentids=None, tag_id=None ): """This method creates the operation and stores it into the agent queue. Args: oper_type (str): The operation type, etc.. install_os_apps, uninstall appids (list): List of the application ids, that you want to install. Kwargs: cpu_throttle (str): Throttle how much cpu to use while installing the applications. default = normal net_throttle (int): Throttle how much bandwidth is being used, while the agent is downloading the applications. default = 0 (unlimited) restart (str): Choose if you want to restart the system after the application is installed. Examples (none, needed, forced) default = 'none' (do not reboot) agentids (str): List of agent ids. default = None tag_id (str): 36 character UUID of the agent. default = None """ oper_plugin = vFensePlugins.RV_PLUGIN results = { ApiResultKeys.DATA: [], ApiResultKeys.USERNAME: self.username, ApiResultKeys.URI: self.uri, ApiResultKeys.HTTP_METHOD: self.method } performed_on = vFenseObjects.AGENT if tag_id: performed_on = vFenseObjects.TAG if not agentids: agentids = get_agent_ids_from_tag(tag_id) else: agentids += get_agent_ids_from_tag(tag_id) operation = ( PatchingOperation( self.username, self.customer_name, ) ) operation_id = ( operation.create_operation( oper_type, oper_plugin, agentids, tag_id, cpu_throttle, net_throttle, restart, performed_on=performed_on ) ) if operation_id: msg = 'operation created' status_code = GenericCodes.ObjectCreated vfense_status_code = AgentOperationCodes.Created results[ApiResultKeys.GENERATED_IDS] = [operation_id] results[ApiResultKeys.GENERIC_STATUS_CODE] = status_code results[ApiResultKeys.VFENSE_STATUS_CODE] = vfense_status_code results[ApiResultKeys.MESSAGE] = msg for agent_id in agentids: valid_appids = ( return_valid_appids_for_agent( appids, agent_id, collection=self.CurrentAppsPerAgentCollection ) ) pkg_data = [] for app_id in valid_appids: update_app_status_by_agentid_and_appid( agent_id, app_id, CommonAppKeys.PENDING, self.CurrentAppsPerAgentCollection ) pkg_data.append( self._get_apps_data(app_id, agent_id) ) operation_data = { AgentOperationKey.Operation: oper_type, AgentOperationKey.OperationId: operation_id, AgentOperationKey.Plugin: oper_plugin, AgentOperationKey.Restart: restart, CommonFileKeys.PKG_FILEDATA: pkg_data, OperationPerAgentKey.AgentId: agent_id, AgentOperationKey.CpuThrottle: cpu_throttle, AgentOperationKey.NetThrottle: net_throttle, } self._store_in_agent_queue(operation_data) operation.add_agent_to_install_operation( agent_id, operation_id, pkg_data ) else: msg = 'operation failed to create' status_code = GenericFailureCodes.FailedToCreateObject vfense_status_code = ( AgentOperationFailureCodes.FailedToCreateOperation ) results[ApiResultKeys.GENERATED_IDS] = [operation_id], results[ApiResultKeys.GENERIC_STATUS_CODE] = status_code results[ApiResultKeys.VFENSE_STATUS_CODE] = vfense_status_code results[ApiResultKeys.MESSAGE] = msg return results