<?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 does one create inline Python scripts for use in Splunk searches? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-does-one-create-inline-Python-scripts-for-use-in-Splunk/m-p/191595#M55164</link>
    <description>&lt;P&gt;After creating the python script, copy the script to $SPLUNK_HOME/etc/system/local directory.&lt;BR /&gt;
reate or edit existing authorize.conf&lt;BR /&gt;
and commands.conf.&lt;/P&gt;

&lt;P&gt;In commands.conf add:&lt;/P&gt;

&lt;P&gt;[youcommandname]&lt;BR /&gt;
FILENAME = yourscript.py&lt;/P&gt;

&lt;P&gt;In authorize.conf add:&lt;/P&gt;

&lt;P&gt;[capability::run_script_yourcustomcommand]&lt;/P&gt;

&lt;P&gt;[role_admin]&lt;BR /&gt;
run_script_yourcustomcommand = enabled&lt;/P&gt;

&lt;P&gt;Restart Splunk to test the command.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 07:04:07 GMT</pubDate>
    <dc:creator>jensonthottian</dc:creator>
    <dc:date>2020-09-29T07:04:07Z</dc:date>
    <item>
      <title>How does one create inline Python scripts for use in Splunk searches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-does-one-create-inline-Python-scripts-for-use-in-Splunk/m-p/191594#M55163</link>
      <description>&lt;P&gt;I am creating a simple script to take a hex(base 16) encoded field and convert it to readable text. For this endeavor, I have decided to use the built-in Python function for strings "&amp;lt;string&amp;gt;.decode("hex")." I would like to use this script in a  search "pipeline" running a field called packet through the statement and creating a new field of decoded text in the process.&lt;/P&gt;

&lt;P&gt;I have read the documentation for the API splunk.Intersplunk, however, I am not 100% understanding what exactly that I need to use to complete my script. Specifically, from the examples I have seen, I do not understand what the following lines do for me?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(isgetinfo, sys.argv) = splunk.Intersplunk.isGetInfo(sys.argv) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Additionally in the case of collecting results and creating the new field, is the following line needed?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;results = splunk.Intersplunk.readResults(None, None, False)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So you are tracking this is what I have thus far and I believe I am close.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
import splunk.Intersplunk
import string


#Program takes hex encoded string from a field and outputs value in search results at the gui
(isgetinfo, sys.argv) = splunk.Intersplunk.isGetInfo(sys.argv) #debug to see arguments I think Does it print these out?
results = splunk.Intersplunk.readResults(None, None, False) 

str=""

if len(sys.argv) &amp;lt; 2: # make sure there is an argument passed if not return error
    splunk.Intersplunk.parseError("[!] No arguments provided, please provide one argument.")
    sys.exit(1)

else: #grab the string from sys.argv and make it uppercase because I like uppercase hex strings :)
    str=sys.argv[1]
    str=str.upper()


if all(char in string.hexdigits for char in str): # make sure all characters are hex    
    decoded_string = str.decode("hex")
    splunk.Intersplunk.outputResults(decoded_string)


else: # return an error if its not a hex string
    splunk.Intersplunk.parseError("[!] String provided is not [A-F 0-9], please validate your inputs")
    sys.exit(1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also I am aware of the need for the STANZA setting below.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[decode_hex]
TYPE = python
FILENAME = decode_hex.py
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Aug 2015 13:27:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-does-one-create-inline-Python-scripts-for-use-in-Splunk/m-p/191594#M55163</guid>
      <dc:creator>dc5553</dc:creator>
      <dc:date>2015-08-24T13:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: How does one create inline Python scripts for use in Splunk searches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-does-one-create-inline-Python-scripts-for-use-in-Splunk/m-p/191595#M55164</link>
      <description>&lt;P&gt;After creating the python script, copy the script to $SPLUNK_HOME/etc/system/local directory.&lt;BR /&gt;
reate or edit existing authorize.conf&lt;BR /&gt;
and commands.conf.&lt;/P&gt;

&lt;P&gt;In commands.conf add:&lt;/P&gt;

&lt;P&gt;[youcommandname]&lt;BR /&gt;
FILENAME = yourscript.py&lt;/P&gt;

&lt;P&gt;In authorize.conf add:&lt;/P&gt;

&lt;P&gt;[capability::run_script_yourcustomcommand]&lt;/P&gt;

&lt;P&gt;[role_admin]&lt;BR /&gt;
run_script_yourcustomcommand = enabled&lt;/P&gt;

&lt;P&gt;Restart Splunk to test the command.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:04:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-does-one-create-inline-Python-scripts-for-use-in-Splunk/m-p/191595#M55164</guid>
      <dc:creator>jensonthottian</dc:creator>
      <dc:date>2020-09-29T07:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: How does one create inline Python scripts for use in Splunk searches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-does-one-create-inline-Python-scripts-for-use-in-Splunk/m-p/191596#M55165</link>
      <description>&lt;P&gt;This does not answer my question. Please read the full text of what i wrote. Explain how i pass values not stanza or administrative settings please&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2015 19:21:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-does-one-create-inline-Python-scripts-for-use-in-Splunk/m-p/191596#M55165</guid>
      <dc:creator>dc5553</dc:creator>
      <dc:date>2015-08-24T19:21:20Z</dc:date>
    </item>
  </channel>
</rss>

