コード例 #1
0
ファイル: resources.py プロジェクト: sainslie/timesketch
    def post(self, sketch_id):
        """Handles POST request to the resource.
        Handler for /api/v1/sketches/:sketch_id/aggregation/

        Args:
            sketch_id: Integer primary key for a sketch database model

        Returns:
            JSON with aggregation results
        """
        sketch = Sketch.query.get_with_acl(sketch_id)
        form = AggregationForm.build(request)

        if form.validate_on_submit():
            query_filter = form.filter.data
            query_dsl = form.dsl.data
            sketch_indices = [
                t.searchindex.index_name for t in sketch.timelines
            ]
            indices = query_filter.get(u'indices', sketch_indices)

            # If _all in indices then execute the query on all indices
            if u'_all' in indices:
                indices = sketch_indices

            # Make sure that the indices in the filter are part of the sketch.
            # This will also remove any deleted timeline from the search result.
            indices = get_validated_indices(indices, sketch_indices)

            # Make sure we have a query string or star filter
            if not (form.query.data, query_filter.get(u'star'),
                    query_filter.get(u'events')):
                abort(HTTP_STATUS_CODE_BAD_REQUEST)

            result = []
            if form.aggtype.data == u'heatmap':
                result = heatmap(
                    es_client=self.datastore,
                    sketch_id=sketch_id,
                    query_string=form.query.data,
                    query_filter=query_filter,
                    query_dsl=query_dsl,
                    indices=indices)
            elif form.aggtype.data == u'histogram':
                result = histogram(
                    es_client=self.datastore,
                    sketch_id=sketch_id,
                    query_string=form.query.data,
                    query_filter=query_filter,
                    query_dsl=query_dsl,
                    indices=indices)

            else:
                abort(HTTP_STATUS_CODE_BAD_REQUEST)

            schema = {u'objects': result}
            return jsonify(schema)
        return abort(HTTP_STATUS_CODE_BAD_REQUEST)
コード例 #2
0
ファイル: resources.py プロジェクト: s4n7h0/timesketch
    def post(self, sketch_id):
        """Handles POST request to the resource.
        Handler for /api/v1/sketches/:sketch_id/aggregation/

        Args:
            sketch_id: Integer primary key for a sketch database model

        Returns:
            JSON with aggregation results
        """
        sketch = Sketch.query.get_with_acl(sketch_id)
        form = AggregationForm.build(request)

        if form.validate_on_submit():
            query_filter = form.filter.data
            sketch_indices = [
                t.searchindex.index_name for t in sketch.timelines
            ]
            indices = query_filter.get(u'indices', sketch_indices)

            # Make sure that the indices in the filter are part of the sketch
            if set(indices) - set(sketch_indices):
                abort(HTTP_STATUS_CODE_BAD_REQUEST)

            # Make sure we have a query string or star filter
            if not form.query.data and not query_filter.get(u'star'):
                abort(HTTP_STATUS_CODE_BAD_REQUEST)

            result = []
            if form.aggtype.data == u'heatmap':
                result = heatmap(es_client=self.datastore,
                                 sketch_id=sketch_id,
                                 query=form.query.data,
                                 query_filter=query_filter,
                                 indices=indices)
            elif form.aggtype.data == u'histogram':
                result = histogram(es_client=self.datastore,
                                   sketch_id=sketch_id,
                                   query=form.query.data,
                                   query_filter=query_filter,
                                   indices=indices)

            else:
                abort(HTTP_STATUS_CODE_BAD_REQUEST)

            schema = {u'objects': result}
            return jsonify(schema)
        return abort(HTTP_STATUS_CODE_BAD_REQUEST)
コード例 #3
0
    def post(self, sketch_id):
        """Handles POST request to the resource.
        Handler for /api/v1/sketches/:sketch_id/aggregation/

        Args:
            sketch_id: Integer primary key for a sketch database model

        Returns:
            JSON with aggregation results
        """
        sketch = Sketch.query.get_with_acl(sketch_id)
        form = AggregationForm.build(request)

        if form.validate_on_submit():
            query_filter = form.filter.data
            sketch_indices = [
                t.searchindex.index_name for t in sketch.timelines]
            indices = query_filter.get(u'indices', sketch_indices)

            # Make sure that the indices in the filter are part of the sketch
            if set(indices) - set(sketch_indices):
                abort(HTTP_STATUS_CODE_BAD_REQUEST)

            # Make sure we have a query string or star filter
            if not form.query.data and not query_filter.get(u'star'):
                abort(HTTP_STATUS_CODE_BAD_REQUEST)

            result = []
            if form.aggtype.data == u'heatmap':
                result = heatmap(
                    es_client=self.datastore, sketch_id=sketch_id,
                    query=form.query.data, query_filter=query_filter,
                    indices=indices)
            elif form.aggtype.data == u'histogram':
                result = histogram(
                    es_client=self.datastore, sketch_id=sketch_id,
                    query=form.query.data, query_filter=query_filter,
                    indices=indices)

            else:
                abort(HTTP_STATUS_CODE_BAD_REQUEST)

            schema = {
                u'objects': result
            }
            return jsonify(schema)
        return abort(HTTP_STATUS_CODE_BAD_REQUEST)
コード例 #4
0
 def test_heatmap(self):
     """Test to get heatmap data."""
     es_client = MockDataStore(u'127.0.0,1', 4711)
     h = heatmap(es_client, 1, u'test', {}, [])
     self.assertEqual(len(h), 168)
     self.assertIsInstance(h, list)
コード例 #5
0
 def test_heatmap(self):
     """Test to get heatmap data."""
     es_client = MockDataStore('127.0.0,1', 4711)
     h = heatmap(es_client, 1, 'test', {}, [], ['all'])
     self.assertIsInstance(h, list)
コード例 #6
0
 def test_heatmap(self):
     """Test to get heatmap data."""
     es_client = MockDataStore(u'127.0.0,1', 4711)
     h = heatmap(es_client, 1, u'test', {}, [])
     self.assertEqual(len(h), 168)
     self.assertIsInstance(h, list)
コード例 #7
0
 def test_heatmap(self):
     """Test to get heatmap data."""
     es_client = MockDataStore('127.0.0,1', 4711)
     h = heatmap(es_client, 1, 'test', {}, [], ['all'])
     self.assertIsInstance(h, list)