<?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 How do I alter props.conf via Python SDK? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-alter-props-conf-via-Python-SDK/m-p/387370#M69480</link>
    <description>&lt;P&gt;I can alter props.conf via the REST API using the following request:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl -k -u admin:password &lt;A href="https://localhost:8089/servicesNS/nobody/search/configs/conf-props" target="test_blank"&gt;https://localhost:8089/servicesNS/nobody/search/configs/conf-props&lt;/A&gt; -d name=source::/logs/mylog.log -d TRANSFORMS-null=setnull
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will add the following stanza to props.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[source::/logs/mylog.log]
TRANSFORMS-null = setnull
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, is there a way I can get the same results using the Python SDK?&lt;/P&gt;</description>
    <pubDate>Thu, 20 Sep 2018 21:03:33 GMT</pubDate>
    <dc:creator>tqi_raurora</dc:creator>
    <dc:date>2018-09-20T21:03:33Z</dc:date>
    <item>
      <title>How do I alter props.conf via Python SDK?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-alter-props-conf-via-Python-SDK/m-p/387370#M69480</link>
      <description>&lt;P&gt;I can alter props.conf via the REST API using the following request:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl -k -u admin:password &lt;A href="https://localhost:8089/servicesNS/nobody/search/configs/conf-props" target="test_blank"&gt;https://localhost:8089/servicesNS/nobody/search/configs/conf-props&lt;/A&gt; -d name=source::/logs/mylog.log -d TRANSFORMS-null=setnull
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will add the following stanza to props.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[source::/logs/mylog.log]
TRANSFORMS-null = setnull
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, is there a way I can get the same results using the Python SDK?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 21:03:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-alter-props-conf-via-Python-SDK/m-p/387370#M69480</guid>
      <dc:creator>tqi_raurora</dc:creator>
      <dc:date>2018-09-20T21:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I alter props.conf via Python SDK?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-alter-props-conf-via-Python-SDK/m-p/387371#M69481</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/133594"&gt;@tqi_raurora&lt;/a&gt;,&lt;/P&gt;

&lt;P&gt;You can use below python sdk script to create and modify props stanza. I am strongly recommending to test this script in Test environment first.&lt;/P&gt;

&lt;P&gt;Let's say script name is test_props_sdk.py&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
sys.path.append('splunk-sdk-python-1.6.4')
import splunklib.six as six
import urllib
from xml.etree import ElementTree
import getpass
import json

HOST = raw_input("Enter splunk server hostname/ip: ")
PORT = 8089
splunkUser = raw_input("Enter Splunk Admin Username: ")
splunkPassword = getpass.getpass("Enter Splunk Admin Password: ")
ce_param = raw_input("Create or Modify props: ")
if ce_param == 'Modify':
    stanza_name = raw_input("Enter props stanza name: ")
    stanza_encoded = urllib.quote_plus(stanza_name)
props_param = raw_input("Props parameter in json format: ")

connection = six.moves.http_client.HTTPSConnection(HOST, PORT)
body = urllib.urlencode({'username': splunkUser, 'password': splunkPassword})
headers = {'Content-Type': "application/x-www-form-urlencoded",
           'Host': HOST
          }

connection.request("POST", "/services/auth/login", body, headers)
response = connection.getresponse()
content = response.read()
connection.close()

session_key = ElementTree.XML(content).findtext("./sessionKey")

connection = six.moves.http_client.HTTPSConnection(HOST, PORT)
headers = {'Content-Type': "application/x-www-form-urlencoded",
           'Host': HOST,
           'Authorization': "Splunk %s" % session_key
          }

body =  urllib.urlencode(json.loads(props_param))

if ce_param == 'Create':
    connection.request("POST", "/servicesNS/nobody/search/configs/conf-props/" , body, headers)
elif ce_param == 'Modify':
    connection.request("POST", "/servicesNS/nobody/search/configs/conf-props/" + stanza_encoded, body, headers)
else:
    print("Please provide correct input")
    sys.exit(1)

response = connection.getresponse()
content = response.read()
connection.close()

print content
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you would like to create new props stanza, script will prompt for many parameters as below (Make sure to use double quotes while passing value in JSON format otherwise script will fail)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$ python test_props_sdk.py
Enter splunk server hostname/ip: SERVERNAME
Enter Splunk Admin Username: admin
Enter Splunk Admin Password:
Create or Modify props: Create
Props parameter in json format: {"name": "source::/log/mylog.log", "TRANSFORMS-null": "setnull"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And if you would like to modify existing props stanza, script will prompt for many parameters as below (Make sure to use double quotes while passing value in JSON format otherwise script will fail)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$ python test_props_sdk.py
Enter splunk server hostname/ip: SERVERNAME
Enter Splunk Admin Username: admin
Enter Splunk Admin Password:
Create or Modify props: Modify
Enter props stanza name: source::/log/mylog.log
Props parameter in json format: {"TRANSFORMS-null": "setnull123"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I hope this helps.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Harshil&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:18:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-alter-props-conf-via-Python-SDK/m-p/387371#M69481</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2020-09-29T21:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do I alter props.conf via Python SDK?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-alter-props-conf-via-Python-SDK/m-p/387372#M69482</link>
      <description>&lt;P&gt;Thank you, very appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jan 2019 14:24:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-alter-props-conf-via-Python-SDK/m-p/387372#M69482</guid>
      <dc:creator>jvardev</dc:creator>
      <dc:date>2019-01-23T14:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I alter props.conf via Python SDK?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-alter-props-conf-via-Python-SDK/m-p/387373#M69483</link>
      <description>&lt;P&gt;A simple way would be using the client module: &lt;A href="http://dev.splunk.com/python#client"&gt;http://dev.splunk.com/python#client&lt;/A&gt; &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;from splunklib.client import connect

print('connecting...')

service = connect(
    host='localhost',
    port='8089',
    username='admin',
    password='password'
)

print('connected!')

service.confs['props'].create(
    'source::/logs/mylog.log'
).submit(
    {'TRANSFORMS-null': 'setnull'}
)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Aug 2019 15:54:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-alter-props-conf-via-Python-SDK/m-p/387373#M69483</guid>
      <dc:creator>tqi_raurora</dc:creator>
      <dc:date>2019-08-08T15:54:33Z</dc:date>
    </item>
  </channel>
</rss>

