# Buggy code
def __init__(
    self,
    output_mediator,
    host,
    port,
    flush_interval,
    index_name,
    mapping,
    doc_type,
    elastic_user,
    elastic_password,
):
    """Create a Elasticsearch helper.

    Args:
      output_mediator (OutputMediator): The output mediator object.
      host (str): IP address or hostname for the server.
      port (int): Port number for the server.
      flush_interval (int): How many events to queue before being indexed.
      index_name (str): Name of the Elasticsearch index.
      mapping (dict): Elasticsearch index configuration.
      doc_type (str): Elasticsearch document type name.
      elastic_user (str): Elasticsearch username to authenticate with.
      elastic_passsword (str): Elasticsearch password to authenticate with
    """
    super(ElasticSearchHelper, self).__init__()
    if elastic_user is None:
        self.client = Elasticsearch([{"host": host, "port": port}])
    else:
        self.client = Elasticsearch(
            [{"host": host, "port": port}], http_auth=(elastic_user, elastic_password)
        )
    self._output_mediator = output_mediator
    self._index = self._EnsureIndexExists(index_name, mapping)
    self._doc_type = doc_type
    self._flush_interval = flush_interval
    self._events = []
    self._counter = Counter()
    self._elastic_user = elastic_user
    self._elastic_password = elastic_password


# Traceback (TypeError)
2017-03-27 09:18:34,497 [INFO] (MainProcess) PID:5106 <timesketch_out> Timeline name: test

2017-03-27 09:18:34,497 [INFO] (MainProcess) PID:5106 <timesketch_out> Owner of the timeline: None
Traceback (most recent call last):
File "/usr/local/bin/psort.py", line 4, in <module>
__import__('pkg_resources').run_script('plaso==1.5.2.post20170221', 'psort.py')
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 719, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1504, in run_script
exec(code, namespace, namespace)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170221-py2.7.egg/EGG-INFO/scripts/psort.py", line 910, in <module>
if not Main():
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170221-py2.7.egg/EGG-INFO/scripts/psort.py", line 896, in Main
tool.ProcessStorage()
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170221-py2.7.egg/EGG-INFO/scripts/psort.py", line 840, in ProcessStorage
time_slice=self._time_slice, use_time_slicer=self._use_time_slicer)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170221-py2.7.egg/plaso/frontend/psort.py", line 225, in ExportEvents
use_time_slicer=use_time_slicer)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170221-py2.7.egg/plaso/multi_processing/psort.py", line 661, in ExportEvents
output_module, deduplicate_events)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170221-py2.7.egg/plaso/output/event_buffer.py", line 92, in __init__
self._output_module.WriteHeader()
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170221-py2.7.egg/plaso/output/timesketch_out.py", line 158, in WriteHeader
self._index_name, _document_mapping, self._doc_type)
TypeError: __init__() takes exactly 10 arguments (8 given)

# Fixed code
def __init__(
    self,
    output_mediator,
    host,
    port,
    flush_interval,
    index_name,
    mapping,
    doc_type,
    elastic_password=None,
    elastic_user=None,
):
    """Create a Elasticsearch helper.

    Args:
      output_mediator (OutputMediator): The output mediator object.
      host (str): IP address or hostname for the server.
      port (int): Port number for the server.
      flush_interval (int): How many events to queue before being indexed.
      index_name (str): Name of the Elasticsearch index.
      mapping (dict): Elasticsearch index configuration.
      doc_type (str): Elasticsearch document type name.
      elastic_passsword (Optional[str]): Elasticsearch password to authenticate
          with.
      elastic_user (Optional[str]): Elasticsearch username to authenticate with.
    """
    super(ElasticSearchHelper, self).__init__()

    elastic_hosts = [{"host": host, "port": port}]
    if elastic_user is None:
        self.client = Elasticsearch(elastic_hosts)
    else:
        self.client = Elasticsearch(
            elastic_hosts, http_auth=(elastic_user, elastic_password)
        )

    self._output_mediator = output_mediator
    self._index = self._EnsureIndexExists(index_name, mapping)
    self._doc_type = doc_type
    self._flush_interval = flush_interval
    self._events = []
    self._counter = Counter()
    self._elastic_user = elastic_user
    self._elastic_password = elastic_password