Example #1
0
  def _StartMonitoringProcess(self, process):
    """Starts monitoring a process.

    Args:
      process (MultiProcessBaseProcess): process.

    Raises:
      IOError: if the RPC client cannot connect to the server.
      KeyError: if the process is not registered with the engine or
          if the process is already being monitored.
      OSError: if the RPC client cannot connect to the server.
      ValueError: if the process is missing.
    """
    if process is None:
      raise ValueError('Missing process.')

    pid = process.pid

    if pid in self._process_information_per_pid:
      raise KeyError(
          'Already monitoring process (PID: {0:d}).'.format(pid))

    if pid in self._rpc_clients_per_pid:
      raise KeyError(
          'RPC client (PID: {0:d}) already exists'.format(pid))

    rpc_client = plaso_xmlrpc.XMLProcessStatusRPCClient()

    # Make sure that a worker process has started its RPC server.
    # The RPC port will be 0 if no server is available.
    rpc_port = process.rpc_port.value
    time_waited_for_process = 0.0
    while not rpc_port:
      time.sleep(0.1)
      rpc_port = process.rpc_port.value
      time_waited_for_process += 0.1

      if time_waited_for_process >= self._RPC_SERVER_TIMEOUT:
        raise IOError(
            'RPC client unable to determine server (PID: {0:d}) port.'.format(
                pid))

    hostname = 'localhost'

    if not rpc_client.Open(hostname, rpc_port):
      raise IOError((
          'RPC client unable to connect to server (PID: {0:d}) '
          'http://{1:s}:{2:d}').format(pid, hostname, rpc_port))

    self._rpc_clients_per_pid[pid] = rpc_client
    self._process_information_per_pid[pid] = process_info.ProcessInfo(pid)
Example #2
0
    def _StartMonitoringProcess(self, pid):
        """Starts monitoring a process.

    Args:
      pid (int): process identifier (PID).

    Raises:
      KeyError: if the process is not registered with the engine or
                if the process if the processed is already being monitored.
      IOError: if the RPC client cannot connect to the server.
    """
        self._RaiseIfNotRegistered(pid)

        if pid in self._process_information_per_pid:
            raise KeyError(
                u'Process (PID: {0:d}) already in monitoring list.'.format(
                    pid))

        if pid in self._rpc_clients_per_pid:
            raise KeyError(
                u'RPC client (PID: {0:d}) already exists'.format(pid))

        process = self._processes_per_pid[pid]
        rpc_client = plaso_xmlrpc.XMLProcessStatusRPCClient()

        # Make sure that a process has started its RPC server. RPC port will
        # be 0 if no server is available.
        rpc_port = process.rpc_port.value
        time_waited_for_process = 0.0
        while not rpc_port:
            time.sleep(0.1)
            rpc_port = process.rpc_port.value
            time_waited_for_process += 0.1

            if time_waited_for_process >= self._RPC_SERVER_TIMEOUT:
                raise IOError(
                    u'RPC client unable to determine server (PID: {0:d}) port.'
                    .format(pid))

        hostname = u'localhost'

        if not rpc_client.Open(hostname, rpc_port):
            raise IOError(
                (u'RPC client unable to connect to server (PID: {0:d}) '
                 u'http://{1:s}:{2:d}').format(pid, hostname, rpc_port))

        self._rpc_clients_per_pid[pid] = rpc_client
        self._process_information_per_pid[pid] = process_info.ProcessInfo(pid)