Splunk Dev

How to read stanza from local app.conf pragmatically in a modular input python?

elephant
Engager

I have some configurations in local app.conf and I would like to read them pragmatically. before streaming events

How to do it using python?

Thanks!
Labels (4)
0 Karma

pmeyerson
Path Finder

Your custom modular input script class should inherit from splunklib.modularinput
But you cannot access the service object in __init__, only in stream_events() onwards as thats when your code receives the payload from Splunk to construct the Service object.

You can use service object at the beginning of your stream_events(inputs, ew):
   stanza = self.service.confs["app"]

https://dev.splunk.com/enterprise/docs/devtools/python/sdk-python/howtousesplunkpython/howtocreatemo...

https://docs.splunk.com/DocumentationStatic/PythonSDK/2.0.1/modularinput.html#splunklib.modularinput...

0 Karma

elephant
Engager

Thank you

 

And how do you read properties from it?

I was looking in the documents you have attached and could not find reference to self.service.confs object... 

could you please attach an example of how to read a specific prop from a specific stanza?

 

Than you 

0 Karma
Get Updates on the Splunk Community!

Enter the Dashboard Challenge and Watch the .conf24 Global Broadcast!

The Splunk Community Dashboard Challenge is still happening, and it's not too late to enter for the week of ...

Join Us at the Builder Bar at .conf24 – Empowering Innovation and Collaboration

What is the Builder Bar? The Builder Bar is more than just a place; it's a hub of creativity, collaboration, ...

Combine Multiline Logs into a Single Event with SOCK - a Guide for Advanced Users

This article is the continuation of the “Combine multiline logs into a single event with SOCK - a step-by-step ...