Пример #1
0
def add_custom_app_to_agents(username,
                             customer_name,
                             uri,
                             method,
                             file_data,
                             agent_id=None,
                             app_id=None):

    if app_id and not agent_id:
        app_info = (fetch_app_data(app_id,
                                   collection=AppCollections.CustomApps))

        agent_ids = get_all_agent_ids(customer_name,
                                      agent_os=app_info[AgentKey.OsCode])
        if len(agent_ids) > 0:
            for agentid in agent_ids:
                add_file_data(app_id, file_data, agent_id)
                agent_info_to_insert = ({
                    CustomAppsPerAgentKey.AgentId:
                    agentid,
                    CustomAppsPerAgentKey.AppId:
                    app_id,
                    CustomAppsPerAgentKey.Status:
                    CommonAppKeys.AVAILABLE,
                    CustomAppsPerAgentKey.CustomerName:
                    customer_name,
                    CustomAppsPerAgentKey.InstallDate:
                    r.epoch_time(0.0)
                })
                insert_app_data(agent_info_to_insert,
                                collection=AppCollections.CustomAppsPerAgent)

    if agent_id and not app_id:
        agent_info = get_agent_info(agent_id)
        apps_info = fetch_apps_data_by_os_code(
            agent_info[AgentKey.OsCode],
            customer_name,
            collection=AppCollections.CustomApps)

        for app_info in apps_info:
            app_id = app_info.get(CustomAppsKey.AppId)
            file_data = fetch_file_data(app_id)
            add_file_data(app_id, file_data, agent_id)

            agent_info_to_insert = {
                CustomAppsPerAgentKey.AgentId: agent_id,
                CustomAppsPerAgentKey.AppId: app_id,
                CustomAppsPerAgentKey.Status: CommonAppKeys.AVAILABLE,
                CustomAppsPerAgentKey.CustomerName: customer_name,
                CustomAppsPerAgentKey.InstallDate: r.epoch_time(0.0)
            }

            insert_app_data(agent_info_to_insert,
                            collection=AppCollections.CustomAppsPerAgent)
Пример #2
0
def add_custom_app_to_agents(username, customer_name, uri, method,
                             file_data, agent_id=None, app_id=None):

    if app_id and not agent_id:
        app_info = (
            fetch_app_data(
                app_id, collection=AppCollections.CustomApps
            )
        )

        agent_ids = get_all_agent_ids(customer_name, agent_os=app_info[AgentKey.OsCode])
        if len(agent_ids) > 0:
            for agentid in agent_ids:
                add_file_data(app_id, file_data, agent_id)
                agent_info_to_insert = (
                    {
                        CustomAppsPerAgentKey.AgentId: agentid,
                        CustomAppsPerAgentKey.AppId: app_id,
                        CustomAppsPerAgentKey.Status: CommonAppKeys.AVAILABLE,
                        CustomAppsPerAgentKey.CustomerName: customer_name,
                        CustomAppsPerAgentKey.InstallDate: r.epoch_time(0.0)
                    }
                )
                insert_app_data(
                    agent_info_to_insert,
                    collection=AppCollections.CustomAppsPerAgent
                )

    if agent_id and not app_id:
        agent_info = get_agent_info(agent_id)
        apps_info = fetch_apps_data_by_os_code(
            agent_info[AgentKey.OsCode], customer_name,
            collection=AppCollections.CustomApps
        )

        for app_info in apps_info:
            app_id = app_info.get(CustomAppsKey.AppId)
            file_data = fetch_file_data(app_id)
            add_file_data(app_id, file_data, agent_id)

            agent_info_to_insert = {
                CustomAppsPerAgentKey.AgentId: agent_id,
                CustomAppsPerAgentKey.AppId: app_id,
                CustomAppsPerAgentKey.Status: CommonAppKeys.AVAILABLE,
                CustomAppsPerAgentKey.CustomerName: customer_name,
                CustomAppsPerAgentKey.InstallDate: r.epoch_time(0.0)
            }

            insert_app_data(
                agent_info_to_insert, collection=AppCollections.CustomAppsPerAgent
            )
Пример #3
0
    def _update_app_status(self, collection):
        """Update the application status per agent as well as update the
            operation
        """
        results = {
            ApiResultKeys.USERNAME: self.username,
            ApiResultKeys.URI: self.uri,
            ApiResultKeys.HTTP_METHOD: self.method
        }

        if self.reboot_required:
            update_agent_field(
                self.agent_id, AgentKey.NeedsReboot,
                CommonKeys.YES, self.username
            )

        if self.success == CommonKeys.TRUE or self.success == CommonKeys.FALSE:
            if (self.success == CommonKeys.TRUE and
                    re.search(r'^install', self.operation_type)):

                status = CommonAppKeys.INSTALLED
                install_date = self.date_now

            elif (self.success == CommonKeys.TRUE and
                    re.search(r'^uninstall', self.operation_type)):

                status = CommonAppKeys.AVAILABLE
                install_date = self.begining_of_time

            elif (self.success == CommonKeys.FALSE and
                    re.search(r'^install', self.operation_type)):

                status = CommonAppKeys.AVAILABLE
                install_date = self.begining_of_time

            elif (self.success == CommonKeys.FALSE and
                    re.search(r'^uninstall', self.operation_type)):

                status = CommonAppKeys.INSTALLED
                install_date = self.begining_of_time


            data_to_update = (
                {
                    SharedAppKeys.Status: status,
                    SharedAppKeys.InstallDate: install_date
                }
            )
            app_exist = fetch_app_data(self.app_id, collection)

            if app_exist:
                if (self.operation_type == AgentOperations.INSTALL_OS_APPS or
                        self.operation_type == AgentOperations.UNINSTALL):

                    update_app_data_by_agentid_and_appid(
                        self.agent_id,
                        self.app_id,
                        data_to_update,
                        AppCollections.AppsPerAgent
                    )

                elif self.operation_type == AgentOperations.INSTALL_CUSTOM_APPS:

                    update_app_data_by_agentid_and_appid(
                        self.agent_id,
                        self.app_id,
                        data_to_update,
                        AppCollections.CustomAppsPerAgent
                    )

                elif self.operation_type == AgentOperations.INSTALL_SUPPORTED_APPS:

                    update_app_data_by_agentid_and_appid(
                        self.agent_id,
                        self.app_id,
                        data_to_update,
                        AppCollections.SupportedAppsPerAgent
                    )

                elif self.operation_type == AgentOperations.INSTALL_AGENT_UPDATE:

                    update_app_data_by_agentid_and_appid(
                        self.agent_id,
                        self.app_id,
                        data_to_update,
                        AppCollections.vFenseAppsPerAgent
                    )

            oper_app_exists = (
                operation_for_agent_and_app_exist(
                    self.operation_id, self.agent_id, self.app_id
                )
            )

            if oper_app_exists:
                if self.success == CommonKeys.TRUE:
                    status_code = AgentOperationCodes.ResultsReceived

                    if self.apps_to_delete:
                        self._apps_to_delete()

                    if self.apps_to_add:
                        self._apps_to_add()

                elif self.success == CommonKeys.FALSE:
                    status_code = AgentOperationCodes.ResultsReceivedWithErrors

                operation_updated = (
                    self.operation.update_app_results(
                        self.operation_id, self.agent_id,
                        self.app_id, status_code,
                        errors=self.error, apps_removed=self.apps_to_delete
                    )
                )
                if operation_updated:
                    msg = 'Results updated'
                    results[ApiResultKeys.GENERIC_STATUS_CODE] = (
                        GenericCodes.ObjectUpdated
                    )

                    results[ApiResultKeys.VFENSE_STATUS_CODE] = (
                        AgentResultCodes.ResultsUpdated
                    )

                    results[ApiResultKeys.MESSAGE] = msg

                else:
                    msg = 'Results failed to update'
                    results[ApiResultKeys.GENERIC_STATUS_CODE] = (
                        GenericFailureCodes.FailedToUpdateObject
                    )

                    results[ApiResultKeys.VFENSE_STATUS_CODE] = (
                        AgentFailureResultCodes.ResultsFailedToUpdate
                    )

                    results[ApiResultKeys.MESSAGE] = msg

            else:
                msg = 'Invalid operation id'
                results[ApiResultKeys.GENERIC_STATUS_CODE] = (
                    GenericFailureCodes.InvalidId
                )

                results[ApiResultKeys.VFENSE_STATUS_CODE] = (
                    AgentFailureResultCodes.InvalidOperationId
                )

                results[ApiResultKeys.MESSAGE] = msg

        else:
            msg = 'Invalid success value'
            results[ApiResultKeys.GENERIC_STATUS_CODE] = (
                GenericFailureCodes.FailedToUpdateObject
            )

            results[ApiResultKeys.VFENSE_STATUS_CODE] = (
                AgentFailureResultCodes.InvalidSuccessValue
            )

            results[ApiResultKeys.MESSAGE] = msg

        return results