Exemple #1
0
    def _exchange_online_delete_messages_from_query_results_function(self, event, *args, **kwargs):
        """Function: This Exchange Online function will delete a list of messages returned from the
        Query Message function.  The input to the function is a string containing the JSON results
        from the Query Messages function."""
        try:
            # Initialize the results payload
            rp = ResultPayload(CONFIG_DATA_SECTION, **kwargs)

            # Validate fields
            validate_fields(['exo_query_messages_results'], kwargs)

            # Get the function parameters
            query_results = kwargs.get('exo_query_messages_results')  # text

            LOG.info(u"exo_query_messages_results: %s", query_results)

            yield StatusMessage(u"Starting delete messages for query results")

            # Get the MS Graph helper class
            MS_graph_helper = MSGraphHelper(self.options.get("microsoft_graph_token_url"),
                                            self.options.get("microsoft_graph_url"),
                                            self.options.get("tenant_id"),
                                            self.options.get("client_id"),
                                            self.options.get("client_secret"),
                                            self.options.get("max_messages"),
                                            self.options.get("max_users"),
                                            RequestsCommon(self.opts, self.options).get_proxies())

            # Delete messages found in the query.
            delete_results = MS_graph_helper.delete_messages_from_query_results(query_results)

            results = rp.done(True, delete_results)

            yield StatusMessage(u"Returning Delete Messages From Query Results results.")

            # Produce a FunctionResult with the results
            yield FunctionResult(results)
        except Exception as err:
            LOG.error(err)
            yield FunctionError(err)
Exemple #2
0
    def _exchange_online_delete_messages_from_query_results_function(
            self, event, *args, **kwargs):
        """Function: This Exchange Online function will delete a list of messages returned from the
        Query Message function.  The input to the function is a string containing the JSON results
        from the Query Messages function."""
        try:
            # Initialize the results payload
            rp = ResultPayload(CONFIG_DATA_SECTION, **kwargs)

            # Validate fields
            validate_fields(['exo_query_messages_results'], kwargs)

            # Get the function parameters

            query_results = kwargs.get('exo_query_messages_results')  # text

            LOG.info(u"exo_query_messages_results: %s", query_results)

            yield StatusMessage(u"Starting delete messages for query results")

            # Get the MS Graph helper class
            MS_graph_helper = MSGraphHelper(
                self.options.get("microsoft_graph_token_url"),
                self.options.get("microsoft_graph_url"),
                self.options.get("tenant_id"), self.options.get("client_id"),
                self.options.get("client_secret"),
                self.options.get("max_messages"),
                self.options.get("max_users"),
                self.options.get("max_retries_total", MAX_RETRIES_TOTAL),
                self.options.get("max_retries_backoff_factor",
                                 MAX_RETRIES_BACKOFF_FACTOR),
                self.options.get("max_batched_requests", MAX_BATCHED_REQUESTS),
                RequestsCommon(self.opts, self.options).get_proxies())

            # Convert string to JSON.
            try:
                query_results_json = json.loads(query_results)
                query_message_results = query_results_json.get('email_results')
                query_output_format = query_results_json.get(
                    'exo_query_output_format')
                incident_id = int(query_results_json.get('incident_id'))
            except ValueError as err:
                raise IntegrationError(
                    "Invalid JSON string in Delete Message from Query Results."
                )

            # Delete messages found in the query.
            delete_results = MS_graph_helper.delete_messages_from_query_results(
                query_message_results)

            delete_message_results = {
                "incident_id": incident_id,
                "exo_query_output_format": query_output_format,
                "delete_results": delete_results
            }

            results = rp.done(True, delete_message_results)

            metrics = results.get("metrics")
            execution_time_ms = metrics.get("execution_time_ms")

            # Write delete messages from query results to an attachment or note as specified by the user
            # in activity field.
            # Writing results to the data table takes place in the post processor script.
            self.write_results_to_note_or_attachment(delete_message_results,
                                                     execution_time_ms)

            yield StatusMessage(
                u"Returning Delete Messages From Query Results results.")

            # Produce a FunctionResult with the results
            yield FunctionResult(results)
        except Exception as err:
            LOG.error(err)
            yield FunctionError(err)