<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Need deployment server to assign hostnames dynamically via inputs.conf in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Need-deployment-server-to-assign-hostnames-dynamically-via/m-p/13575#M1225</link>
    <description>&lt;P&gt;Great question.  I doubt it's possible.  The deployment process seem to be pretty limited, IMHO.&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;WARNING:  UGLY UGLY HACK...&lt;/STRONG&gt;&lt;/EM&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I guess you could do a hack with an input script...&lt;/P&gt;

&lt;P&gt;Make sure your existing &lt;CODE&gt;inputs.conf&lt;/CODE&gt; is in the &lt;CODE&gt;default&lt;/CODE&gt; directory.  Then write a simple python script to check for the existence of the &lt;CODE&gt;local/inputs.conf&lt;/CODE&gt; in your app.  If it does not already exist, then your app should create it with the following template:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[tcp:://localhost:9997]
host = &amp;lt;host to be dynamically filled in by script&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;After the &lt;CODE&gt;local/inputs.conf&lt;/CODE&gt; file is written, it should issue a &lt;CODE&gt;splunk restart&lt;/CODE&gt; command so that the local entry takes effect.  When splunk startup up again, the script will run again, but this time since &lt;CODE&gt;local/inputs.conf&lt;/CODE&gt; exists, it will not make any changes or restart splunkd.  (You really don't want a recursive restart loop.  That would be bad, especially on 50 machines).&lt;/P&gt;

&lt;P&gt;You would probably want to schedule this script to run like once every 31536000 seconds (every year); so that it will only effectively run once a splunkd restart.&lt;/P&gt;

&lt;P&gt;When you redeploy your app, obviously your &lt;CODE&gt;local/input.conf&lt;/CODE&gt; will be wiped out.  This shouldn't be a problem though because splunkd will have to restart once (oh yeah, make sure you have &lt;CODE&gt;restartSplunkd=true&lt;/CODE&gt; in your deployment config).  So when &lt;CODE&gt;splunkd&lt;/CODE&gt; restarts with the newly deployed app, since &lt;CODE&gt;local/inputs.conf&lt;/CODE&gt; will be missing again, the file will be written and splunkd will be restarted again, but this time with your proper host entry...&lt;/P&gt;

&lt;P&gt;Wow!  That's ugly.  not as bad as it could be, definitely doable, but certainly not pretty.&lt;/P&gt;

&lt;P&gt;Do you have any python experience?  I could probably whip up a prototype if you want.  I know there have been times where I've wanted a feature like this before.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;UPDATE...   I went ahead and wrote a quick python script that should get the job done (I haven't actually tested it, so there could be issues.)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;""" hack_local_inputs.py:  Simple hack to write out a local/inputs.conf file
for this app with a hardcoded host value.
"""

import os
import socket
from subprocess import call

APP_NAME = "my_app_name"
SPLUNK_HOME = os.evniron["SPLUNK_HOME"]
HOSTNAME = socket.gethostname()

conf_file = os.path.join(SPLUNK_HOME, "etc", "apps", APP_NAME, "local", "inputs.conf")

if os.path.exists(conf_file):
    # This is for debugging this script
    print 'Nothing to do here, conf file already exists...  conf="%s"' % conf_file
else:
    stream = open(conf_file, "w")
    stream.write("[tcp:://localhost:9997]\n")
    stream.write("host = %s\n" % HOSTNAME)
    stream.write("disabled = 0\n")
    stream.close()
    # This is for debugging this script
    print 'Finished Hardcoding host hack!  splunk_app=%s new_host=%s conf="%s"' \
            % (APP_NAME, HOSTNAME, conf_file)
    splunk_exe = os.path.join(SPLUNK_HOME, "bin", "splunk")
    call([splunk_exe, "restart", "splunkd"])
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then, in your &lt;CODE&gt;default/inputs.conf&lt;/CODE&gt; add something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[script::$SPLUNK_HOME/etc/apps/my_app_name/bin/hack_local_inputs.py]
sourcetype = hack_local_inputs
interval = 31536000
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 15 May 2010 05:36:44 GMT</pubDate>
    <dc:creator>Lowell</dc:creator>
    <dc:date>2010-05-15T05:36:44Z</dc:date>
    <item>
      <title>Need deployment server to assign hostnames dynamically via inputs.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Need-deployment-server-to-assign-hostnames-dynamically-via/m-p/13574#M1224</link>
      <description>&lt;P&gt;I have a deployment server app with a single inputs.conf file.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[tcp://localhost:9997]
sourcetype = tcp-raw
index = pp-dev
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;A windows .NET application writes to this port with XML data. Splunk is indexing the data correctly, although the host is showing up as 127.0.0.1. I have this app deployed on about 50 hosts via the deployment server. Is there a way for the Splunk to show the hostname vs. 127.0.0.1 on the indexer?&lt;/P&gt;

&lt;P&gt;I am looking for a way to dynamically assign the name. If I have to hardcode the name, then this defeats the benefits of the deployment server.&lt;/P&gt;</description>
      <pubDate>Sat, 15 May 2010 05:04:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Need-deployment-server-to-assign-hostnames-dynamically-via/m-p/13574#M1224</guid>
      <dc:creator>Jaci</dc:creator>
      <dc:date>2010-05-15T05:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: Need deployment server to assign hostnames dynamically via inputs.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Need-deployment-server-to-assign-hostnames-dynamically-via/m-p/13575#M1225</link>
      <description>&lt;P&gt;Great question.  I doubt it's possible.  The deployment process seem to be pretty limited, IMHO.&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;WARNING:  UGLY UGLY HACK...&lt;/STRONG&gt;&lt;/EM&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I guess you could do a hack with an input script...&lt;/P&gt;

&lt;P&gt;Make sure your existing &lt;CODE&gt;inputs.conf&lt;/CODE&gt; is in the &lt;CODE&gt;default&lt;/CODE&gt; directory.  Then write a simple python script to check for the existence of the &lt;CODE&gt;local/inputs.conf&lt;/CODE&gt; in your app.  If it does not already exist, then your app should create it with the following template:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[tcp:://localhost:9997]
host = &amp;lt;host to be dynamically filled in by script&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;After the &lt;CODE&gt;local/inputs.conf&lt;/CODE&gt; file is written, it should issue a &lt;CODE&gt;splunk restart&lt;/CODE&gt; command so that the local entry takes effect.  When splunk startup up again, the script will run again, but this time since &lt;CODE&gt;local/inputs.conf&lt;/CODE&gt; exists, it will not make any changes or restart splunkd.  (You really don't want a recursive restart loop.  That would be bad, especially on 50 machines).&lt;/P&gt;

&lt;P&gt;You would probably want to schedule this script to run like once every 31536000 seconds (every year); so that it will only effectively run once a splunkd restart.&lt;/P&gt;

&lt;P&gt;When you redeploy your app, obviously your &lt;CODE&gt;local/input.conf&lt;/CODE&gt; will be wiped out.  This shouldn't be a problem though because splunkd will have to restart once (oh yeah, make sure you have &lt;CODE&gt;restartSplunkd=true&lt;/CODE&gt; in your deployment config).  So when &lt;CODE&gt;splunkd&lt;/CODE&gt; restarts with the newly deployed app, since &lt;CODE&gt;local/inputs.conf&lt;/CODE&gt; will be missing again, the file will be written and splunkd will be restarted again, but this time with your proper host entry...&lt;/P&gt;

&lt;P&gt;Wow!  That's ugly.  not as bad as it could be, definitely doable, but certainly not pretty.&lt;/P&gt;

&lt;P&gt;Do you have any python experience?  I could probably whip up a prototype if you want.  I know there have been times where I've wanted a feature like this before.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;UPDATE...   I went ahead and wrote a quick python script that should get the job done (I haven't actually tested it, so there could be issues.)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;""" hack_local_inputs.py:  Simple hack to write out a local/inputs.conf file
for this app with a hardcoded host value.
"""

import os
import socket
from subprocess import call

APP_NAME = "my_app_name"
SPLUNK_HOME = os.evniron["SPLUNK_HOME"]
HOSTNAME = socket.gethostname()

conf_file = os.path.join(SPLUNK_HOME, "etc", "apps", APP_NAME, "local", "inputs.conf")

if os.path.exists(conf_file):
    # This is for debugging this script
    print 'Nothing to do here, conf file already exists...  conf="%s"' % conf_file
else:
    stream = open(conf_file, "w")
    stream.write("[tcp:://localhost:9997]\n")
    stream.write("host = %s\n" % HOSTNAME)
    stream.write("disabled = 0\n")
    stream.close()
    # This is for debugging this script
    print 'Finished Hardcoding host hack!  splunk_app=%s new_host=%s conf="%s"' \
            % (APP_NAME, HOSTNAME, conf_file)
    splunk_exe = os.path.join(SPLUNK_HOME, "bin", "splunk")
    call([splunk_exe, "restart", "splunkd"])
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then, in your &lt;CODE&gt;default/inputs.conf&lt;/CODE&gt; add something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[script::$SPLUNK_HOME/etc/apps/my_app_name/bin/hack_local_inputs.py]
sourcetype = hack_local_inputs
interval = 31536000
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 15 May 2010 05:36:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Need-deployment-server-to-assign-hostnames-dynamically-via/m-p/13575#M1225</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-05-15T05:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: Need deployment server to assign hostnames dynamically via inputs.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Need-deployment-server-to-assign-hostnames-dynamically-via/m-p/13576#M1226</link>
      <description>&lt;P&gt;Thank you for the answer and the python script.&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2010 03:58:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Need-deployment-server-to-assign-hostnames-dynamically-via/m-p/13576#M1226</guid>
      <dc:creator>Jaci</dc:creator>
      <dc:date>2010-05-25T03:58:07Z</dc:date>
    </item>
  </channel>
</rss>

