diff --git a/docs/REFERENCE.md b/docs/REFERENCE.md index dd44553a..25d08b77 100644 --- a/docs/REFERENCE.md +++ b/docs/REFERENCE.md @@ -320,9 +320,10 @@ backfillSearchUrl = in a cluster. count = - * Maximum number of events to generate per sample file + * Maximum number of events to generate per sample file (only used with sample mode). * -1 means replay the entire sample. * Defaults to -1. + * When count is -1 and the default generator is used, count depends on the size of the sample. perDayVolume = * This is used in place of count. The perDayVolume is a size supplied in GB per Day. This value will allow diff --git a/splunk_eventgen/lib/eventgentimer.py b/splunk_eventgen/lib/eventgentimer.py index e82168b8..6079cbaa 100644 --- a/splunk_eventgen/lib/eventgentimer.py +++ b/splunk_eventgen/lib/eventgentimer.py @@ -37,6 +37,7 @@ def __init__(self, time, sample=None, config=None, genqueue=None, outputqueue=No self.time = time self.stopping = False self.countdown = 0 + self.executions = 0 self.interval = getattr(self.sample, "interval", config.interval) #enable the logger self._setup_logging() @@ -101,10 +102,12 @@ def real_run(self): self.logger.debug("Timer creating plugin for '%s'" % self.sample.name) - self.executions = 0 end = False previous_count_left = 0 raw_event_size = self.predict_event_size() + if self.end and int(self.end) == 0: + self.logger.info("End = 0, no events will be generated for sample '%s'" % self.sample.name) + end = True while not end: # Need to be able to stop threads by the main thread or this thread. self.config will stop all threads # referenced in the config object, while, self.stopping will only stop this one. diff --git a/splunk_eventgen/lib/plugins/generator/windbag.py b/splunk_eventgen/lib/plugins/generator/windbag.py index a279f008..a8276382 100644 --- a/splunk_eventgen/lib/plugins/generator/windbag.py +++ b/splunk_eventgen/lib/plugins/generator/windbag.py @@ -1,7 +1,6 @@ from __future__ import division from generatorplugin import GeneratorPlugin -import logging -import datetime, time +import datetime from datetime import timedelta class WindbagGenerator(GeneratorPlugin): @@ -9,7 +8,9 @@ def __init__(self, sample): GeneratorPlugin.__init__(self, sample) def gen(self, count, earliest, latest, samplename=None): - # print type(latest - earliest).total_seconds() + if count < 0: + self.logger.warn('Sample size not found for count=-1 and generator=windbag, defaulting to count=60') + count = 60 time_interval = timedelta.total_seconds((latest - earliest)) / count for i in xrange(count): current_time_object = earliest + datetime.timedelta(0, time_interval*(i+1)) diff --git a/splunk_eventgen/lib/plugins/rater/config.py b/splunk_eventgen/lib/plugins/rater/config.py index 1784de87..d15136bd 100644 --- a/splunk_eventgen/lib/plugins/rater/config.py +++ b/splunk_eventgen/lib/plugins/rater/config.py @@ -3,6 +3,7 @@ import logging.handlers import datetime import random +import os class ConfigRater(object): @@ -43,7 +44,10 @@ def _setup_logging(self): def rate(self): self._sample.count = int(self._sample.count) - if self._sample.count == -1: + # Let generators handle infinite count for themselves + if self._sample.count == -1 and self._sample.generator == 'default': + if not self._sample.sampleDict: + self.logger.error('No sample found for default generator, cannot generate events') self._sample.count = len(self._sample.sampleDict) self._generatorWorkers = int(self._generatorWorkers) count = self._sample.count/self._generatorWorkers diff --git a/tests/sample_eventgen_conf/replay/eventgen.conf.replay b/tests/sample_eventgen_conf/replay/eventgen.conf.replay index 7ecbaf29..6011721f 100755 --- a/tests/sample_eventgen_conf/replay/eventgen.conf.replay +++ b/tests/sample_eventgen_conf/replay/eventgen.conf.replay @@ -1,13 +1,8 @@ [replay] sampleDir = tests/sample_eventgen_conf/replay -timeMultiple = 1 backfill = -5s sampletype = raw outputMode = stdout -index = main -sourcetype = windbag -source = windbag.log -host = localhost end = 1 mode = replay