Skip to content

Commit d2bf2a6

Browse files
author
David Noble
committed
Search command example/tests update + fix to boolean value conversion issue
1 parent 4633fb1 commit d2bf2a6

14 files changed

+993
-691
lines changed

examples/searchcommands_app/bin/countmatches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CountMatchesCommand(StreamingCommand):
4141
## Example
4242
4343
```
44-
countmatches fieldname=word_count pattern="\w+" some_text_field
44+
| inputcsv tweets.csv | countmatches fieldname=word_count pattern=\w+ text
4545
```
4646
4747
Counts the number of words in `some_text_field` and stores the result in

examples/searchcommands_app/bin/simulate.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SimulateCommand(GeneratingCommand):
3131
##Syntax
3232
3333
simulate csv=<path> rate=<expected-event-count> interval=<sampling-period>
34-
duration=<execution-period>
34+
duration=<execution-period> [seed=<
3535
3636
##Description
3737
@@ -81,13 +81,14 @@ class SimulateCommand(GeneratingCommand):
8181

8282
seed = Option(
8383
doc='''**Syntax:** **seed=***<string>*
84-
**Description:** Value for initializing the random number generator ''',
85-
require=False)
84+
**Description:** Value for initializing the random number generator ''')
8685

8786
def generate(self):
8887
""" Yields one random record at a time for the duration of `duration` """
8988
self.logger.debug('SimulateCommand: %s' % self) # log command line
9089
if not self.records:
90+
if self.seed is not None:
91+
random.seed(self.seed)
9192
self.records = [record for record in csv.DictReader(self.csv_file)]
9293
self.lambda_value = 1.0 / (self.rate / float(self.interval))
9394
duration = self.duration

examples/searchcommands_scaffolding/default/commands.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
[%(command.lower()]
55
filename = %(command.lower()).py
66
supports_getinfo = true
7+
supports_rawargs = true

splunklib/searchcommands/search_command.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ def process(self, args=argv, input_file=stdin, output_file=stdout):
156156
return
157157
self._configuration = ConfigurationSettings(self)
158158
if self.show_configuration:
159-
self.logger.debug(str(self.configuration))
160-
self.messages.append('info_message', str(self.configuration))
159+
self.messages.append('info_message', str(self._configuration))
161160
writer = csv.DictWriter(
162161
output_file, self, self.configuration.keys(), mv_delimiter=',')
163162
writer.writerow(self.configuration.items())

splunklib/searchcommands/validators.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ class Boolean(Validator):
3737
't': True, 'f': False,
3838
'true': True, 'false': False,
3939
'y': True, 'n': False,
40-
'yes': True, 'No': False
40+
'yes': True, 'no': False
4141
}
4242

4343
def __call__(self, value):
44-
if not isinstance(value, bool):
44+
if not (value is None or isinstance(value, bool)):
4545
value = str(value).lower()
4646
if value not in Boolean.truth_values:
4747
raise ValueError('Unrecognized truth value: %s' % value)
@@ -155,18 +155,8 @@ def __init__(self, *args):
155155
self.membership = args
156156

157157
def __call__(self, value):
158-
value = str(value)
159-
if value not in self.membership:
160-
raise ValueError('Unrecognized value: %s' % value)
158+
if value is not None:
159+
value = str(value)
160+
if value not in self.membership:
161+
raise ValueError('Unrecognized value: %s' % value)
161162
return value
162-
163-
164-
class String(Validator):
165-
""" TODO: Documentation
166-
167-
"""
168-
def __call__(self, value):
169-
return str(value)
170-
171-
def format(self, value):
172-
return str(value)

tests/searchcommands_data/_expected_results/countmatches __EXECUTE__ fieldname=word_count pattern=w+ text

Lines changed: 0 additions & 630 deletions
This file was deleted.

tests/searchcommands_data/_expected_results/countmatches __GETINFO__ fieldname=word_count pattern=w+ text

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/searchcommands_data/_expected_results/simulate __EXECUTE__ csv=tweets.csv rate=200 interval=00-00-01 runtime=00-00-10

Whitespace-only changes.

tests/searchcommands_data/_expected_results/simulate __GETINFO__ csv=tweets.csv rate=200 interval=00-00-01 runtime=00-00-10

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/searchcommands_data/_expected_results/sum __EXECUTE__ __map__ total=total count

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)