|
3 | 3 |
|
4 | 4 | # The Splunk Enterprise Software Development Kit for Python |
5 | 5 |
|
6 | | -#### Version 1.6.16 |
| 6 | +#### Version 1.6.17 |
7 | 7 |
|
8 | 8 | The Splunk Enterprise Software Development Kit (SDK) for Python contains library code and examples designed to enable developers to build applications using the Splunk platform. |
9 | 9 |
|
@@ -112,8 +112,18 @@ Save the file as **.splunkrc** in the current user's home directory. |
112 | 112 |
|
113 | 113 | Examples are located in the **/splunk-sdk-python/examples** directory. To run the examples at the command line, use the Python interpreter and include any arguments that are required by the example. In the commands below, replace "examplename" with the name of the specific example in the directory that you want to run: |
114 | 114 |
|
| 115 | +Using username and Password |
| 116 | + |
115 | 117 | python examplename.py --username="admin" --password="changeme" |
116 | 118 |
|
| 119 | +Using Bearer token |
| 120 | + |
| 121 | + python examplename.py --bearerToken=<value> |
| 122 | + |
| 123 | +Using Session key |
| 124 | + |
| 125 | + python examplename.py --sessionKey="<value>" |
| 126 | + |
117 | 127 | If you saved your login credentials in the **.splunkrc** file, you can omit those arguments: |
118 | 128 |
|
119 | 129 | python examplename.py |
@@ -150,6 +160,53 @@ The test suite uses Python's standard library, the built-in `unittest` library, |
150 | 160 | |/tests | Source for unit tests | |
151 | 161 | |/utils | Source for utilities shared by the examples and unit tests | |
152 | 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 | +class CustomStreamingCommand(StreamingCommand): |
| 172 | + def stream(self, records): |
| 173 | + for index, record in enumerate(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 | +class CustomStreamingCommand(StreamingCommand): |
| 182 | + def stream(self, records): |
| 183 | + for index, record in enumerate(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 | + class GeneratorTest(GeneratingCommand): |
| 196 | + def generate(self): |
| 197 | + yield self.gen_record(_time=time.time(), one=1) |
| 198 | + yield self.gen_record(_time=time.time(), two=2) |
| 199 | +``` |
| 200 | + |
| 201 | +Don't |
| 202 | +```python |
| 203 | +@Configuration() |
| 204 | + class GeneratorTest(GeneratingCommand): |
| 205 | + def generate(self): |
| 206 | + yield {'_time': time.time(), 'one': 1} |
| 207 | + yield {'_time': time.time(), 'two': 2} |
| 208 | +``` |
| 209 | + |
153 | 210 | ### Changelog |
154 | 211 |
|
155 | 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