# Path: splunklib/client.py
# def connect(**kwargs):
#     """This function connects and logs in to a Splunk instance.
# 
#     This function is a shorthand for :meth:`Service.login`.
#     The ``connect`` function makes one round trip to the server (for logging in).
# 
#     :param host: The host name (the default is "localhost").
#     :type host: ``string``
#     :param port: The port number (the default is 8089).
#     :type port: ``integer``
#     :param scheme: The scheme for accessing the service (the default is "https").
#     :type scheme: "https" or "http"
#     :param verify: Enable (True) or disable (False) SSL verification for
#                    https connections. (optional, the default is True)
#     :type verify: ``Boolean``
#     :param `owner`: The owner context of the namespace (optional).
#     :type owner: ``string``
#     :param `app`: The app context of the namespace (optional).
#     :type app: ``string``
#     :param sharing: The sharing mode for the namespace (the default is "user").
#     :type sharing: "global", "system", "app", or "user"
#     :param `token`: The current session token (optional). Session tokens can be
#                     shared across multiple service instances.
#     :type token: ``string``
#     :param cookie: A session cookie. When provided, you don't need to call :meth:`login`.
#         This parameter is only supported for Splunk 6.2+.
#     :type cookie: ``string``
#     :param autologin: When ``True``, automatically tries to log in again if the
#         session terminates.
#     :type autologin: ``boolean``
#     :param `username`: The Splunk account username, which is used to
#                        authenticate the Splunk instance.
#     :type username: ``string``
#     :param `password`: The password for the Splunk account.
#     :type password: ``string``
#     :param `context`: The SSLContext that can be used when setting verify=True (optional)
#     :type context: ``SSLContext``
#     :return: An initialized :class:`Service` connection.
# 
#     **Example**::
# 
#         import splunklib.client as client
#         s = client.connect(...)
#         a = s.apps["my_app"]
#         ...
#     """
#     s = Service(**kwargs)
#     s.login()
#     return s


import socket
import sys, os
import time
import datetime
from six.moves import range
from splunklib.client import connect
    from utils import parse
        'help': "input host port when using tcp ingest, default is %d" % \
                SPLUNK_PORT
    },
}

def feed_index(service, opts):
    """Feed the named index in a specific manner."""

    indexname = opts.args[0]
    itype = opts.kwargs['ingest']


    # get index handle
    try:
        index = service.indexes[indexname]
    except KeyError:
        print("Index %s not found" % indexname)
        return

    if itype in ["stream", "submit"]:
        stream = index.attach()
    else:
        # create a tcp input if one doesn't exist
        input_host = opts.kwargs.get("inputhost", SPLUNK_HOST)
        input_port = int(opts.kwargs.get("inputport", SPLUNK_PORT))
        input_name = "tcp:%s" % (input_port)
        if input_name not in service.inputs.list():
            service.inputs.create("tcp", input_port, index=indexname)
        # connect to socket
        ingest = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Path: splunklib/client.py
# def connect(**kwargs):
#     """This function connects and logs in to a Splunk instance.
# 
#     This function is a shorthand for :meth:`Service.login`.
#     The ``connect`` function makes one round trip to the server (for logging in).
# 
#     :param host: The host name (the default is "localhost").
#     :type host: ``string``
#     :param port: The port number (the default is 8089).
#     :type port: ``integer``
#     :param scheme: The scheme for accessing the service (the default is "https").
#     :type scheme: "https" or "http"
#     :param verify: Enable (True) or disable (False) SSL verification for
#                    https connections. (optional, the default is True)
#     :type verify: ``Boolean``
#     :param `owner`: The owner context of the namespace (optional).
#     :type owner: ``string``
#     :param `app`: The app context of the namespace (optional).
#     :type app: ``string``
#     :param sharing: The sharing mode for the namespace (the default is "user").
#     :type sharing: "global", "system", "app", or "user"
#     :param `token`: The current session token (optional). Session tokens can be
#                     shared across multiple service instances.
#     :type token: ``string``
#     :param cookie: A session cookie. When provided, you don't need to call :meth:`login`.
#         This parameter is only supported for Splunk 6.2+.
#     :type cookie: ``string``
#     :param autologin: When ``True``, automatically tries to log in again if the
#         session terminates.
#     :type autologin: ``boolean``
#     :param `username`: The Splunk account username, which is used to
#                        authenticate the Splunk instance.
#     :type username: ``string``
#     :param `password`: The password for the Splunk account.
#     :type password: ``string``
#     :param `context`: The SSLContext that can be used when setting verify=True (optional)
#     :type context: ``SSLContext``
#     :return: An initialized :class:`Service` connection.
# 
#     **Example**::
# 
#         import splunklib.client as client
#         s = client.connect(...)
#         a = s.apps["my_app"]
#         ...
#     """
#     s = Service(**kwargs)
#     s.login()
#     return s


# Path: examples/genevents.py
import socket
import sys, os
import time
import datetime
from six.moves import range
from splunklib.client import connect
    from utils import parse

        'help': "input host port when using tcp ingest, default is %d" % \
                SPLUNK_PORT
    },
}

def feed_index(service, opts):
    """Feed the named index in a specific manner."""

    indexname = opts.args[0]
    itype = opts.kwargs['ingest']


    # get index handle
    try:
        index = service.indexes[indexname]
    except KeyError:
        print("Index %s not found" % indexname)
        return

    if itype in ["stream", "submit"]:
        stream = index.attach()
    else:
        # create a tcp input if one doesn't exist
        input_host = opts.kwargs.get("inputhost", SPLUNK_HOST)
        input_port = int(opts.kwargs.get("inputport", SPLUNK_PORT))
        input_name = "tcp:%s" % (input_port)
        if input_name not in service.inputs.list():
            service.inputs.create("tcp", input_port, index=indexname)
        # connect to socket
        ingest = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        ingest.connect((input_host, input_port))