<?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 to pass custom strings from a Splunk Alert into a python script as arguments in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/how-to-pass-custom-strings-from-a-Splunk-Alert-into-a-python/m-p/322664#M5727</link>
    <description>&lt;P&gt;hi all, we are using the python script below to pass a JSON structure from an Splunk alert.&lt;BR /&gt;
I need to pass 2 more custom strings but I am not sure how.&lt;BR /&gt;
Inside a Splunk alert I have the "Description" field which I could use to type my custom string but how do I pass that down to the script as an argument?&lt;BR /&gt;
Also, I would need to pass the 2nd custom string as another argument. How do I do that?&lt;BR /&gt;
Here is my python script:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import json
import requests
import sys
import pprint

url = 'http://10.10.10.10:8080/api/2.0/ICTAPIHandlers/JSON.php'

if len (sys.argv) != 9 :
    print("Usage: python ict.py count terms query name reason url tags path")
    sys.exit (1)

searchCount = sys.argv[1] # $1 - Number of events returned
searchTerms = sys.argv[2] # $2 - Search terms
searchQuery = sys.argv[3] # $3 - Fully qualified query string
searchName = sys.argv[4] # $4 - Name of saved search
searchReason = sys.argv[5] # $5 - Reason saved search triggered
searchURL = sys.argv[6] # $6 - URL/Permalink of saved search
searchTags = sys.argv[7] # $7 - Always empty as of 4.1
searchPath = sys.argv[8] # $8 - Path to raw saved results in Splunk instance (advanced)

data = {"searchCount":searchCount, "searchTerms":searchTerms, "searchQuery":searchQuery, "searchName":searchName, "searchReason":searchReason, "searchURL":searchURL,"searchTags":searchTags,"searchPath":searchPath }

data_json = json.dumps(data)
headers = {'Content-type': 'application/json'}
response = requests.post(url, data=data_json, headers=headers)
pprint.pprint(response.json())
pprint.pprint(response.json()['json'])
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
    <pubDate>Tue, 30 May 2017 20:02:07 GMT</pubDate>
    <dc:creator>maximusdm</dc:creator>
    <dc:date>2017-05-30T20:02:07Z</dc:date>
    <item>
      <title>how to pass custom strings from a Splunk Alert into a python script as arguments</title>
      <link>https://community.splunk.com/t5/Alerting/how-to-pass-custom-strings-from-a-Splunk-Alert-into-a-python/m-p/322664#M5727</link>
      <description>&lt;P&gt;hi all, we are using the python script below to pass a JSON structure from an Splunk alert.&lt;BR /&gt;
I need to pass 2 more custom strings but I am not sure how.&lt;BR /&gt;
Inside a Splunk alert I have the "Description" field which I could use to type my custom string but how do I pass that down to the script as an argument?&lt;BR /&gt;
Also, I would need to pass the 2nd custom string as another argument. How do I do that?&lt;BR /&gt;
Here is my python script:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import json
import requests
import sys
import pprint

url = 'http://10.10.10.10:8080/api/2.0/ICTAPIHandlers/JSON.php'

if len (sys.argv) != 9 :
    print("Usage: python ict.py count terms query name reason url tags path")
    sys.exit (1)

searchCount = sys.argv[1] # $1 - Number of events returned
searchTerms = sys.argv[2] # $2 - Search terms
searchQuery = sys.argv[3] # $3 - Fully qualified query string
searchName = sys.argv[4] # $4 - Name of saved search
searchReason = sys.argv[5] # $5 - Reason saved search triggered
searchURL = sys.argv[6] # $6 - URL/Permalink of saved search
searchTags = sys.argv[7] # $7 - Always empty as of 4.1
searchPath = sys.argv[8] # $8 - Path to raw saved results in Splunk instance (advanced)

data = {"searchCount":searchCount, "searchTerms":searchTerms, "searchQuery":searchQuery, "searchName":searchName, "searchReason":searchReason, "searchURL":searchURL,"searchTags":searchTags,"searchPath":searchPath }

data_json = json.dumps(data)
headers = {'Content-type': 'application/json'}
response = requests.post(url, data=data_json, headers=headers)
pprint.pprint(response.json())
pprint.pprint(response.json()['json'])
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2017 20:02:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/how-to-pass-custom-strings-from-a-Splunk-Alert-into-a-python/m-p/322664#M5727</guid>
      <dc:creator>maximusdm</dc:creator>
      <dc:date>2017-05-30T20:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to pass custom strings from a Splunk Alert into a python script as arguments</title>
      <link>https://community.splunk.com/t5/Alerting/how-to-pass-custom-strings-from-a-Splunk-Alert-into-a-python/m-p/322665#M5728</link>
      <description>&lt;P&gt;See my unaccepted answer here:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/41949/passing-search-results-to-external-python-script.html"&gt;https://answers.splunk.com/answers/41949/passing-search-results-to-external-python-script.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2017 21:47:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/how-to-pass-custom-strings-from-a-Splunk-Alert-into-a-python/m-p/322665#M5728</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-05-30T21:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to pass custom strings from a Splunk Alert into a python script as arguments</title>
      <link>https://community.splunk.com/t5/Alerting/how-to-pass-custom-strings-from-a-Splunk-Alert-into-a-python/m-p/322666#M5729</link>
      <description>&lt;P&gt;sorry but I didnt understand that post. Bear in mind that the 2 extra custom strings I need, I am trying to type them somewhere inside the alert and pass as a argument.&lt;BR /&gt;
If that is not possible I could pull that info from a static file but that would only appear in the results of the query. I am new to Splunk; it is still a black box for me. Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 31 May 2017 14:30:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/how-to-pass-custom-strings-from-a-Splunk-Alert-into-a-python/m-p/322666#M5729</guid>
      <dc:creator>maximusdm</dc:creator>
      <dc:date>2017-05-31T14:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to pass custom strings from a Splunk Alert into a python script as arguments</title>
      <link>https://community.splunk.com/t5/Alerting/how-to-pass-custom-strings-from-a-Splunk-Alert-into-a-python/m-p/322667#M5730</link>
      <description>&lt;P&gt;My answer does exactly that.  It is a complete walk-through.  Just give the code a try.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 15:33:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/how-to-pass-custom-strings-from-a-Splunk-Alert-into-a-python/m-p/322667#M5730</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-06-20T15:33:53Z</dc:date>
    </item>
  </channel>
</rss>

