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!

Community Content Calendar, November Edition

Welcome to the November edition of our Community Spotlight! Each month, we dive into the Splunk Community to ...

October Community Champions: A Shoutout to Our Contributors!

As October comes to a close, we want to take a moment to celebrate the people who make the Splunk Community ...

Stay Connected: Your Guide to November Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...