You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -160,6 +160,53 @@ The test suite uses Python's standard library, the built-in `unittest` library,
160
160
|/tests | Source for unit tests |
161
161
|/utils | Source for utilities shared by the examples and unit tests |
162
162
163
+
### Customization
164
+
* 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.
165
+
* Structural changes like this may not be preserved.
166
+
* Make sure to use ``add_field(record, fieldname, value)`` method from SearchCommand to add a new field and value to the record.
167
+
*___Note:__ Usage of ``add_field`` method is completely optional, if you are not facing any issues with field retention._
168
+
169
+
Do
170
+
```python
171
+
classCustomStreamingCommand(StreamingCommand):
172
+
defstream(self, records):
173
+
for index, record inenumerate(records):
174
+
if index %1==0:
175
+
self.add_field(record, "odd_record", "true")
176
+
yield record
177
+
```
178
+
179
+
Don't
180
+
```python
181
+
classCustomStreamingCommand(StreamingCommand):
182
+
defstream(self, records):
183
+
for index, record inenumerate(records):
184
+
if index %1==0:
185
+
record["odd_record"] ="true"
186
+
yield record
187
+
```
188
+
### Customization for Generating Custom Search Command
189
+
* Generating Custom Search Command is used to generate events using SDK code.
190
+
* Make sure to use ``gen_record()`` method from SearchCommand to add a new record and pass event data as a key=value pair separated by , (mentioned in below example).
191
+
192
+
Do
193
+
```python
194
+
@Configuration()
195
+
classGeneratorTest(GeneratingCommand):
196
+
defgenerate(self):
197
+
yieldself.gen_record(_time=time.time(), one=1)
198
+
yieldself.gen_record(_time=time.time(), two=2)
199
+
```
200
+
201
+
Don't
202
+
```python
203
+
@Configuration()
204
+
classGeneratorTest(GeneratingCommand):
205
+
defgenerate(self):
206
+
yield {'_time': time.time(), 'one': 1}
207
+
yield {'_time': time.time(), 'two': 2}
208
+
```
209
+
163
210
### Changelog
164
211
165
212
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