# 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
    try:
        for i in range(0, 10):
            for j in range(0, 5000):
                lastevent = "%s: event bunch %d, number %d\n" % \
                             (datetime.datetime.now().isoformat(), i, j)

                if itype == "stream":
                    stream.write(lastevent + "\n")
                elif itype == "submit":
                    index.submit(lastevent + "\n")
                else:
                    ingest.send(lastevent + "\n")

                count = count + 1
            
            print("submitted %d events, sleeping 1 second" % count)
            time.sleep(1)
    except KeyboardInterrupt:
        print("^C detected, last event written:")
        print(lastevent)

def main():
    usage = "usage: %prog [options] <command> [<args>]"

    argv = sys.argv[1:]
    if len(argv) == 0:
        print("must supply an index name")
        sys.exit(1)

    opts = parse(argv, RULES, ".splunkrc", usage=usage)

# 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

    try:
        for i in range(0, 10):
            for j in range(0, 5000):
                lastevent = "%s: event bunch %d, number %d\n" % \
                             (datetime.datetime.now().isoformat(), i, j)

                if itype == "stream":
                    stream.write(lastevent + "\n")
                elif itype == "submit":
                    index.submit(lastevent + "\n")
                else:
                    ingest.send(lastevent + "\n")

                count = count + 1
            
            print("submitted %d events, sleeping 1 second" % count)
            time.sleep(1)
    except KeyboardInterrupt:
        print("^C detected, last event written:")
        print(lastevent)

def main():
    usage = "usage: %prog [options] <command> [<args>]"

    argv = sys.argv[1:]
    if len(argv) == 0:
        print("must supply an index name")
        sys.exit(1)

    opts = parse(argv, RULES, ".splunkrc", usage=usage)

    service = connect(**opts.kwargs)