Skip to content

Commit ae817d9

Browse files
vmalaviya-splunkakaila-splunk
authored andcommitted
Update README.md
Description added for how to use add_field method to preserve conditionally added new fields and values.
1 parent e37c691 commit ae817d9

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,31 @@ The test suite uses Python's standard library, the built-in `unittest` library,
150150
|/tests | Source for unit tests |
151151
|/utils | Source for utilities shared by the examples and unit tests |
152152

153+
### Customization
154+
* When working with custom search commands such as Custom Streaming Commands or Custom Generating Commands, We may need to add new fields to the records based on certain conditions.
155+
* Structural changes like this may not be preserved.
156+
* Make sure to use ``add_field(record, fieldname, value)`` method from SearchCommand to add a new field and value to the record.
157+
158+
Do
159+
```python
160+
class CustomStreamingCommand(StreamingCommand):
161+
def stream(self, records):
162+
for index, record in enumerate(records):
163+
if index % 1 == 0:
164+
self.add_field(record, "odd_record", "true")
165+
yield record
166+
```
167+
168+
Don't
169+
```python
170+
class CustomStreamingCommand(StreamingCommand):
171+
def stream(self, records):
172+
for index, record in enumerate(records):
173+
if index % 1 == 0:
174+
record["odd_record"] = "true"
175+
yield record
176+
```
177+
153178
### Changelog
154179

155180
The [CHANGELOG](CHANGELOG.md) contains a description of changes for each version of the SDK. For the latest version, see the [CHANGELOG.md](https://github.com/splunk/splunk-sdk-python/blob/master/CHANGELOG.md) on GitHub.

0 commit comments

Comments
 (0)