<?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 to create a custom alert action Python script with parameters from search results? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-to-create-a-custom-alert-action-Python-script-with/m-p/643844#M11057</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I saw that you send 10 events to alert action but you just get one event in result. Is there any way that we can capture all 10 events?&lt;/P&gt;</description>
    <pubDate>Thu, 18 May 2023 23:15:46 GMT</pubDate>
    <dc:creator>vietlq414</dc:creator>
    <dc:date>2023-05-18T23:15:46Z</dc:date>
    <item>
      <title>How to create a custom alert action Python script with parameters from search results?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-create-a-custom-alert-action-Python-script-with/m-p/467048#M8420</link>
      <description>&lt;P&gt;Hi, I tried to create a custom alert action that operates a script, but I didn't understand how to send parameters from the search results to the script.&lt;/P&gt;
&lt;P&gt;For example: a script that checks Windows version for every IP address in the search results. How do I send the results to my script? What do I have to put in alert_actions.conf and in my script?&lt;/P&gt;
&lt;P&gt;Please try to explain instead of just sending links to Splunk Docs, I read these and still didn't find my answer.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 20:55:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-create-a-custom-alert-action-Python-script-with/m-p/467048#M8420</guid>
      <dc:creator>agentsofshield</dc:creator>
      <dc:date>2020-06-17T20:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a custom alert action Python script with parameters from search results?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-create-a-custom-alert-action-Python-script-with/m-p/467049#M8421</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;The results of your SPL search are passed to your custom alert action script from stdin as json format. &lt;BR /&gt;
This example will create a file testResult.txt within bin directory.. you can check out the json there..&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;from __future__ import print_function
from future import standard_library
standard_library.install_aliases()
import sys, json, urllib.request, urllib.error, urllib.parse

if __name__ == "__main__":
    if len(sys.argv) &amp;lt; 2 or sys.argv[1] != "--execute":
        print("FATAL Unsupported execution mode (expected --execute flag)", file=sys.stderr)
        sys.exit(1)
    else:
        #settings = json.loads(sys.stdin.read())
        result = sys.stdin.read()
        settings = json.loads(result)

        file = open("testResult.txt", "w")
        file.write(result)
        file.close()

        print("here we go", settings)
        sys.exit(0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;resulting json for search:&lt;BR /&gt;
   index=_internal | head 10 | rename host as testhost sourcetype as testsourcetype source as testsource | table testhost testsourcetype testsource&lt;/P&gt;

&lt;P&gt;{"app":"search"...","&lt;STRONG&gt;result":{"testhost":"hostname","testsourcetype":"splunkd_ui_access","testsource":"/Users/andreas/splunk/var/log/splunk/splunkd_ui_access.log"&lt;/STRONG&gt;}}&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:02:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-create-a-custom-alert-action-Python-script-with/m-p/467049#M8421</guid>
      <dc:creator>schose</dc:creator>
      <dc:date>2020-09-30T02:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a custom alert action Python script with parameters from search results?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-create-a-custom-alert-action-Python-script-with/m-p/643844#M11057</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I saw that you send 10 events to alert action but you just get one event in result. Is there any way that we can capture all 10 events?&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 23:15:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-create-a-custom-alert-action-Python-script-with/m-p/643844#M11057</guid>
      <dc:creator>vietlq414</dc:creator>
      <dc:date>2023-05-18T23:15:46Z</dc:date>
    </item>
  </channel>
</rss>

