<?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 pass alert results to custom alert action? in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/How-to-pass-alert-results-to-custom-alert-action/m-p/414983#M12577</link>
    <description>&lt;P&gt;Here is the portion of the script which I have in custom alert action and in alert_actions.conf, I have configured to retrieve payload in json format ( &lt;CODE&gt;payload_format = json&lt;/CODE&gt; )&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if len(sys.argv) &amp;gt; 1 and sys.argv[1] == "--execute":
    payload = json.loads(sys.stdin.read())
    result_file = payload['results_file']
    with gzip.open(result_file, 'rb') as f:
        reader = csv.reader(f)
        header_line = next(reader)
        data = list(reader)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 30 Sep 2020 01:31:31 GMT</pubDate>
    <dc:creator>harsmarvania57</dc:creator>
    <dc:date>2020-09-30T01:31:31Z</dc:date>
    <item>
      <title>How to pass alert results to custom alert action?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-pass-alert-results-to-custom-alert-action/m-p/414978#M12572</link>
      <description>&lt;P&gt;how do I pass my search output results to a custom alert action script(&lt;STRONG&gt;test.py&lt;/STRONG&gt;) which has some static parameters ? for ex. I have a statistics table which has two columns Hosts and Count.. I want to pass the results of these two columns to a static parameter say &lt;STRONG&gt;Description&lt;/STRONG&gt;.&lt;/P&gt;

&lt;P&gt;Ive come across SPLUNK_ARG_8(sys.argv[8])... tried this but it am getting an error " Alert script returned error code 1., search='sendalert test_dropdown results_file="/opt/splunk/var/run/splunk/dispatch/scheduler_&lt;EM&gt;admin&lt;/EM&gt;&lt;EM&gt;search&lt;/EM&gt;_RMD51340b9f59d2d65d1_at_1564127640_31/results.csv.gz "   .&lt;/P&gt;

&lt;P&gt;How do I use it in my script? Or is der any other way. Any suggestions? Below is part of my script&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def openany(p):
       if p.endswith(".gz"):
               return gzip.open(p)
       else:
               return open(p)

results_file = sys.argv[8]

for row in csv.DictReader(openany(results_file)):
        description = "Alert Triggered for " + row["component"] + " value is " + row["count"]


# TODO: Implement your alert action logic here
        url = "https://ensrqbrq8xubd.x.pipedream.net"

        payload = '''{\"Description\\\":\\\"''' + description + '''\\\"}'''.encode('utf8')

    headers = {
    'content-type': "application/json"
    }

        response = requests.request("POST", url, data = payload, headers=headers)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:31:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-pass-alert-results-to-custom-alert-action/m-p/414978#M12572</guid>
      <dc:creator>vinod94</dc:creator>
      <dc:date>2020-09-30T01:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass alert results to custom alert action?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-pass-alert-results-to-custom-alert-action/m-p/414979#M12573</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Have a look at documentation for Custom Alert Action &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.0/AdvancedDev/ModAlertsIntro"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.0/AdvancedDev/ModAlertsIntro&lt;/A&gt; for how to setup custom alert action.&lt;/P&gt;

&lt;P&gt;Here is sample script &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.0/AdvancedDev/ModAlertsBasicExample"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.0/AdvancedDev/ModAlertsBasicExample&lt;/A&gt; splunk has provided. When you look at the output, you can see &lt;CODE&gt;results_file&lt;/CODE&gt; in payload output. Read that file in your script and then you can use that output data in your script to do other magic as per your requirement.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2019 12:26:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-pass-alert-results-to-custom-alert-action/m-p/414979#M12573</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-07-26T12:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass alert results to custom alert action?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-pass-alert-results-to-custom-alert-action/m-p/414980#M12574</link>
      <description>&lt;P&gt;Hi @harsmarvania57 ,&lt;/P&gt;

&lt;P&gt;I've tried reading the file...but it throwing me an error..&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search='sendalert test_dropdown results_file="/opt/splunk/var/run/splunk/dispatch/scheduler_adminsearch_RMD51340b9f59d2d65d1_at_1564127640_31/results.csv.gz " 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jul 2019 07:52:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-pass-alert-results-to-custom-alert-action/m-p/414980#M12574</guid>
      <dc:creator>vinod94</dc:creator>
      <dc:date>2019-07-29T07:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass alert results to custom alert action?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-pass-alert-results-to-custom-alert-action/m-p/414981#M12575</link>
      <description>&lt;P&gt;You need to read that file in your python script, not using Splunk Query.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 07:58:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-pass-alert-results-to-custom-alert-action/m-p/414981#M12575</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-07-29T07:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass alert results to custom alert action?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-pass-alert-results-to-custom-alert-action/m-p/414982#M12576</link>
      <description>&lt;P&gt;I am reading with the script only&lt;/P&gt;

&lt;P&gt;here's the sample ..&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; def openany(p):
        if p.endswith(".gz"):
                return gzip.open(p)
        else:
                return open(p)
 results_file = sys.argv[8]

 for row in csv.DictReader(openany(results_file)):
         description = "Alert Triggered for " + row["component"] + " value is " + row["count"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;not sure if iam doing it in the right way!&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 08:03:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-pass-alert-results-to-custom-alert-action/m-p/414982#M12576</guid>
      <dc:creator>vinod94</dc:creator>
      <dc:date>2019-07-29T08:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass alert results to custom alert action?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-pass-alert-results-to-custom-alert-action/m-p/414983#M12577</link>
      <description>&lt;P&gt;Here is the portion of the script which I have in custom alert action and in alert_actions.conf, I have configured to retrieve payload in json format ( &lt;CODE&gt;payload_format = json&lt;/CODE&gt; )&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if len(sys.argv) &amp;gt; 1 and sys.argv[1] == "--execute":
    payload = json.loads(sys.stdin.read())
    result_file = payload['results_file']
    with gzip.open(result_file, 'rb') as f:
        reader = csv.reader(f)
        header_line = next(reader)
        data = list(reader)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:31:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-pass-alert-results-to-custom-alert-action/m-p/414983#M12577</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2020-09-30T01:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass alert results to custom alert action?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-pass-alert-results-to-custom-alert-action/m-p/607237#M14057</link>
      <description>&lt;P class="lia-align-left"&gt;Just a note: I had to use &lt;FONT color="#FF6600"&gt;gzip.open()&lt;/FONT&gt; with mode='rt' for text instead of binary&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 18:08:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-pass-alert-results-to-custom-alert-action/m-p/607237#M14057</guid>
      <dc:creator>kmarx</dc:creator>
      <dc:date>2022-07-27T18:08:44Z</dc:date>
    </item>
  </channel>
</rss>

