examples/submit.py packs multiple lines in a single event
Hi,
We have a tool that generates CSVs to stdout and we are trying to pipe its output to examples/submit.py in order to create an event in Splunk for each line in the CSV. Playing around, we've noticed that:
#
# The following code uses the Splunk streaming receiver in order
# to reduce the buffering of event data read from stdin, which makes
# this tool a little friendlier for submitting large event streams,
# however if the buffering is not a concern, you can achieve the
# submit somewhat more directly using Splunk's 'simple' receiver,
# as follows:
#
# event = sys.stdin.read()
# service.indexes[index].submit(event, **kwargs_submit)
#
cn = service.indexes[index].attach(**kwargs_submit)
try:
while True:
line = sys.stdin.readline().rstrip('\r\n')
if len(line) == 0: break
cn.write(line)
finally:
cn.close()
, using the version shown, all lines get bunched up into the same event. However, if we use the commented version, it works perfectly.
I'm not sure what's the right thing to do, but the latter behavior seems to be much more useful
The example is designed to write all of its stdin as a single event. We should make that clearer.
If you're generating a lot of CSV, you'll be happier if you submit to a TCP input or write it to a file and have Splunk monitor it. Both routes scale better than the current incarnation of HTTP inputs. See the genevents example for a way to do that.
If you remove the .rstrip('\r\n') from this example you'll probably get what you expect. That takes the newlines off of each line of stdin, which makes everything seem like one event to Splunk unless you configure different line breaking rules.
Is that helpful?
Hi,
Yeah, we kinda figured this out. However, submitting csv's via HTTP was quick enough for us. It's a pretty useful command, so it might be interesting to ship such an example with the SDK.
However, not really a bug, so feel free to close this.
Cheers,
Álex
It's a good idea. We'll look into adding that variation as an example in a future release.