<?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: Custom Alert Action Arguments in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/Custom-Alert-Action-Arguments/m-p/390990#M6869</link>
    <description>&lt;P&gt;I found that Splunk has its own symlink that points to Python 2.7, so after changing the code to work with Python 2.7, the scripts works fine.&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jun 2019 21:38:28 GMT</pubDate>
    <dc:creator>sochsenbein</dc:creator>
    <dc:date>2019-06-12T21:38:28Z</dc:date>
    <item>
      <title>Custom Alert Action Arguments</title>
      <link>https://community.splunk.com/t5/Alerting/Custom-Alert-Action-Arguments/m-p/390987#M6866</link>
      <description>&lt;P&gt;I wrote a Python 3.7.3 script to interact with our paging system's web api. It takes three parameters from the alert's html UI: To, From, and Message. Inspecting the Job for the alert, I can see that the correct values are assigned to these parameters, however, we never receive a page. I believe that perhaps I am not reading them into the script correctly using sys.stdin.read() and parsing out the values. Any guidance would be appreciated.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Script&lt;/STRONG&gt;: (constants declarations not included)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if __name__ == "__main__":
    try:
        # Get Arguments
        payload = json.loads(sys.stdin.read())
        payload = payload['configuration']
        _to = payload['to']
        _from = payload['from']
        _message = payload['message']

        # Start a request session
        session = requests.Session()

        # Get Access Token
        auth = '%s:%s' % (CONSUMER_KEY, CONSUMER_SECRET)
        encodedCred = str(base64.b64encode(bytes(auth, 'ascii')))[2:-1]

        header = {'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Bearer ' + encodedCred}
        body = "grant_type=client_credentials"
        request = requests.Request('POST', TOKEN_URL, data=body, headers=header)
        prepped = request.prepare()
        response = session.send(prepped, verify=False)

        if response.status_code != 200:
            sys.exit(1)

        prettyJSON = json.loads(response.text)
        token = prettyJSON['access_token']

        # Send Page
        query_parameters = {'To': _to,
                            'From': _from,
                            'Message': _message
                            }
        header = {"Authorization": "Bearer  %s" % token, "Accept": "application/json"}
        request = requests.Request('POST', PAGE_URL, data=query_parameters, headers=header)
        prepped = request.prepare()
        response = session.send(prepped, verify=False)

        if response.status_code != 200:
            sys.exit(1)

    except Exception as ex:
        sys.exit(1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;alert_actions.conf&lt;/STRONG&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[ui]
is_visible = 1
label = Send a Page

[launcher]
author = sochsenbein
description = Send a page using the web api
version = 1.0

[install]
state = enabled
is_configured = 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;HTML&lt;/STRONG&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form class="form-horizontal form-complex"&amp;gt;

    &amp;lt;div class="control-group"&amp;gt;
        &amp;lt;label class="control-label" for="send_a_page_from"&amp;gt;From &amp;lt;/label&amp;gt;
        &amp;lt;div class="controls"&amp;gt;
            &amp;lt;textarea name="action.send_a_page.param.from" id="send_a_page_from" placeholder="// your username here"&amp;gt;&amp;lt;/textarea&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;div class="control-group"&amp;gt;
        &amp;lt;label class="control-label" for="send_a_page_to"&amp;gt;To &amp;lt;/label&amp;gt;
        &amp;lt;div class="controls"&amp;gt;
            &amp;lt;textarea name="action.send_a_page.param.to" id="send_a_page_to" placeholder="// comma separate usernames"&amp;gt;&amp;lt;/textarea&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;div class="control-group"&amp;gt;
        &amp;lt;label class="control-label" for="send_a_page_message"&amp;gt;Message &amp;lt;/label&amp;gt;
        &amp;lt;div class="controls"&amp;gt;
            &amp;lt;textarea name="action.send_a_page.param.message" id="send_a_page_message" placeholder="// remember to keep the message short..."&amp;gt;&amp;lt;/textarea&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

&amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Documentation/References&lt;/STRONG&gt;:&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.6/AdvancedDev/CustomAlertConvertScripted"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.6/AdvancedDev/CustomAlertConvertScripted&lt;/A&gt;&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.6/AdvancedDev/ModAlertsCreate"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.6/AdvancedDev/ModAlertsCreate&lt;/A&gt;&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/442603/how-do-i-get-the-8-standard-alert-action-script-pa-1.html"&gt;https://answers.splunk.com/answers/442603/how-do-i-get-the-8-standard-alert-action-script-pa-1.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 19:44:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Custom-Alert-Action-Arguments/m-p/390987#M6866</guid>
      <dc:creator>sochsenbein</dc:creator>
      <dc:date>2019-05-24T19:44:37Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Alert Action Arguments</title>
      <link>https://community.splunk.com/t5/Alerting/Custom-Alert-Action-Arguments/m-p/390988#M6867</link>
      <description>&lt;P&gt;Hi, &lt;BR /&gt;
I just worked on a script that takes arguments.  Here are the bits you need I believe:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;payload = json.loads(sys.stdin.read())&lt;/CODE&gt;&lt;BR /&gt;
 &lt;CODE&gt;config = payload['configuration']&lt;/CODE&gt;&lt;BR /&gt;
 &lt;CODE&gt;_to = config.get('to')&lt;/CODE&gt;&lt;BR /&gt;
 &lt;CODE&gt;_from = config.get('from')&lt;/CODE&gt;&lt;BR /&gt;
 &lt;CODE&gt;_message = config.get('message')&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Make sure you're importing the right Splunk libraries as well (not sure you need all these)&lt;BR /&gt;
 &lt;CODE&gt;import sys, os&lt;/CODE&gt;&lt;BR /&gt;
 &lt;CODE&gt;import splunk&lt;/CODE&gt;&lt;BR /&gt;
 &lt;CODE&gt;import json&lt;/CODE&gt;&lt;BR /&gt;
 &lt;CODE&gt;from urllib import urlencode&lt;/CODE&gt;&lt;BR /&gt;
 &lt;CODE&gt;import urllib2&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 19:56:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Custom-Alert-Action-Arguments/m-p/390988#M6867</guid>
      <dc:creator>jnudell_2</dc:creator>
      <dc:date>2019-05-24T19:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Alert Action Arguments</title>
      <link>https://community.splunk.com/t5/Alerting/Custom-Alert-Action-Arguments/m-p/390989#M6868</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/186296"&gt;@jnudell_2&lt;/a&gt; the script works when ran from the command line. The imports I use are sys, requests, json, and base64 (Python 3.7.3). I compared that to another script we have that does work and it's only using sys, json, and urllib2. I am using those functions you listed, as well, minus the "get", I believe that's just Python 2. In 3 you can do var[key]. Do you know if Splunk logs errors for failed scripts? I looked through splunkd_stderr.log and splunkd_stdout.log but nothing referencing the script.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:42:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Custom-Alert-Action-Arguments/m-p/390989#M6868</guid>
      <dc:creator>sochsenbein</dc:creator>
      <dc:date>2020-09-30T00:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Alert Action Arguments</title>
      <link>https://community.splunk.com/t5/Alerting/Custom-Alert-Action-Arguments/m-p/390990#M6869</link>
      <description>&lt;P&gt;I found that Splunk has its own symlink that points to Python 2.7, so after changing the code to work with Python 2.7, the scripts works fine.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 21:38:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Custom-Alert-Action-Arguments/m-p/390990#M6869</guid>
      <dc:creator>sochsenbein</dc:creator>
      <dc:date>2019-06-12T21:38:28Z</dc:date>
    </item>
  </channel>
</rss>

