<?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 do I get the 8 standard alert action script parameters AND custom parameters defined in savedsearches.conf.spec into a custom Python alert action script at the same time? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235079#M2983</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have always used Perl for this, but that should not matter.  The arguments are passed in @ARGV.  I Googled how to access that in Python and I found these two link pretty useful:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://www.pythonforbeginners.com/system/python-sys-argv"&gt;http://www.pythonforbeginners.com/system/python-sys-argv&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://stackoverflow.com/questions/4117530/sys-argv1-meaning-in-script"&gt;http://stackoverflow.com/questions/4117530/sys-argv1-meaning-in-script&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I hope that helps.&lt;/P&gt;</description>
    <pubDate>Tue, 23 Aug 2016 01:11:15 GMT</pubDate>
    <dc:creator>jdonn_splunk</dc:creator>
    <dc:date>2016-08-23T01:11:15Z</dc:date>
    <item>
      <title>How do I get the 8 standard alert action script parameters AND custom parameters defined in savedsearches.conf.spec into a custom Python alert action script at the same time?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235078#M2982</link>
      <description>&lt;P&gt;I've been able to successfully access the 8 command line parameters passed into a regular alert action shell script just fine. Now I've graduated to building a custom alert action patterned after the python-based JIRA example.I can successfully access custom alert action parameters that I've defined in savedsearches.conf.spec and populated from a custom .html fragment. But I can't seem to also access the original 8 parameters in the same custom Python alert action script.  How do I access both sets of parameters in the same script at the same time?    &lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 20:59:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235078#M2982</guid>
      <dc:creator>fsw2364</dc:creator>
      <dc:date>2016-08-22T20:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get the 8 standard alert action script parameters AND custom parameters defined in savedsearches.conf.spec into a custom Python alert action script at the same time?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235079#M2983</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have always used Perl for this, but that should not matter.  The arguments are passed in @ARGV.  I Googled how to access that in Python and I found these two link pretty useful:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://www.pythonforbeginners.com/system/python-sys-argv"&gt;http://www.pythonforbeginners.com/system/python-sys-argv&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://stackoverflow.com/questions/4117530/sys-argv1-meaning-in-script"&gt;http://stackoverflow.com/questions/4117530/sys-argv1-meaning-in-script&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I hope that helps.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2016 01:11:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235079#M2983</guid>
      <dc:creator>jdonn_splunk</dc:creator>
      <dc:date>2016-08-23T01:11:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get the 8 standard alert action script parameters AND custom parameters defined in savedsearches.conf.spec into a custom Python alert action script at the same time?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235080#M2984</link>
      <description>&lt;P&gt;Thank you.  When my python script is run, it sees len(sys.argv) = 2.  sys.argv[0]=full path to my script, and sys.argv[1]='--execute'   both of which I expect.  Per the Jira example, the script does a sys.stdin.read() to get the 'payload', which contains the custom parameters I've defined in savedsearches.conf.spec.  So perhaps a better question is 'how do I get the 8 standard parameters to be included in the payload'.  Here's the script I adapted from the Jira example.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
import json
import requests
from myapp_helpers import get_myapp_password
def send_message(payload):
    config = payload.get('configuration')
    EXECUTE_ASYNC_PATH = "/mypath"
    url = config.get('myapp_url')
    myapp_url = url + EXECUTE_ASYNC_PATH
    body = json.dumps({
        mybody
        })
    print &amp;gt;&amp;gt; sys.stderr, "*****about to POST to: %s" % url
    try:
        headers = {"Content-Type": "application/json"}
        result = requests.post(url=myapp_url, data=body, headers=headers)
        print &amp;gt;&amp;gt;sys.stderr, "INFO myapp app launch HTTP status= %s" % result
        print &amp;gt;&amp;gt;sys.stderr, "INFO myappapp launch server response: %s" % config
    except Exception, e:
        print &amp;gt;&amp;gt; sys.stderr, "ERROR Error sending message: %s" % e
        return False

if __name__ == "__main__":
    if len(sys.argv) &amp;gt; 1 and sys.argv[1] == "--execute":
        print &amp;gt;&amp;gt; sys.stderr, "****HERE IS THE len(sys.argv)****: %s" % len(sys.argv)
        print &amp;gt;&amp;gt; sys.stderr, "****HERE IS THE sys.argv****: %s" % sys.argv
        try:
           raw_payload = sys.stdin.read()
            payload = json.loads(raw_payload)
            send_message(payload)
        except Exception, e:
            print &amp;gt;&amp;gt; sys.stderr, "ERROR Unexpected error: %s" % e
            sys.exit(3)
    else:
        print &amp;gt;&amp;gt; sys.stderr, "FATAL Unsupported execution mode (expected --execute flag)"
        sys.exit(1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Appreciate the help!&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2016 07:04:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235080#M2984</guid>
      <dc:creator>fsw2364</dc:creator>
      <dc:date>2016-08-23T07:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get the 8 standard alert action script parameters AND custom parameters defined in savedsearches.conf.spec into a custom Python alert action script at the same time?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235081#M2985</link>
      <description>&lt;P&gt;Hey, sorry about the formatting mess...&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2016 07:05:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235081#M2985</guid>
      <dc:creator>fsw2364</dc:creator>
      <dc:date>2016-08-23T07:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get the 8 standard alert action script parameters AND custom parameters defined in savedsearches.conf.spec into a custom Python alert action script at the same time?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235082#M2986</link>
      <description>&lt;P&gt;I am out of my depth here for Python specifics, but I did find another example Python script - &lt;A href="https://github.com/georgestarcher/Splunk-Alert"&gt;https://github.com/georgestarcher/Splunk-Alert&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Perhaps the answer is in there?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2016 16:53:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235082#M2986</guid>
      <dc:creator>jdonn_splunk</dc:creator>
      <dc:date>2016-08-23T16:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get the 8 standard alert action script parameters AND custom parameters defined in savedsearches.conf.spec into a custom Python alert action script at the same time?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235083#M2987</link>
      <description>&lt;P&gt;I tried os.environ['SPLUNK_ARG_8'] as shown in the cited example, but no SPLUNK_ARGs were in the environment.   I did finally figure it out - explained the next post.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 10:47:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235083#M2987</guid>
      <dc:creator>fsw2364</dc:creator>
      <dc:date>2020-09-29T10:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get the 8 standard alert action script parameters AND custom parameters defined in savedsearches.conf.spec into a custom Python alert action script at the same time?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235084#M2988</link>
      <description>&lt;P&gt;It turns out the entire circumstances of the alert were in fact available in the payload passed to my custom Python script via sys.stdin.read().   The example from which I derived this script only showed getting the custom configuration parameters via payload.get('configuration').  I had no idea there was a so much more structure to that payload because I couldn't find any Splunk documentation on it.  I've included a snapshot of the full payload structure below.  Respectfully suggest that Splunk folks incorporate some good explanation of this structure into their otherwise very helpful documentation. &lt;/P&gt;

&lt;P&gt;Thanks very much for the pointers, jdonn.  Cheers!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"app":"",
"owner":"",
"results_file":"",
"results_link":"",
"server_host":"",
"server_uri":"",
"session_key":"",
"sid":"",
"search_name":"",
"configuration":{"myCustomParam1":"","myCustomParam2":"","myCustomParam3":"","myCustomParam4":"","myCustomParam5":""},
"result":{"_confstr":"",
    "_eventtype_color":"",
    "_indextime":"",
    "_kv":"",
    "_raw":"",
    "_serial":"",
    "_sourcetype":"",
    "_time":"",
    "date_hour":"",
    "date_mday":"",
    "date_minute":"",
    "date_month":"",
    "date_second":"",
    "date_wday":"",
    "date_year":"",
    "date_zone":"",
    "eventtype":"",
    "host":"",
    "index":"",
    "linecount":"",
    "punct":"",
    "source":"",
    "sourcetype":"",
    "splunk_server":"",
    "timeendpos":"",
    "timestartpos":""}
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Aug 2016 00:35:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235084#M2988</guid>
      <dc:creator>fsw2364</dc:creator>
      <dc:date>2016-08-31T00:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get the 8 standard alert action script parameters AND custom parameters defined in savedsearches.conf.spec into a custom Python alert action script at the same time?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235085#M2989</link>
      <description>&lt;P&gt;I have created a setup.xml file for my app and saving user name and password in alert_actions.conf. I am reading those parameters in Python script using similar code mentioned here. But the problem I am facing is the configuration passed to the python script does not gets the updated values of the service end points I used.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 09:40:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-get-the-8-standard-alert-action-script-parameters-AND/m-p/235085#M2989</guid>
      <dc:creator>santosh_sshanbh</dc:creator>
      <dc:date>2019-03-13T09:40:33Z</dc:date>
    </item>
  </channel>
</rss>

