Splunk Search

Best way to set host key in Modular Inputs

bmacias84
Champion

I am building a Modular Input but would like to set the host behind the scene. I know that I can use Scheme Default but that sets the default for all stanza.


[poll://Server1]
port=4532
comString=helloworld
id=1.23.22.15.3
#I want the value of poll to automagicly set value for host when the user goes through the Manager.
host=Server1

I know I could use a transform to set the Server1 host value during indexing, but there is got to be a better way with modular inputs. I don't want the user to retype Server1 Manager screen.

How would I accomplish this with the <manager>.xml, in a introspection, or in my .py script?

1 Solution

Simon
Contributor

You could use XML streaming mode (http://docs.splunk.com/Documentation/Splunk/latest/AdvancedDev/ModInputsStream) and then set the host value on each event in your python script, for example:

print "<stream><event><data>09/08/2011 14:01:59.0398 event_status="(0)The operation completed successfully."</data><host>yourhost</host></event></stream>"

You can get the stanza name by parsing the input configuration (http://docs.splunk.com/Documentation/Splunk/latest/AdvancedDev/ModInputsScripts see "Example code reading XML configuration") and use this value in the host attribute.

View solution in original post

Simon
Contributor

You could use XML streaming mode (http://docs.splunk.com/Documentation/Splunk/latest/AdvancedDev/ModInputsStream) and then set the host value on each event in your python script, for example:

print "<stream><event><data>09/08/2011 14:01:59.0398 event_status="(0)The operation completed successfully."</data><host>yourhost</host></event></stream>"

You can get the stanza name by parsing the input configuration (http://docs.splunk.com/Documentation/Splunk/latest/AdvancedDev/ModInputsScripts see "Example code reading XML configuration") and use this value in the host attribute.

Simon
Contributor

Of course you can use the host key from inputs.conf by parsing the XML. See an example here:
http://docs.splunk.com/Documentation/Splunk/latest/AdvancedDev/ModInputsExample

After parsing the XML, just replace

<host>yourhost</host>

from my streaming sample above to something like

print "<stream><event><data>09/08/2011 14:01:59.0398 event_status="(0)The operation completed successfully."</data>%s</host></event></stream>" % config['host']
0 Karma

bmacias84
Champion

I was hoping to set the create the host key parsing by the XML feed from the Inputs Manager and place it in the inputs.conf.

0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...