예제 #1
0
  def testMain(self):
    """Tests the _Main function."""
    output_event_queue = zeromq_queue.ZeroMQPushBindQueue(
        name='test output event queue', timeout_seconds=self._QUEUE_TIMEOUT)
    output_event_queue.Open()

    input_event_queue = zeromq_queue.ZeroMQPullConnectQueue(
        name='test input event queue', delay_open=True,
        port=output_event_queue.port,
        timeout_seconds=self._QUEUE_TIMEOUT)

    session = sessions.Session()
    analysis_plugin = TestAnalysisPlugin()

    with shared_test_lib.TempDirectory() as temp_directory:
      # Set up the processed for the task storage file generated by the
      # analysis plugin.
      os.mkdir(os.path.join(temp_directory, 'processed'))

      configuration = configurations.ProcessingConfiguration()
      configuration.task_storage_path = temp_directory

      test_process = analysis_process.AnalysisProcess(
          input_event_queue, None, session, analysis_plugin, configuration,
          name='TestAnalysis')
      test_process._FOREMAN_STATUS_WAIT = 1

      test_process.start()

      output_event_queue.PushItem(plaso_queue.QueueAbort(), block=False)
      output_event_queue.Close(abort=True)

      # Sleep for 1 second to allow the analysis process to terminate.
      # Before the temporary directory is removed.
      time.sleep(1)
예제 #2
0
    def _StartWorkerProcess(self, process_name):
        """Creates, starts, monitors and registers a worker process.

    Args:
      process_name (str): process name.

    Returns:
      MultiProcessWorkerProcess: extraction worker process or None on error.
    """
        analysis_plugin = self._analysis_plugins.get(process_name, None)
        if not analysis_plugin:
            logger.error('Missing analysis plugin: {0:s}'.format(process_name))
            return None

        queue_name = '{0:s} output event queue'.format(process_name)
        output_event_queue = zeromq_queue.ZeroMQPushBindQueue(
            name=queue_name, timeout_seconds=self._QUEUE_TIMEOUT)
        # Open the queue so it can bind to a random port, and we can get the
        # port number to use in the input queue.
        output_event_queue.Open()

        self._event_queues[process_name] = output_event_queue

        queue_name = '{0:s} input event queue'.format(process_name)
        input_event_queue = zeromq_queue.ZeroMQPullConnectQueue(
            name=queue_name,
            delay_open=True,
            port=output_event_queue.port,
            timeout_seconds=self._QUEUE_TIMEOUT)

        process = analysis_process.AnalysisProcess(
            input_event_queue,
            self._knowledge_base,
            self._session,
            analysis_plugin,
            self._processing_configuration,
            data_location=self._data_location,
            event_filter_expression=self._event_filter_expression,
            name=process_name)

        process.start()

        logger.info('Started analysis plugin: {0:s} (PID: {1:d}).'.format(
            process_name, process.pid))

        try:
            self._StartMonitoringProcess(process)
        except (IOError, KeyError) as exception:
            logger.error(
                ('Unable to monitor analysis plugin: {0:s} (PID: {1:d}) '
                 'with error: {2!s}').format(process_name, process.pid,
                                             exception))

            process.terminate()
            return None

        self._RegisterProcess(process)
        return process
예제 #3
0
    def testInitialization(self):
        """Tests the initialization."""
        with shared_test_lib.TempDirectory() as temp_directory:
            configuration = configurations.ProcessingConfiguration()
            configuration.task_storage_path = temp_directory

            test_process = analysis_process.AnalysisProcess(
                None, None, None, None, configuration, name='TestAnalysis')
            self.assertIsNotNone(test_process)
예제 #4
0
    def testSignalAbort(self):
        """Tests the SignalAbort function."""
        with shared_test_lib.TempDirectory() as temp_directory:
            configuration = configurations.ProcessingConfiguration()
            configuration.task_storage_path = temp_directory

            test_process = analysis_process.AnalysisProcess(
                None, None, None, None, configuration, name='TestAnalysis')
            test_process.SignalAbort()
예제 #5
0
    def testGetStatus(self):
        """Tests the _GetStatus function."""
        with shared_test_lib.TempDirectory() as temp_directory:
            configuration = configurations.ProcessingConfiguration()
            configuration.task_storage_path = temp_directory

            test_process = analysis_process.AnalysisProcess(
                None, None, None, None, configuration, name='TestAnalysis')
            status_attributes = test_process._GetStatus()

            self.assertIsNotNone(status_attributes)
            self.assertEqual(status_attributes['identifier'], 'TestAnalysis')
            self.assertIsNone(status_attributes['number_of_produced_reports'])