code: def feed_index(service, opts):
      
  
      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))
  
      count = 0
      lastevent = ""
      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)
docs: Feed the named index in a specific manner.