Skip to content

Commit

Permalink
Merge pull request #115 from google/111-data-location-for-frontend
Browse files Browse the repository at this point in the history
111 data location for frontend
  • Loading branch information
berggren committed Sep 24, 2015
2 parents c419c9d + f5ca294 commit 87b8ac9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
4 changes: 4 additions & 0 deletions timesketch.conf
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ UPLOAD_FOLDER = u'/tmp'
# server is running.
CELERY_BROKER_URL='redis://ip:port',
CELERY_RESULT_BACKEND='redis://ip:port'

# Path to plaso data directory.
# If not set, defaults to system prefix + share/plaso
#PLASO_DATA_LOCATION = u'/path/to/dir/with/plaso/data/files'
28 changes: 27 additions & 1 deletion timesketch/lib/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,37 @@
# limitations under the License.
"""Celery task for processing Plaso storage files."""

from plaso.frontend import psort
import os
import sys

from flask import current_app
# We currently don't have plaso in our Travis setup. This is a workaround
# for that until we fix the Travis environment.
# TODO: Add Plaso to our Travis environment we are running our tests in.
try:
from plaso.frontend import psort
except ImportError:
pass

from timesketch import create_celery_app

celery = create_celery_app()


def get_data_location():
"""Path to the plaso data directory.
Returns:
The path to where the plaso data directory is or None if not existing.
"""
data_location = current_app.config.get(u'PLASO_DATA_LOCATION', None)
if not data_location:
data_location = os.path.join(sys.prefix, u'share', u'plaso')
if not os.path.exists(data_location):
data_location = None
return data_location


@celery.task(track_started=True)
def run_plaso(source_file_path, timeline_name, index_name):
"""Create a Celery task for processing Plaso storage file.
Expand All @@ -32,11 +56,13 @@ def run_plaso(source_file_path, timeline_name, index_name):
Returns:
Dictionary with count of processed events.
"""
plaso_data_location = get_data_location()
analysis_plugins = None
flush_interval_ms = 1000

# Use the Psort frontend for processing.
frontend = psort.PsortFrontend()
frontend.SetDataLocation(plaso_data_location)
storage_file = frontend.OpenStorage(
source_file_path, read_only=True)

Expand Down
30 changes: 30 additions & 0 deletions timesketch/lib/tasks_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for tasks."""

from flask import current_app

from timesketch.lib.testlib import BaseTest
from timesketch.lib.tasks import get_data_location


class TestTasks(BaseTest):
"""Tests for the functionality on the tasks module."""
def test_get_data_location(self):
"""Test to get data_location path."""
data_location_none = get_data_location()
current_app.config[u'PLASO_DATA_LOCATION'] = u'/tmp'
data_location_exists = get_data_location()
self.assertFalse(data_location_none)
self.assertEqual(u'/tmp', data_location_exists)
2 changes: 1 addition & 1 deletion wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""This module is for creating the app for a WSGI server.
Example with Gunicorn:
$ gunicorn -b 127.0.0.1:4000 --log-file - wsgi:application
$ gunicorn -b 127.0.0.1:4000 --log-file --timeout 120 - wsgi:application
Example configuration for Apache with mod_wsgi (a2enmod mod_wsgi):
<VirtualHost *:443>
Expand Down

0 comments on commit 87b8ac9

Please sign in to comment.