<?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 Find splunkd Port from Scripted Input in Monitoring Splunk</title>
    <link>https://community.splunk.com/t5/Monitoring-Splunk/Find-splunkd-Port-from-Scripted-Input/m-p/165977#M1837</link>
    <description>&lt;P&gt;Similar to  &lt;A href="http://answers.splunk.com/answers/232122/find-splunkd-port-from-custom-search-command.html"&gt;http://answers.splunk.com/answers/232122/find-splunkd-port-from-custom-search-command.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I have a scripted input that runs a number of API searches. This worked in my lab environment where I had hardcoded port 8089, but failed when I switched to a production instance that had splunkd listening on a different port (error message &lt;CODE&gt;splunklib.binding.AuthenticationError: Request failed: Session is not logged in.&lt;/CODE&gt;). It was not immediately clear how to figure out the port dynamically.&lt;/P&gt;</description>
    <pubDate>Sun, 26 Apr 2015 23:25:08 GMT</pubDate>
    <dc:creator>David</dc:creator>
    <dc:date>2015-04-26T23:25:08Z</dc:date>
    <item>
      <title>Find splunkd Port from Scripted Input</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/Find-splunkd-Port-from-Scripted-Input/m-p/165977#M1837</link>
      <description>&lt;P&gt;Similar to  &lt;A href="http://answers.splunk.com/answers/232122/find-splunkd-port-from-custom-search-command.html"&gt;http://answers.splunk.com/answers/232122/find-splunkd-port-from-custom-search-command.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I have a scripted input that runs a number of API searches. This worked in my lab environment where I had hardcoded port 8089, but failed when I switched to a production instance that had splunkd listening on a different port (error message &lt;CODE&gt;splunklib.binding.AuthenticationError: Request failed: Session is not logged in.&lt;/CODE&gt;). It was not immediately clear how to figure out the port dynamically.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Apr 2015 23:25:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/Find-splunkd-Port-from-Scripted-Input/m-p/165977#M1837</guid>
      <dc:creator>David</dc:creator>
      <dc:date>2015-04-26T23:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Find splunkd Port from Scripted Input</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/Find-splunkd-Port-from-Scripted-Input/m-p/165978#M1838</link>
      <description>&lt;P&gt;I was able to leverage a similar solution to the one linked to above:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunklib.results as results
import splunklib.client as client
import sys
from datetime import datetime
sessionKey = ""

for line in sys.stdin:
  sessionKey = line

import splunk.entity, splunk.Intersplunk
settings = dict()
records = splunk.Intersplunk.readResults(settings = settings, has_header = True)
entity = splunk.entity.getEntity('/server','settings', namespace='[INSERT APP]', sessionKey=sessionKey, owner='-')
mydict = dict()
mydict = entity
myPort = mydict['mgmtHostPort']

service = client.Service(token=sessionKey, host="127.0.0.1", port=myPort, user="admin")
kwargs_normalsearch = {"exec_mode": "normal", "app": "[INSERT APP]"}

searchquery_normal = '[MySearch]'
job = service.jobs.create(searchquery_normal, **kwargs_normalsearch)

while True:
    job.refresh()
    stats = {"isDone": job["isDone"],
             "doneProgress": float(job["doneProgress"])*100}
    if stats["isDone"] == "1":
        break
    time.sleep(2)
for result in results.ResultsReader(job.results()):
    [...]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For completeness, my inputs.conf stanza is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[script://$SPLUNK_HOME/etc/apps/[MyAppName]/bin/CheckDataStats-search.py]
disabled = 0
interval = 600
source = [MySource]
sourcetype = [MySourcetype]
passAuth = admin
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Apr 2015 23:25:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/Find-splunkd-Port-from-Scripted-Input/m-p/165978#M1838</guid>
      <dc:creator>David</dc:creator>
      <dc:date>2015-04-26T23:25:20Z</dc:date>
    </item>
  </channel>
</rss>

