From 103cc954e4d6a418cd4424ccac3db0e9f70e7550 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Mon, 2 Jan 2023 14:03:22 +0530 Subject: [PATCH 1/2] Update README.md README updated on how to access service instance created using the server_uri and sessionkey metadata --- README.md | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 29b75704f..34b753a7f 100644 --- a/README.md +++ b/README.md @@ -209,7 +209,67 @@ class GeneratorTest(GeneratingCommand): checkpoint_dir = inputs.metadata["checkpoint_dir"] ``` -#### Optional:Set up logging for splunklib +### Access service object in Custom Search Command & Modular Input apps + +#### Custom Search Commands +* The service object is created from the Splunkd URI and session key passed to the command invocation the search results info file. +* Generating Custom Search Command + ```python + def generate(self): + # other code + + # access service object that can be used to connect Splunk Service + service = self.service + # to get Splunk Service Info + info = service.info + ``` + * Eventing Custom Search Command + ```python + def transform(self, records): + # other code + + # access service object that can be used to connect Splunk Service + service = self.service + # to get Splunk Service Info + info = service.info + ``` + * Streaming Custom Search Command + ```python + def stream(self, records): + # other code + + # access service object that can be used to connect Splunk Service + service = self.service + # to get Splunk Service Info + info = service.info + ``` + * Reporting Custom Search Command + ```python + def reduce(self, records): + # other code + + # access service object that can be used to connect Splunk Service + service = self.service + # to get Splunk Service Info + info = service.info + ``` +* Service object can be accessed using `self.service` in `generate`/`transform`/`stream`/`reduce` methods depending on the Custom Search Command + +#### Modular Inputs app: +* The service object is created from the Splunkd URI and session key passed to the command invocation on the modular input stream respectively. +* It is available as soon as the :code:`Script.stream_events` method is called. +```python + def stream_events(self, inputs, ew): + # other code + + # access service object that can be used to connect Splunk Service + service = self.service + # to get Splunk Service Info + info = service.info +``` + + +### Optional:Set up logging for splunklib + The default level is WARNING, which means that only events of this level and above will be visible + To change a logging level we can call setup_logging() method and pass the logging level as an argument. + Optional: we can also pass log format and date format string as a method argument to modify default format From 83d753468a52e71ae46428dc5a370640e5e27521 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Tue, 10 Jan 2023 11:51:05 +0530 Subject: [PATCH 2/2] Update README.md --- README.md | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 34b753a7f..6b1b87728 100644 --- a/README.md +++ b/README.md @@ -213,7 +213,8 @@ class GeneratorTest(GeneratingCommand): #### Custom Search Commands * The service object is created from the Splunkd URI and session key passed to the command invocation the search results info file. -* Generating Custom Search Command +* Service object can be accessed using `self.service` in `generate`/`transform`/`stream`/`reduce` methods depending on the Custom Search Command. +* For Generating Custom Search Command ```python def generate(self): # other code @@ -223,41 +224,12 @@ class GeneratorTest(GeneratingCommand): # to get Splunk Service Info info = service.info ``` - * Eventing Custom Search Command - ```python - def transform(self, records): - # other code - - # access service object that can be used to connect Splunk Service - service = self.service - # to get Splunk Service Info - info = service.info - ``` - * Streaming Custom Search Command - ```python - def stream(self, records): - # other code - - # access service object that can be used to connect Splunk Service - service = self.service - # to get Splunk Service Info - info = service.info - ``` - * Reporting Custom Search Command - ```python - def reduce(self, records): - # other code - - # access service object that can be used to connect Splunk Service - service = self.service - # to get Splunk Service Info - info = service.info - ``` -* Service object can be accessed using `self.service` in `generate`/`transform`/`stream`/`reduce` methods depending on the Custom Search Command + + #### Modular Inputs app: * The service object is created from the Splunkd URI and session key passed to the command invocation on the modular input stream respectively. -* It is available as soon as the :code:`Script.stream_events` method is called. +* It is available as soon as the `Script.stream_events` method is called. ```python def stream_events(self, inputs, ew): # other code