예제 #1
0
    def reboot(self):
        """This will update the needs_reboot flag in the agent collection as
            well as update the operation with reboot succeeded
        """
        oper_type = AgentOperations.REBOOT
        results = self.update_operation(oper_type)

        if self.success == CommonKeys.TRUE:
            update_agent_field(self.agent_id, AgentKey.NeedsReboot,
                               CommonKeys.NO, self.username, self.uri,
                               self.method)

        return (results)
예제 #2
0
    def reboot(self):
        """This will update the needs_reboot flag in the agent collection as
            well as update the operation with reboot succeeded
        """
        oper_type = AgentOperations.REBOOT
        results = self.update_operation(oper_type)

        if self.success == CommonKeys.TRUE:
            update_agent_field(
                self.agent_id,
                AgentKey.NeedsReboot,
                CommonKeys.NO, self.username,
                self.uri, self.method
            )

        return(results)
예제 #3
0
    def change_customer(self, customer_name, uri, method, conn=None):
        try:
            cexists = (
                r
                .table(Collection.Customers)
                .get(customer_name)
                .run(conn)
            )
            customer_data = {AgentKey.CustomerName: customer_name}
            if cexists:
                update_agent_field(
                    self.agent_id,
                    AgentKey.CustomerName,
                    customer_name,
                    self.username,
                    uri, method
                )
                delete_agent_from_all_tags(self.agent_id)
                rv_q = Queue('move_agent', connection=rq_pool)
                rv_q.enqueue_call(
                    func=update_all_app_data_for_agent,
                    args=(self.agent_id, customer_data),
                    timeout=3600,
                )
                status = (
                    GenericResults(
                        self.username, uri, method
                    ).object_updated(self.agent_id, 'agent', customer_data)
                )
            else:
                status = (
                    GenericResults(
                        self.username, uri, method
                    ).invalid_id(self.agent_id, 'agent')
                )

        except Exception as e:
            status = (
                GenericResults(
                    self.username, uri, method
                ).something_broke(self.agent_id, 'agents', e)
            )
            logger.exception(e)
        
        return(status)
예제 #4
0
    def _changer(self, newname, name_type=AgentKey.DisplayName,
                 uri=None, method=None):
        if newname:
            agent_updated = (
                update_agent_field(
                    self.agent_id, name_type, newname, self.username,
                    uri, method
                )
            )

        return(agent_updated)
예제 #5
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