Skip to content

Commit 103cc95

Browse files
committed
Update README.md
README updated on how to access service instance created using the server_uri and sessionkey metadata
1 parent 418a174 commit 103cc95

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,67 @@ class GeneratorTest(GeneratingCommand):
209209
checkpoint_dir = inputs.metadata["checkpoint_dir"]
210210
```
211211

212-
#### Optional:Set up logging for splunklib
212+
### Access service object in Custom Search Command & Modular Input apps
213+
214+
#### Custom Search Commands
215+
* The service object is created from the Splunkd URI and session key passed to the command invocation the search results info file.
216+
* Generating Custom Search Command
217+
```python
218+
def generate(self):
219+
# other code
220+
221+
# access service object that can be used to connect Splunk Service
222+
service = self.service
223+
# to get Splunk Service Info
224+
info = service.info
225+
```
226+
* Eventing Custom Search Command
227+
```python
228+
def transform(self, records):
229+
# other code
230+
231+
# access service object that can be used to connect Splunk Service
232+
service = self.service
233+
# to get Splunk Service Info
234+
info = service.info
235+
```
236+
* Streaming Custom Search Command
237+
```python
238+
def stream(self, records):
239+
# other code
240+
241+
# access service object that can be used to connect Splunk Service
242+
service = self.service
243+
# to get Splunk Service Info
244+
info = service.info
245+
```
246+
* Reporting Custom Search Command
247+
```python
248+
def reduce(self, records):
249+
# other code
250+
251+
# access service object that can be used to connect Splunk Service
252+
service = self.service
253+
# to get Splunk Service Info
254+
info = service.info
255+
```
256+
* Service object can be accessed using `self.service` in `generate`/`transform`/`stream`/`reduce` methods depending on the Custom Search Command
257+
258+
#### Modular Inputs app:
259+
* The service object is created from the Splunkd URI and session key passed to the command invocation on the modular input stream respectively.
260+
* It is available as soon as the :code:`Script.stream_events` method is called.
261+
```python
262+
def stream_events(self, inputs, ew):
263+
# other code
264+
265+
# access service object that can be used to connect Splunk Service
266+
service = self.service
267+
# to get Splunk Service Info
268+
info = service.info
269+
```
270+
271+
272+
### Optional:Set up logging for splunklib
213273
+ The default level is WARNING, which means that only events of this level and above will be visible
214274
+ To change a logging level we can call setup_logging() method and pass the logging level as an argument.
215275
+ Optional: we can also pass log format and date format string as a method argument to modify default format

0 commit comments

Comments
 (0)