<?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: How to connect to management port REST API from the Python Module which sits in controller directory? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-to-connect-to-management-port-REST-API-from-the-Python/m-p/257387#M3207</link>
    <description>&lt;P&gt;So to use the REST interface with python perhaps something like this.&lt;/P&gt;

&lt;P&gt;The below code is partially based on the &lt;A href="http://blogs.splunk.com/2011/08/02/splunk-rest-api-is-easy-to-use/"&gt;"Splunk REST API is easy to use"&lt;/A&gt; blog post , and also on some other documentation on the Splunk website:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import urllib
import urllib2
import ssl
import base64

#Send a request using a POST command to the required URL
#SSL checking is disabled due to use of the self-signed certificates
def sendrequest(values, server, url):
    ctx = ssl.create_default_context()
    ctx.check_hostname = False
    ctx.verify_mode = ssl.CERT_NONE
    data = urllib.urlencode(values)
    req = urllib2.Request(server + url, data)

    req.add_header("Authorization", "Basic %s" % base64string)
    response = urllib2.urlopen(req, context=ctx)
    the_page = response.read()


username = "username"
password = "&amp;lt;yourpassword&amp;gt;"
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
server = "https://localhost:8089/"
url = "/servicesNS/nobody/&amp;lt;app...&amp;gt;"

#Create the Oracle_SIEMUser_ChangePassword identity with username SIEM_USER
values = {"parameter1" : "value1",
}

#Actually run the HTTP request
sendrequest(values, server, url)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I normally determine the endpoint by hitting:&lt;BR /&gt;
&lt;A href="https://:8089/servicesNS/nobody" target="test_blank"&gt;https://:8089/servicesNS/nobody&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;And then determining where I should go, there is likely a better way to do it !&lt;/P&gt;</description>
    <pubDate>Wed, 30 Nov 2016 07:31:00 GMT</pubDate>
    <dc:creator>gjanders</dc:creator>
    <dc:date>2016-11-30T07:31:00Z</dc:date>
    <item>
      <title>How to connect to management port REST API from the Python Module which sits in controller directory?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-connect-to-management-port-REST-API-from-the-Python/m-p/257386#M3206</link>
      <description>&lt;P&gt;I am stuck at one point where i have to make a POST request from the UI to management port API. Now i cannot do that as i need session token and have to allow the Splunk server to accept any request from the IP, which is not an efficient way. So i want to make a REST Request to the custom URL, which in turn should make request the Splunk webserver. I have to do it with Python, but the only concern is how can i make the custom URL in the existing app and handle it , &lt;/P&gt;

&lt;P&gt;i am making the ajax request at /custom/app_name/module/function&lt;/P&gt;

&lt;P&gt;and in the controller i have a function defined, but still i am not able to get success.&lt;/P&gt;

&lt;P&gt;Any sort of help will be appreciated.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 11:35:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-connect-to-management-port-REST-API-from-the-Python/m-p/257386#M3206</guid>
      <dc:creator>kartik13</dc:creator>
      <dc:date>2016-11-29T11:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to connect to management port REST API from the Python Module which sits in controller directory?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-connect-to-management-port-REST-API-from-the-Python/m-p/257387#M3207</link>
      <description>&lt;P&gt;So to use the REST interface with python perhaps something like this.&lt;/P&gt;

&lt;P&gt;The below code is partially based on the &lt;A href="http://blogs.splunk.com/2011/08/02/splunk-rest-api-is-easy-to-use/"&gt;"Splunk REST API is easy to use"&lt;/A&gt; blog post , and also on some other documentation on the Splunk website:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import urllib
import urllib2
import ssl
import base64

#Send a request using a POST command to the required URL
#SSL checking is disabled due to use of the self-signed certificates
def sendrequest(values, server, url):
    ctx = ssl.create_default_context()
    ctx.check_hostname = False
    ctx.verify_mode = ssl.CERT_NONE
    data = urllib.urlencode(values)
    req = urllib2.Request(server + url, data)

    req.add_header("Authorization", "Basic %s" % base64string)
    response = urllib2.urlopen(req, context=ctx)
    the_page = response.read()


username = "username"
password = "&amp;lt;yourpassword&amp;gt;"
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
server = "https://localhost:8089/"
url = "/servicesNS/nobody/&amp;lt;app...&amp;gt;"

#Create the Oracle_SIEMUser_ChangePassword identity with username SIEM_USER
values = {"parameter1" : "value1",
}

#Actually run the HTTP request
sendrequest(values, server, url)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I normally determine the endpoint by hitting:&lt;BR /&gt;
&lt;A href="https://:8089/servicesNS/nobody" target="test_blank"&gt;https://:8089/servicesNS/nobody&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;And then determining where I should go, there is likely a better way to do it !&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 07:31:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-connect-to-management-port-REST-API-from-the-Python/m-p/257387#M3207</guid>
      <dc:creator>gjanders</dc:creator>
      <dc:date>2016-11-30T07:31:00Z</dc:date>
    </item>
  </channel>
</rss>

