<?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: Connecting to splunk server using python script from Python IDLE shell but data is not displaying? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Connecting-to-splunk-server-using-python-script-from-Python-IDLE/m-p/404468#M71812</link>
    <description>&lt;P&gt;Hi @ramesh12345,&lt;/P&gt;

&lt;P&gt;I don't see in your code that you are calling &lt;CODE&gt;setServer&lt;/CODE&gt; function in your python script after defining it.&lt;/P&gt;

&lt;P&gt;Please find below script which is displaying correct data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
import getpass
sys.path.append('splunk-sdk-python-1.6.4')
import splunklib.client as client

def setServer(hostname, splunkuser, splunkpassword):
    HOST = hostname
    PORT = 8089
    USERNAME = splunkuser
    PASSWORD = splunkpassword
    service = client.connect(host=HOST,port=PORT,username=USERNAME,password=PASSWORD)

    for app in service.apps:
        print app.name

if __name__ == "__main__":
    hostname = raw_input("Enter Splunk Hostname/IP: ")
    splunkUser = raw_input("Enter Splunk Admin Username: ")
    splunkPassword = getpass.getpass("Enter Splunk Admin Password: ")
    setServer(hostname, splunkUser, splunkPassword)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When you run above script with Splunk Python SDK you need to enter 3 pramater value, so when you will run above script you will able to see below prompts (You can remove those prompts and pass hostname, username and password hardcoded or pass it from some other function based on your requirement.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$ python test.py
Enter Splunk Hostname/IP: localhost
Enter Splunk Admin Username: admin
Enter Splunk Admin Password:
alert_logevent
alert_webhook
appsbrowser
framework
gettingstarted
introspection_generator_addon
launcher
learned
legacy
sample_app
search
splunk_archiver
splunk_httpinput
splunk_instrumentation
splunk_monitoring_console
SplunkForwarder
SplunkLightForwarder
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I hope this helps.&lt;/P&gt;</description>
    <pubDate>Fri, 30 Nov 2018 10:32:39 GMT</pubDate>
    <dc:creator>harsmarvania57</dc:creator>
    <dc:date>2018-11-30T10:32:39Z</dc:date>
    <item>
      <title>Connecting to splunk server using python script from Python IDLE shell but data is not displaying?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Connecting-to-splunk-server-using-python-script-from-Python-IDLE/m-p/404467#M71811</link>
      <description>&lt;P&gt;import splunklib.client as client&lt;/P&gt;

&lt;P&gt;def setServer(HOST, PORT, USERNAME, PASSWORD):&lt;BR /&gt;
    HOST = "hostname"&lt;BR /&gt;
    PORT = 8089&lt;BR /&gt;
    USERNAME = "User"&lt;BR /&gt;
    PASSWORD = "Password"&lt;BR /&gt;
    service = client.connect(host=HOST,port=PORT,username=USERNAME,password=PASSWORD)&lt;BR /&gt;
    for app in service.apps:&lt;BR /&gt;
       print app.name&lt;/P&gt;

&lt;P&gt;After executing this script not showing any output?Please help how to resolve&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 12:51:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Connecting-to-splunk-server-using-python-script-from-Python-IDLE/m-p/404467#M71811</guid>
      <dc:creator>ramesh12345</dc:creator>
      <dc:date>2018-11-27T12:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: Connecting to splunk server using python script from Python IDLE shell but data is not displaying?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Connecting-to-splunk-server-using-python-script-from-Python-IDLE/m-p/404468#M71812</link>
      <description>&lt;P&gt;Hi @ramesh12345,&lt;/P&gt;

&lt;P&gt;I don't see in your code that you are calling &lt;CODE&gt;setServer&lt;/CODE&gt; function in your python script after defining it.&lt;/P&gt;

&lt;P&gt;Please find below script which is displaying correct data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
import getpass
sys.path.append('splunk-sdk-python-1.6.4')
import splunklib.client as client

def setServer(hostname, splunkuser, splunkpassword):
    HOST = hostname
    PORT = 8089
    USERNAME = splunkuser
    PASSWORD = splunkpassword
    service = client.connect(host=HOST,port=PORT,username=USERNAME,password=PASSWORD)

    for app in service.apps:
        print app.name

if __name__ == "__main__":
    hostname = raw_input("Enter Splunk Hostname/IP: ")
    splunkUser = raw_input("Enter Splunk Admin Username: ")
    splunkPassword = getpass.getpass("Enter Splunk Admin Password: ")
    setServer(hostname, splunkUser, splunkPassword)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When you run above script with Splunk Python SDK you need to enter 3 pramater value, so when you will run above script you will able to see below prompts (You can remove those prompts and pass hostname, username and password hardcoded or pass it from some other function based on your requirement.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$ python test.py
Enter Splunk Hostname/IP: localhost
Enter Splunk Admin Username: admin
Enter Splunk Admin Password:
alert_logevent
alert_webhook
appsbrowser
framework
gettingstarted
introspection_generator_addon
launcher
learned
legacy
sample_app
search
splunk_archiver
splunk_httpinput
splunk_instrumentation
splunk_monitoring_console
SplunkForwarder
SplunkLightForwarder
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I hope this helps.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 10:32:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Connecting-to-splunk-server-using-python-script-from-Python-IDLE/m-p/404468#M71812</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2018-11-30T10:32:39Z</dc:date>
    </item>
  </channel>
</rss>

